Changeset 7562
- Timestamp:
- Nov 19, 2009, 5:23:52 PM (15 years ago)
- Location:
- anuga_core/source
- Files:
-
- 1 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/domain.py
r7519 r7562 1138 1138 # Input checks 1139 1139 if quantities is None: 1140 quantities = self. conserved_quantities1140 quantities = self.evolved_quantities 1141 1141 elif type(quantities) == types.StringType: 1142 1142 quantities = [quantities] #Turn it into a list … … 1752 1752 ## 1753 1753 # @brief Mapping between conserved quantites and evolved quantities 1754 # @param q_cons array of conserved quantity values 1755 # @param q_evolved array of current evolved quantity values 1756 def conserved_to_evolved(self, q_cons, q_evolved): 1754 # @param Input: q_cons array of conserved quantity values 1755 # @param Input: q_evol array of current evolved quantity values 1756 # @note Output: Updated q_evol array 1757 def conserved_values_to_evolved_values(self, q_cons, q_evol): 1757 1758 """Needs to be overridden by Domain subclass 1758 1759 """ 1759 1760 1760 if len(q_cons) == len(q_evol ved):1761 q_evol ved[:] = q_cons1761 if len(q_cons) == len(q_evol): 1762 q_evol[:] = q_cons 1762 1763 else: 1763 msg = 'Method conserved_ to_evolvedmust be overridden by Domain subclass'1764 msg = 'Method conserved_values_to_evolved_values must be overridden by Domain subclass' 1764 1765 raise Exception, msg 1766 1767 return q_evol 1765 1768 1766 1769 ## … … 1781 1784 log.critical('WARNING: Ignored boundary segment (None)') 1782 1785 else: 1783 q_ cons= B.evaluate(vol_id, edge_id)1784 1785 if len(q_ cons) == len(self.evolved_quantities):1786 q_bdry = B.evaluate(vol_id, edge_id) 1787 1788 if len(q_bdry) == len(self.evolved_quantities): 1786 1789 # conserved and evolved quantities are the same 1787 q_evol = q_ cons1788 elif len(q_ cons) == len(self.conserved_quantities):1790 q_evol = q_bdry 1791 elif len(q_bdry) == len(self.conserved_quantities): 1789 1792 # boundary just returns conserved quantities 1790 1793 # Need to calculate all the evolved quantities … … 1793 1796 q_evol = self.get_evolved_quantities(vol_id, edge = edge_id) 1794 1797 1795 self.conserved_to_evolved(q_cons, q_evol)1798 q_evol = self.conserved_values_to_evolved_values(q_bdry, q_evol) 1796 1799 else: 1797 1800 msg = 'Boundary must return array of either conserved or evolved quantities' -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_domain.py
r7519 r7562 606 606 pass 607 607 else: 608 msg = 'Should have caught the lack of conserved_ to_evolvedmember function'608 msg = 'Should have caught the lack of conserved_values_to_evolved_values member function' 609 609 raise Exception, msg 610 610 611 611 612 def conserved_ to_evolved(q_cons, q_evol):612 def conserved_values_to_evolved_values(q_cons, q_evol): 613 613 614 614 q_evol[0:3] = q_cons … … 616 616 q_evol[4] = q_cons[2]/q_cons[0] 617 617 618 domain.conserved_to_evolved = conserved_to_evolved 618 return q_evol 619 620 domain.conserved_values_to_evolved_values = conserved_values_to_evolved_values 619 621 620 622 domain.update_boundary() -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_util.py
r7342 r7562 140 140 domain1.store = True 141 141 domain1.set_datadir('.') 142 domain1.set_name('spatio_temporal_boundary_source_%d' %(id(self))) 142 sww_file = 'spatio_temporal_boundary_source_%d' %(id(self)) 143 domain1.set_name(sww_file) 143 144 144 145 #Bed-slope, friction and IC at vertices (and interpolated elsewhere) -
anuga_core/source/anuga/culvert_flows/test_culvert_class.py
r7497 r7562 124 124 125 125 126 os.remove('Test_culvert_shallow.sww') 126 127 127 128 class Test_Culvert(unittest.TestCase): … … 243 244 assert min_delta_w < 0 244 245 assert max_delta_w > 10 245 246 247 248 os.remove('Test_culvert.sww') 246 249 247 250 def test_that_culvert_dry_bed_rating_does_not_produce_flow(self): … … 346 349 347 350 348 351 os.remove('Test_culvert_dry.sww') 349 352 350 353 def test_that_culvert_flows_conserves_volume(self): -
anuga_core/source/anuga/shallow_water/data_manager.py
r7520 r7562 644 644 fid.close() 645 645 646 647 ## 648 # @brief Class to open an sww file so that domain can be populated with quantity values 649 class Read_sww: 650 651 def __init__(self, source): 652 """The source parameter is assumed to be a NetCDF sww file. 653 """ 654 655 self.source = source 656 657 self.frame_number = 0 658 659 fin = NetCDFFile(self.source, 'r') 660 661 self.time = num.array(fin.variables['time'], num.float) 662 self.last_frame_number = self.time.shape[0] - 1 663 664 self.frames = num.arange(self.last_frame_number+1) 665 666 fin.close() 667 668 self.read_mesh() 669 670 self.quantities = {} 671 672 self.read_quantities() 673 674 675 def read_mesh(self): 676 fin = NetCDFFile(self.source, 'r') 677 678 self.vertices = num.array(fin.variables['volumes'], num.int) 679 680 self.x = x = num.array(fin.variables['x'], num.float) 681 self.y = y = num.array(fin.variables['y'], num.float) 682 683 assert len(self.x) == len(self.y) 684 685 self.xmin = num.min(x) 686 self.xmax = num.max(x) 687 self.ymin = num.min(y) 688 self.ymax = num.max(y) 689 690 691 692 fin.close() 693 694 def read_quantities(self, frame_number=0): 695 696 assert frame_number >= 0 and frame_number <= self.last_frame_number 697 698 self.frame_number = frame_number 699 700 M = len(self.x)/3 701 702 fin = NetCDFFile(self.source, 'r') 703 704 for q in filter(lambda n:n != 'x' and n != 'y' and n != 'z' and n != 'time' and n != 'volumes' and \ 705 '_range' not in n, \ 706 fin.variables.keys()): 707 if len(fin.variables[q].shape) == 1: # Not a time-varying quantity 708 self.quantities[q] = num.ravel(num.array(fin.variables[q], num.float)).reshape(M,3) 709 else: # Time-varying, get the current timestep data 710 self.quantities[q] = num.array(fin.variables[q][self.frame_number], num.float).reshape(M,3) 711 fin.close() 712 return self.quantities 713 714 def get_bounds(self): 715 return [self.xmin, self.xmax, self.ymin, self.ymax] 716 717 def get_last_frame_number(self): 718 return self.last_frame_number 719 720 def get_time(self): 721 return self.time[self.frame_number] 646 722 647 723 … … 2530 2606 verbose = False, 2531 2607 origin = None): 2608 2532 2609 log.critical('sww2asc will soon be obsoleted - please use sww2dem') 2533 2610 sww2dem(basename_in, … … 2540 2617 verbose = verbose, 2541 2618 origin = origin, 2542 datum = 'WGS84',2543 format = 'asc')2619 datum = 'WGS84', 2620 format = 'asc') 2544 2621 2545 2622 … … 6379 6456 6380 6457 6458 6459 6381 6460 ## 6382 6461 # @brief A class to write STS files. -
anuga_core/source/anuga/shallow_water/shallow_water_domain.py
r7539 r7562 102 102 from anuga.geospatial_data.geospatial_data import ensure_geospatial 103 103 104 from anuga.config import minimum_storable_height105 from anuga.config import minimum_allowed_height, maximum_allowed_speed106 from anuga.config import g, epsilon, beta_w, beta_w_dry,\107 beta_uh, beta_uh_dry, beta_vh, beta_vh_dry, tight_slope_limiters108 from anuga.config import alpha_balance109 from anuga.config import optimise_dry_cells110 from anuga.config import optimised_gradient_limiter111 from anuga.config import use_edge_limiter112 from anuga.config import use_centroid_velocities113 104 from anuga.config import netcdf_mode_r, netcdf_mode_w, netcdf_mode_a 114 105 … … 199 190 number_of_full_triangles=number_of_full_triangles) 200 191 192 self.set_defaults() 193 194 195 self.forcing_terms.append(manning_friction_implicit) 196 self.forcing_terms.append(gravity) 197 198 # Stored output 199 self.store = True 200 self.set_store_vertices_uniquely(False) 201 202 self.quantities_to_be_stored = {'elevation': 1, 203 'stage': 2, 204 'xmomentum': 2, 205 'ymomentum': 2} 206 207 208 209 210 ## 211 # @brief Set default values, usually read in from a config file 212 # @param flag 213 def set_defaults(self): 214 """Set the default values in this routine. That way we can inherit class 215 and just over redefine the defaults for the new class 216 """ 217 218 from anuga.config import minimum_storable_height 219 from anuga.config import minimum_allowed_height, maximum_allowed_speed 220 from anuga.config import g, epsilon, beta_w, beta_w_dry,\ 221 beta_uh, beta_uh_dry, beta_vh, beta_vh_dry, tight_slope_limiters 222 from anuga.config import alpha_balance 223 from anuga.config import optimise_dry_cells 224 from anuga.config import optimised_gradient_limiter 225 from anuga.config import use_edge_limiter 226 from anuga.config import use_centroid_velocities 227 228 229 201 230 self.set_minimum_allowed_height(minimum_allowed_height) 202 203 231 self.maximum_allowed_speed = maximum_allowed_speed 232 204 233 self.g = g 205 234 self.beta_w = beta_w … … 214 243 self.optimise_dry_cells = optimise_dry_cells 215 244 216 self.use_new_mannings = False 217 self.forcing_terms.append(manning_friction_implicit) 218 self.forcing_terms.append(gravity) 219 220 # Stored output 221 self.store = True 222 self.set_store_vertices_uniquely(False) 245 246 self.set_new_mannings_function(False) 247 223 248 self.minimum_storable_height = minimum_storable_height 224 self.quantities_to_be_stored = {'elevation': 1, 225 'stage': 2, 226 'xmomentum': 2, 227 'ymomentum': 2} 228 229 # Limiters 249 250 # Limiters 230 251 self.use_edge_limiter = use_edge_limiter 231 252 self.optimised_gradient_limiter = optimised_gradient_limiter 232 self.use_centroid_velocities = use_centroid_velocities 233 253 self.use_centroid_velocities = use_centroid_velocities 234 254 235 255 ## -
anuga_core/source/anuga/shallow_water/test_shallow_water_domain.py
r7539 r7562 6677 6677 assert num.allclose(q, ref_flow) 6678 6678 6679 os.remove('Inflow_flowline_test.sww') 6679 6680 6680 6681 def test_volume_conservation_inflow(self): … … 6776 6777 6777 6778 6779 os.remove('Inflow_volume_test.sww') 6780 6781 6782 6778 6783 def test_volume_conservation_rain(self): 6779 6784 """test_volume_conservation … … 6881 6886 ref_volume += ys * delta_V 6882 6887 6888 os.remove('Rain_volume_test.sww') 6883 6889 6884 6890 def Xtest_rain_conservation_and_runoff(self): … … 7084 7090 # Check that quantities have been stored correctly 7085 7091 from Scientific.IO.NetCDF import NetCDFFile 7086 fid = NetCDFFile(domain.get_name() + '.sww') 7092 sww_file = domain.get_name() + '.sww' 7093 fid = NetCDFFile(sww_file) 7087 7094 7088 7095 x = fid.variables['x'][:] … … 7091 7098 elevation = fid.variables['elevation'][:] 7092 7099 fid.close() 7100 7101 os.remove(sww_file) 7102 7093 7103 7094 7104 assert len(stage.shape) == 2 … … 7261 7271 % (q, ref_flow)) 7262 7272 assert num.allclose(q, ref_flow, rtol=1.0e-2), msg 7273 7274 os.remove('inflow_flowline_test.sww') 7263 7275 7264 7276 … … 7552 7564 % (domain_depth, normal_depth)) 7553 7565 7566 os.remove('Inflow_flowline_test.sww') 7567 7554 7568 ################################################################################# 7555 7569 -
anuga_core/source/anuga/shallow_water_balanced/test_swb_distribute.py
r7559 r7562 147 147 148 148 # First order 149 domain._order_ = 1 150 domain.distribute_to_vertices_and_edges() 149 domain.set_default_order(1) 150 domain.distribute_to_vertices_and_edges() 151 151 152 assert num.allclose(L[1], val1) 152 153 153 154 # Second order 154 domain._order_ = 2 155 domain.beta_w = 0.9 156 domain.beta_w_dry = 0.9 157 domain.beta_uh = 0.9 158 domain.beta_uh_dry = 0.9 159 domain.beta_vh = 0.9 160 domain.beta_vh_dry = 0.9 161 domain.distribute_to_vertices_and_edges() 162 assert num.allclose(L[1], [2.2, 4.9, 4.9]) 155 domain.set_default_order(2) 156 domain.distribute_to_vertices_and_edges() 157 158 assert num.allclose(L[1], [1.00000000e-03, 5.99950000e+00, 5.99950000e+00]) 159 160 assert num.allclose(val1, num.sum(L[1])/3) 163 161 164 162 def test_distribute_away_from_bed(self): … … 192 190 assert num.allclose(b[1], 0.0) 193 191 194 domain._order_ = 1 195 domain.distribute_to_vertices_and_edges() 192 domain.set_default_order(1) 193 domain.distribute_to_vertices_and_edges() 194 196 195 assert num.allclose(L[1], 1.77777778) 197 196 198 domain._order_ = 2 199 domain.beta_w = 0.9 200 domain.beta_w_dry = 0.9 201 domain.beta_uh = 0.9 202 domain.beta_uh_dry = 0.9 203 domain.beta_vh = 0.9 204 domain.beta_vh_dry = 0.9 205 domain.distribute_to_vertices_and_edges() 206 assert num.allclose(L[1], [0.57777777, 2.37777778, 2.37777778]) 197 domain.set_default_order(2) 198 domain.distribute_to_vertices_and_edges() 199 200 assert num.allclose(L[1], [1.00000000e-03, 2.66616667e+00, 2.66616667e+00]) 201 202 assert num.allclose(1.77777778, num.sum(L[1])/3) 207 203 208 204 def test_distribute_away_from_bed1(self): … … 234 230 assert num.allclose(b[1], 3.33333333) 235 231 236 domain._order_ = 1 237 domain.distribute_to_vertices_and_edges() 232 domain.set_default_order(1) 233 domain.distribute_to_vertices_and_edges() 234 238 235 assert num.allclose(L[1], 4.9382716) 239 236 240 domain._order_ = 2 241 domain.beta_w = 0.9 242 domain.beta_w_dry = 0.9 243 domain.beta_uh = 0.9 244 domain.beta_uh_dry = 0.9 245 domain.beta_vh = 0.9 246 domain.beta_vh_dry = 0.9 247 domain.distribute_to_vertices_and_edges() 248 assert num.allclose(L[1], [1.07160494, 6.46058131, 7.28262855]) 237 domain.set_default_order(2) 238 domain.distribute_to_vertices_and_edges() 239 240 assert num.allclose(L[1], [ 1.00000000e-03, 6.88207932e+00, 7.93173549e+00]) 241 249 242 250 243 def test_distribute_near_bed(self): … … 283 276 domain.quantities['stage'].centroid_values[i]) 284 277 285 domain. _order_ = 1286 287 domain.tight_slope_limiters = 0 288 domain.distribute_to_vertices_and_edges()289 assert num.allclose(L[1], [0. 1, 20.1, 20.1])278 domain.set_default_order(1) 279 domain.distribute_to_vertices_and_edges() 280 281 282 assert num.allclose(L[1], [0.298, 20.001, 20.001]) 290 283 for i in range(len(L)): 291 284 assert num.allclose(volumes[i], num.sum(L[i])/3) 292 285 293 # Allow triangle to be flatter (closer to bed) 294 domain.tight_slope_limiters = 1 295 296 domain.distribute_to_vertices_and_edges() 297 assert num.allclose(L[1], [0.298, 20.001, 20.001]) 298 for i in range(len(L)): 299 assert num.allclose(volumes[i], num.sum(L[i])/3) 300 301 domain._order_ = 2 302 303 domain.tight_slope_limiters = 0 304 domain.distribute_to_vertices_and_edges() 305 assert num.allclose(L[1], [0.1, 20.1, 20.1]) 306 for i in range(len(L)): 307 assert num.allclose(volumes[i], num.sum(L[i])/3) 308 309 # Allow triangle to be flatter (closer to bed) 310 domain.tight_slope_limiters = 1 311 312 domain.distribute_to_vertices_and_edges() 313 assert num.allclose(L[1], [0.298, 20.001, 20.001]) 286 domain.set_default_order(2) 287 domain.distribute_to_vertices_and_edges() 288 289 290 assert num.allclose(L[1], [ 0.1, 20.1, 20.1]) 314 291 for i in range(len(L)): 315 292 assert num.allclose(volumes[i], num.sum(L[i])/3) … … 378 355 379 356 domain.distribute_to_vertices_and_edges() 380 assert num.allclose(L[1], [4.23370103, 16.06529897, 20.001]) or\ 381 num.allclose(L[1], [4.18944138, 16.10955862, 20.001]) or\ 382 num.allclose(L[1], [4.19351461, 16.10548539, 20.001]) # old limiters 357 358 359 360 361 assert num.allclose(L[1], [4.001, 16.15377472, 20.14522528],rtol=1.0e-3) 383 362 384 363 for i in range(len(L)): … … 440 419 domain.distribute_to_vertices_and_edges() 441 420 442 assert num.allclose(L[1,:], [-0.00825735775384, 443 -0.00801881482869, 444 0.0272445025825]) 445 assert num.allclose(X[1,:], [0.0143507718962, 446 0.0142502147066, 447 0.00931268339717]) 448 assert num.allclose(Y[1,:], [-0.000117062180693, 449 7.94434448109e-005, 450 -0.000151505429018]) 421 422 assert num.allclose(L[1,:],[-0.01434766, -0.01292565, 0.03824164]) 423 424 assert num.allclose(X[1,:],[ 0.01649334, 0.016267, 0.00515332]) 425 426 assert num.allclose(Y[1,:],[-0.00027927, 0.00050728, -0.00041714]) 451 427 452 428 -
anuga_core/source/anuga/shallow_water_balanced/test_swb_forcing_terms.py
r7559 r7562 24 24 25 25 26 27 28 class Test_swb_clean(unittest.TestCase): 26 # Variable windfield implemented using functions 27 def speed(t, x, y): 28 """Large speeds halfway between center and edges 29 30 Low speeds at center and edges 31 """ 32 33 from math import exp, cos, pi 34 35 x = num.array(x) 36 y = num.array(y) 37 38 N = len(x) 39 s = 0*x #New array 40 41 for k in range(N): 42 r = num.sqrt(x[k]**2 + y[k]**2) 43 factor = exp(-(r-0.15)**2) 44 s[k] = 4000 * factor * (cos(t*2*pi/150) + 2) 45 46 return s 47 48 def scalar_func(t, x, y): 49 """Function that returns a scalar. 50 51 Used to test error message when numeric array is expected 52 """ 53 54 return 17.7 55 56 def scalar_func_list(t, x, y): 57 """Function that returns a scalar. 58 59 Used to test error message when numeric array is expected 60 """ 61 62 return [17.7] 63 64 65 def angle(t, x, y): 66 """Rotating field 67 """ 68 from math import atan, pi 69 70 x = num.array(x) 71 y = num.array(y) 72 73 N = len(x) 74 a = 0 * x # New array 75 76 for k in range(N): 77 r = num.sqrt(x[k]**2 + y[k]**2) 78 79 angle = atan(y[k]/x[k]) 80 81 if x[k] < 0: 82 angle += pi 83 84 # Take normal direction 85 angle -= pi/2 86 87 # Ensure positive radians 88 if angle < 0: 89 angle += 2*pi 90 91 a[k] = angle/pi*180 92 93 return a 94 95 96 ############################################################################### 97 98 class Test_swb_forcing_terms(unittest.TestCase): 29 99 def setUp(self): 30 100 pass … … 1723 1793 1724 1794 if __name__ == "__main__": 1725 suite = unittest.makeSuite(Test_swb_ clean, 'test')1795 suite = unittest.makeSuite(Test_swb_forcing_terms, 'test') 1726 1796 runner = unittest.TextTestRunner(verbosity=1) 1727 1797 runner.run(suite) -
anuga_core/source/anuga/test_all.py
r7318 r7562 23 23 24 24 # Directories that should not be searched for test files. 25 exclude_dirs = ['pypar_dist', 26 '.svn', 25 exclude_dirs = ['pypar_dist', # Special requirements 26 '.svn', # subversion 27 27 'props', 'wcprops', 'prop-base', 'text-base', 'tmp'] 28 28 -
anuga_core/source/anuga_parallel/interface.py
r7453 r7562 8 8 from anuga_parallel.parallel_api import myid, numprocs, get_processor_name 9 9 from anuga_parallel.parallel_api import send, receive 10 from anuga_parallel.parallel_api import pypar_available, barrier 10 from anuga_parallel.parallel_api import pypar_available, barrier, finalize 11 11 12 12 from anuga_parallel.parallel_meshes import parallel_rectangle -
anuga_core/source/anuga_parallel/test_parallel_distribute_domain.py
r7505 r7562 35 35 36 36 37 from anuga_parallel.interface import distribute, myid, numprocs 37 from anuga_parallel.interface import distribute, myid, numprocs, finalize 38 38 39 39 … … 222 222 223 223 224 225 finalize() -
anuga_core/source/anuga_parallel/test_parallel_distribute_mesh.py
r7507 r7562 15 15 from anuga_parallel.distribute_mesh import extract_hostmesh, rec_submesh, send_submesh 16 16 17 from anuga_parallel.interface import myid, numprocs, barrier 17 from anuga_parallel.interface import myid, numprocs, barrier, finalize 18 18 19 19 import numpy as num … … 302 302 distibute_three_processors() 303 303 304 304 finalize() 305 305 306 306 -
anuga_core/source/anuga_parallel/test_parallel_sw_flow.py
r7505 r7562 27 27 28 28 29 from anuga_parallel.interface import distribute, myid, numprocs, send, receive, barrier 29 from anuga_parallel.interface import distribute, myid, numprocs, send, receive, barrier, finalize 30 30 31 31 #-------------------------------------------------------------------------- … … 37 37 N = 25 38 38 M = 25 39 verbose = False39 verbose = True 40 40 41 41 #--------------------------------- … … 212 212 evolution_test(parallel=True, G=G, seq_interpolation_points = interpolation_points) 213 213 214 215 216 214 finalize() 215 216
Note: See TracChangeset
for help on using the changeset viewer.