Changeset 4685 for anuga_core/source/anuga/shallow_water
- Timestamp:
- Aug 28, 2007, 2:23:35 PM (17 years ago)
- Location:
- anuga_core/source/anuga/shallow_water
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/shallow_water_domain.py
r4631 r4685 102 102 beta_uh, beta_uh_dry, beta_vh, beta_vh_dry, tight_slope_limiters 103 103 from anuga.config import alpha_balance 104 from anuga.config import optimise_dry_cells 104 105 105 106 … … 164 165 165 166 self.tight_slope_limiters = tight_slope_limiters 167 self.optimise_dry_cells = optimise_dry_cells 166 168 167 169 self.flux_function = flux_function_central … … 889 891 Ymom.explicit_update, 890 892 domain.already_computed_flux, 891 domain.max_speed) 893 domain.max_speed, 894 int(domain.optimise_dry_cells)) 892 895 893 896 -
anuga_core/source/anuga/shallow_water/shallow_water_ext.c
r4682 r4685 245 245 soundspeed_right = sqrt(g*h_right); 246 246 247 248 247 s_max = max(u_left+soundspeed_left, u_right+soundspeed_right); 249 248 if (s_max < 0.0) s_max = 0.0; 250 249 251 250 s_min = min(u_left-soundspeed_left, u_right-soundspeed_right); 252 if (s_min > 0.0) s_min = 0.0; 253 251 if (s_min > 0.0) s_min = 0.0; 252 253 254 254 //Flux formulas 255 255 flux_left[0] = u_left*h_left; … … 261 261 flux_right[2] = u_right*vh_right; 262 262 263 263 264 264 265 //Flux computation 265 266 denom = s_max-s_min; … … 1281 1282 Xmom.explicit_update, 1282 1283 Ymom.explicit_update, 1283 already_computed_flux) 1284 already_computed_flux, 1285 optimise_dry_cells) 1284 1286 1285 1287 … … 1308 1310 *max_speed_array; //Keeps track of max speeds for each triangle 1309 1311 1312 1310 1313 // Local variables 1311 1314 double timestep, max_speed, epsilon, g, H0, length, area; 1315 int optimise_dry_cells=0; // Optimisation flag 1312 1316 double normal[2], ql[3], qr[3], zl, zr; 1313 1317 double edgeflux[3]; // Work array for summing up fluxes 1314 1318 1315 int number_of_elements, k, i, j, m, n, computation_needed; 1319 int number_of_elements, k, i, m, n; //, j, computation_needed; 1320 1316 1321 int ki, nm=0, ki2; // Index shorthands 1317 1322 static long call=1; // Static local variable flagging already computed flux … … 1319 1324 1320 1325 // Convert Python arguments to C 1321 if (!PyArg_ParseTuple(args, "ddddOOOOOOOOOOOOOOOOOOO ",1326 if (!PyArg_ParseTuple(args, "ddddOOOOOOOOOOOOOOOOOOOi", 1322 1327 ×tep, 1323 1328 &epsilon, … … 1340 1345 &ymom_explicit_update, 1341 1346 &already_computed_flux, 1342 &max_speed_array)) { 1347 &max_speed_array, 1348 &optimise_dry_cells)) { 1343 1349 PyErr_SetString(PyExc_RuntimeError, "Input arguments failed"); 1344 1350 return NULL; 1345 1351 } 1352 1346 1353 1347 1354 number_of_elements = stage_edge_values -> dimensions[0]; … … 1367 1374 // We've already computed the flux across this edge 1368 1375 continue; 1376 1369 1377 1370 1378 ql[0] = ((double *) stage_edge_values -> data)[ki]; … … 1393 1401 1394 1402 1395 // Check if flux calculation is necessary across this edge 1396 // FIXME (Ole): Work in progress! 1397 computation_needed = 0; 1398 //for (j=0; j<3; j++) { 1399 //if (ql[j] != qr[j]) computation_needed = 1; 1400 //} 1401 1402 //if (computation_needed == 0) { 1403 //printf("flux exemption identified\n"); 1403 if (optimise_dry_cells) { 1404 // Check if flux calculation is necessary across this edge 1405 // This check will exclude dry cells. 1406 // This will also optimise cases where zl != zr as 1407 // long as both are dry 1408 1409 if ( fabs(ql[0] - zl) < epsilon && 1410 fabs(qr[0] - zr) < epsilon ) { 1411 // Cell boundary is dry 1412 1413 ((long *) already_computed_flux -> data)[ki] = call; // #k Done 1414 if (n>=0) 1415 ((long *) already_computed_flux -> data)[nm] = call; // #n Done 1404 1416 1405 //((long *) already_computed_flux -> data)[ki] = call; // #k Done 1406 //if (n>=0) 1407 // ((long *) already_computed_flux -> data)[nm] = call; // #n Done 1408 1409 //max_speed = 0.0; 1410 //continue; 1411 //} 1417 max_speed = 0.0; 1418 continue; 1419 } 1420 } 1412 1421 1413 1422 … … 1459 1468 } 1460 1469 } 1470 1461 1471 } // End edge i 1462 1472 -
anuga_core/source/anuga/shallow_water/test_shallow_water_domain.py
r4684 r4685 229 229 domain.compute_fluxes() 230 230 231 print domain.get_quantity('stage').explicit_update231 #print domain.get_quantity('stage').explicit_update 232 232 # FIXME (Ole): TODO the general case 233 233 #assert allclose(domain.get_quantity('stage').explicit_update[1], ........??) … … 1306 1306 1307 1307 ##################################################### 1308 def test_initial_condition(self): 1309 """Test that initial condition is output at time == 0 1308 1309 def test_flux_optimisation(self): 1310 """test_flux_optimisation 1311 Test that fluxes are correctly computed using 1312 dry and still cell exclusions 1310 1313 """ 1311 1314 … … 1344 1347 domain.set_boundary({'exterior': Reflective_boundary(domain)}) 1345 1348 1349 1350 # Check that update arrays are initialised to zero 1351 assert allclose(domain.get_quantity('stage').explicit_update, 0) 1352 assert allclose(domain.get_quantity('xmomentum').explicit_update, 0) 1353 assert allclose(domain.get_quantity('ymomentum').explicit_update, 0) 1354 1355 1356 # Get true values 1357 domain.optimise_dry_cells = False 1358 domain.compute_fluxes() 1359 stage_ref = copy.copy(domain.get_quantity('stage').explicit_update) 1360 xmom_ref = copy.copy(domain.get_quantity('xmomentum').explicit_update) 1361 ymom_ref = copy.copy(domain.get_quantity('ymomentum').explicit_update) 1362 1363 # Try with flux optimisation 1364 domain.optimise_dry_cells = True 1365 domain.compute_fluxes() 1366 1367 assert allclose(stage_ref, domain.get_quantity('stage').explicit_update) 1368 assert allclose(xmom_ref, domain.get_quantity('xmomentum').explicit_update) 1369 assert allclose(ymom_ref, domain.get_quantity('ymomentum').explicit_update) 1370 1371 1372 1373 def test_initial_condition(self): 1374 """test_initial_condition 1375 Test that initial condition is output at time == 0 and that 1376 computed values change as system evolves 1377 """ 1378 1379 from anuga.config import g 1380 import copy 1381 1382 a = [0.0, 0.0] 1383 b = [0.0, 2.0] 1384 c = [2.0, 0.0] 1385 d = [0.0, 4.0] 1386 e = [2.0, 2.0] 1387 f = [4.0, 0.0] 1388 1389 points = [a, b, c, d, e, f] 1390 #bac, bce, ecf, dbe 1391 vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]] 1392 1393 domain = Domain(points, vertices) 1394 1395 #Set up for a gradient of (3,0) at mid triangle (bce) 1396 def slope(x, y): 1397 return 3*x 1398 1399 h = 0.1 1400 def stage(x,y): 1401 return slope(x,y)+h 1402 1403 domain.set_quantity('elevation', slope) 1404 domain.set_quantity('stage', stage) 1405 1406 # Allow slope limiters to work (FIXME (Ole): Shouldn't this be automatic in ANUGA?) 1407 domain.distribute_to_vertices_and_edges() 1408 1409 initial_stage = copy.copy(domain.quantities['stage'].vertex_values) 1410 1411 domain.set_boundary({'exterior': Reflective_boundary(domain)}) 1412 1413 domain.optimise_dry_cells = True 1346 1414 #Evolution 1347 for t in domain.evolve(yieldstep = 1.0, finaltime = 2.0):1415 for t in domain.evolve(yieldstep = 0.5, finaltime = 2.0): 1348 1416 stage = domain.quantities['stage'].vertex_values 1349 1417 … … 1352 1420 else: 1353 1421 assert not allclose(stage, initial_stage) 1422 1354 1423 1355 1424 os.remove(domain.get_name() + '.sww') … … 4799 4868 4800 4869 if __name__ == "__main__": 4801 suite = unittest.makeSuite(Test_Shallow_Water,'test_flux_computation') 4870 4871 suite = unittest.makeSuite(Test_Shallow_Water,'test') 4802 4872 #suite = unittest.makeSuite(Test_Shallow_Water,'test_tight_slope_limiters') 4803 4873 #suite = unittest.makeSuite(Test_Shallow_Water,'test_get_maximum_inundation_from_sww')
Note: See TracChangeset
for help on using the changeset viewer.