1 |
# $Id$ |
2 |
|
3 |
|
4 |
from esys.escript import * |
5 |
from esys.escript.modelframe import Model,ParameterSet |
6 |
from esys import finley |
7 |
|
8 |
class FinleyReader(ParameterSet): |
9 |
""" |
10 |
Generates a mesh over a rectangular domain finley. |
11 |
|
12 |
@ivar filename: |
13 |
@ivar intergrationOrder |
14 |
@ivar domain: |
15 |
""" |
16 |
def __init__(self,debug=False): |
17 |
Model.__init__(self,debug=debug) |
18 |
self.declareParameter(source="none",\ |
19 |
integrationOrder=-1) |
20 |
self._domain=None |
21 |
|
22 |
def domain(self): |
23 |
if self._domain==None: |
24 |
self._domain=finley.ReadMesh(self.source,integrationOrder) |
25 |
self.trace("mesh read from %s"%self.source) |
26 |
return self.domain |
27 |
|
28 |
class RectangularDomain(ParameterSet): |
29 |
""" |
30 |
Generates a mesh over a rectangular domain finley. |
31 |
|
32 |
@ivar dim: |
33 |
@ivar l: |
34 |
@ivar n: |
35 |
@ivar order: |
36 |
@ivar periodic: |
37 |
@ivar intergration order: |
38 |
@ivar domain: |
39 |
""" |
40 |
def __init__(self,debug=False): |
41 |
Model.__init__(self,debug=debug) |
42 |
self.declareParameter(dim=2,\ |
43 |
l=[1.,1.,1.],\ |
44 |
n=[10,10,10], \ |
45 |
order=1,\ |
46 |
periodic=[False,False,False],\ |
47 |
integrationOrder=-1) |
48 |
self._domain=None |
49 |
|
50 |
def domain(self): |
51 |
if self._domain==None: |
52 |
if self.dim==2: |
53 |
self._domain=finley.Rectangle(n0=self.n[0],\ |
54 |
n1=self.n[1],\ |
55 |
l0=self.l[0],\ |
56 |
l1=self.l[1],\ |
57 |
order=self.order, \ |
58 |
periodic0=self.periodic[0], \ |
59 |
periodic1=self.periodic[1], \ |
60 |
integrationOrder=self.integrationOrder) |
61 |
else: |
62 |
self._domain=finley.Brick(n0=self.n[0],\ |
63 |
n1=self.n[1],\ |
64 |
n2=self.n[2],\ |
65 |
l0=self.l[0],\ |
66 |
l1=self.l[1],\ |
67 |
l2=self.l[2],\ |
68 |
order=self.order, \ |
69 |
periodic0=self.periodic[0], \ |
70 |
periodic1=self.periodic[1], \ |
71 |
periodic2=self.periodic[2], \ |
72 |
integrationOrder=self.integrationOrder) |
73 |
|
74 |
return self._domain |
75 |
|
76 |
class ConstrainValue(Model): |
77 |
""" |
78 |
selects values for a given distribution to be used as a constrain. the location of the |
79 |
constrain are he faces of a rectangular domain. This Model is typically used in |
80 |
time dependend problems to fix the values in a given initial condition. |
81 |
""" |
82 |
def __init__(self,debug=False): |
83 |
Model.__init__(self,debug=debug) |
84 |
self.declareParameter(domain=None, \ |
85 |
value=0, \ |
86 |
top=True, \ |
87 |
bottom=True,\ |
88 |
front=False, \ |
89 |
back=False,\ |
90 |
left=False,\ |
91 |
right=False,\ |
92 |
constrain_value = None, \ |
93 |
location_constrained_value=None) |
94 |
def doInitialization(self): |
95 |
""" |
96 |
initialize time stepping |
97 |
""" |
98 |
x=self.domain.getX() |
99 |
d=self.domain.getDim() |
100 |
self.location_constrained_value=0 |
101 |
x0=x[0] |
102 |
if self.left: |
103 |
self.location_constrained_value=self.location_constrained_value+whereZero(x0-inf(x0)) |
104 |
if self.right: |
105 |
self.location_constrained_value=self.location_constrained_value+whereZero(x0-sup(x0)) |
106 |
x0=x[d-1] |
107 |
if self.buttom: |
108 |
self.location_constrained_value=self.location_constrained_value+whereZero(x0-inf(x0)) |
109 |
if self.top: |
110 |
self.location_constrained_value=self.location_constrained_value+whereZero(x0-sup(x0)) |
111 |
if d>2: |
112 |
x0=x[1] |
113 |
if self.front: |
114 |
self.location_constrained_value=self.location_constrained_value+whereZero(x0-inf(x0)) |
115 |
if self.back: |
116 |
self.location_constrained_value=self.location_constrained_value+whereZero(x0-sup(x0)) |
117 |
self.constrain_value=self.value*self.location_constrained_value |
118 |
|
119 |
class ScalarConstrainer(ParameterSet): |
120 |
""" |
121 |
Creates a characteristic function for the location of constraints |
122 |
for a scalar value. |
123 |
|
124 |
In the case that the spatial dimension is two, the arguments front |
125 |
and back are ignored. |
126 |
|
127 |
@ivar domain (in): rectangular domain |
128 |
@ivar left (in): True to set a constraint at the left face of the |
129 |
domain (x[0]=min x[0]), default is False |
130 |
@ivar right (in): True to set a constraint at the left face of the |
131 |
domain (x[0]=max x[0]), default is False |
132 |
@ivar top (in): True to set a constraint at the left face of the |
133 |
domain (x[1]=min x[1]), default is False |
134 |
@ivar bottom (in): True to set a constraint at the left face of the |
135 |
domain (x[1]=max x[1]), default is False |
136 |
@ivar front (in): True to set a constraint at the left face of the |
137 |
domain (x[2]=min x[2]), default is False |
138 |
@ivar back (in): True to set a constraint at the left face of the |
139 |
domain (x[2]=max x[2]), default is False |
140 |
@ivar location_of_constraint (out): object that defines the location |
141 |
of the constraints. |
142 |
""" |
143 |
def __init__(self,debug=False): |
144 |
ParameterSet.__init__(self,debug=debug) |
145 |
self.declareParameter(domain=None, \ |
146 |
left=False, \ |
147 |
right=False, \ |
148 |
top=False, \ |
149 |
bottom=False, \ |
150 |
front=False, \ |
151 |
back=False) |
152 |
self._location_of_constraint=None |
153 |
|
154 |
def location_of_constraint(self): |
155 |
""" |
156 |
Returns the mask of the location of constraint. |
157 |
""" |
158 |
if self._location_of_constraint==None: |
159 |
x=self.domain.getX() |
160 |
self._location_of_constraint=Scalar(0,x.getFunctionSpace()) |
161 |
if self.domain.getDim()==3: |
162 |
if self.left: self._location_of_constraint+=whereZero(x[0]-inf(x[0])) |
163 |
if self.right: self._location_of_constraint+=whereZero(x[0]-sup(x[0])) |
164 |
if self.front: self._location_of_constraint+=whereZero(x[1]-inf(x[1])) |
165 |
if self.back: self._location_of_constraint+=whereZero(x[1]-sup(x[1])) |
166 |
if self.bottom: self._location_of_constraint+=whereZero(x[2]-inf(x[2])) |
167 |
if self.top: self._location_of_constraint+=whereZero(x[2]-sup(x[2])) |
168 |
else: |
169 |
if self.left: self._location_of_constraint+=whereZero(x[0]-inf(x[0])) |
170 |
if self.right: self._location_of_constraint+=whereZero(x[0]-sup(x[0])) |
171 |
if self.bottom: self._location_of_constraint+=whereZero(x[1]-inf(x[1])) |
172 |
if self.top: self._location_of_constraint+=whereZero(x[1]-sup(x[1])) |
173 |
return self._location_of_constraint |
174 |
|
175 |
class VectorConstrainer(ParameterSet): |
176 |
""" |
177 |
Creates a characteristic function for the location of constraints |
178 |
for a scalar value. |
179 |
|
180 |
@ivar domain (in): rectangular domain |
181 |
@ivar left (in): list of three boolean. left[i]==True sets a |
182 |
constraint for the i-th component at the left |
183 |
face of the domain (x[0]=min x[0]), |
184 |
default is [False,False,False] |
185 |
@ivar right (in): list of three boolean. left[i]==True sets a |
186 |
constraint for the i-th component at the right |
187 |
face of the domain (x[0]=max x[0]), |
188 |
default is [False,False,False] |
189 |
@ivar top (in): list of three boolean. left[i]==True sets a |
190 |
constraint for the i-th component at the top |
191 |
face of the domain (x[1]=min x[1]), |
192 |
default is [False,False,False] |
193 |
@ivar bottom (in): list of three boolean. left[i]==True sets a |
194 |
constraint for the i-th component at the bottom |
195 |
face of the domain (x[1]=min x[1]), |
196 |
default is [False,False,False] |
197 |
@ivar front (in): list of three boolean. left[i]==True sets a |
198 |
constraint for the i-th component at the front |
199 |
face of the domain (x[2]=min x[2]), |
200 |
default is [False,False,False] |
201 |
@ivar back (in): list of three boolean. left[i]==True sets a |
202 |
constraint for the i-th component at the back |
203 |
face of the domain (x[2]=max x[2]), |
204 |
default is [False,False,False] |
205 |
@ivar location_of_constraint (callable): object that defines the location of the constraints for each vector component. |
206 |
|
207 |
In the case that the spatial dimension is two, thh arguments front and |
208 |
back as well as the third component of each argument is ignored. |
209 |
""" |
210 |
def __init__(self,debug=False): |
211 |
ParameterSet.__init__(self,debug=debug) |
212 |
self.declareParameter(domain=None, \ |
213 |
left=[0,0,0], \ |
214 |
right=[0,0,0], \ |
215 |
top=[0,0,0], \ |
216 |
bottom=[0,0,0], \ |
217 |
front=[0,0,0], |
218 |
back=[0,0,0]) |
219 |
self._location_of_constraint=None |
220 |
def location_of_constraint(self): |
221 |
""" |
222 |
Returns the mask of the location of constraint. |
223 |
""" |
224 |
if self._location_of_constraint==None: |
225 |
x=self.domain.getX() |
226 |
self._location_of_constraint=Vector(0,x.getFunctionSpace()) |
227 |
if self.domain.getDim()==3: |
228 |
left_mask=whereZero(x[0]-inf(x[0])) |
229 |
if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.,0.] |
230 |
if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.,0.] |
231 |
if self.left[2]: self._location_of_constraint+=left_mask*[0.,0.,1.] |
232 |
right_mask=whereZero(x[0]-sup(x[0])) |
233 |
if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.,0.] |
234 |
if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.,0.] |
235 |
if self.right[2]: self._location_of_constraint+=right_mask*[0.,0.,1.] |
236 |
front_mask=whereZero(x[1]-inf(x[1])) |
237 |
if self.front[0]: self._location_of_constraint+=front_mask*[1.,0.,0.] |
238 |
if self.front[1]: self._location_of_constraint+=front_mask*[0.,1.,0.] |
239 |
if self.front[2]: self._location_of_constraint+=front_mask*[0.,0.,1.] |
240 |
back_mask=whereZero(x[1]-sup(x[1])) |
241 |
if self.back[0]: self._location_of_constraint+=back_mask*[1.,0.,0.] |
242 |
if self.back[1]: self._location_of_constraint+=back_mask*[0.,1.,0.] |
243 |
if self.back[2]: self._location_of_constraint+=back_mask*[0.,0.,1.] |
244 |
bottom_mask=whereZero(x[2]-inf(x[2])) |
245 |
if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.,0.] |
246 |
if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.,0.] |
247 |
if self.bottom[2]: self._location_of_constraint+=bottom_mask*[0.,0.,1.] |
248 |
top_mask=whereZero(x[2]-sup(x[2])) |
249 |
if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.,0.] |
250 |
if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.,0.] |
251 |
if self.top[2]: self._location_of_constraint+=top_mask*[0.,0.,1.] |
252 |
else: |
253 |
left_mask=whereZero(x[0]-inf(x[0])) |
254 |
if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.] |
255 |
if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.] |
256 |
right_mask=whereZero(x[0]-sup(x[0])) |
257 |
if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.] |
258 |
if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.] |
259 |
bottom_mask=whereZero(x[1]-inf(x[1])) |
260 |
if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.] |
261 |
if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.] |
262 |
top_mask=whereZero(x[1]-sup(x[1])) |
263 |
if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.] |
264 |
if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.] |
265 |
return self._location_of_constraint |
266 |
|
267 |
# vim: expandtab shiftwidth=4: |