Changeset 7342
- Timestamp:
- Aug 9, 2009, 1:20:42 AM (16 years ago)
- Location:
- anuga_core
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/documentation/user_manual/anuga_user_manual.tex
r7313 r7342 386 386 In addition, the following statement could be used to state that 387 387 quantities \code{stage}, \code{xmomentum} and \code{ymomentum} are 388 to be stored: 389 390 \begin{verbatim} 391 domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) 392 \end{verbatim} 393 394 However, this is not necessary, as the above quantities are always stored by default. 388 to be stored at every timestep and \code{elevation} only once at 389 the beginning of the simulation: 390 391 \begin{verbatim} 392 domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1}) 393 \end{verbatim} 394 395 However, this is not necessary, as the above is the default behaviour. 395 396 396 397 \subsection{Initial Conditions} … … 1959 1960 data from the SWW files with that of the model internally. 1960 1961 \end{methoddesc} 1962 1963 1964 \begin{methoddesc}{\emph{<domain>}.set_quantities_to_be_stored}{quantity_dictionary} 1965 Module: \module{shallow_water.shallow_water_domain} 1966 1967 Selects quantities that is to be stored in the sww files. 1968 The argument can be None, in which case nothing is stored. 1969 1970 Otherwise, the argument must be a dictionary where the keys are names of quantities 1971 already defined within ANUGA and the values are either 1 or 2. If the value is 1, the quantity 1972 will be stored once at the beginning of the simulation, if the value is 2 it will be stored 1973 at each timestep. The ANUGA default is equivalent to the call 1974 \begin{verbatim} 1975 domain.set_quantities_to_be_stored({'elevation': 1, 1976 'stage': 2, 1977 'xmomentum': 2, 1978 'ymomentum': 2}) 1979 \end{verbatim} 1980 \end{methoddesc} 1981 1961 1982 1962 1983 % Structural methods -
anuga_core/source/anuga/abstract_2d_finite_volumes/domain.py
r7317 r7342 162 162 self.quantities = {} 163 163 164 # FIXME: remove later - maybe OK, though....165 164 for name in self.conserved_quantities: 166 165 self.quantities[name] = Quantity(self) -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_util.py
r7340 r7342 141 141 domain1.set_datadir('.') 142 142 domain1.set_name('spatio_temporal_boundary_source_%d' %(id(self))) 143 domain1.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum']144 143 145 144 #Bed-slope, friction and IC at vertices (and interpolated elsewhere) … … 359 358 domain1.set_datadir('.') 360 359 domain1.set_name('spatio_temporal_boundary_source_%d' %(id(self))) 361 domain1.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum']362 360 363 361 #Bed-slope, friction and IC at vertices (and interpolated elsewhere) … … 820 818 #Store and advance time 821 819 domain.time = t 822 domain.store_timestep( domain.conserved_quantities)820 domain.store_timestep() 823 821 t += dt 824 822 … … 1618 1616 sww = SWW_file(domain) 1619 1617 sww.store_connectivity() 1620 sww.store_timestep( ['stage', 'xmomentum', 'ymomentum','elevation'])1618 sww.store_timestep() 1621 1619 domain.set_quantity('stage', 10.0) # This is automatically limited 1622 1620 # so it will not be less than the elevation 1623 1621 domain.time = 2. 1624 sww.store_timestep( ['stage','elevation', 'xmomentum', 'ymomentum'])1622 sww.store_timestep() 1625 1623 1626 1624 # test the function … … 1738 1736 sww = SWW_file(domain) 1739 1737 sww.store_connectivity() 1740 sww.store_timestep( ['stage', 'xmomentum', 'ymomentum'])1738 sww.store_timestep() 1741 1739 domain.set_quantity('stage', 10.0) # This is automatically limited 1742 1740 # so it will not be less than the elevation 1743 1741 domain.time = 2. 1744 sww.store_timestep( ['stage', 'xmomentum', 'ymomentum'])1742 sww.store_timestep() 1745 1743 1746 1744 # test the function … … 1857 1855 sww = SWW_file(domain) 1858 1856 sww.store_connectivity() 1859 sww.store_timestep( ['stage', 'xmomentum', 'ymomentum','elevation'])1857 sww.store_timestep() 1860 1858 domain.set_quantity('stage', 10.0) # This is automatically limited 1861 1859 # so it will not be less than the elevation 1862 1860 domain.time = 2. 1863 sww.store_timestep( ['stage','elevation', 'xmomentum', 'ymomentum'])1861 sww.store_timestep() 1864 1862 1865 1863 # test the function -
anuga_core/source/anuga/damage_modelling/test_inundation_damage.py
r7340 r7342 114 114 sww = SWW_file(self.domain) 115 115 sww.store_connectivity() 116 sww.store_timestep( ['stage', 'xmomentum', 'ymomentum'])116 sww.store_timestep() 117 117 self.domain.time = 2. 118 sww.store_timestep( ['stage', 'xmomentum', 'ymomentum'])118 sww.store_timestep() 119 119 self.sww = sww # so it can be deleted 120 120 … … 184 184 sww = SWW_file(domain) 185 185 sww.store_connectivity() 186 sww.store_timestep( ['stage', 'xmomentum', 'ymomentum'])186 sww.store_timestep() 187 187 domain.time = 2. 188 sww.store_timestep( ['stage', 'xmomentum', 'ymomentum'])188 sww.store_timestep() 189 189 self.swwII = sww # so it can be deleted 190 190 … … 284 284 sww = SWW_file(domain) 285 285 sww.store_connectivity() 286 sww.store_timestep( ['stage', 'xmomentum', 'ymomentum'])286 sww.store_timestep() 287 287 domain.set_quantity('stage', -0.3) 288 288 domain.time = 2. 289 sww.store_timestep( ['stage', 'xmomentum', 'ymomentum'])289 sww.store_timestep() 290 290 291 291 #Create a csv file … … 356 356 sww = SWW_file(domain) 357 357 sww.store_connectivity() 358 sww.store_timestep( ['stage', 'xmomentum', 'ymomentum'])358 sww.store_timestep() 359 359 domain.set_quantity('stage', -0.3) 360 360 domain.time = 2. 361 sww.store_timestep( ['stage', 'xmomentum', 'ymomentum'])361 sww.store_timestep() 362 362 363 363 #Create a csv file -
anuga_core/source/anuga/fit_interpolate/test_interpolate.py
r7340 r7342 1715 1715 sww = SWW_file(domain) 1716 1716 sww.store_connectivity() 1717 sww.store_timestep( ['stage', 'xmomentum', 'ymomentum'])1717 sww.store_timestep() 1718 1718 domain.set_quantity('stage', 10.0) # This is automatically limited 1719 1719 # So it will not be less than the elevation 1720 1720 domain.time = 2. 1721 sww.store_timestep( ['stage', 'xmomentum', 'ymomentum'])1721 sww.store_timestep() 1722 1722 1723 1723 # Test the function -
anuga_core/source/anuga/shallow_water/data_manager.py
r7340 r7342 347 347 # @param recursion ?? 348 348 # @note Prepare the underlying data file if mode starts with 'w'. 349 def __init__(self, domain, mode=netcdf_mode_w, max_size=2000000000, recursion=False): 349 def __init__(self, domain, 350 mode=netcdf_mode_w, max_size=2000000000, recursion=False): 350 351 from Scientific.IO.NetCDF import NetCDFFile 351 352 … … 362 363 self.minimum_storable_height = default_minimum_storable_height 363 364 364 # call owningconstructor365 # Call parent constructor 365 366 Data_format.__init__(self, domain, 'sww', mode) 366 367 368 # Get static and dynamic quantities from domain 369 static_quantities = [] 370 dynamic_quantities = [] 371 372 for q in domain.quantities_to_be_stored: 373 flag = domain.quantities_to_be_stored[q] 374 375 msg = 'Quantity %s is requested to be stored ' % q 376 msg += 'but it does not exist in domain.quantities' 377 assert q in domain.quantities, msg 378 379 assert flag in [1,2] 380 if flag == 1: static_quantities.append(q) 381 if flag == 2: dynamic_quantities.append(q) 382 383 367 384 # NetCDF file definition 368 385 fid = NetCDFFile(self.filename, mode) … … 370 387 description = 'Output from anuga.abstract_2d_finite_volumes ' \ 371 388 'suitable for plotting' 372 self.writer = Write_sww(['elevation'], domain.conserved_quantities) 389 390 self.writer = Write_sww(static_quantities, dynamic_quantities) 373 391 self.writer.store_header(fid, 374 392 domain.starttime, … … 421 439 # @brief Store connectivity data into the underlying data file. 422 440 def store_connectivity(self): 423 """Specialisation of store_connectivity for net CDF format 424 425 Writes x,y,z coordinates of triangles constituting 426 the bed elevation. 441 """Store information about nodes, triangles and static quantities 442 443 Writes x,y coordinates of triangles and their connectivity. 444 445 Store also any quantity that has been identified as static. 427 446 """ 428 447 448 # FIXME: Change name to reflect the fact thta this function 449 # stores both connectivity (triangulation) and static quantities 450 429 451 from Scientific.IO.NetCDF import NetCDFFile 430 452 … … 434 456 fid = NetCDFFile(self.filename, netcdf_mode_a) 435 457 436 # Get X, Y and bed elevation Z437 Q = domain.quantities ['elevation']438 X,Y, Z,V = Q.get_vertex_values(xy=True, precision=self.precision)458 # Get X, Y from one (any) of the quantities 459 Q = domain.quantities.values()[0] 460 X,Y,_,V = Q.get_vertex_values(xy=True, precision=self.precision) 439 461 440 462 # store the connectivity data 441 points = num.concatenate( (X[:,num.newaxis],Y[:,num.newaxis]), axis=1)463 points = num.concatenate((X[:,num.newaxis],Y[:,num.newaxis]), axis=1) 442 464 self.writer.store_triangulation(fid, 443 465 points, 444 466 V.astype(num.float32), 445 Z,446 467 points_georeference=\ 447 468 domain.geo_reference) 448 469 470 471 # Get names of static quantities 472 static_quantities = {} 473 for name in self.writer.static_quantities: 474 Q = domain.quantities[name] 475 A, _ = Q.get_vertex_values(xy=False, 476 precision=self.precision) 477 static_quantities[name] = A 478 479 # Store static quantities 480 self.writer.store_static_quantities(fid, **static_quantities) 481 449 482 fid.close() 450 483 … … 452 485 # @brief Store time and time dependent quantities 453 486 # to the underlying data file. 454 def store_timestep(self , names=None):487 def store_timestep(self): 455 488 """Store time and time dependent quantities 456 489 """ … … 460 493 from time import sleep 461 494 from os import stat 462 463 # Get names of quantities to be stored every time step464 names = self.writer.dynamic_quantities465 495 466 496 # Get NetCDF … … 469 499 while not file_open and retries < 10: 470 500 try: 471 fid = NetCDFFile(self.filename, netcdf_mode_a) # Open existing file 501 # Open existing file 502 fid = NetCDFFile(self.filename, netcdf_mode_a) 472 503 except IOError: 473 504 # This could happen if someone was reading the file. … … 497 528 # other modules (I think). 498 529 499 # Write a filename addon that won't break swollens reader530 # Write a filename addon that won't break the anuga viewers 500 531 # (10.sww is bad) 501 532 filename_ext = '_time_%s' % self.domain.time … … 508 539 self.domain.set_name(old_domain_filename + filename_ext) 509 540 510 # Change the domain starttime to the current time541 # Temporarily change the domain starttime to the current time 511 542 old_domain_starttime = self.domain.starttime 512 self.domain.starttime = self.domain. time543 self.domain.starttime = self.domain.get_time() 513 544 514 545 # Build a new data_structure. 515 546 next_data_structure = SWW_file(self.domain, mode=self.mode, 516 517 547 max_size=self.max_size, 548 recursion=self.recursion+1) 518 549 if not self.recursion: 519 550 log.critical(' file_size = %s' % file_size) … … 521 552 % next_data_structure.filename) 522 553 523 # set up the new data_structure554 # Set up the new data_structure 524 555 self.domain.writer = next_data_structure 525 556 526 # FIXME - could be cleaner to use domain.store_timestep etc.557 # Store connectivity and first timestep 527 558 next_data_structure.store_connectivity() 528 next_data_structure.store_timestep( names)559 next_data_structure.store_timestep() 529 560 fid.sync() 530 561 fid.close() 531 562 532 # restore the old starttime and filename563 # Restore the old starttime and filename 533 564 self.domain.starttime = old_domain_starttime 534 565 self.domain.set_name(old_domain_filename) … … 539 570 # Get the variables 540 571 time = fid.variables['time'] 541 stage = fid.variables['stage']542 xmomentum = fid.variables['xmomentum']543 ymomentum = fid.variables['ymomentum']544 572 i = len(time) 545 if type(names) not in [types.ListType, types.TupleType]: 546 names = [names] 547 548 if 'stage' in names \ 549 and 'xmomentum' in names \ 550 and 'ymomentum' in names: 551 # Get stage, elevation, depth and select only those 552 # values where minimum_storable_height is exceeded 573 574 if 'stage' in self.writer.dynamic_quantities: 575 # Select only those values for stage, 576 # xmomentum and ymomentum (if stored) where 577 # depth exceeds minimum_storable_height 578 # 579 # In this branch it is assumed that elevation 580 # is also available as a quantity 581 553 582 Q = domain.quantities['stage'] 554 A, _ = Q.get_vertex_values(xy=False, precision=self.precision) 555 z = fid.variables['elevation'] 556 557 storable_indices = (A-z[:] >= self.minimum_storable_height) 558 stage = num.choose(storable_indices, (z[:], A)) 559 560 # Define a zero vector of same size and type as A 561 # for use with momenta 562 null = num.zeros(num.size(A), A.dtype.char) 563 564 # Get xmomentum where depth exceeds minimum_storable_height 565 Q = domain.quantities['xmomentum'] 566 xmom, _ = Q.get_vertex_values(xy=False, 567 precision=self.precision) 568 xmomentum = num.choose(storable_indices, (null, xmom)) 569 570 571 # Get ymomentum where depth exceeds minimum_storable_height 572 Q = domain.quantities['ymomentum'] 573 ymom, _ = Q.get_vertex_values(xy=False, 574 precision=self.precision) 575 ymomentum = num.choose(storable_indices, (null, ymom)) 576 577 # Write quantities to underlying data file 578 self.writer.store_quantities(fid, 579 time=self.domain.time, 580 sww_precision=self.precision, 581 stage=stage, 582 xmomentum=xmomentum, 583 ymomentum=ymomentum) 583 w, _ = Q.get_vertex_values(xy=False) 584 585 Q = domain.quantities['elevation'] 586 z, _ = Q.get_vertex_values(xy=False) 587 588 storable_indices = (w-z >= self.minimum_storable_height) 584 589 else: 585 msg = 'Quantities stored must be: stage, xmomentum, ymomentum, ' 586 msg += 'but I got: ' + str(names) 587 raise Exception, msg 590 # Very unlikely branch 591 storable_indices = None # This means take all 592 593 594 # Now store dynamic quantities 595 dynamic_quantities = {} 596 for name in self.writer.dynamic_quantities: 597 netcdf_array = fid.variables[name] 598 599 Q = domain.quantities[name] 600 A, _ = Q.get_vertex_values(xy=False, 601 precision=self.precision) 602 603 if storable_indices is not None: 604 if name == 'stage': 605 A = num.choose(storable_indices, (z, A)) 606 607 if name in ['xmomentum', 'ymomentum']: 608 # Get xmomentum where depth exceeds 609 # minimum_storable_height 610 611 # Define a zero vector of same size and type as A 612 # for use with momenta 613 null = num.zeros(num.size(A), A.dtype.char) 614 A = num.choose(storable_indices, (null, A)) 615 616 dynamic_quantities[name] = A 617 618 619 # Store dynamic quantities 620 self.writer.store_quantities(fid, 621 time=self.domain.time, 622 sww_precision=self.precision, 623 **dynamic_quantities) 624 588 625 589 626 # Update extrema if requested … … 608 645 609 646 647 610 648 ## 611 649 # @brief Class for handling checkpoints data … … 630 668 fid = NetCDFFile(self.filename, mode) 631 669 if mode[0] == 'w': 632 # Create new file670 # Create new file 633 671 fid.institution = 'Geoscience Australia' 634 672 fid.description = 'Checkpoint data' … … 636 674 fid.order = domain.default_order 637 675 638 # dimension definitions676 # Dimension definitions 639 677 fid.createDimension('number_of_volumes', self.number_of_volumes) 640 678 fid.createDimension('number_of_vertices', 3) 641 679 642 # Store info at all vertices (no smoothing)680 # Store info at all vertices (no smoothing) 643 681 fid.createDimension('number_of_points', 3*self.number_of_volumes) 644 682 fid.createDimension('number_of_timesteps', None) #extensible 645 683 646 # variable definitions647 648 # Mesh684 # Variable definitions 685 686 # Mesh 649 687 fid.createVariable('x', self.precision, ('number_of_points',)) 650 688 fid.createVariable('y', self.precision, ('number_of_points',)) … … 5322 5360 5323 5361 sww.store_triangulation(outfile, points_utm, volumes, 5324 elevation, zone, new_origin=origin, 5362 zone, 5363 new_origin=origin, 5325 5364 verbose=verbose) 5365 sww.store_static_quantities(outfile, elevation=elevation) 5326 5366 5327 5367 if verbose: log.critical('Converting quantities') … … 5871 5911 number_of_volumes, 5872 5912 number_of_points, 5873 description=' Converted from XXX',5913 description='Generated by ANUGA', 5874 5914 smoothing=True, 5875 5915 order=1, … … 5918 5958 number_of_times = 0 5919 5959 starttime = times 5920 #times = ensure_numeric([]) 5960 5921 5961 5922 5962 outfile.starttime = starttime … … 5992 6032 # @param points_utm List or array of points in UTM. 5993 6033 # @param volumes 5994 # @param elevation5995 6034 # @param zone 5996 6035 # @param new_origin georeference that the points can be set to. … … 6001 6040 points_utm, 6002 6041 volumes, 6003 elevation, zone=None, new_origin=None, 6004 points_georeference=None, verbose=False): 6042 zone=None, 6043 new_origin=None, 6044 points_georeference=None, 6045 verbose=False): 6005 6046 """ 6006 6047 new_origin - qa georeference that the points can be set to. (Maybe … … 6036 6077 points_utm = num.array(points_utm) 6037 6078 6038 # given the two geo_refs and the points, do the stuff6079 # Given the two geo_refs and the points, do the stuff 6039 6080 # described in the method header 6040 6081 # if this is needed else where, pull out as a function … … 6061 6102 x = points[:,0] 6062 6103 y = points[:,1] 6063 z = outfile.variables['z'][:]6064 6104 6065 6105 if verbose: … … 6071 6111 log.critical(' y in [%f, %f], len(lon) == %d' 6072 6112 % (min(y), max(y), len(y))) 6073 log.critical(' z in [%f, %f], len(z) == %d'6074 % (min(elevation), max(elevation), len(elevation)))6113 #log.critical(' z in [%f, %f], len(z) == %d' 6114 # % (min(elevation), max(elevation), len(elevation))) 6075 6115 log.critical('geo_ref: %s' % str(geo_ref)) 6076 6116 log.critical('------------------------------------------------') … … 6078 6118 outfile.variables['x'][:] = points[:,0] #- geo_ref.get_xllcorner() 6079 6119 outfile.variables['y'][:] = points[:,1] #- geo_ref.get_yllcorner() 6080 outfile.variables['z'][:] = elevation6081 outfile.variables['elevation'][:] = elevation #FIXME HACK6082 6120 outfile.variables['volumes'][:] = volumes.astype(num.int32) #On Opteron 64 6083 6121 6084 q = 'elevation' 6085 # This updates the _range values 6086 outfile.variables[q + Write_sww.RANGE][0] = num.min(elevation) 6087 outfile.variables[q + Write_sww.RANGE][1] = num.max(elevation) 6088 6089 6122 6123 6124 # @brief Write the static quantity data to the underlying file. 6125 # @param outfile Handle to open underlying file. 6126 # @param sww_precision Format of quantity data to write (default Float32). 6127 # @param verbose True if this function is to be verbose. 6128 # @param **quant 6129 def store_static_quantities(self, 6130 outfile, 6131 sww_precision=num.float32, 6132 verbose=False, 6133 **quant): 6134 """ 6135 Write the static quantity info. 6136 6137 **quant is extra keyword arguments passed in. These must be 6138 the numpy arrays to be stored in the sww file at each timestep. 6139 6140 The argument sww_precision allows for storing as either 6141 * single precision (default): num.float32 6142 * double precision: num.float64 or num.float 6143 6144 Precondition: 6145 store_triangulation and 6146 store_header have been called. 6147 """ 6148 6149 # The dictionary quant must contain numpy arrays for each name. 6150 # These will typically be quantities from Domain such as friction 6151 # 6152 # Arrays not listed in static_quantitiues will be ignored, silently. 6153 # 6154 # This method will also write the ranges for each quantity, 6155 # e.g. stage_range, xmomentum_range and ymomentum_range 6156 for q in self.static_quantities: 6157 if not quant.has_key(q): 6158 msg = 'Values for quantity %s was not specified in ' % q 6159 msg += 'store_quantities so they cannot be stored.' 6160 raise NewQuantity, msg 6161 else: 6162 q_values = ensure_numeric(quant[q]) 6163 6164 x = q_values.astype(sww_precision) 6165 outfile.variables[q][:] = x 6166 6167 # This populates the _range values 6168 outfile.variables[q + Write_sww.RANGE][0] = num.min(x) 6169 outfile.variables[q + Write_sww.RANGE][1] = num.max(x) 6170 6171 outfile.variables['z'][:] = outfile.variables['elevation'][:] #FIXME HACK 6172 6173 6174 6175 6176 6090 6177 ## 6091 6178 # @brief Write the quantity data to the underlying file. … … 6148 6235 raise NewQuantity, msg 6149 6236 else: 6150 q_values = quant[q]6237 q_values = ensure_numeric(quant[q]) 6151 6238 6152 6239 x = q_values.astype(sww_precision) -
anuga_core/source/anuga/shallow_water/shallow_water_domain.py
r7340 r7342 120 120 import anuga.utilities.log as log 121 121 122 import types 122 123 from types import IntType, FloatType 123 124 from warnings import warn … … 132 133 class Domain(Generic_Domain): 133 134 134 conserved_quantities = ['stage', 'xmomentum', 'ymomentum']135 other_quantities = ['elevation', 'friction']135 #conserved_quantities = ['stage', 'xmomentum', 'ymomentum'] 136 #other_quantities = ['elevation', 'friction'] 136 137 137 138 ## … … 169 170 number_of_full_triangles=None): 170 171 172 # Define quantities for the shallow_water domain 173 conserved_quantities = ['stage', 'xmomentum', 'ymomentum'] 171 174 other_quantities = ['elevation', 'friction'] 175 172 176 Generic_Domain.__init__(self, 173 177 coordinates, 174 178 vertices, 175 179 boundary, 176 Domain.conserved_quantities,177 Domain.other_quantities,180 conserved_quantities, 181 other_quantities, 178 182 tagged_elements, 179 183 geo_reference, … … 209 213 # Stored output 210 214 self.store = True 211 #self.format = 'sww'212 215 self.set_store_vertices_uniquely(False) 213 216 self.minimum_storable_height = minimum_storable_height 214 self.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] 217 self.quantities_to_be_stored = {'elevation': 1, 218 'stage': 2, 219 'xmomentum': 2, 220 'ymomentum': 2} 215 221 216 222 # Limiters … … 317 323 self.points_file_block_line_size = points_file_block_line_size 318 324 325 326 # FIXME: Probably obsolete in its curren form 319 327 ## 320 328 # @brief Set the quantities that will be written to an SWW file. … … 323 331 # @note If 'q' is None, no quantities will be stored in the SWW file. 324 332 def set_quantities_to_be_stored(self, q): 325 """Specify which quantities will be stored in the sww file .326 333 """Specify which quantities will be stored in the sww file 334 327 335 q must be either: 328 - the name of a quantity329 - a list of quantity names 336 - a dictionary with quantity names 337 - a list of quantity names (for backwards compatibility) 330 338 - None 331 339 332 In the two first cases, the named quantities will be stored at 333 each yieldstep (This is in addition to the quantities elevation 334 and friction) 335 340 The format of the dictionary is as follows 341 342 quantity_name: flag where flag must be either 1 or 2. 343 If flag is 1, the quantity is considered static and will be 344 stored once at the beginning of the simulation in a 1D array. 345 346 If flag is 2, the quantity is considered time dependent and 347 it will be stored at each yieldstep by appending it to the 348 appropriate 2D array in the sww file. 349 336 350 If q is None, storage will be switched off altogether. 351 352 Once the simulation has started and thw sww file opened, 353 this function will have no effect. 354 355 The format, where q is a list of names is for backwards compatibility only. 356 It will take the specified quantities to be time dependent and assume 357 'elevation' to be static regardless. 337 358 """ 338 359 339 360 if q is None: 340 self.quantities_to_be_stored = []361 self.quantities_to_be_stored = {} 341 362 self.store = False 342 363 return 343 344 if isinstance(q, basestring):345 q = [q] # Turn argument into a list346 364 347 365 # Check correcness … … 349 367 msg = ('Quantity %s is not a valid conserved quantity' 350 368 % quantity_name) 351 assert quantity_name in self.conserved_quantities, msg 352 369 assert quantity_name in self.quantities, msg 370 371 if type(q) == types.ListType: 372 373 msg = 'List arguments to set_quantities_to_be_stored ' 374 msg += 'has been deprecated and will be removed in future ' 375 msg += 'versions of ANUGA.' 376 msg += 'Please use dictionary argument instead' 377 warn(msg, DeprecationWarning) 378 379 380 381 # FIXME: Raise deprecation warning 382 tmp = {} 383 for x in q: 384 tmp[x] = 2 385 tmp['elevation'] = 1 386 q = tmp 387 388 assert type(q) == types.DictType 353 389 self.quantities_to_be_stored = q 354 390 … … 658 694 659 695 from anuga.shallow_water.data_manager import SWW_file 660 696 661 697 # Initialise writer 662 698 self.writer = SWW_file(self) -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r7340 r7342 1451 1451 1452 1452 self.domain.set_datadir('.') 1453 self.domain.format = 'sww'1454 1453 self.domain.smooth = True 1455 1454 self.domain.set_quantity('elevation', lambda x,y: -x-y) … … 1532 1531 1533 1532 self.domain.set_datadir('.') 1534 self.domain.format = 'sww'1535 1533 self.domain.smooth = True 1536 1534 self.domain.set_quantity('elevation', lambda x,y: -x-y) … … 3610 3608 domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd}) 3611 3609 3612 domain.quantities_to_be_stored.extend(['xmomentum','ymomentum']) 3610 domain.quantities_to_be_stored['xmomentum'] = 2 3611 domain.quantities_to_be_stored['ymomentum'] = 2 3613 3612 #Initial condition 3614 3613 h = 0.05 … … 3641 3640 3642 3641 bits = ['vertex_coordinates'] 3643 for quantity in ['elevation']+domain.quantities_to_be_stored:3644 bits.append('get_quantity("%s").get_integral()' % quantity)3645 bits.append('get_quantity("%s").get_values()' % quantity)3642 for quantity in domain.quantities_to_be_stored: 3643 bits.append('get_quantity("%s").get_integral()' % quantity) 3644 bits.append('get_quantity("%s").get_values()' % quantity) 3646 3645 3647 3646 for bit in bits: … … 3730 3729 domain.set_datadir('.') 3731 3730 domain.default_order=2 3732 #domain.quantities_to_be_stored=['stage']3733 3731 3734 3732 domain.set_quantity('elevation', lambda x,y: -x/3) … … 3780 3778 'vertex_coordinates'] 3781 3779 3782 for quantity in ['elevation']+domain.quantities_to_be_stored:3780 for quantity in domain.quantities_to_be_stored: 3783 3781 bits.append('get_quantity("%s").get_integral()' %quantity) 3784 3782 bits.append('get_quantity("%s").get_values()' %quantity) … … 3851 3849 domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd}) 3852 3850 3853 domain.quantities_to_be_stored.extend(['xmomentum','ymomentum']) 3851 domain.quantities_to_be_stored['xmomentum'] = 2 3852 domain.quantities_to_be_stored['ymomentum'] = 2 3854 3853 #Initial condition 3855 3854 h = 0.05 … … 3884 3883 3885 3884 3886 bits = [] #'vertex_coordinates']3887 for quantity in ['elevation']+domain.quantities_to_be_stored:3885 bits = [] 3886 for quantity in domain.quantities_to_be_stored: 3888 3887 bits.append('quantities["%s"].get_integral()'%quantity) 3889 3888 … … 10456 10455 verbose=self.verbose,sww_precision=netcdf_float) 10457 10456 sww.store_triangulation(outfile, points_utm, volumes, 10458 elevation,new_origin=new_origin,10457 new_origin=new_origin, 10459 10458 verbose=self.verbose) 10459 sww.store_static_quantities(outfile, elevation=elevation) 10460 10460 10461 outfile.close() 10461 10462 fid = NetCDFFile(filename) -
anuga_core/source/anuga/shallow_water/test_shallow_water_domain.py
r7340 r7342 3732 3732 domain.smooth = False 3733 3733 domain.default_order = 2 3734 domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) 3734 3735 3735 3736 3736 # IC … … 5095 5095 # FIXME: This is extremely important! 5096 5096 # How can we test if they weren't stored? 5097 domain1.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum']5098 5097 5099 5098 … … 5200 5199 # FIXME: This is extremely important! 5201 5200 # How can we test if they weren't stored? 5202 domain1.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] 5201 domain1.quantities_to_be_stored = {'elevation': 1, 5202 'stage': 2, 5203 'xmomentum': 2, 5204 'ymomentum': 2} 5203 5205 5204 5206 # Bed-slope and friction at vertices (and interpolated elsewhere) … … 5373 5375 # FIXME: This is extremely important! 5374 5376 # How can we test if they weren't stored? 5375 domain1.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum']5376 5377 5377 5378 # Bed-slope and friction at vertices (and interpolated elsewhere) … … 5545 5546 # FIXME: This is extremely important! 5546 5547 # How can we test if they weren't stored? 5547 domain1.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] 5548 domain1.set_quantities_to_be_stored({'elevation': 1, 5549 'stage': 2, 5550 'xmomentum': 2, 5551 'ymomentum': 2}) 5548 5552 5549 5553
Note: See TracChangeset
for help on using the changeset viewer.