Changeset 5755 for anuga_work/production/carnarvon/run_carnarvon.py
- Timestamp:
- Sep 9, 2008, 2:18:01 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_work/production/carnarvon/run_carnarvon.py
r5442 r5755 17 17 # Standard modules 18 18 from os import sep 19 import os 19 20 from os.path import dirname, basename 20 21 from os import mkdir, access, F_OK … … 30 31 from anuga.shallow_water import Field_boundary 31 32 from Numeric import allclose 32 from anuga.shallow_water.data_manager import export_grid 33 from anuga.shallow_water.data_manager import export_grid, create_sts_boundary 33 34 34 35 from anuga.pmesh.mesh_interface import create_mesh_from_regions 35 36 from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files,store_parameters 36 from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier37 #from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier 37 38 from anuga_parallel.parallel_abstraction import get_processor_name 38 39 from anuga.caching import myhash 39 40 from anuga.damage_modelling.inundation_damage import add_depth_and_momentum2csv, inundation_damage 40 41 from anuga.fit_interpolate.benchmark_least_squares import mem_usage 42 from anuga.utilities.polygon import read_polygon, plot_polygons, polygon_area, is_inside_polygon 43 from anuga.geospatial_data.geospatial_data import find_optimal_smoothing_parameter 41 44 42 45 # Application specific imports 43 46 import project # Definition of file names and polygons 47 numprocs = 1 48 myid = 0 44 49 45 50 def run_model(**kwargs): … … 62 67 store_parameters(**kwargs) 63 68 64 barrier()69 # barrier() 65 70 66 71 start_screen_catcher(kwargs['output_dir'], myid, numprocs) … … 68 73 print "Processor Name:",get_processor_name() 69 74 70 # filenames 71 # meshes_dir_name = project.meshes_dir_name+'.msh' 72 73 # creates copy of code in output dir 74 print 'min triangles', project.trigs_min, 75 print 'Note: This is generally about 20% less than the final amount' 76 75 76 #----------------------------------------------------------------------- 77 # Domain definitions 78 #----------------------------------------------------------------------- 79 80 # Read in boundary from ordered sts file 81 urs_bounding_polygon=create_sts_boundary(os.path.join(project.boundaries_dir,project.scenario_name)) 82 83 # Reading the landward defined points, this incorporates the original clipping 84 # polygon minus the 100m contour 85 landward_bounding_polygon = read_polygon(project.boundaries_dir+'landward_bounding_polygon.txt') 86 87 # Combine sts polyline with landward points 88 bounding_polygon = urs_bounding_polygon + landward_bounding_polygon 89 90 # counting segments 91 N = len(urs_bounding_polygon)-1 92 boundary_tags={'back': [N+1,N+2,N+3], 'side': [N,N+4],'ocean': range(N)} 93 94 77 95 #-------------------------------------------------------------------------- 78 96 # Create the triangular mesh based on overall clipping polygon with a … … 88 106 print 'start create mesh from regions' 89 107 90 create_mesh_from_regions( project.poly_all,91 boundary_tags= project.boundary_tags,108 create_mesh_from_regions(bounding_polygon, 109 boundary_tags=boundary_tags, 92 110 maximum_triangle_area=project.res_poly_all, 93 111 interior_regions=project.interior_regions, 94 112 filename=project.meshes_dir_name+'.msh', 95 use_cache= False,113 use_cache=True, 96 114 verbose=True) 97 barrier() 98 115 # barrier() 116 117 ## covariance_value,alpha = find_optimal_smoothing_parameter (data_file= kwargs['elevation_file'], 118 ## alpha_list=[0.001, 0.01, 0.1, 0.15, 0.2, 0.25, 0.3, 0.4, 0.5], 119 ## mesh_file = project.meshes_dir_name+'.msh') 120 ## print 'optimal alpha', covariance_value,alpha 99 121 100 122 #------------------------------------------------------------------------- … … 103 125 print 'Setup computational domain' 104 126 105 #domain = cache(Domain, (meshes_dir_name), {'use_cache':True, 'verbose':True}, verbose=True)106 #above don't work107 127 domain = Domain(project.meshes_dir_name+'.msh', use_cache=False, verbose=True) 108 128 print 'memory usage before del domain',mem_usage() … … 123 143 from polygon import Polygon_function 124 144 #following sets the stage/water to be offcoast only 125 IC = Polygon_function( [(project.poly_mainland, -1.0)], default = kwargs['tide'],145 IC = Polygon_function( [(project.poly_mainland, 0)], default = kwargs['tide'], 126 146 geo_reference = domain.geo_reference) 127 147 domain.set_quantity('stage', IC) 128 # domain.set_quantity('stage', kwargs['tide'])148 #domain.set_quantity('stage',kwargs['tide'] ) 129 149 domain.set_quantity('friction', kwargs['friction']) 130 150 131 print 'Start Set quantity',kwargs[' bathy_file']151 print 'Start Set quantity',kwargs['elevation_file'] 132 152 133 153 domain.set_quantity('elevation', 134 filename = kwargs[' bathy_file'],135 use_cache = True,154 filename = kwargs['elevation_file'], 155 use_cache = False, 136 156 verbose = True, 137 157 alpha = kwargs['alpha']) 138 158 print 'Finished Set quantity' 139 barrier() 140 159 #barrier() 160 161 ## #------------------------------------------------------ 162 ## # Create x,y,z file of mesh vertex!!! 163 ## #------------------------------------------------------ 164 ## coord = domain.get_vertex_coordinates() 165 ## depth = domain.get_quantity('elevation') 166 ## 167 ## # Write vertex coordinates to file 168 ## filename=project.vertex_filename 169 ## fid=open(filename,'w') 170 ## fid.write('x (m), y (m), z(m)\n') 171 ## for i in range(len(coord)): 172 ## pt=coord[i] 173 ## x=pt[0] 174 ## y=pt[1] 175 ## z=depth[i] 176 ## fid.write('%.6f,%.6f,%.6f\n' %(x, y, z)) 177 ## 141 178 142 179 #------------------------------------------------------ … … 157 194 domain.set_store_vertices_uniquely(False) 158 195 domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) 159 domain. set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK)196 domain.tight_slope_limiters = 1 160 197 print 'domain id', id(domain) 161 162 198 163 199 #------------------------------------------------------------------------- … … 166 202 print 'Available boundary tags', domain.get_boundary_tags() 167 203 print 'domain id', id(domain) 168 #print 'Reading Boundary file',project.boundaries_dir_namea + '.sww' 169 170 if project.source != 'other': 171 Bf = Field_boundary(kwargs['boundary_file'], 172 domain, time_thinning=kwargs['time_thinning'], mean_stage=kwargs['tide'], 173 use_cache=True, verbose=True) 174 175 kwargs['input_start_time']=domain.starttime 176 177 print 'finished reading boundary file' 204 205 boundary_urs_out=project.boundaries_dir_name 178 206 179 207 Br = Reflective_boundary(domain) 180 208 Bd = Dirichlet_boundary([kwargs['tide'],0,0]) 181 Bo = Dirichlet_boundary([kwargs['tide']+5.0,0,0]) 182 183 184 print'set_boundary' 209 210 print 'Available boundary tags', domain.get_boundary_tags() 211 Bf = Field_boundary(boundary_urs_out+'.sts', # Change from file_boundary 212 domain, mean_stage= project.tide, 213 time_thinning=1, 214 default_boundary=Bd, 215 use_cache=True, 216 verbose = True, 217 boundary_polygon=bounding_polygon) 185 218 186 219 domain.set_boundary({'back': Br, 187 220 'side': Bd, 188 221 'ocean': Bf}) 222 223 kwargs['input_start_time']=domain.starttime 224 189 225 print'finish set boundary' 190 226 … … 194 230 t0 = time.time() 195 231 196 for t in domain.evolve(yieldstep = 240, finaltime = kwargs['starttime']): 232 for t in domain.evolve(yieldstep = project.yieldstep, finaltime = kwargs['finaltime'] 233 ,skip_initial_step = False): 197 234 domain.write_time() 198 domain.write_boundary_statistics(tags = 'ocean') 199 200 if allclose(t, 120): 201 domain.set_boundary({'back': Br, 'side': Bd, 'ocean': Bo}) 202 203 if allclose(t, 720): 204 domain.set_boundary({'back': Br, 'side': Bd, 'ocean': Bd}) 205 206 # for t in domain.evolve(yieldstep = kwargs['yieldstep'], finaltime = kwargs['midtime'] 207 # ,skip_initial_step = True): 208 # domain.write_time() 209 # domain.write_boundary_statistics(tags = 'ocean') 210 # 211 # for t in domain.evolve(yieldstep = 240, finaltime = kwargs['finaltime'] 212 # ,skip_initial_step = True): 213 # domain.write_time() 214 # domain.write_boundary_statistics(tags = 'ocean') 235 domain.write_boundary_statistics(tags = 'ocean') 215 236 216 237 x, y = domain.get_maximum_inundation_location() … … 226 247 if myid==0: 227 248 store_parameters(**kwargs) 228 barrier249 # barrier 229 250 230 251 print 'memory usage before del domain1',mem_usage() 231 252 232 def export_model(**kwargs):233 #store_parameters(**kwargs)234 235 # print 'memory usage before del domain',mem_usage()236 #del domain237 print 'memory usage after del domain',mem_usage()238 239 swwfile = kwargs['output_dir']+kwargs['aa_scenario_name']240 print'swwfile',swwfile241 242 export_grid(swwfile, extra_name_out = 'town',243 quantities = ['speed','depth','elevation','stage'], # '(xmomentum**2 + ymomentum**2)**0.5' defaults to elevation244 #quantities = ['speed','depth'], # '(xmomentum**2 + ymomentum**2)**0.5' defaults to elevation245 timestep = None,246 reduction = max,247 cellsize = kwargs['export_cellsize'],248 NODATA_value = -9999,249 easting_min = project.eastingmin,250 easting_max = project.eastingmax,251 northing_min = project.northingmin,252 northing_max = project.northingmax,253 verbose = False,254 origin = None,255 datum = 'GDA94',256 format = 'asc')257 258 inundation_damage(swwfile+'.sww', project.buildings_filename,259 project.buildings_filename_out)260 253 261 254 #------------------------------------------------------------- … … 269 262 kwargs['starttime']=project.starttime 270 263 kwargs['yieldstep']=project.yieldstep 271 kwargs['midtime']=project.midtime272 264 kwargs['finaltime']=project.finaltime 273 265 274 266 kwargs['output_dir']=project.output_run_time_dir 275 kwargs['bathy_file']=project.combined_dir_name 276 # kwargs['bathy_file']=project.combined_small_dir_name + '.pts' 267 kwargs['elevation_file']=project.combined_dir_name+'.txt' 277 268 kwargs['boundary_file']=project.boundaries_in_dir_name + '.sww' 278 269 kwargs['file_name']=project.home+'detail.csv' … … 291 282 run_model(**kwargs) 292 283 293 if myid==0: 294 export_model(**kwargs) 295 barrier 284 #barrier
Note: See TracChangeset
for help on using the changeset viewer.