Changeset 9215
- Timestamp:
- Jun 23, 2014, 11:26:26 PM (11 years ago)
- Location:
- trunk/anuga_core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga_parallel/parallel_shallow_water.py
r8956 r9215 168 168 merge.sww_merge_parallel(global_name,self.numproc,verbose,delete_old) 169 169 170 # make sure all the merge completes on processor 0 before other 171 # processors complete (like when finalize is forgotten in main script) 172 173 pypar.barrier() 174 170 175 def write_time(self): 171 176 -
trunk/anuga_core/validation_tests/analytical_exact/trapezoidal_channel/numerical_channel_floodplain.py
r9155 r9215 10 10 import anuga 11 11 import numpy 12 from anuga .structures.inlet_operatorimport Inlet_operator13 from anuga import *12 from anuga import Inlet_operator 13 from anuga import myid, finalize, distribute 14 14 15 15 #------------------------------------------------------------------------------ 16 16 # Useful parameters for controlling this case 17 17 #------------------------------------------------------------------------------ 18 args = anuga.get_args() 19 verbose = args.verbose 20 alg = args.alg 21 22 18 23 floodplain_length = 800.0 # Model domain length 19 24 floodplain_width = 14.0 # Model domain width … … 54 59 [floodplain_width/2. + chan_width/2., +l0] 55 60 ] 56 57 # Define domain with appropriate boundary conditions58 domain =create_domain_from_regions( boundary_polygon,59 boundary_tags={'left': [0],60 'top1': [1],61 'chan_out': [2],62 'top2': [3],63 'right': [4],64 'bottom1': [5],65 'chan_in': [6],66 'bottom2': [7] },67 maximum_triangle_area = 0.5*l0*l0,68 minimum_triangle_angle = 28.0,69 mesh_filename = 'channel_floodplain.msh',70 interior_regions = [ ],71 #interior_regions = [\72 # [channel_polygon, 0.5*l0*l0] ],73 use_cache=False,74 verbose=True)75 76 domain.set_name('channel_floodplain') # Output name77 78 #------------------------------------------------------------------------------ 79 # Setup Algorithm, either using command line arguments 80 # or override manually yourself 81 #------------------------------------------------------------------------------82 from anuga.utilities.argparsing import parse_standard_args 83 alg, cfl = parse_standard_args() 84 domain.set_flow_algorithm(alg) 85 #domain.set_CFL(cfl) 86 87 #------------------------------------------------------------------------------ 88 # 89 # Setup initial conditions 90 # 91 #------------------------------------------------------------------------------ 92 93 # Function for topography 94 def elevation(x, y): 95 elev1= -y*floodplain_slope - chan_bankfull_depth*\96 (x>(floodplain_width/2. - chan_width/2.))*\97 (x<(floodplain_width/2. + chan_width/2.))98 # Add banks99 if(bankwidth>0.0):100 leftbnk = floodplain_width/2. - chan_width/2.101 rightbnk = floodplain_width/2. + chan_width/2.102 # Left bank103 elev2 = elev1 + (chan_bankfull_depth \ 104 - chan_bankfull_depth/bankwidth*(x - leftbnk))*\ 105 (x>leftbnk)*(x < leftbnk + bankwidth)106 # Right bank107 elev2 = elev2 + (chan_bankfull_depth \108 + chan_bankfull_depth/bankwidth*(x - rightbnk))*\ 109 (x>rightbnk-bankwidth)*(x < rightbnk)110 if(bankwidth==0.0):111 elev2 = elev1112 return elev2 113 114 115 #Function for stage116 def stage(x,y): 117 return -y*floodplain_slope -chan_bankfull_depth + chan_initial_depth 118 119 domain.set_quantity('elevation', elevation) # Use function for elevation 120 domain .set_quantity('friction', man_n) # Constant friction121 domain.set_quantity('stage', stage) # Use function for stage 122 61 if myid == 0: 62 # Define domain with appropriate boundary conditions 63 domain = anuga.create_domain_from_regions( boundary_polygon, 64 boundary_tags={'left': [0], 65 'top1': [1], 66 'chan_out': [2], 67 'top2': [3], 68 'right': [4], 69 'bottom1': [5], 70 'chan_in': [6], 71 'bottom2': [7] }, 72 maximum_triangle_area = 0.5*l0*l0, 73 minimum_triangle_angle = 28.0, 74 mesh_filename = 'channel_floodplain.msh', 75 interior_regions = [ ], 76 #interior_regions = [\ 77 # [channel_polygon, 0.5*l0*l0] ], 78 use_cache=False, 79 verbose=verbose) 80 81 domain.set_name('channel_floodplain') # Output name 82 domain.set_flow_algorithm(alg) 83 84 #------------------------------------------------------------------------------ 85 # Setup initial conditions 86 #------------------------------------------------------------------------------ 87 88 # Function for topography 89 def elevation(x, y): 90 elev1= -y*floodplain_slope - chan_bankfull_depth*\ 91 (x>(floodplain_width/2. - chan_width/2.))*\ 92 (x<(floodplain_width/2. + chan_width/2.)) 93 # Add banks 94 if(bankwidth>0.0): 95 leftbnk = floodplain_width/2. - chan_width/2. 96 rightbnk = floodplain_width/2. + chan_width/2. 97 # Left bank 98 elev2 = elev1 + (chan_bankfull_depth \ 99 - chan_bankfull_depth/bankwidth*(x - leftbnk))*\ 100 (x>leftbnk)*(x < leftbnk + bankwidth) 101 # Right bank 102 elev2 = elev2 + (chan_bankfull_depth \ 103 + chan_bankfull_depth/bankwidth*(x - rightbnk))*\ 104 (x>rightbnk-bankwidth)*(x < rightbnk) 105 if(bankwidth==0.0): 106 elev2 = elev1 107 return elev2 108 109 110 #Function for stage 111 def stage(x,y): 112 return -y*floodplain_slope -chan_bankfull_depth + chan_initial_depth 113 114 domain.set_quantity('elevation', elevation) # Use function for elevation 115 domain.set_quantity('friction', man_n) # Constant friction 116 domain.set_quantity('stage', stage) # Use function for stage 117 118 else: 119 120 domain = None 121 122 #===================================================== 123 # Parallel Domain 124 #===================================================== 125 domain = distribute(domain) 126 127 #--------------------------------------------------------------------- 123 128 # Define inlet operator 129 #--------------------------------------------------------------------- 124 130 flow_in_yval=0.0 125 if True: 126 line1 = [ [floodplain_width/2. - chan_width/2., flow_in_yval],\127 [floodplain_width/2. + chan_width/2., flow_in_yval] ] 128 131 line1 = [ [floodplain_width/2. - chan_width/2., flow_in_yval],\ 132 [floodplain_width/2. + chan_width/2., flow_in_yval] ] 133 134 Qin = 0.5*(floodplain_slope*(chan_width*chan_initial_depth)**2.*man_n**(-2.)\ 129 135 *chan_initial_depth**(4./3.) )**0.5 130 131 print 'Discharge in = ', Qin 132 133 #------------------------------------------------------------------------------ 134 # 136 Inlet_operator(domain, line1, Qin) 137 138 if myid == 0 and verbose : print 'Discharge in = ', Qin 139 140 #--------------------------------------------------------------------- 135 141 # Setup boundary conditions 136 # 137 #------------------------------------------------------------------------------ 142 #--------------------------------------------------------------------- 138 143 139 144 Br = anuga.Reflective_boundary(domain) # Solid reflective wall … … 158 163 159 164 # Set up file to record computations of discharge at several points. 160 discharge_outfile=open('discharge_outputs.txt', 'w')161 discharge_outfile.write('Time (s)'+","+ 'Discharge@10' + ","+ 'Discharge@700'+","+ 'Discharge@1000' + "\n")165 #discharge_outfile=open('discharge_outputs.txt', 'w') 166 #discharge_outfile.write('Time (s)'+","+ 'Discharge@10' + ","+ 'Discharge@700'+","+ 'Discharge@1000' + "\n") 162 167 163 168 … … 165 170 # Produce a documentation of parameters 166 171 #------------------------------------------------------------------------------ 167 parameter_file=open('parameters.tex', 'w') 168 parameter_file.write('\\begin{verbatim}\n') 169 from pprint import pprint 170 pprint(domain.get_algorithm_parameters(),parameter_file,indent=4) 171 parameter_file.write('\\end{verbatim}\n') 172 parameter_file.close() 172 if myid == 0: 173 parameter_file=open('parameters.tex', 'w') 174 parameter_file.write('\\begin{verbatim}\n') 175 from pprint import pprint 176 pprint(domain.get_algorithm_parameters(),parameter_file,indent=4) 177 parameter_file.write('\\end{verbatim}\n') 178 parameter_file.close() 173 179 174 180 #------------------------------------------------------------------------------ 175 181 # Evolve system through time 176 182 #------------------------------------------------------------------------------ 177 for t in domain.evolve(yieldstep=10.0, finaltime=1200.0): 178 print domain.timestepping_statistics() 179 xx=domain.quantities['ymomentum'].centroid_values 180 dd=(domain.quantities['stage'].centroid_values - domain.quantities['elevation'].centroid_values) 181 dd=dd*(dd>0.) 182 183 tmp = xx/(dd+1.0e-06)*(dd>0.0) 184 print tmp.max(), tmp.argmax(), tmp.min(), tmp.argmin() 185 186 # Compute flow through cross-section -- check that the inflow boundary condition is doing its job 187 # This also provides another useful steady-state check 188 if( numpy.floor(t/100.) == t/100. ): 189 print '#### COMPUTING FLOW THROUGH CROSS-SECTIONS########' 190 s0 = domain.get_flow_through_cross_section([[0., 10.0], [floodplain_width, 10.0]]) 191 s1 = domain.get_flow_through_cross_section([[0., floodplain_length-300.0], [floodplain_width, floodplain_length-300.0]]) 192 s2 = domain.get_flow_through_cross_section([[0., floodplain_length-1.0], [floodplain_width, floodplain_length-1.0]]) 183 for t in domain.evolve(yieldstep=10.0, finaltime=500.0): 184 if myid == 0 and verbose: print domain.timestepping_statistics() 185 186 ## xx=domain.quantities['ymomentum'].centroid_values 187 ## dd=(domain.quantities['stage'].centroid_values - domain.quantities['elevation'].centroid_values) 188 ## dd=dd*(dd>0.) 189 190 ## tmp = xx/(dd+1.0e-06)*(dd>0.0) 191 ## print tmp.max(), tmp.argmax(), tmp.min(), tmp.argmin() 192 193 ## # Compute flow through cross-section -- check that the inflow boundary condition is doing its job 194 ## # This also provides another useful steady-state check 195 ## if( numpy.floor(t/100.) == t/100. ): 196 ## print '#### COMPUTING FLOW THROUGH CROSS-SECTIONS########' 197 ## s0 = domain.get_flow_through_cross_section([[0., 10.0], [floodplain_width, 10.0]]) 198 ## s1 = domain.get_flow_through_cross_section([[0., floodplain_length-300.0], [floodplain_width, floodplain_length-300.0]]) 199 ## s2 = domain.get_flow_through_cross_section([[0., floodplain_length-1.0], [floodplain_width, floodplain_length-1.0]]) 193 200 194 print 'Cross sectional flows: ',s0, s1, s2 195 print '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' 196 discharge_outfile.write(str(t) + "," +str(s0) + ","+ str(s1) +"," + str(s2) + "\n") 197 discharge_outfile.close() 201 ## print 'Cross sectional flows: ',s0, s1, s2 202 ## print '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' 203 ## discharge_outfile.write(str(t) + "," +str(s0) + ","+ str(s1) +"," + str(s2) + "\n") 204 205 ## discharge_outfile.close() 206 207 domain.sww_merge(delete_old=True) 208 209 210 finalize()
Note: See TracChangeset
for help on using the changeset viewer.