source: inundation/ga/storm_surge/pyvolution/_test_sww2domain2.py @ 1122

Last change on this file since 1122 was 1090, checked in by prow, 20 years ago

Removing tracing.
More testing.

File size: 2.6 KB
Line 
1"""Simple example of shallow water wave equation using Pyvolution
2
3Water driven by linear slope and Dirichlet boundary
4
5"""
6
7######################
8# Module imports
9#
10from mesh_factory import rectangular
11from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\
12     Constant_height, Time_boundary, Transmissive_boundary
13from Numeric import array
14
15#Create basic mesh
16points, vertices, boundary = rectangular(10, 10)
17
18#Create shallow water domain
19domain = Domain(points, vertices, boundary)
20domain.smooth = False
21domain.visualise = False
22domain.store = True
23domain.filename = 'bedslope'
24domain.default_order=2
25
26#######################
27#Bed-slope and friction
28domain.set_quantity('elevation', lambda x,y: -x/3)
29domain.set_quantity('friction', 0.1)
30
31######################
32# Boundary conditions
33from math import sin, pi
34Br = Reflective_boundary(domain)
35Bt = Transmissive_boundary(domain)
36Bd = Dirichlet_boundary([0.2,0.,0.])
37Bw = Time_boundary(domain=domain,
38                   f=lambda t: [(0.1*sin(t*2*pi)), 0.0, 0.0])
39
40domain.set_boundary({'left': Bd, 'right': Br, 'top': Br, 'bottom': Br})
41
42######################
43#Initial condition
44h = 0.05
45elevation = domain.quantities['elevation'].vertex_values
46domain.set_quantity('stage', elevation + h)
47#elevation = domain.get_quantity('elevation',location='unique vertices')
48#domain.set_quantity('stage', elevation + h,location='unique vertices')
49
50domain.check_integrity()
51dir(domain)
52
53######################
54#Evolution
55for t in domain.evolve(yieldstep = 1, finaltime = 2.0):
56    domain.write_time()
57
58
59##NOW TEST IT!!!
60
61from data_manager import sww2domain
62from Numeric import allclose
63
64filename = domain.filename+'.sww'
65
66try:
67    domain2 = sww2domain(filename)
68    assert True == False
69except:
70    domain2 = sww2domain(filename,fail_if_NaN=False)
71
72bits = ['xllcorner','yllcorner','vertex_coordinates','time','starttime']
73
74for quantity in ['elevation']+domain.quantities_to_be_stored:
75    bits.append('get_quantity("%s")'%quantity)
76
77for bit in bits:
78    print 'testing that domain.'+bit+' has been restored'
79    assert allclose(eval('domain.'+bit),eval('domain2.'+bit))
80
81print max(max(domain2.get_quantity('xmomentum')))
82print min(min(domain2.get_quantity('xmomentum')))
83print max(max(domain2.get_quantity('ymomentum')))
84print min(min(domain2.get_quantity('ymomentum')))
85
86assert max(max(domain2.get_quantity('xmomentum')))==0
87assert min(min(domain2.get_quantity('xmomentum')))==0
88assert max(max(domain2.get_quantity('ymomentum')))==0
89assert min(min(domain2.get_quantity('ymomentum')))==0
90
91print 'passed'
Note: See TracBrowser for help on using the repository browser.