1 | |
---|
2 | #MOVED from generic boundary conditions 27 Nov 2008 |
---|
3 | |
---|
4 | |
---|
5 | |
---|
6 | |
---|
7 | |
---|
8 | #THIS FAR (10/8/4) |
---|
9 | class Connective_boundary(Boundary): |
---|
10 | """Connective boundary returns values for the |
---|
11 | conserved quantities from a volume as defined by a connection table |
---|
12 | mapping between tuples of (volume id, face id) for volumes that |
---|
13 | have their boundaries connected. |
---|
14 | |
---|
15 | FIXME: Perhaps include possibility of mapping between |
---|
16 | different domains as well |
---|
17 | |
---|
18 | FIXME: In case of shallow water we may want to have a |
---|
19 | special version that casts this in terms of height rather than stage |
---|
20 | """ |
---|
21 | |
---|
22 | |
---|
23 | def __init__(self, table): |
---|
24 | from domain import Volume |
---|
25 | |
---|
26 | Boundary.__init__(self) |
---|
27 | |
---|
28 | self.connection_table = table |
---|
29 | self.Volume = Volume |
---|
30 | |
---|
31 | def __repr__(self): |
---|
32 | return 'Connective boundary' |
---|
33 | |
---|
34 | #FIXME: IF we ever need to get field_values from connected volume, |
---|
35 | #that method could be overridden here (using same idea as in |
---|
36 | #get_conserved_quantities |
---|
37 | #def get_field_values() |
---|
38 | |
---|
39 | def get_conserved_quantities(self, volume, face=0): |
---|
40 | |
---|
41 | id = volume.id |
---|
42 | if self.connection_table.has_key((id, face)): |
---|
43 | other_id, other_face = self.connection_table[(id, face)] |
---|
44 | |
---|
45 | other_volume = self.Volume.instances[other_id] |
---|
46 | cmd = 'q = other_volume.conserved_quantities_face%d' %face; |
---|
47 | exec(cmd) |
---|
48 | return q |
---|
49 | else: |
---|
50 | msg = 'Volume, face tuple ($d, %d) has not been mapped'\ |
---|
51 | %(id, face) |
---|
52 | raise msg |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | #FIXME: Add a boundary with a general function of x,y, and t |
---|
59 | |
---|
60 | #FIXME: Add periodic boundaries e.g.: |
---|
61 | # Attempt at periodic conditions from advection_spik. Remember this |
---|
62 | # |
---|
63 | #first = 2*(N-1)*N |
---|
64 | #for i in range(1,2*N+1,2): |
---|
65 | # k = first + i-1# |
---|
66 | # |
---|
67 | # print i,k |
---|
68 | # |
---|
69 | # domain[i].faces[2].neighbour = domain[k].faces[1] |
---|
70 | # domain[k].faces[1].neighbour = domain[i].faces[2] |
---|
71 | |
---|
72 | |
---|
73 | |
---|
74 | class General_boundary(Boundary): |
---|
75 | """General boundary which can compute conserved quantities based on |
---|
76 | their previous value, conserved quantities of its neighbour and model time. |
---|
77 | |
---|
78 | Must specify initial conserved quantities, |
---|
79 | neighbour, |
---|
80 | domain to get access to model time |
---|
81 | a function f(q_old, neighbours_q, t) which must return |
---|
82 | new conserved quantities q as a function time |
---|
83 | |
---|
84 | FIXME: COMPLETE UNTESTED - JUST AN IDEA |
---|
85 | """ |
---|
86 | |
---|
87 | def __init__(self, neighbour=None, conserved_quantities=None, domain=None, f=None): |
---|
88 | Boundary.__init__(self, neighbour=neighbour, conserved_quantities=conserved_quantities) |
---|
89 | |
---|
90 | self.f = f |
---|
91 | self.domain = domain |
---|
92 | |
---|
93 | |
---|
94 | def get_conserved_quantities(self, volume=None, face=0): |
---|
95 | |
---|
96 | # FIXME (Ole): I think this should be get_time(), see ticket:306 |
---|
97 | return self.f(self.conserved_quantities, |
---|
98 | neighbour.conserved_quantities, |
---|
99 | self.domain.time) |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | |
---|