source: trunk/anuga_work/development/gareth/tests/ras_bridge/channel_floodplain1.py @ 9673

Last change on this file since 9673 was 9673, checked in by davies, 10 years ago

New pumping station function + tests, and a slight update to a bridge validation report

File size: 10.0 KB
Line 
1"""
2
3Water flowing down a channel with a floodplain and a bridge
4
5"""
6
7#------------------------------------------------------------------------------
8# Import necessary modules
9#------------------------------------------------------------------------------
10# Import standard shallow water domain and standard boundaries.
11import anuga
12import numpy
13from anuga.parallel.parallel_operator_factory import Inlet_operator, Boyd_box_operator, Internal_boundary_operator
14from anuga.parallel import distribute, myid, numprocs, finalize, barrier
15from anuga.structures.internal_boundary_functions import hecras_internal_boundary_function
16
17#------------------------------------------------------------------------------
18# Useful parameters for controlling this case
19#------------------------------------------------------------------------------
20
21floodplain_length = 1000.0 # Model domain length
22floodplain_width = 30.0 # Model domain width
23floodplain_slope = 1./200.
24chan_initial_depth = 0.25 # Initial depth of water in the channel
25chan_bankfull_depth = 1.0 # Bankfull depth of the channel
26chan_width = 10.0 # Bankfull width of the channel
27bankwidth = 0.01 # Width of the bank regions -- note that these protrude into the channel
28man_n=0.045 # Manning's n
29l0 = 5.000 # Length scale associated with triangle side length in channel (min_triangle area = 0.5*l0^2)
30
31bridge_us = 520.
32bridge_ds = 480.
33
34assert chan_width < floodplain_width, \
35        ' ERROR: Channel width is greater than floodplain width'
36
37assert bankwidth < chan_width/2., \
38        'ERROR: The bank width must be less than half the channel width'
39
40#------------------------------------------------------------------------------
41# Setup computational domain
42#------------------------------------------------------------------------------
43
44# Define boundary polygon -- in this case clockwise around the proposed boundary
45boundary_polygon = [ [0.,0.], 
46                     [0., floodplain_length], 
47                     [floodplain_width/2. - chan_width/2., floodplain_length], 
48                     [floodplain_width/2. + chan_width/2., floodplain_length], 
49                     [floodplain_width, floodplain_length], 
50                     [floodplain_width, 0.], 
51                     [floodplain_width/2. + chan_width/2., 0.], 
52                     [floodplain_width/2. - chan_width/2., 0.] 
53                     ]
54
55breakLines = { # Put breaklines around edge of channel [think it helps the numerics]
56               'n1': [[floodplain_width/2.0 - chan_width/2., floodplain_length, -999.+0.*floodplain_length*floodplain_slope],
57                      [floodplain_width/2.0 - chan_width/2., 0., -999.0]],
58               'n3': [[floodplain_width/2.0 + chan_width/2.0, floodplain_length-l0*0, -999.+0.*floodplain_slope*floodplain_length],
59                      [floodplain_width/2.0 + chan_width/2.0,     l0*0, -999.]],
60                # Put breaklines for bridge, so the edges are 'sharp'
61               'n4': [ [0., bridge_ds, -0.99], [floodplain_width, bridge_ds, -0.99]],
62               'n5': [ [0., bridge_us, -0.99], [floodplain_width, bridge_us, -0.99]],
63             }
64
65regionPtAreas=[ [0.01, 0.01, 0.5*l0*l0*4], # lower-left
66                [floodplain_width/2., 0.01, 0.5*l0*l0], # lower channel
67                [floodplain_width-0.01, 0.01, 0.5*l0*l0*4], # lower_right
68                [0.01, floodplain_length-0.01, 0.5*l0*l0*4], # upper_left
69                [floodplain_width/2., floodplain_length-0.01, 0.5*l0*l0], # Upper_channel
70                [floodplain_width-0.01, floodplain_length-0.01, 0.5*l0*l0*4], # upper_right
71                # Bridge
72                [floodplain_width/2., floodplain_length/2., 0.5*l0*l0], 
73                [floodplain_width-0.01, floodplain_length/2., 0.5*l0*l0], 
74                [floodplain_width+0.01, floodplain_length/2., 0.5*l0*l0], 
75
76              ]
77
78if(myid==0):
79    # Define domain with appropriate boundary conditions
80    anuga.create_mesh_from_regions(boundary_polygon, 
81                                   boundary_tags={'left': [0],
82                                                  'top1': [1],
83                                                  'chan_out': [2],
84                                                  'top2': [3],
85                                                  'right': [4],
86                                                  'bottom1': [5],
87                                                  'chan_in': [6],
88                                                  'bottom2': [7] },
89                                   maximum_triangle_area = 1.0e+06, #0.5*l0*l0,
90                                   minimum_triangle_angle = 28.0,
91                                   filename = 'channel_floodplain1.msh',
92                                   interior_regions = [ ],
93                                   breaklines=breakLines.values(),
94                                   regionPtArea=regionPtAreas,
95                                   verbose=True)
96    domain=anuga.create_domain_from_file('channel_floodplain1.msh')
97    domain.set_name('channel_floodplain1') # Output name
98    domain.set_flow_algorithm('DE1')
99else:
100    domain=None
101
102barrier()
103domain=distribute(domain)
104barrier()
105
106domain.set_store_vertices_uniquely(True)
107
108#------------------------------------------------------------------------------
109#
110# Setup initial conditions
111#
112#------------------------------------------------------------------------------
113
114# Function for topography
115def topography(x, y):
116    # Longitudinally sloping floodplain with channel in centre
117    elev1= -y*floodplain_slope - chan_bankfull_depth*\
118            (x>(floodplain_width/2. - chan_width/2.))*\
119            (x<(floodplain_width/2. + chan_width/2.)) 
120    # Add banks
121    if(bankwidth>0.0):
122        leftbnk = floodplain_width/2. - chan_width/2.
123        rightbnk = floodplain_width/2. + chan_width/2.
124        # Left bank
125        elev2 = elev1 + (chan_bankfull_depth \
126                - chan_bankfull_depth/bankwidth*(x - leftbnk))*\
127                (x>leftbnk)*(x < leftbnk + bankwidth)
128        # Right bank
129        elev2 = elev2 + (chan_bankfull_depth \
130                + chan_bankfull_depth/bankwidth*(x - rightbnk))*\
131                (x>rightbnk-bankwidth)*(x < rightbnk)
132   
133    if(bankwidth==0.0):
134        elev2 = elev1
135
136    # Add bridge
137    elev2=elev2*( (y<bridge_ds) + (y>bridge_us)) -1.0*( (y>=bridge_ds)*(y<=bridge_us))
138   
139    return elev2
140
141#Function for stage
142def stagetopo(x,y):
143    return -y*floodplain_slope -chan_bankfull_depth + chan_initial_depth
144
145domain.set_quantity('elevation', topography, location='centroids') # Use function for elevation
146domain.set_quantity('friction', man_n) # Constant friction
147domain.set_quantity('stage', stagetopo) # Use function for stage
148
149#domain.riverwallData.create_riverwalls(breakLines,
150#    default_riverwallPar = {'Qfactor': 0.65}, # Weir coefficient of 1.1 (0.65*default_value)
151#    output_dir='riverwall_text')
152
153# Define inlet operator
154flow_in_yval = 10.0
155if True:
156    line1 = [ [floodplain_width/2. - chan_width/2., flow_in_yval],\
157              [floodplain_width/2. + chan_width/2., flow_in_yval] \
158              ]
159    Qdata = [3., 3., 3., 3., 3., 3., 4., 5., 6., 6., 6., 6., 6., 7., 8., 9., 10., 10., 10., 10., 10.,\
160           11., 12., 13., 14., 15., 15., 15., 15., 16., 17., 18., 19., 20., 21., 23., 25.,\
161           30., 35.,40., 45., 50., 55., 60., 65., 70., 70., 70., 70.]+10*[70.]
162
163    dtQdata=300.
164    def Qin(t):
165        t_hour=t/dtQdata # Used for time index for Qdata
166        indL=numpy.floor(t_hour).astype(int)
167        indU=numpy.ceil(t_hour).astype(int)
168        w1=(t_hour-1.0*indL)
169        w2=(1.0*indU-t_hour)
170        Qout=Qdata[indL]*w2+Qdata[indU]*w1
171        return Qout
172   
173    Inlet_operator(domain, line1, Qin)
174   
175# Set up bridge
176bridge_in = [ [floodplain_width/2. - chan_width/2.+0.01, bridge_ds-0.01],\
177              [floodplain_width/2. + chan_width/2.-0.01, bridge_ds-0.01] ]
178bridge_out = [ [floodplain_width/2. - chan_width/2.+0.01, bridge_us+0.01],\
179               [floodplain_width/2. + chan_width/2.-0.01, bridge_us+0.01] ]
180
181hecras_discharge_function = hecras_internal_boundary_function(
182    'hecras_bridge_table_high_deck.csv',
183    allow_sign_reversal=True)
184
185bridge = Internal_boundary_operator(
186    domain,
187    hecras_discharge_function,
188    exchange_lines=[bridge_in, bridge_out],
189    enquiry_gap=0.01,
190    zero_outflow_momentum=False,
191    smoothing_timescale=30.0,
192    logging=True)
193   
194#------------------------------------------------------------------------------
195#
196# Setup boundary conditions
197#
198#------------------------------------------------------------------------------
199
200Br = anuga.Reflective_boundary(domain) # Solid reflective wall
201Bt = anuga.Transmissive_boundary(domain) # Transmissive boundary
202
203
204Bout_sub = anuga.Dirichlet_boundary( \
205        [-floodplain_length*floodplain_slope - chan_bankfull_depth + \
206        chan_initial_depth, 0., 0.]) #An outflow boundary for subcritical steady flow
207
208def outflow_stage_boundary(t):
209    return -floodplain_length*floodplain_slope \
210            + chan_initial_depth - chan_bankfull_depth
211
212Bout_tmss = anuga.shallow_water.boundaries.Transmissive_momentum_set_stage_boundary(domain, function = outflow_stage_boundary) 
213
214domain.set_boundary({'left': Br, 
215                     'right': Br, 
216                     'top1': Bout_tmss, 
217                     'top2': Bout_tmss, 
218                     'bottom1': Br, 
219                     'bottom2': Br, 
220                     'chan_out': Bout_tmss, 
221                     'chan_in': Br})
222
223
224#------------------------------------------------------------------------------
225#
226# Evolve system through time
227#
228#------------------------------------------------------------------------------
229
230barrier()
231
232for t in domain.evolve(yieldstep=10.0, finaltime=dtQdata*(len(Qdata)-2)):
233    if(myid==0):
234        print domain.timestepping_statistics()
235
236    vol = domain.report_water_volume_statistics()
237
238barrier()
239
240# Run sww merge
241if( (myid==0) & (numprocs>1)):
242    print 'Merging sww files: ', numprocs, myid
243    #os.chdir(project.output_run)
244    anuga.utilities.sww_merge.sww_merge_parallel('channel_floodplain1',np=numprocs,verbose=True,delete_old=True)
245
246barrier()
247finalize()
Note: See TracBrowser for help on using the repository browser.