Changeset 8570
- Timestamp:
- Sep 12, 2012, 10:24:57 AM (13 years ago)
- Location:
- trunk/anuga_core/source/anuga
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/generic_domain.py
r8543 r8570 245 245 246 246 Vol_ids = self.vertex_value_indices/3 247 W = num.repeat(self.tri_full_flag, 3) 247 248 # want this 249 # W = num.repeat(self.tri_full_flag, 3) 250 # but without creating extra memeory 251 # Got this 252 # b = np.lib.stride_tricks.as_strided(a, (1000, a.size), (0, a.itemsize)) 253 # from 254 # http://stackoverflow.com/questions/5564098/repeat-numpy-array-without-replicating-data 255 a = self.tri_full_flag 256 b = num.lib.stride_tricks.as_strided(a, (a.size, 3), (a.itemsize,0)) 257 W = b.flat 258 259 # print a 260 # print a.itemsize 261 # print list(b) 262 # print num.repeat(self.tri_full_flag, 3) 263 248 264 249 265 self.node_full_flag = num.minimum(num.bincount(self.triangles.flat, weights = W).astype(num.int), 1) … … 1001 1017 if N > 10: 1002 1018 msg += ' Percentiles (10%):\n' 1003 speed = self.max_speed.tolist() 1004 speed.sort() 1019 #speed = self.max_speed.tolist() 1020 #speed.sort() 1021 speed = num.sort(self.max_speed) 1005 1022 1006 1023 k = 0 1007 lower = min(speed)1024 lower = num.min(speed) 1008 1025 for i, a in enumerate(speed): 1009 1026 if i % (N/10) == 0 and i != 0: -
trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/neighbour_mesh.py
r8556 r8570 933 933 str += ' Number of triangles = %d\n' %len(self) 934 934 str += ' Extent [m]:\n' 935 str += ' x in [% f, %f]\n' %(min(x),max(x))936 str += ' y in [% f, %f]\n' %(min(y),max(y))935 str += ' x in [%8.5e, %8.5e]\n' %(num.amin(x), num.amax(x)) 936 str += ' y in [%8.5e, %8.5e]\n' % (num.amin(y), num.amax(y)) 937 937 str += ' Areas [m^2]:\n' 938 str += ' A in [% f, %f]\n' %(min(areas),max(areas))938 str += ' A in [%8.5e, %8.5e]\n' %(num.amin(areas), num.amax(areas)) 939 939 str += ' number of distinct areas: %d\n' %(len(areas)) 940 940 str += ' Histogram:\n' … … 946 946 #Open upper interval 947 947 hi = bins[i+1] 948 str += ' [% f, %f[: %d\n' %(lo, hi, count)948 str += ' [%8.5e, %8.5e[: %d\n' %(lo, hi, count) 949 949 else: 950 950 #Closed upper interval 951 hi = max(areas)952 str += ' [% f, %f]: %d\n' %(lo, hi, count)951 hi = num.max(areas) 952 str += ' [%8.5e, %8.5e]: %d\n' %(lo, hi, count) 953 953 954 954 N = len(areas) … … 959 959 960 960 k = 0 961 lower = min(areas)961 lower = num.min(areas) 962 962 for i, a in enumerate(areas): 963 963 if i % (N/10) == 0 and i != 0: #For every 10% of the sorted areas 964 str += ' %d triangles in [% f, %f]\n' %(i-k, lower, a)964 str += ' %d triangles in [%8.5e, %8.5e]\n' %(i-k, lower, a) 965 965 lower = a 966 966 k = i 967 967 968 str += ' %d triangles in [% f, %f]\n'\968 str += ' %d triangles in [%8.5e, %8.5e]\n'\ 969 969 %(N-k, lower, max(areas)) 970 970 -
trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/test_domain.py
r8486 r8570 898 898 899 899 if __name__ == "__main__": 900 suite = unittest.makeSuite(Test_Domain,'test ')900 suite = unittest.makeSuite(Test_Domain,'test_') 901 901 runner = unittest.TextTestRunner() 902 902 runner.run(suite) -
trunk/anuga_core/source/anuga/shallow_water/shallow_water_domain.py
r8539 r8570 300 300 301 301 302 def set_tsunami_defaults(self): 303 """Set up the defaults for running the flow_algorithm "tsunami" 304 """ 305 306 self.set_CFL(1.0) 307 #self.set_use_kinematic_viscosity(False) 308 309 self.set_timestepping_method(2) 310 self.set_default_order(2) 311 self.set_compute_fluxes_method('tsunami') 312 self.set_extrapolate_velocity() 313 self.set_distribute_to_vertices_and_edges_method('tsunami') 314 self.use_edge_limiter=True 315 316 # The following allows storage of the negative depths associated with this method 317 self.minimum_storable_height=-99999999999.0 318 319 320 # Note that the extrapolation method used in quantity_ext.c (e.g. 321 # extrapolate_second_order_and_limit_by_edge) uses a constant value for 322 # all the betas. 323 self.beta_w=1.0 324 self.beta_w_dry=1.0 325 self.beta_uh=1.0 326 self.beta_uh_dry=1.0 327 self.beta_vh=1.0 328 self.beta_vh_dry=1.0 329 330 #self.optimise_dry_cells=True 331 # "self.optimise_dry_cells=False" presently ensures that the stage is 332 # always >= minimum_bed_edge value. Actually, we should only need to 333 # apply 'False' on the very first time step (to deal with stage values 334 # that were initialised below the bed by the user). After this, the 335 # algorithm should take care of itself, and 'True' should be okay. 336 self.optimise_dry_cells=False 337 338 # Because gravity is treated within the flux function, 339 # we remove it from the forcing terms. 340 #self.forcing_terms.remove(gravity) 341 342 # We need the edge_coordinates for the extrapolation 343 self.edge_coordinates=self.get_edge_midpoint_coordinates() 344 345 # We demand that vertex values are stored uniquely 346 self.set_store_vertices_smoothly(False) 347 348 self.maximum_allowed_speed=0.0 349 #self.forcing_terms.append(manning_friction_explicit) 350 #self.forcing_terms.remove(manning_friction_implicit) 351 352 print '##########################################################################' 353 print '#' 354 print '# Using anuga_tsunami solver in anuga_work/development/gareth/experimental/anuga_tsunami/' 355 print "#" 356 print "# This solver is experimental. Here are some tips on using it" 357 print "#" 358 print "# 1) When plotting outputs, I strongly suggest you examine centroid values, not vertex values" 359 print "# , as the latter can be completely misleading near strong gradients in the flow. " 360 print "# There is a plot_util.py script in anuga_core/utilities/ which might help you extract" 361 print "# quantities at centroid values from sww files." 362 print "# Note that to accuractely compute centroid values from sww files, the files need to store " 363 print "# vertices uniquely. This makes for large sww files (3x), but is the price to pay for the right answer" 364 print "# (unless we alter IO to allow centroids to be written to sww files, which would then affect" 365 print "# ANUGA viewer as well -- I expect this would be lots of work)" 366 print "#" 367 print "# 2) In field scale applications (where the depth is typically > 1m), I suggest you set" 368 print "# domain.minimum_allowed_height=0.01 (the default is 1.0e-3). " 369 print "#" 370 print "# 3) This solver is not expected to perform well in problems with very" 371 print "# shallow water flowing down steep slopes (such that the stage_centroid_value " 372 print "# is less than the maximum bed_edge_value on a given triangle). However, analytical tests" 373 print "# suggest it can do typical wetting/drying situations very well (parabolic oscillations test case) " 374 print "#" 375 print "# 4) This solver allows the stage_centroid_value to drop to slightly below the minimum bed_vertex_value" 376 print "# on it's triangle. In other ANUGA versions (e.g. 1.2.1), the limit would be the" 377 print "# bed_centroid_value. This means that triangles store slightly more water than they are" 378 print "# typically interpreted to store, which might have significance in some applications." 379 print "#" 380 print "# You will probably be able to tell this is causing you problems by convergence testing" 381 print "#" 382 print '# 5) Note that many options in config.py have been overridden by the solver -- I have ' 383 print '# deliberately attempted to get the solver to perform well with consistent values of ' 384 print '# these parameters -- so I would advise against changing them unless you at least check that ' 385 print '# it really does improve things' 386 print '#' 387 print '##########################################################################' 388 389 390 391 392 302 393 def update_special_conditions(self): 303 394 … … 438 529 ', '.join(flow_algorithms)+'.' 439 530 raise Exception(msg) 531 532 440 533 441 534 … … 494 587 495 588 if self.flow_algorithm == 'tsunami': 496 self.set_timestepping_method(2) 497 self.set_default_order(2) 498 beta_w = 1.9 499 beta_w_dry = 0.2 500 beta_uh = 1.9 501 beta_uh_dry = 0.2 502 beta_vh = 1.9 503 beta_vh_dry = 0.2 504 self.set_betas(beta_w, beta_w_dry, beta_uh, beta_uh_dry, beta_vh, beta_vh_dry) 505 self.set_CFL(1.0) 506 self.set_compute_fluxes_method('wb_2') 507 self.set_extrapolate_velocity() 508 self.set_distribute_to_vertices_and_edges_method('tsunami') 589 590 self.set_tsunami_defaults() 509 591 510 592 … … 959 1041 gravity_wb_c(self) 960 1042 1043 elif self.compute_fluxes_method == 'tsunami': 1044 # Using Gareth Davies well nbalanced scheme 1045 # Flux calculation and gravity incorporated in same 1046 # procedure 1047 1048 1049 # FIXME SR: This needs cleaning up, should just be passing through 1050 # the domain as in other compute flux calls 1051 1052 from swb2_domain_ext import compute_fluxes_ext_central \ 1053 as compute_fluxes_ext 1054 1055 # Shortcuts 1056 Stage = domain.quantities['stage'] 1057 Xmom = domain.quantities['xmomentum'] 1058 Ymom = domain.quantities['ymomentum'] 1059 Bed = domain.quantities['elevation'] 1060 1061 timestep = self.evolve_max_timestep 1062 1063 self.flux_timestep = compute_fluxes_ext(timestep, 1064 self.epsilon, 1065 self.H0, 1066 self.g, 1067 self.neighbours, 1068 self.neighbour_edges, 1069 self.normals, 1070 self.edgelengths, 1071 self.radii, 1072 self.areas, 1073 self.tri_full_flag, 1074 Stage.edge_values, 1075 Xmom.edge_values, 1076 Ymom.edge_values, 1077 Bed.edge_values, 1078 Stage.boundary_values, 1079 Xmom.boundary_values, 1080 Ymom.boundary_values, 1081 self.boundary_flux_type, 1082 Stage.explicit_update, 1083 Xmom.explicit_update, 1084 Ymom.explicit_update, 1085 self.already_computed_flux, 1086 self.max_speed, 1087 int(self.optimise_dry_cells), 1088 Stage.centroid_values, 1089 Bed.centroid_values, 1090 Bed.vertex_values) 1091 961 1092 else: 962 1093 raise Exception('unknown compute_fluxes_method') … … 975 1106 """ Call correct module function """ 976 1107 977 #Shortcuts 978 #W = self.quantities['stage'] 979 #Z = self.quantities['elevation'] 980 981 #Arrays 982 #w_C = W.centroid_values 983 #z_C = Z.centroid_values 984 985 #num_min = num.min(w_C-z_C) 986 #if num_min < 0.0: 987 # print 'num.min(w_C-z_C)', num_min 988 989 if self.use_edge_limiter: 990 distribute_using_edge_limiter(self) 1108 1109 if self.compute_fluxes_method == 'tsunami': 1110 1111 from swb2_domain_ext import protect 1112 1113 # shortcuts 1114 wc = self.quantities['stage'].centroid_values 1115 wv = self.quantities['stage'].vertex_values 1116 zc = self.quantities['elevation'].centroid_values 1117 zv = self.quantities['elevation'].vertex_values 1118 xmomc = self.quantities['xmomentum'].centroid_values 1119 ymomc = self.quantities['ymomentum'].centroid_values 1120 areas = self.areas 1121 1122 protect(self.minimum_allowed_height, domain.maximum_allowed_speed, 1123 domain.epsilon, wc, wv, zc,zv, xmomc, ymomc, areas) 1124 1125 1126 from swb2_domain_ext import extrapolate_second_order_edge_sw as extrapol2 1127 1128 # Shortcuts 1129 Stage = self.quantities['stage'] 1130 Xmom = self.quantities['xmomentum'] 1131 Ymom = self.quantities['ymomentum'] 1132 Elevation = self.quantities['elevation'] 1133 1134 extrapol2(self, 1135 self.surrogate_neighbours, 1136 self.number_of_boundaries, 1137 self.centroid_coordinates, 1138 Stage.centroid_values, 1139 Xmom.centroid_values, 1140 Ymom.centroid_values, 1141 Elevation.centroid_values, 1142 self.edge_coordinates, 1143 Stage.edge_values, 1144 Xmom.edge_values, 1145 Ymom.edge_values, 1146 Elevation.edge_values, 1147 Stage.vertex_values, 1148 Xmom.vertex_values, 1149 Ymom.vertex_values, 1150 Elevation.vertex_values, 1151 int(self.optimise_dry_cells), 1152 int(self.extrapolate_velocity_second_order)) 1153 1154 991 1155 else: 992 distribute_using_vertex_limiter(self) 1156 if self.use_edge_limiter: 1157 self.distribute_using_edge_limiter() 1158 else: 1159 #distribute_using_vertex_limiter(self) 1160 self.distribute_using_vertex_limiter() 1161 1162 1163 1164 def distribute_using_edge_limiter(self): 1165 """Distribution from centroids to edges specific to the SWW eqn. 1166 1167 It will ensure that h (w-z) is always non-negative even in the 1168 presence of steep bed-slopes by taking a weighted average between shallow 1169 and deep cases. 1170 1171 In addition, all conserved quantities get distributed as per either a 1172 constant (order==1) or a piecewise linear function (order==2). 1173 1174 1175 Precondition: 1176 All quantities defined at centroids and bed elevation defined at 1177 vertices. 1178 1179 Postcondition 1180 Conserved quantities defined at vertices 1181 """ 1182 1183 # Remove very thin layers of water 1184 self.protect_against_infinitesimal_and_negative_heights() 1185 1186 for name in self.conserved_quantities: 1187 Q = self.quantities[name] 1188 if self._order_ == 1: 1189 Q.extrapolate_first_order() 1190 elif self._order_ == 2: 1191 Q.extrapolate_second_order_and_limit_by_edge() 1192 else: 1193 raise Exception('Unknown order') 1194 1195 balance_deep_and_shallow(self) 1196 1197 # Compute edge values by interpolation 1198 for name in self.conserved_quantities: 1199 Q = domain.quantities[name] 1200 Q.interpolate_from_vertices_to_edges() 1201 1202 def distribute_using_vertex_limiter(domain): 1203 """Distribution from centroids to vertices specific to the SWW equation. 1204 1205 It will ensure that h (w-z) is always non-negative even in the 1206 presence of steep bed-slopes by taking a weighted average between shallow 1207 and deep cases. 1208 1209 In addition, all conserved quantities get distributed as per either a 1210 constant (order==1) or a piecewise linear function (order==2). 1211 1212 FIXME: more explanation about removal of artificial variability etc 1213 1214 Precondition: 1215 All quantities defined at centroids and bed elevation defined at 1216 vertices. 1217 1218 Postcondition 1219 Conserved quantities defined at vertices 1220 """ 1221 1222 # Remove very thin layers of water 1223 domain.protect_against_infinitesimal_and_negative_heights() 1224 1225 # Extrapolate all conserved quantities 1226 if domain.optimised_gradient_limiter: 1227 # MH090605 if second order, 1228 # perform the extrapolation and limiting on 1229 # all of the conserved quantities 1230 1231 if (domain._order_ == 1): 1232 for name in domain.conserved_quantities: 1233 Q = domain.quantities[name] 1234 Q.extrapolate_first_order() 1235 elif domain._order_ == 2: 1236 domain.extrapolate_second_order_sw() 1237 else: 1238 raise Exception('Unknown order') 1239 else: 1240 # Old code: 1241 for name in domain.conserved_quantities: 1242 Q = domain.quantities[name] 1243 1244 if domain._order_ == 1: 1245 Q.extrapolate_first_order() 1246 elif domain._order_ == 2: 1247 Q.extrapolate_second_order_and_limit_by_vertex() 1248 else: 1249 raise Exception('Unknown order') 1250 1251 # Take bed elevation into account when water heights are small 1252 balance_deep_and_shallow(domain) 1253 1254 # Compute edge values by interpolation 1255 for name in domain.conserved_quantities: 1256 Q = domain.quantities[name] 1257 Q.interpolate_from_vertices_to_edges() 1258 993 1259 994 1260 def protect_against_infinitesimal_and_negative_heights(self): … … 996 1262 """ 997 1263 998 protect_against_infinitesimal_and_negative_heights(self) 1264 if self.flow_algorithm == 'tsunami': 1265 1266 from swb2_domain_ext import protect 1267 1268 # shortcuts 1269 wc = domain.quantities['stage'].centroid_values 1270 wv = domain.quantities['stage'].vertex_values 1271 zc = domain.quantities['elevation'].centroid_values 1272 zv = domain.quantities['elevation'].vertex_values 1273 xmomc = domain.quantities['xmomentum'].centroid_values 1274 ymomc = domain.quantities['ymomentum'].centroid_values 1275 areas = domain.areas 1276 1277 protect(domain.minimum_allowed_height, domain.maximum_allowed_speed, 1278 domain.epsilon, wc, wv, zc,zv, xmomc, ymomc, areas) 1279 1280 else: 1281 from shallow_water_ext import protect 1282 1283 # Shortcuts 1284 wc = self.quantities['stage'].centroid_values 1285 zc = self.quantities['elevation'].centroid_values 1286 xmomc = self.quantities['xmomentum'].centroid_values 1287 ymomc = self.quantities['ymomentum'].centroid_values 1288 1289 protect(self.minimum_allowed_height, self.maximum_allowed_speed, 1290 self.epsilon, wc, zc, xmomc, ymomc) 1291 999 1292 1000 1293 … … 1609 1902 1610 1903 # Remove very thin layers of water 1611 protect_against_infinitesimal_and_negative_heights(domain)1904 domain.protect_against_infinitesimal_and_negative_heights() 1612 1905 1613 1906 # Extrapolate all conserved quantities … … 1645 1938 Q.interpolate_from_vertices_to_edges() 1646 1939 1647 def distribute_using_edge_limiter(domain):1648 """Distribution from centroids to edges specific to the SWW eqn.1649 1650 It will ensure that h (w-z) is always non-negative even in the1651 presence of steep bed-slopes by taking a weighted average between shallow1652 and deep cases.1653 1654 In addition, all conserved quantities get distributed as per either a1655 constant (order==1) or a piecewise linear function (order==2).1656 1657 1658 Precondition:1659 All quantities defined at centroids and bed elevation defined at1660 vertices.1661 1662 Postcondition1663 Conserved quantities defined at vertices1664 """1665 1666 # Remove very thin layers of water1667 protect_against_infinitesimal_and_negative_heights(domain)1668 1669 for name in domain.conserved_quantities:1670 Q = domain.quantities[name]1671 if domain._order_ == 1:1672 Q.extrapolate_first_order()1673 elif domain._order_ == 2:1674 Q.extrapolate_second_order_and_limit_by_edge()1675 else:1676 raise Exception('Unknown order')1677 1678 balance_deep_and_shallow(domain)1679 1680 # Compute edge values by interpolation1681 for name in domain.conserved_quantities:1682 Q = domain.quantities[name]1683 Q.interpolate_from_vertices_to_edges()1684 1685 def protect_against_infinitesimal_and_negative_heights(domain):1686 """Protect against infinitesimal heights and associated high velocities"""1687 1688 from shallow_water_ext import protect1689 1690 # Shortcuts1691 wc = domain.quantities['stage'].centroid_values1692 zc = domain.quantities['elevation'].centroid_values1693 xmomc = domain.quantities['xmomentum'].centroid_values1694 ymomc = domain.quantities['ymomentum'].centroid_values1695 1696 protect(domain.minimum_allowed_height, domain.maximum_allowed_speed,1697 domain.epsilon, wc, zc, xmomc, ymomc)1940 #def distribute_using_edge_limiter(domain): 1941 # """Distribution from centroids to edges specific to the SWW eqn. 1942 # 1943 # It will ensure that h (w-z) is always non-negative even in the 1944 # presence of steep bed-slopes by taking a weighted average between shallow 1945 # and deep cases. 1946 # 1947 # In addition, all conserved quantities get distributed as per either a 1948 # constant (order==1) or a piecewise linear function (order==2). 1949 # 1950 # 1951 # Precondition: 1952 # All quantities defined at centroids and bed elevation defined at 1953 # vertices. 1954 # 1955 # Postcondition 1956 # Conserved quantities defined at vertices 1957 # """ 1958 # 1959 # # Remove very thin layers of water 1960 # domain.protect_against_infinitesimal_and_negative_heights() 1961 # 1962 # for name in domain.conserved_quantities: 1963 # Q = domain.quantities[name] 1964 # if domain._order_ == 1: 1965 # Q.extrapolate_first_order() 1966 # elif domain._order_ == 2: 1967 # Q.extrapolate_second_order_and_limit_by_edge() 1968 # else: 1969 # raise Exception('Unknown order') 1970 # 1971 # balance_deep_and_shallow(domain) 1972 # 1973 # # Compute edge values by interpolation 1974 # for name in domain.conserved_quantities: 1975 # Q = domain.quantities[name] 1976 # Q.interpolate_from_vertices_to_edges() 1977 # 1978 ##def protect_against_infinitesimal_and_negative_heights(domain): 1979 ## """Protect against infinitesimal heights and associated high velocities""" 1980 ## 1981 ## from shallow_water_ext import protect 1982 ## 1983 ## # Shortcuts 1984 ## wc = domain.quantities['stage'].centroid_values 1985 ## zc = domain.quantities['elevation'].centroid_values 1986 ## xmomc = domain.quantities['xmomentum'].centroid_values 1987 ## ymomc = domain.quantities['ymomentum'].centroid_values 1988 ## 1989 ## protect(domain.minimum_allowed_height, domain.maximum_allowed_speed, 1990 ## domain.epsilon, wc, zc, xmomc, ymomc) 1698 1991 1699 1992 def balance_deep_and_shallow(domain): … … 1737 2030 # Standard forcing terms 1738 2031 ################################################################################ 1739 1740 #def gravity(domain):1741 # """Apply gravitational pull in the presence of bed slope1742 # Wrapper calls underlying C implementation1743 # """1744 #1745 # from shallow_water_ext import gravity as gravity_c1746 #1747 # xmom_update = domain.quantities['xmomentum'].explicit_update1748 # ymom_update = domain.quantities['ymomentum'].explicit_update1749 #1750 # stage = domain.quantities['stage']1751 # elevation = domain.quantities['elevation']1752 #1753 # #FIXME SR Should avoid allocating memory!1754 # height = stage.centroid_values - elevation.centroid_values1755 #1756 #1757 # elevation = elevation.vertex_values1758 #1759 # point = domain.get_vertex_coordinates()1760 #1761 # gravity_c(domain.g, height, elevation, point, xmom_update, ymom_update)1762 1763 1764 2032 1765 2033 -
trunk/anuga_core/source/anuga/shallow_water/test_tsunami_okada.py
r8550 r8570 109 109 return el 110 110 111 print int(l/dx)112 print int(w/dy)111 #print int(l/dx) 112 #print int(w/dy) 113 113 points, vertices, boundary = rectangular_cross(int(l/dx), int(w/dy), 114 114 len1=l, len2=w)
Note: See TracChangeset
for help on using the changeset viewer.