- Timestamp:
- Mar 29, 2005, 1:09:46 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/test_data_manager.py
r1151 r1155 1341 1341 1342 1342 #Create basic mesh 1343 points, vertices, boundary = rectangular(2,2) 1344 1343 1344 yiel=0.01 1345 points, vertices, boundary = rectangular(10,10) 1345 1346 #Create shallow water domain 1346 1347 domain = Domain(points, vertices, boundary) … … 1358 1359 Bt = Transmissive_boundary(domain) 1359 1360 Bd = Dirichlet_boundary([0.2,0.,0.]) 1360 Bw = Time_boundary(domain=domain,1361 Bw = Time_boundary(domain=domain, 1361 1362 f=lambda t: [(0.1*sin(t*2*pi)), 0.0, 0.0]) 1362 1363 1363 1364 domain.set_boundary({'left': Bd, 'right': Br, 'top': Br, 'bottom': Br}) 1365 1364 1366 domain.quantities_to_be_stored.extend(['xmomentum','ymomentum']) 1365 1367 #Initial condition … … 1367 1369 elevation = domain.quantities['elevation'].vertex_values 1368 1370 domain.set_quantity('stage', elevation + h) 1369 #elevation = domain.get_quantity('elevation' ,location='unique vertices')1370 #domain.set_quantity('stage', elevation + h ,location='unique vertices')1371 #elevation = domain.get_quantity('elevation') 1372 #domain.set_quantity('stage', elevation + h) 1371 1373 1372 1374 domain.check_integrity() 1373 dir(domain)1374 1375 #Evolution 1375 for t in domain.evolve(yieldstep = 1, finaltime = 2.0):1376 for t in domain.evolve(yieldstep = yiel, finaltime = 0.05): 1376 1377 # domain.write_time() 1377 1378 pass … … 1383 1384 from data_manager import sww2domain 1384 1385 from Numeric import allclose 1385 import os 1386 1387 filename = domain.datadir+os.sep+domain.filename+'.sww' 1388 1389 domain2 = sww2domain(filename,fail_if_NaN=False,verbose = False) 1386 1387 filename = domain.datadir+'\\'+domain.filename+'.sww' 1388 domain2 = sww2domain(filename,None,fail_if_NaN=False,verbose = False) 1389 #points, vertices, boundary = rectangular(15,15) 1390 #domain2.boundary = boundary 1391 ################### 1392 ##NOW TEST IT!!! 1393 ################### 1394 1395 bits = ['xllcorner','yllcorner','vertex_coordinates'] 1396 1397 for quantity in ['elevation']+domain.quantities_to_be_stored: 1398 bits.append('quantities["%s"].get_integral()'%quantity) 1399 bits.append('get_quantity("%s")'%quantity) 1400 1401 for bit in bits: 1402 # print 'testing that domain.'+bit+' has been restored' 1403 # print bit 1404 #print 'done' 1405 assert allclose(eval('domain.'+bit),eval('domain2.'+bit)) 1406 1407 ###################################### 1408 #Now evolve them both, just to be sure 1409 visualise = False 1410 #visualise = True 1411 domain.visualise = visualise 1412 domain.time = 0. 1413 from time import sleep 1414 1415 final = .1 1416 domain.set_quantity('friction', 0.1) 1417 domain.store = False 1418 domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd}) 1419 1420 1421 for t in domain.evolve(yieldstep = yiel, finaltime = final): 1422 if visualise: sleep(1.) 1423 #domain.write_time() 1424 pass 1425 1426 domain2.smooth = False 1427 domain2.visualise = visualise 1428 domain2.store = False 1429 domain2.default_order=2 1430 domain2.set_quantity('friction', 0.1) 1431 #Bed-slope and friction 1432 # Boundary conditions 1433 Bd2=Dirichlet_boundary([0.2,0.,0.]) 1434 domain2.boundary = domain.boundary 1435 #print 'domain2.boundary' 1436 #print domain2.boundary 1437 domain2.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd}) 1438 #domain2.set_boundary({'exterior': Bd}) 1439 1440 domain2.check_integrity() 1441 1442 for t in domain2.evolve(yieldstep = yiel, finaltime = final): 1443 if visualise: sleep(1.) 1444 #domain2.write_time() 1445 pass 1446 1390 1447 1391 1448 ################### … … 1393 1450 ################## 1394 1451 1395 bits = ['xllcorner','yllcorner','vertex_coordinates','time','starttime'] 1396 1397 for quantity in ['elevation']+domain.quantities_to_be_stored: 1452 bits = ['xllcorner','yllcorner','vertex_coordinates'] 1453 1454 for quantity in ['elevation','xmomentum','ymomentum']:#+domain.quantities_to_be_stored: 1455 bits.append('quantities["%s"].get_integral()'%quantity) 1398 1456 bits.append('get_quantity("%s")'%quantity) 1399 1457 1400 1458 for bit in bits: 1401 # print 'testing that domain.'+bit+' has been restored' 1459 #print bit 1402 1460 assert allclose(eval('domain.'+bit),eval('domain2.'+bit)) 1403 1461 1404 #print 'passed' 1405 1462 1406 1463 1407 1464 def test_sww2domain2(self): … … 1443 1500 elevation = domain.quantities['elevation'].vertex_values 1444 1501 domain.set_quantity('stage', elevation + h) 1445 #elevation = domain.get_quantity('elevation',location='unique vertices')1446 #domain.set_quantity('stage', elevation + h,location='unique vertices')1447 1502 1448 1503 domain.check_integrity() … … 1451 1506 pass 1452 1507 #domain.write_time() 1508 1509 1453 1510 1454 1511 ################################## … … 1459 1516 import os 1460 1517 1461 1462 1518 filename = domain.datadir+os.sep+domain.filename+'.sww' 1463 1519 1464 1520 #Fail because NaNs are present 1465 1521 try: 1466 domain2 = sww2domain(filename, fail_if_NaN=True,verbose=False)1522 domain2 = sww2domain(filename,boundary,fail_if_NaN=True,verbose=False) 1467 1523 assert True == False 1468 1524 except: 1469 1525 #Now import it, filling NaNs to be 0 1470 1526 filler = 0 1471 domain2 = sww2domain(filename, fail_if_NaN=False,NaN_filler = filler,verbose=False)1472 1473 bits = ['xllcorner','yllcorner','vertex_coordinates' ,'time','starttime']1527 domain2 = sww2domain(filename,None,fail_if_NaN=False,NaN_filler = filler,verbose=False) 1528 1529 bits = ['xllcorner','yllcorner','vertex_coordinates'] 1474 1530 1475 1531 for quantity in ['elevation']+domain.quantities_to_be_stored: 1532 bits.append('quantities["%s"].get_integral()'%quantity) 1476 1533 bits.append('get_quantity("%s")'%quantity) 1477 1534 … … 1479 1536 # print 'testing that domain.'+bit+' has been restored' 1480 1537 assert allclose(eval('domain.'+bit),eval('domain2.'+bit)) 1481 1482 #print max(max(domain2.get_quantity('xmomentum')))1483 #print min(min(domain2.get_quantity('xmomentum')))1484 #print max(max(domain2.get_quantity('ymomentum')))1485 #print min(min(domain2.get_quantity('ymomentum')))1486 1538 1487 1539 assert max(max(domain2.get_quantity('xmomentum')))==filler … … 1496 1548 #os.remove(domain.datadir+'/'+domain.filename+'.sww') 1497 1549 1550 1551 #def test_weed(self): 1552 #from data_manager import weed 1553 1554 #coordinates1 = [[0.,0.],[1.,0.],[1.,1.],[1.,0.],[2.,0.],[1.,1.]] 1555 #volumes1 = [[0,1,2],[3,4,5]] 1556 #boundary1= {(0,1): 'external',(1,2): 'not external',(2,0): 'external',(3,4): 'external',(4,5): 'external',(5,3): 'not external'} 1557 #unique2,coordinates2,volumes2,boundary2=weed(coordinates1,volumes1,boundary1) 1558 #print 'coordinates2' 1559 #print coordinates2 1560 #print 'volumes2' 1561 #print volumes2 1562 #print 'boundary2' 1563 #print boundary2 1564 1565 1498 1566 #------------------------------------------------------------- 1499 1567 if __name__ == "__main__": 1500 1568 suite = unittest.makeSuite(Test_Data_Manager,'test') 1501 #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2asc_ mis')1569 #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2asc_stage') 1502 1570 runner = unittest.TextTestRunner() 1503 1571 runner.run(suite)
Note: See TracChangeset
for help on using the changeset viewer.