Changeset 9019
- Timestamp:
- Nov 9, 2013, 6:13:58 PM (11 years ago)
- Location:
- trunk/anuga_core/source
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/file/sww.py
r9018 r9019 93 93 static_quantities = [] 94 94 dynamic_quantities = [] 95 static_c_quantities = [] 96 dynamic_c_quantities = [] 95 97 96 98 for q in domain.quantities_to_be_stored: … … 102 104 103 105 assert flag in [1,2] 104 if flag == 1: static_quantities.append(q) 105 if flag == 2: dynamic_quantities.append(q) 106 if flag == 1: 107 static_quantities.append(q) 108 if self.store_centroids: static_c_quantities.append(q+'_c') 109 110 if flag == 2: 111 dynamic_quantities.append(q) 112 if self.store_centroids: dynamic_c_quantities.append(q+'_c') 106 113 107 114 … … 112 119 'suitable for plotting' 113 120 114 self.writer = Write_sww(static_quantities, dynamic_quantities, store_centroids=self.store_centroids) 121 self.writer = Write_sww(static_quantities, 122 dynamic_quantities, 123 static_c_quantities, 124 dynamic_c_quantities) 125 115 126 self.writer.store_header(fid, 116 127 domain.starttime, … … 187 198 V.astype(num.float32), 188 199 points_georeference=\ 189 200 domain.geo_reference) 190 201 191 202 … … 202 213 static_quantities = {} 203 214 static_quantities_centroid = {} 215 204 216 for name in self.writer.static_quantities: 205 217 Q = domain.quantities[name] … … 207 219 precision=self.precision) 208 220 static_quantities[name] = A 209 210 if self.store_centroids: 211 static_quantities_centroid[name] = Q.centroid_values 221 222 #print domain.quantities 223 #print self.writer.static_c_quantities 224 225 for name in self.writer.static_c_quantities: 226 Q = domain.quantities[name[:-2]] # rip off _c from name 227 static_quantities_centroid[name] = Q.centroid_values 212 228 213 229 # Store static quantities 214 230 self.writer.store_static_quantities(fid, **static_quantities) 215 216 if self.store_centroids: 217 self.writer.store_static_quantities_centroid(fid, **static_quantities_centroid) 231 self.writer.store_static_quantities_centroid(fid, **static_quantities_centroid) 218 232 219 233 fid.close() … … 357 371 dynamic_quantities[name] = A 358 372 359 if self.store_centroids: 360 dynamic_quantities_centroid[name] = Q.centroid_values 373 for name in self.writer.dynamic_c_quantities: 374 Q = domain.quantities[name[:-2]] 375 dynamic_quantities_centroid[name] = Q.centroid_values 361 376 362 377 … … 493 508 """ 494 509 495 def __init__(self, static_quantities, dynamic_quantities, store_centroids=False): 496 """Initialise Write_sww with two list af quantity names: 510 def __init__(self, 511 static_quantities, 512 dynamic_quantities, 513 static_c_quantities = [], 514 dynamic_c_quantities = []): 515 516 """Initialise Write_sww with two (or 4) list af quantity names: 497 517 498 518 static_quantities (e.g. elevation or friction): … … 501 521 dynamic_quantities (e.g stage): 502 522 Stored every timestep in a 2D array with 503 dimensions number_of_points X number_of_timesteps 523 dimensions number_of_points X number_of_timesteps 524 525 static_c_quantities (e.g. elevation_c or friction_c): 526 Stored once at the beginning of the simulation in a 1D array 527 of length number_of_triangles 528 dynamic_c_quantities (e.g stage_c): 529 Stored every timestep in a 2D array with 530 dimensions number_of_triangles X number_of_timesteps 504 531 505 532 """ 506 533 self.static_quantities = static_quantities 507 534 self.dynamic_quantities = dynamic_quantities 508 self.store_centroids = store_centroids 535 self.static_c_quantities = static_c_quantities 536 self.dynamic_c_quantities = dynamic_c_quantities 537 538 self.store_centroids = False 539 if static_c_quantities or dynamic_c_quantities: 540 self.store_centroids = True 509 541 510 542 … … 606 638 ('numbers_in_range',)) 607 639 608 if self.store_centroids:609 outfile.createVariable(q + '_c', sww_precision,610 ('number_of_volumes',))611 612 640 # Initialise ranges with small and large sentinels. 613 641 # If this was in pure Python we could have used None sensibly … … 615 643 outfile.variables[q+Write_sww.RANGE][1] = -max_float # Max 616 644 617 618 self.write_dynamic_quantities(outfile, self.dynamic_quantities, times, \ 619 precis = sww_precision) 645 646 for q in self.static_c_quantities: 647 outfile.createVariable(q, sww_precision, 648 ('number_of_volumes',)) 649 650 651 self.write_dynamic_quantities(outfile, times, precis = sww_precision) 620 652 621 653 … … 734 766 735 767 736 def write_dynamic_quantities(self, outfile, quantities,737 times, precis = netcdf_float32, verbose = False):768 def write_dynamic_quantities(self, outfile, 769 times, precis = netcdf_float32, verbose = False): 738 770 """ 739 771 Write out given quantities to file. … … 741 773 742 774 743 for q in quantities:775 for q in self.dynamic_quantities: 744 776 outfile.createVariable(q, precis, ('number_of_timesteps', 745 777 'number_of_points')) 746 778 outfile.createVariable(q + Write_sts.RANGE, precis, 747 779 ('numbers_in_range',)) 748 780 749 if self.store_centroids:750 outfile.createVariable(q + '_c', precis,751 ('number_of_timesteps','number_of_volumes'))752 753 781 # Initialise ranges with small and large sentinels. 754 782 # If this was in pure Python we could have used None sensibly 755 783 outfile.variables[q+Write_sts.RANGE][0] = max_float # Min 756 784 outfile.variables[q+Write_sts.RANGE][1] = -max_float # Max 785 786 for q in self.dynamic_c_quantities: 787 outfile.createVariable(q, precis, ('number_of_timesteps', 788 'number_of_volumes')) 757 789 758 790 # Doing sts_precision instead of Float gives cast errors. … … 888 920 # This method will also write the ranges for each quantity, 889 921 # e.g. stage_range, xmomentum_range and ymomentum_range 890 for q in self.static_quantities: 922 923 #print outfile.variables.keys() 924 #print self.static_c_quantities 925 926 for q in self.static_c_quantities: 891 927 if not quant.has_key(q): 892 928 msg = 'Values for quantity %s was not specified in ' % q … … 897 933 898 934 x = q_values.astype(sww_precision) 899 outfile.variables[q +'_c'][:] = x935 outfile.variables[q][:] = x 900 936 901 937 … … 1014 1050 # This method will also write the ranges for each quantity, 1015 1051 # e.g. stage_range, xmomentum_range and ymomentum_range 1016 for q in self.dynamic_quantities: 1052 1053 #print 50*"=" 1054 #print quant 1055 #print self.dynamic_c_quantities 1056 1057 for q in self.dynamic_c_quantities: 1017 1058 if not quant.has_key(q): 1018 1059 msg = 'Values for quantity %s was not specified in ' % q … … 1023 1064 1024 1065 q_retyped = q_values.astype(sww_precision) 1025 outfile.variables[q +'_c'][slice_index] = q_retyped1066 outfile.variables[q][slice_index] = q_retyped 1026 1067 1027 1068 -
trunk/anuga_core/source/anuga/file/test_read_sww.py
r9018 r9019 177 177 178 178 # Clean up 179 os.remove(source)179 #os.remove(source) 180 180 181 181 def test_read_sww_with_centroids(self): … … 277 277 assert num.allclose(sww_file.get_bounds(), [0.0, length, 0.0, width]) 278 278 279 #print 50*"=" 280 #print sww_file.quantities.keys() 281 279 282 assert 'stage' in sww_file.quantities.keys() 280 283 assert 'friction' in sww_file.quantities.keys() -
trunk/anuga_core/source/anuga/utilities/plot_utils.py
r8950 r9019 1 """ Random utilities for reading sww file data and for plotting (in ipython, or2 1 """ Random utilities for reading sww file data and for plotting 2 (in ipython, or in scripts) 3 3 4 4 Functionality of note: 5 5 6 util.get_outputs -- read the data from a single sww file into a single object 7 8 util.combine_outputs -- read the data from a list of sww files into a single object 9 10 util.near_transect -- for finding the indices of points 'near' to a given 11 line, and assigning these points a coordinate along that line. 12 This is useful for plotting outputs which are 'almost' along a 13 transect (e.g. a channel cross-section) -- see example below 6 util.get_outputs -- read the data from a single sww file 7 into a single object 8 9 util.combine_outputs -- read the data from a list of sww 10 files into a single object 11 12 util.near_transect -- for finding the indices of points 13 'near' to a given line, and 14 assigning these points a 15 coordinate along that line. 16 17 This is useful for plotting outputs which are 'almost' along a 18 transect (e.g. a channel cross-section) -- see example below 14 19 15 20 util.sort_sww_filenames -- match sww filenames by a wildcard, and order 16 21 them according to their 'time'. This means that 17 they can be stuck together using 'combine_outputs' correctly 18 19 util.triangle_areas -- compute the areas of every triangle in a get_outputs object [ must be vertex-based] 20 21 util.water_volume -- compute the water volume at every time step in an sww file (needs both vertex and centroid value input). 22 they can be stuck together using 23 'combine_outputs' correctly 24 25 util.triangle_areas -- compute the areas of every triangle 26 in a get_outputs object [ must be vertex-based] 27 28 util.water_volume -- compute the water volume at every 29 time step in an sww file (needs both 30 vertex and centroid value input). 22 31 23 32 Here is an example ipython session which uses some of these functions: … … 417 426 ### 418 427 419 def water_volume(p, p2, per_unit_area=False, subset=None):428 def water_volume(p, p2, per_unit_area=False, subset=None): 420 429 # Compute the water volume from p(vertex values) and p2(centroid values) 421 430 -
trunk/anuga_core/source/anuga/utilities/sww_merge.py
r8809 r9019 240 240 out_d_quantities = {} 241 241 242 out_s_c_quantities = {} 243 out_d_c_quantities = {} 244 242 245 243 246 xllcorner = fid.xllcorner … … 262 265 g_points = num.zeros((number_of_global_nodes,2),num.float32) 263 266 267 #===================================== 268 # Deal with the vertex based variables 269 #===================================== 264 270 quantities = set(['elevation', 'friction', 'stage', 'xmomentum', 265 271 'ymomentum', 'xvelocity', 'yvelocity', 'height']) … … 272 278 273 279 for quantity in quantities: 274 # Test if elevationis static280 # Test if quantity is static 275 281 if n_steps == fid.variables[quantity].shape[0]: 276 282 dynamic_quantities.append(quantity) … … 285 291 out_d_quantities[quantity] = \ 286 292 num.zeros((n_steps,number_of_global_nodes),num.float32) 293 294 #======================================= 295 # Deal with the centroid based variables 296 #======================================= 297 quantities = set(['elevation_c', 'friction_c', 'stage_c', 'xmomentum_c', 298 'ymomentum_c', 'xvelocity_c', 'yvelocity_c', 'height_c']) 299 variables = set(fid.variables.keys()) 300 301 quantities = list(quantities & variables) 302 303 static_c_quantities = [] 304 dynamic_c_quantities = [] 305 306 for quantity in quantities: 307 # Test if quantity is static 308 if n_steps == fid.variables[quantity].shape[0]: 309 dynamic_c_quantities.append(quantity) 310 else: 311 static_c_quantities.append(quantity) 312 313 for quantity in static_c_quantities: 314 out_s_c_quantities[quantity] = num.zeros((number_of_global_triangles,),num.float32) 315 316 # Quantities are stored as a 2D array of timesteps x data. 317 for quantity in dynamic_c_quantities: 318 out_d_c_quantities[quantity] = \ 319 num.zeros((n_steps,number_of_global_triangles),num.float32) 287 320 288 321 description = 'merged:' + getattr(fid, 'description') … … 321 354 322 355 # Just pick out the full triangles 356 ftri_ids = num.where(tri_full_flag>0) 323 357 ftri_l2g = num.compress(tri_full_flag, tri_l2g) 324 358 … … 379 413 380 414 415 # Read in static c quantities 416 for quantity in static_c_quantities: 417 #out_s_quantities[quantity][node_l2g] = \ 418 # num.array(fid.variables[quantity],dtype=num.float32) 419 q = fid.variables[quantity] 420 out_s_c_quantities[quantity][ftri_l2g] = \ 421 num.array(q,dtype=num.float32)[ftri_ids] 422 423 424 #Collate all dynamic c quantities according to their timestep 425 for quantity in dynamic_c_quantities: 426 q = fid.variables[quantity] 427 #print q.shape 428 for i in range(n_steps): 429 out_d_c_quantities[quantity][i][ftri_l2g] = \ 430 num.array(q[i],dtype=num.float32)[ftri_ids] 381 431 382 432 … … 396 446 print 'Writing file ', output, ':' 397 447 fido = NetCDFFile(output, netcdf_mode_w) 398 sww = Write_sww(static_quantities, dynamic_quantities) 448 449 sww = Write_sww(static_quantities, dynamic_quantities, static_c_quantities, dynamic_c_quantities) 399 450 sww.store_header(fido, starttime, 400 451 number_of_global_triangles, … … 420 471 421 472 sww.store_static_quantities(fido, verbose=verbose, **out_s_quantities) 473 sww.store_static_quantities_centroid(fido, verbose=verbose, **out_s_c_quantities) 422 474 423 475 # Write out all the dynamic quantities for each timestep … … 439 491 if q_values_max > q_range[1]: 440 492 fido.variables[q + Write_sww.RANGE][1] = q_values_max 493 494 for q in dynamic_c_quantities: 495 q_values = out_d_c_quantities[q] 496 for i in range(n_steps): 497 fido.variables[q][i] = q_values[i] 441 498 442 499 -
trunk/anuga_core/source/anuga_parallel/run_parallel_sw_merimbula.py
r8950 r9019 43 43 #-------------------------------------------------------------------------- 44 44 45 mesh_filename = "merimbula_10785_1.tsh" ; x0 = 756000.0 ; x1 = 756500.0; yieldstep = 10; finaltime = 1045 #mesh_filename = "merimbula_10785_1.tsh" ; x0 = 756000.0 ; x1 = 756500.0; yieldstep = 10; finaltime = 10 46 46 #mesh_filename = "merimbula_17156.tsh" ; x0 = 756000.0 ; x1 = 756500.0; yieldstep = 50; finaltime = 500 47 47 #mesh_filename = "merimbula_43200_1.tsh" ; x0 = 756000.0 ; x1 = 756500.0; yieldstep = 50; finaltime = 500 48 #mesh_filename = "test-100.tsh" ; x0 = 200.0 ; x1 = 300.0; yieldstep = 1; finaltime = 5048 mesh_filename = "test-100.tsh" ; x0 = 200.0 ; x1 = 300.0; yieldstep = 1; finaltime = 10 49 49 #mesh_filename = "test-20.tsh" ; x0 = 250.0 ; x1 = 350.0; yieldstep = 1; finaltime = 50 50 50 … … 85 85 if myid == 0: 86 86 domain = create_domain_from_file(mesh_filename) 87 #domain.set_quantity('stage', Set_Stage(x0, x1, 1.0))88 domain.set_quantity('stage', 0.0)87 domain.set_quantity('stage', Set_Stage(x0, x1, 1.0)) 88 #domain.set_quantity('stage', 0.0) 89 89 #domain.set_datadir('.') 90 90 domain.set_name('merimbula_new') … … 113 113 114 114 domain.set_flow_algorithm('2_0') 115 115 domain.set_store_centroids() 116 116 117 117 #for p in range(numprocs):
Note: See TracChangeset
for help on using the changeset viewer.