source: anuga_core/source/obsolete_code/_test_sww2domain.py @ 6011

Last change on this file since 6011 was 3565, checked in by ole, 18 years ago

Moved obsolete code and examples to their appropriate locations

File size: 2.2 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})
41domain.quantities_to_be_stored.extend(['xmomentum','ymomentum'])
42
43######################
44#Initial condition
45h = 0.05
46elevation = domain.quantities['elevation'].vertex_values
47domain.set_quantity('stage', elevation + h)
48#elevation = domain.get_quantity('elevation',location='unique vertices')
49#domain.set_quantity('stage', elevation + h,location='unique vertices')
50
51domain.check_integrity()
52dir(domain)
53
54######################
55#Evolution
56for t in domain.evolve(yieldstep = 1, finaltime = 2.0):
57#    domain.write_time()
58    pass
59
60
61##NOW TEST IT!!!
62
63from anuga.pyvolution.data_manager import sww2domain
64from Numeric import allclose
65
66filename = domain.datadir+'\\'+domain.filename+'.sww'
67
68domain2 = sww2domain(filename,fail_if_NaN=False,verbose = False)
69
70
71bits = ['xllcorner','yllcorner','vertex_coordinates','time','starttime']
72
73for quantity in ['elevation']+domain.quantities_to_be_stored:
74    bits.append('get_quantity("%s")'%quantity)
75
76for bit in bits:
77#    print 'testing that domain.'+bit+' has been restored'
78    assert allclose(eval('domain.'+bit),eval('domain2.'+bit))
79
80#print 'passed'
Note: See TracBrowser for help on using the repository browser.