1 | """Simple example of shallow water wave equation using Pyvolution |
---|
2 | |
---|
3 | Water driven by linear slope and Dirichlet boundary |
---|
4 | |
---|
5 | """ |
---|
6 | |
---|
7 | ###################### |
---|
8 | # Module imports |
---|
9 | # |
---|
10 | from mesh_factory import rectangular |
---|
11 | from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ |
---|
12 | Constant_height, Time_boundary, Transmissive_boundary |
---|
13 | from Numeric import array |
---|
14 | |
---|
15 | #Create basic mesh |
---|
16 | points, vertices, boundary = rectangular(10, 10) |
---|
17 | |
---|
18 | #Create shallow water domain |
---|
19 | domain = Domain(points, vertices, boundary) |
---|
20 | domain.smooth = False |
---|
21 | domain.visualise = False |
---|
22 | domain.store = True |
---|
23 | domain.filename = 'bedslope' |
---|
24 | domain.default_order=2 |
---|
25 | |
---|
26 | ####################### |
---|
27 | #Bed-slope and friction |
---|
28 | domain.set_quantity('elevation', lambda x,y: -x/3) |
---|
29 | domain.set_quantity('friction', 0.1) |
---|
30 | |
---|
31 | ###################### |
---|
32 | # Boundary conditions |
---|
33 | from math import sin, pi |
---|
34 | Br = Reflective_boundary(domain) |
---|
35 | Bt = Transmissive_boundary(domain) |
---|
36 | Bd = Dirichlet_boundary([0.2,0.,0.]) |
---|
37 | Bw = Time_boundary(domain=domain, |
---|
38 | f=lambda t: [(0.1*sin(t*2*pi)), 0.0, 0.0]) |
---|
39 | |
---|
40 | domain.set_boundary({'left': Bd, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
41 | domain.quantities_to_be_stored.extend(['xmomentum','ymomentum']) |
---|
42 | |
---|
43 | ###################### |
---|
44 | #Initial condition |
---|
45 | h = 0.05 |
---|
46 | elevation = domain.quantities['elevation'].vertex_values |
---|
47 | domain.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 | |
---|
51 | domain.check_integrity() |
---|
52 | dir(domain) |
---|
53 | |
---|
54 | ###################### |
---|
55 | #Evolution |
---|
56 | for t in domain.evolve(yieldstep = 1, finaltime = 2.0): |
---|
57 | # domain.write_time() |
---|
58 | pass |
---|
59 | |
---|
60 | |
---|
61 | ##NOW TEST IT!!! |
---|
62 | |
---|
63 | from anuga.pyvolution.data_manager import sww2domain |
---|
64 | from Numeric import allclose |
---|
65 | |
---|
66 | filename = domain.datadir+'\\'+domain.filename+'.sww' |
---|
67 | |
---|
68 | domain2 = sww2domain(filename,fail_if_NaN=False,verbose = False) |
---|
69 | |
---|
70 | |
---|
71 | bits = ['xllcorner','yllcorner','vertex_coordinates','time','starttime'] |
---|
72 | |
---|
73 | for quantity in ['elevation']+domain.quantities_to_be_stored: |
---|
74 | bits.append('get_quantity("%s")'%quantity) |
---|
75 | |
---|
76 | for 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' |
---|