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 ScalarConstrainer(ParameterSet): |
77 |
""" |
78 |
Creates a characteristic function for the location of constraints |
79 |
for a scalar value. |
80 |
|
81 |
In the case that the spatial dimension is two, the arguments front |
82 |
and back are ignored. |
83 |
|
84 |
@ivar domain (in): rectangular domain |
85 |
@ivar left (in): True to set a constraint at the left face of the |
86 |
domain (x[0]=min x[0]), default is False |
87 |
@ivar right (in): True to set a constraint at the left face of the |
88 |
domain (x[0]=max x[0]), default is False |
89 |
@ivar top (in): True to set a constraint at the left face of the |
90 |
domain (x[1]=min x[1]), default is False |
91 |
@ivar bottom (in): True to set a constraint at the left face of the |
92 |
domain (x[1]=max x[1]), default is False |
93 |
@ivar front (in): True to set a constraint at the left face of the |
94 |
domain (x[2]=min x[2]), default is False |
95 |
@ivar back (in): True to set a constraint at the left face of the |
96 |
domain (x[2]=max x[2]), default is False |
97 |
@ivar location_of_constraint (out): object that defines the location |
98 |
of the constraints. |
99 |
""" |
100 |
def __init__(self,debug=False): |
101 |
ParameterSet.__init__(self,debug=debug) |
102 |
self.declareParameter(domain=None, \ |
103 |
left=False, \ |
104 |
right=False, \ |
105 |
top=False, \ |
106 |
bottom=False, \ |
107 |
front=False, \ |
108 |
back=False) |
109 |
self._location_of_constraint=None |
110 |
|
111 |
def location_of_constraint(self): |
112 |
""" |
113 |
Returns the mask of the location of constraint. |
114 |
""" |
115 |
if self._location_of_constraint==None: |
116 |
x=self.domain.getX() |
117 |
self._location_of_constraint=Scalar(0,x.getFunctionSpace()) |
118 |
if self.domain.getDim()==3: |
119 |
if self.left: self._location_of_constraint+=whereZero(x[0]-inf(x[0])) |
120 |
if self.right: self._location_of_constraint+=whereZero(x[0]-sup(x[0])) |
121 |
if self.front: self._location_of_constraint+=whereZero(x[1]-inf(x[1])) |
122 |
if self.back: self._location_of_constraint+=whereZero(x[1]-sup(x[1])) |
123 |
if self.bottom: self._location_of_constraint+=whereZero(x[2]-inf(x[2])) |
124 |
if self.top: self._location_of_constraint+=whereZero(x[2]-sup(x[2])) |
125 |
else: |
126 |
if self.left: self._location_of_constraint+=whereZero(x[0]-inf(x[0])) |
127 |
if self.right: self._location_of_constraint+=whereZero(x[0]-sup(x[0])) |
128 |
if self.bottom: self._location_of_constraint+=whereZero(x[1]-inf(x[1])) |
129 |
if self.top: self._location_of_constraint+=whereZero(x[1]-sup(x[1])) |
130 |
return self._location_of_constraint |
131 |
|
132 |
class VectorConstrainer(ParameterSet): |
133 |
""" |
134 |
Creates a characteristic function for the location of constraints |
135 |
for a scalar value. |
136 |
|
137 |
@ivar domain (in): rectangular domain |
138 |
@ivar left (in): list of three boolean. left[i]==True sets a |
139 |
constraint for the i-th component at the left |
140 |
face of the domain (x[0]=min x[0]), |
141 |
default is [False,False,False] |
142 |
@ivar right (in): list of three boolean. left[i]==True sets a |
143 |
constraint for the i-th component at the right |
144 |
face of the domain (x[0]=max x[0]), |
145 |
default is [False,False,False] |
146 |
@ivar top (in): list of three boolean. left[i]==True sets a |
147 |
constraint for the i-th component at the top |
148 |
face of the domain (x[1]=min x[1]), |
149 |
default is [False,False,False] |
150 |
@ivar bottom (in): list of three boolean. left[i]==True sets a |
151 |
constraint for the i-th component at the bottom |
152 |
face of the domain (x[1]=min x[1]), |
153 |
default is [False,False,False] |
154 |
@ivar front (in): list of three boolean. left[i]==True sets a |
155 |
constraint for the i-th component at the front |
156 |
face of the domain (x[2]=min x[2]), |
157 |
default is [False,False,False] |
158 |
@ivar back (in): list of three boolean. left[i]==True sets a |
159 |
constraint for the i-th component at the back |
160 |
face of the domain (x[2]=max x[2]), |
161 |
default is [False,False,False] |
162 |
@ivar location_of_constraint (callable): object that defines the location of the constraints for each vector component. |
163 |
|
164 |
In the case that the spatial dimension is two, thh arguments front and |
165 |
back as well as the third component of each argument is ignored. |
166 |
""" |
167 |
def __init__(self,debug=False): |
168 |
ParameterSet.__init__(self,debug=debug) |
169 |
self.declareParameter(domain=None, \ |
170 |
left=[0,0,0], \ |
171 |
right=[0,0,0], \ |
172 |
top=[0,0,0], \ |
173 |
bottom=[0,0,0], \ |
174 |
front=[0,0,0], |
175 |
back=[0,0,0]) |
176 |
self._location_of_constraint=None |
177 |
def location_of_constraint(self): |
178 |
""" |
179 |
Returns the mask of the location of constraint. |
180 |
""" |
181 |
if self._location_of_constraint==None: |
182 |
x=self.domain.getX() |
183 |
self._location_of_constraint=Vector(0,x.getFunctionSpace()) |
184 |
if self.domain.getDim()==3: |
185 |
left_mask=whereZero(x[0]-inf(x[0])) |
186 |
if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.,0.] |
187 |
if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.,0.] |
188 |
if self.left[2]: self._location_of_constraint+=left_mask*[0.,0.,1.] |
189 |
right_mask=whereZero(x[0]-sup(x[0])) |
190 |
if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.,0.] |
191 |
if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.,0.] |
192 |
if self.right[2]: self._location_of_constraint+=right_mask*[0.,0.,1.] |
193 |
front_mask=whereZero(x[1]-inf(x[1])) |
194 |
if self.front[0]: self._location_of_constraint+=front_mask*[1.,0.,0.] |
195 |
if self.front[1]: self._location_of_constraint+=front_mask*[0.,1.,0.] |
196 |
if self.front[2]: self._location_of_constraint+=front_mask*[0.,0.,1.] |
197 |
back_mask=whereZero(x[1]-sup(x[1])) |
198 |
if self.back[0]: self._location_of_constraint+=back_mask*[1.,0.,0.] |
199 |
if self.back[1]: self._location_of_constraint+=back_mask*[0.,1.,0.] |
200 |
if self.back[2]: self._location_of_constraint+=back_mask*[0.,0.,1.] |
201 |
bottom_mask=whereZero(x[2]-inf(x[2])) |
202 |
if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.,0.] |
203 |
if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.,0.] |
204 |
if self.bottom[2]: self._location_of_constraint+=bottom_mask*[0.,0.,1.] |
205 |
top_mask=whereZero(x[2]-sup(x[2])) |
206 |
if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.,0.] |
207 |
if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.,0.] |
208 |
if self.top[2]: self._location_of_constraint+=top_mask*[0.,0.,1.] |
209 |
else: |
210 |
left_mask=whereZero(x[0]-inf(x[0])) |
211 |
if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.] |
212 |
if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.] |
213 |
right_mask=whereZero(x[0]-sup(x[0])) |
214 |
if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.] |
215 |
if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.] |
216 |
bottom_mask=whereZero(x[1]-inf(x[1])) |
217 |
if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.] |
218 |
if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.] |
219 |
top_mask=whereZero(x[1]-sup(x[1])) |
220 |
if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.] |
221 |
if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.] |
222 |
return self._location_of_constraint |
223 |
|
224 |
# vim: expandtab shiftwidth=4: |