1 | #! /usr/bin/python |
---|
2 | |
---|
3 | """ |
---|
4 | Boundaries - specific to the shallow water wave equation |
---|
5 | """ |
---|
6 | __author__="Stephen Roberts" |
---|
7 | __date__ ="$05/06/2010 5:44:05 PM$" |
---|
8 | |
---|
9 | from anuga_1d.base.generic_domain import * |
---|
10 | |
---|
11 | class Dirichlet_boundary(Boundary): |
---|
12 | """Dirichlet boundary returns constant values for the |
---|
13 | conserved quantities |
---|
14 | """ |
---|
15 | |
---|
16 | def __init__(self, quantities=None): |
---|
17 | Boundary.__init__(self) |
---|
18 | |
---|
19 | if quantities is None: |
---|
20 | msg = 'Must specify one value for each evolved quantity, w,uh,z,h,u' |
---|
21 | raise msg |
---|
22 | |
---|
23 | self.quantities=numpy.array(quantities, numpy.float) |
---|
24 | |
---|
25 | def __repr__(self): |
---|
26 | return 'Dirichlet boundary (%s)' %self.quantities |
---|
27 | |
---|
28 | def evaluate(self, vol_id=None, edge_id=None): |
---|
29 | return self.quantities |
---|
30 | |
---|
31 | |
---|
32 | class Reflective_boundary(Boundary): |
---|
33 | """Reflective boundary returns same conserved quantities as |
---|
34 | those present in its neighbour volume but reflected. |
---|
35 | |
---|
36 | This class is specific to the shallow water equation as it |
---|
37 | works with the momentum quantities assumed to be the second |
---|
38 | conserved quantities. |
---|
39 | """ |
---|
40 | |
---|
41 | def __init__(self, domain = None): |
---|
42 | Boundary.__init__(self) |
---|
43 | |
---|
44 | if domain is None: |
---|
45 | msg = 'Domain must be specified for reflective boundary' |
---|
46 | raise msg |
---|
47 | |
---|
48 | #Handy shorthands |
---|
49 | self.normals = domain.normals |
---|
50 | self.stage = domain.quantities['stage'].vertex_values |
---|
51 | self.xmom = domain.quantities['xmomentum'].vertex_values |
---|
52 | self.bed = domain.quantities['elevation'].vertex_values |
---|
53 | self.height = domain.quantities['height'].vertex_values |
---|
54 | self.velocity = domain.quantities['velocity'].vertex_values |
---|
55 | |
---|
56 | |
---|
57 | self.quantities = numpy.zeros(5, numpy.float) |
---|
58 | |
---|
59 | def __repr__(self): |
---|
60 | return 'Reflective_boundary' |
---|
61 | |
---|
62 | |
---|
63 | def evaluate(self, vol_id, edge_id): |
---|
64 | """Reflective boundaries reverses the outward momentum |
---|
65 | of the volume they serve. |
---|
66 | """ |
---|
67 | |
---|
68 | q = self.quantities |
---|
69 | q[0] = self.stage[vol_id, edge_id] |
---|
70 | q[1] = -self.xmom[vol_id, edge_id] |
---|
71 | q[2] = self.bed[vol_id, edge_id] |
---|
72 | q[3] = self.height[vol_id, edge_id] |
---|
73 | q[4] = -self.velocity[vol_id, edge_id] |
---|
74 | |
---|
75 | #normal = self.normals[vol_id,edge_id] |
---|
76 | |
---|
77 | return q |
---|
78 | |
---|
79 | |
---|
80 | class Transmissive_boundary(Boundary): |
---|
81 | """Transmissive boundary returns same conserved quantities as |
---|
82 | those present in its neighbour volume but reflected. |
---|
83 | |
---|
84 | This class is specific to the shallow water equation as it |
---|
85 | works with the momentum quantities assumed to be the second |
---|
86 | quantities. |
---|
87 | """ |
---|
88 | |
---|
89 | def __init__(self, domain = None): |
---|
90 | Boundary.__init__(self) |
---|
91 | |
---|
92 | if domain is None: |
---|
93 | msg = 'Domain must be specified for transmissive boundary' |
---|
94 | raise msg |
---|
95 | |
---|
96 | #Handy shorthands |
---|
97 | self.normals = domain.normals |
---|
98 | self.stage = domain.quantities['stage'].vertex_values |
---|
99 | self.xmom = domain.quantities['xmomentum'].vertex_values |
---|
100 | self.bed = domain.quantities['elevation'].vertex_values |
---|
101 | self.height = domain.quantities['height'].vertex_values |
---|
102 | self.velocity = domain.quantities['velocity'].vertex_values |
---|
103 | |
---|
104 | |
---|
105 | self.quantities = numpy.zeros(5, numpy.float) |
---|
106 | |
---|
107 | def __repr__(self): |
---|
108 | return 'Transmissive_boundary' |
---|
109 | |
---|
110 | |
---|
111 | def evaluate(self, vol_id, edge_id): |
---|
112 | """Transmissive boundaries mimics the outward momentum |
---|
113 | of the volume they serve. |
---|
114 | """ |
---|
115 | |
---|
116 | q = self.quantities |
---|
117 | q[0] = self.stage[vol_id, edge_id] |
---|
118 | q[1] = self.xmom[vol_id, edge_id] |
---|
119 | q[2] = self.bed[vol_id, edge_id] |
---|
120 | q[3] = self.height[vol_id, edge_id] |
---|
121 | q[4] = self.velocity[vol_id, edge_id] |
---|
122 | |
---|
123 | #normal = self.normals[vol_id,edge_id] |
---|
124 | |
---|
125 | return q |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | if __name__ == "__main__": |
---|
130 | print "Hello World"; |
---|