Changeset 4712
- Timestamp:
- Sep 7, 2007, 10:43:46 PM (17 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/domain.py
r4711 r4712 31 31 32 32 import types 33 34 33 35 34 36 class Domain(Mesh): … … 176 178 from anuga.config import max_smallsteps, beta_w, beta_h, epsilon 177 179 from anuga.config import CFL 180 from anuga.config import timestepping_method 178 181 from anuga.config import protect_against_isolated_degenerate_timesteps 179 182 self.beta_w = beta_w … … 182 185 self.protect_against_isolated_degenerate_timesteps = protect_against_isolated_degenerate_timesteps 183 186 187 184 188 185 189 # FIXME: Maybe have separate orders for h-limiter and w-limiter? … … 194 198 self.number_of_first_order_steps = 0 195 199 self.CFL = CFL 196 200 self.set_timestepping_method(timestepping_method) 201 197 202 self.boundary_map = None # Will be populated by set_boundary 198 203 … … 954 959 return msg 955 960 961 def get_timestepping_method(self): 962 return self.timestepping_method 963 964 def set_timestepping_method(self,timestepping_method): 965 966 if timestepping_method in ['euler', 'rk2']: 967 self.timestepping_method = timestepping_method 968 return 969 970 msg = '%s is an incorrect timestepping type'% timestepping_method 971 raise Exception, msg 956 972 957 973 def get_name(self): … … 973 989 def set_datadir(self, name): 974 990 self.datadir = name 991 992 def get_starttime(self): 993 return self.starttime 994 995 def set_starttime(self, time): 996 self.starttime = float(time) 975 997 976 998 … … 1085 1107 1086 1108 while True: 1087 # Compute fluxes across each element edge 1088 self.compute_fluxes() 1089 1090 # Update timestep to fit yieldstep and finaltime 1091 self.update_timestep(yieldstep, finaltime) 1092 1093 # Update conserved quantities 1094 self.update_conserved_quantities() 1095 1096 # Update ghosts 1097 self.update_ghosts() 1098 1099 # Update vertex and edge values 1100 self.distribute_to_vertices_and_edges() 1109 1110 # Evolve One Step, using appropriate timestepping method 1111 if self.get_timestepping_method() == 'euler': 1112 self.evolve_one_euler_step(yieldstep,finaltime) 1113 1114 elif self.get_timestepping_method() == 'rk2': 1115 self.evolve_one_rk2_step(yieldstep,finaltime) 1101 1116 1102 1117 # Update extrema if necessary (for reporting) 1103 1118 self.update_extrema() 1104 1119 1105 # Update boundary values 1106 self.update_boundary() 1107 1108 # Update time 1109 self.time += self.timestep 1120 1110 1121 self.yieldtime += self.timestep 1111 1122 self.number_of_steps += 1 … … 1145 1156 1146 1157 1158 def evolve_one_euler_step(self, yieldstep, finaltime): 1159 """One Euler Time Step""" 1160 1161 #Compute fluxes across each element edge 1162 self.compute_fluxes() 1163 1164 #Update timestep to fit yieldstep and finaltime 1165 self.update_timestep(yieldstep, finaltime) 1166 1167 #Update conserved quantities 1168 self.update_conserved_quantities() 1169 1170 #update ghosts 1171 self.update_ghosts() 1172 1173 #Update vertex and edge values 1174 self.distribute_to_vertices_and_edges() 1175 1176 #Update boundary values 1177 self.update_boundary() 1178 1179 #Update time 1180 self.time += self.timestep 1181 1182 1183 1184 1185 def evolve_one_rk2_step(self,yieldstep, finaltime): 1186 """One 2nd order RK timestep""" 1187 1188 #Save initial initial conserved quantities values 1189 self.backup_conserved_quantities() 1190 1191 #-------------------------------------- 1192 #First euler step 1193 #-------------------------------------- 1194 1195 #Compute fluxes across each element edge 1196 self.compute_fluxes() 1197 1198 #Update timestep to fit yieldstep and finaltime 1199 self.update_timestep(yieldstep, finaltime) 1200 1201 #Update conserved quantities 1202 self.update_conserved_quantities() 1203 1204 #update ghosts 1205 self.update_ghosts() 1206 1207 #Update vertex and edge values 1208 self.distribute_to_vertices_and_edges() 1209 1210 #Update boundary values 1211 self.update_boundary() 1212 1213 #Update time 1214 self.time += self.timestep 1215 1216 #------------------------------------ 1217 #Second Euler step 1218 #------------------------------------ 1219 1220 #Compute fluxes across each element edge 1221 self.compute_fluxes() 1222 1223 #Update conserved quantities 1224 self.update_conserved_quantities() 1225 1226 #------------------------------------ 1227 #Combine initial and final values 1228 #of conserved quantities 1229 #------------------------------------ 1230 1231 self.saxpy_conserved_quantities(0.5, 0.5) 1232 1233 #------------------------------------ 1234 #Clean up rk step 1235 #------------------------------------ 1236 1237 #update ghosts 1238 self.update_ghosts() 1239 1240 #Update vertex and edge values 1241 self.distribute_to_vertices_and_edges() 1242 1243 #Update boundary values 1244 self.update_boundary() 1245 1246 1147 1247 def evolve_to_end(self, finaltime = 1.0): 1148 1248 """Iterate evolve all the way to the end … … 1153 1253 1154 1254 1255 def backup_conserved_quantities(self): 1256 N = len(self) #number_of_triangles 1257 1258 #backup conserved_quantities centroid values 1259 for name in self.conserved_quantities: 1260 Q = self.quantities[name] 1261 Q.backup_centroid_values() 1262 1263 def saxpy_conserved_quantities(self,a,b): 1264 N = len(self) #number_of_triangles 1265 1266 #backup conserved_quantities centroid values 1267 for name in self.conserved_quantities: 1268 Q = self.quantities[name] 1269 Q.saxpy_centroid_values(a,b) 1270 1155 1271 1156 1272 def update_boundary(self): -
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r4704 r4712 1305 1305 self.explicit_update = zeros(N, Float ) 1306 1306 self.semi_implicit_update = zeros(N, Float ) 1307 self.centroid_backup_values = zeros(N, Float) 1308 1309 1307 1310 1308 1311 … … 1318 1321 return compute_gradients(self) 1319 1322 1320 1321 1323 def limit(self): 1322 1324 #Call correct module function … … 1324 1326 limit(self) 1325 1327 1326 1327 1328 def extrapolate_second_order(self): 1328 1329 #Call correct module function … … 1330 1331 extrapolate_second_order(self) 1331 1332 1333 def backup_centroid_values(self): 1334 #Call correct module function 1335 #(either from this module or C-extension) 1336 backup_centroid_values(self) 1337 1338 def saxpy_centroid_values(self,a,b): 1339 #Call correct module function 1340 #(either from this module or C-extension) 1341 saxpy_centroid_values(self,a,b) 1342 1332 1343 1333 1344 def update(quantity, timestep): … … 1417 1428 1418 1429 1419 def extrapolate_second_order(quantity): 1420 """Extrapolate conserved quantities from centroid to 1421 vertices for each volume using 1422 second order scheme. 1423 """ 1424 1425 a, b = quantity.compute_gradients() 1426 1427 X = quantity.domain.get_vertex_coordinates() 1430 def backup_centroid_values(quantity): 1431 """Copy centroid values to backup array""" 1432 1428 1433 qc = quantity.centroid_values 1429 q v = quantity.vertex_values1434 qb = quantity.centroid_backup_values 1430 1435 1431 1436 #Check each triangle 1432 1437 for k in range(len(quantity.domain)): 1433 #Centroid coordinates 1434 x, y = quantity.domain.centroid_coordinates[k] 1435 1436 #vertex coordinates 1437 x0, y0, x1, y1, x2, y2 = X[k,:] 1438 1439 #Extrapolate 1440 qv[k,0] = qc[k] + a[k]*(x0-x) + b[k]*(y0-y) 1441 qv[k,1] = qc[k] + a[k]*(x1-x) + b[k]*(y1-y) 1442 qv[k,2] = qc[k] + a[k]*(x2-x) + b[k]*(y2-y) 1438 qb[k] = qc[k] 1439 1440 1441 def saxpy_centroid_values(quantity,a,b): 1442 """saxpy operation between centroid value and backup""" 1443 1444 qc = quantity.centroid_values 1445 qb = quantity.centroid_backup_values 1446 1447 #Check each triangle 1448 for k in range(len(quantity.domain)): 1449 qc[k] = a*qc[k]+b*qb[k] 1443 1450 1444 1451 … … 1582 1589 #Replace python version with c implementations 1583 1590 1584 from quantity_ext import average_vertex_values 1591 from quantity_ext import average_vertex_values, backup_centroid_values, \ 1592 saxpy_centroid_values 1585 1593 1586 1594 from quantity_ext import compute_gradients, limit,\ -
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity_ext.c
r4536 r4712 100 100 101 101 102 102 103 int _extrapolate(int N, 103 104 double* centroids, … … 162 163 return 0; 163 164 } 165 166 int _backup_centroid_values(int N, 167 double* centroid_values, 168 double* centroid_backup_values) { 169 //Backup centroid values 170 171 172 int k; 173 174 for (k=0; k<N; k++) { 175 centroid_backup_values[k] = centroid_values[k]; 176 } 177 178 179 return 0; 180 } 181 182 183 int _saxpy_centroid_values(int N, 184 double a, 185 double b, 186 double* centroid_values, 187 double* centroid_backup_values) { 188 //saxby centroid values 189 190 191 int k; 192 193 194 for (k=0; k<N; k++) { 195 centroid_values[k] = a*centroid_values[k] + b*centroid_backup_values[k]; 196 } 197 198 199 return 0; 200 } 201 164 202 165 203 int _update(int N, … … 305 343 306 344 345 PyObject *backup_centroid_values(PyObject *self, PyObject *args) { 346 347 PyObject *quantity; 348 PyArrayObject *centroid_values, *centroid_backup_values; 349 350 int N, err; 351 352 353 // Convert Python arguments to C 354 if (!PyArg_ParseTuple(args, "O", &quantity)) { 355 PyErr_SetString(PyExc_RuntimeError, 356 "quantity_ext.c: backup_centroid_values could not parse input"); 357 return NULL; 358 } 359 360 centroid_values = get_consecutive_array(quantity, "centroid_values"); 361 centroid_backup_values = get_consecutive_array(quantity, "centroid_backup_values"); 362 363 N = centroid_values -> dimensions[0]; 364 365 err = _backup_centroid_values(N, 366 (double*) centroid_values -> data, 367 (double*) centroid_backup_values -> data); 368 369 370 //Release and return 371 Py_DECREF(centroid_values); 372 Py_DECREF(centroid_backup_values); 373 374 return Py_BuildValue(""); 375 } 376 377 PyObject *saxpy_centroid_values(PyObject *self, PyObject *args) { 378 379 PyObject *quantity; 380 PyArrayObject *centroid_values, *centroid_backup_values; 381 382 double a,b; 383 int N, err; 384 385 386 // Convert Python arguments to C 387 if (!PyArg_ParseTuple(args, "Odd", &quantity, &a, &b)) { 388 PyErr_SetString(PyExc_RuntimeError, 389 "quantity_ext.c: saxpy_centroid_values could not parse input"); 390 return NULL; 391 } 392 393 centroid_values = get_consecutive_array(quantity, "centroid_values"); 394 centroid_backup_values = get_consecutive_array(quantity, "centroid_backup_values"); 395 396 N = centroid_values -> dimensions[0]; 397 398 err = _saxpy_centroid_values(N,a,b, 399 (double*) centroid_values -> data, 400 (double*) centroid_backup_values -> data); 401 402 403 //Release and return 404 Py_DECREF(centroid_values); 405 Py_DECREF(centroid_backup_values); 406 407 return Py_BuildValue(""); 408 } 409 410 307 411 PyObject *interpolate_from_vertices_to_edges(PyObject *self, PyObject *args) { 308 412 … … 645 749 {"limit", limit, METH_VARARGS, "Print out"}, 646 750 {"update", update, METH_VARARGS, "Print out"}, 751 {"backup_centroid_values", backup_centroid_values, METH_VARARGS, "Print out"}, 752 {"saxpy_centroid_values", saxpy_centroid_values, METH_VARARGS, "Print out"}, 647 753 {"compute_gradients", compute_gradients, METH_VARARGS, "Print out"}, 648 754 {"extrapolate_second_order", extrapolate_second_order, -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_domain.py
r4704 r4712 319 319 320 320 321 322 323 321 def test_setting_timestepping_method(self): 322 """test_set_quanitities_to_be_monitored 323 """ 324 325 a = [0.0, 0.0] 326 b = [0.0, 2.0] 327 c = [2.0,0.0] 328 d = [0.0, 4.0] 329 e = [2.0, 2.0] 330 f = [4.0,0.0] 331 332 points = [a, b, c, d, e, f] 333 #bac, bce, ecf, dbe, daf, dae 334 vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]] 335 336 337 domain = Domain(points, vertices, boundary=None, 338 conserved_quantities =\ 339 ['stage', 'xmomentum', 'ymomentum'], 340 other_quantities = ['elevation', 'friction', 'depth']) 341 342 343 domain.timestepping_method = None 344 345 346 # Check that invalid requests are dealt with 347 try: 348 domain.set_timestepping_method('eee') 349 except: 350 pass 351 else: 352 msg = 'Should have caught illegal method' 353 raise Exception, msg 354 355 356 #Should have no trouble with euler or rk2 357 domain.set_timestepping_method('euler') 358 domain.set_timestepping_method('rk2') 359 360 #test get timestepping method 361 assert domain.get_timestepping_method() == 'rk2' 324 362 325 363 -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py
r4704 r4712 1368 1368 1369 1369 1370 def test_backup_saxpy_centroid_values(self): 1371 quantity = Conserved_quantity(self.mesh4) 1372 1373 #Set up for a gradient of (3,1), f(x) = 3x+y 1374 c_values = array([2.0+2.0/3, 4.0+4.0/3, 8.0+2.0/3, 2.0+8.0/3]) 1375 d_values = array([1.0, 2.0, 3.0, 4.0]) 1376 quantity.set_values(c_values, location = 'centroids') 1377 1378 #Backup 1379 quantity.backup_centroid_values() 1380 1381 #print quantity.vertex_values 1382 assert allclose(quantity.centroid_values, quantity.centroid_backup_values) 1383 1384 1385 quantity.set_values(d_values, location = 'centroids') 1386 1387 quantity.saxpy_centroid_values(2.0, 3.0) 1388 1389 assert(quantity.centroid_values, 2.0*d_values + 3.0*c_values) 1390 1391 1392 1370 1393 def test_first_order_extrapolator(self): 1371 1394 quantity = Conserved_quantity(self.mesh4) -
anuga_core/source/anuga/abstract_2d_finite_volumes/util.py
r4704 r4712 85 85 quantities = domain.conserved_quantities 86 86 87 domain_starttime = domain. starttime87 domain_starttime = domain.get_starttime() 88 88 else: 89 89 domain_starttime = None … … 140 140 141 141 if verbose: print msg 142 domain.s tarttime = starttime#Modifying model time142 domain.set_starttime(starttime) #Modifying model time 143 143 if verbose: print 'Domain starttime is now set to %f'\ 144 144 %domain.starttime -
anuga_core/source/anuga/config.py
r4699 r4712 104 104 #make changes 105 105 106 # Choose type of timestepping, 107 timestepping_method = 'euler' # 1st order euler 108 #timestepping_method = 'rk2' # 2nd Order TVD scheme 109 106 110 # Option to search for signatures where isolated triangles are 107 111 # responsible for a small global timestep. -
anuga_core/source/anuga/shallow_water/shallow_water_domain.py
r4710 r4712 446 446 447 447 448 #Initial update of vertex and edge values before any storage448 #Initial update of vertex and edge values before any STORAGE 449 449 #and or visualisation 450 #This is done again in the initialisation of the Generic_Domain 451 #evolve loop but we do it here to ensure the values are ok for storage 450 452 self.distribute_to_vertices_and_edges() 451 453 -
anuga_core/source/anuga/shallow_water/test_system.py
r4561 r4712 47 47 domain.set_name(boundary_name) 48 48 domain.set_datadir(dir) 49 domain.s tarttime = boundary_starttime49 domain.set_starttime(boundary_starttime) 50 50 51 51 # Setup initial conditions … … 71 71 72 72 """ 73 73 74 boundary_starttime = 500 74 75 boundary_filename = self.create_sww_boundary(boundary_starttime) … … 95 96 # Setup boundary conditions 96 97 domain.set_boundary({'exterior': Bf}) 97 for t in domain.evolve(yieldstep = 5, finaltime = 10.0): 98 99 100 for t in domain.evolve(yieldstep = 5.0, finaltime = 10.0): 98 101 pass 99 # domain.write_time()102 #print domain.write_time() 100 103 #print "domain.time", domain.time 101 104 … … 117 120 Test that starttime can be set in the middle of a boundary condition 118 121 """ 122 119 123 boundary_starttime = 500 120 124 boundary_filename = self.create_sww_boundary(boundary_starttime) … … 134 138 domain.set_datadir(dir) 135 139 new_starttime = 510. 136 domain.s tarttime = new_starttime140 domain.set_starttime(new_starttime) 137 141 138 142 # Setup initial conditions … … 146 150 for t in domain.evolve(yieldstep = 5, finaltime = 9.0): 147 151 pass 148 # domain.write_time()152 #print domain.write_time() 149 153 #print "domain.time", domain.time 150 154 -
anuga_core/source/anuga/utilities/compile.py
r4493 r4712 201 201 # This will make compile work locally 202 202 utilities_include_dir = '.' 203 utilities_include_dir = '../utilities' 203 204 204 205
Note: See TracChangeset
for help on using the changeset viewer.