1 |
# $Id$ |
2 |
|
3 |
__copyright__=""" Copyright (c) 2006 by ACcESS MNRF |
4 |
http://www.access.edu.au |
5 |
Primary Business: Queensland, Australia""" |
6 |
__license__="""Licensed under the Open Software License version 3.0 |
7 |
http://www.opensource.org/licenses/osl-3.0.php""" |
8 |
|
9 |
|
10 |
from esys.escript import * |
11 |
from esys.escript.modelframe import Model,ParameterSet |
12 |
from esys import finley |
13 |
|
14 |
class Domain(Model): |
15 |
""" |
16 |
template L{Model} for a domain. |
17 |
|
18 |
@ivar intergrationOrder: integration order, default -1 (in). |
19 |
@type intergrationOrder: C{int} |
20 |
@ivar displacement: displacements applied to the original mesh coordinates |
21 |
@type displacement: C{None} or L{escript.Vector} |
22 |
@ivar domain: domain (out) |
23 |
@type domain: L{escript.Domain} |
24 |
""" |
25 |
def __init__(self,debug=False): |
26 |
""" |
27 |
initializes the object |
28 |
""" |
29 |
super(Domain, self).__init__(debug=debug) |
30 |
self.declareParameter(domain=None,\ |
31 |
displacement=None,\ |
32 |
integrationOrder=-1) |
33 |
|
34 |
|
35 |
def doInitialization(self): |
36 |
""" |
37 |
applies an initial L{displacement} to the mesh nodes (if not equal to C{None}) |
38 |
""" |
39 |
self.__x=self.domain.getX() |
40 |
if self.displacement: |
41 |
self.trace("mesh nodes updated in initialization.") |
42 |
self.domain.setX(self.__x+self.displacement) |
43 |
|
44 |
def doStepPreprocessing(self,dt): |
45 |
""" |
46 |
applies the final L{displacement} to mesh nodes. |
47 |
""" |
48 |
self.__do_final_update=True |
49 |
|
50 |
def doStep(self,dt): |
51 |
""" |
52 |
applies the current L{displacement} to mesh nodes. |
53 |
""" |
54 |
if self.displacement: |
55 |
self.trace("mesh nodes updated in update.") |
56 |
self.domain.setX(self.__x+self.displacement) |
57 |
self.__do_final_update=False |
58 |
|
59 |
def doStepPostprocessing(self,dt): |
60 |
""" |
61 |
applies the final L{displacement} to mesh nodes. |
62 |
""" |
63 |
if self.displacement and self.__do_final_update: |
64 |
self.trace("final mesh nodes update.") |
65 |
self.domain.setX(self.__x+self.displacement) |
66 |
self.__update=False |
67 |
|
68 |
class FinleyReader(Domain): |
69 |
""" |
70 |
reads finley mesh file. |
71 |
|
72 |
@ivar source: file name of the finley input file |
73 |
@type source: C{str} |
74 |
""" |
75 |
def __init__(self,debug=False): |
76 |
super(FinleyReader,self).__init__(debug=debug) |
77 |
self.declareParameter(source="none") |
78 |
|
79 |
def doInitialization(self): |
80 |
self.domain=finley.ReadMesh(self.source,self.integrationOrder) |
81 |
self.trace("mesh read from %s"%self.source) |
82 |
super(FinleyReader, self).doInitialization() |
83 |
|
84 |
class RectangularDomain(Domain): |
85 |
""" |
86 |
Generates a mesh over a rectangular domain finley. |
87 |
|
88 |
@ivar dim: spatial dimension, default =2 (in). |
89 |
@type dim: spatial dimension |
90 |
@ivar l: spatial lengths, default [1.,1.,1.] (in). |
91 |
@type l: C{list} of C{floats}s |
92 |
@ivar n: number of elements, default [10,10,10] (in). |
93 |
@type n: C{list} of C{int}s |
94 |
@ivar order: element order, default 1 (in). |
95 |
@type order: C{int} |
96 |
@ivar periodic: flags for periodicity, default [False,False,False] (in). |
97 |
@type periodic: C{list} of C{bool}s |
98 |
""" |
99 |
def __init__(self,debug=False): |
100 |
""" |
101 |
initializes the object |
102 |
""" |
103 |
super(RectangularDomain,self).__init__(debug=debug) |
104 |
self.declareParameter(dim=2,\ |
105 |
l=[1.,1.,1.],\ |
106 |
n=[10,10,10], \ |
107 |
order=1,\ |
108 |
periodic=[False,False,False]) |
109 |
|
110 |
def doInitialization(self): |
111 |
""" |
112 |
initializes the object |
113 |
""" |
114 |
if self.dim==2: |
115 |
self.domain=finley.Rectangle(n0=self.n[0],\ |
116 |
n1=self.n[1],\ |
117 |
l0=self.l[0],\ |
118 |
l1=self.l[1],\ |
119 |
order=self.order, \ |
120 |
periodic0=self.periodic[0], \ |
121 |
periodic1=self.periodic[1], \ |
122 |
integrationOrder=self.integrationOrder) |
123 |
else: |
124 |
self.__domain=finley.Brick(n0=self.n[0],\ |
125 |
n1=self.n[1],\ |
126 |
n2=self.n[2],\ |
127 |
l0=self.l[0],\ |
128 |
l1=self.l[1],\ |
129 |
l2=self.l[2],\ |
130 |
order=self.order, \ |
131 |
periodic0=self.periodic[0], \ |
132 |
periodic1=self.periodic[1], \ |
133 |
periodic2=self.periodic[2], \ |
134 |
integrationOrder=self.integrationOrder) |
135 |
super(RectangularDomain, self).doInitialization() |
136 |
|
137 |
|
138 |
class ScalarConstrainer(Model): |
139 |
""" |
140 |
Creates a characteristic function for the location of constraints |
141 |
for a scalar value and selects the value from an initial value |
142 |
ate these locations. |
143 |
|
144 |
In the case that the spatial dimension is two, the arguments front and back are ignored. |
145 |
|
146 |
@ivar domain: domain (in). |
147 |
@ivar left: True to set a constraint at the left face of the domain (x[0]=min x[0]), default False (in). |
148 |
@ivar right: True to set a constraint at the left face of the domain (x[0]=max x[0]), default False (in). |
149 |
@ivar top: True to set a constraint at the left face of the domain (x[1]=min x[1]), default False (in). |
150 |
@ivar bottom: True to set a constraint at the left face of the domain (x[1]=max x[1]), default False (in). |
151 |
@ivar front: True to set a constraint at the left face of the domain (x[2]=min x[2]), default False (in). |
152 |
@ivar back: True to set a constraint at the left face of the domain (x[2]=max x[2]), default False (in). |
153 |
@ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in). |
154 |
@ivar location_of_constraint: locations of the constraints (out). |
155 |
@ivar constraint: locations of the constraints (out). |
156 |
""" |
157 |
def __init__(self,debug=False): |
158 |
ParameterSet.__init__(self,debug=debug) |
159 |
self.declareParameter(domain=None, \ |
160 |
value=0, \ |
161 |
left=False, \ |
162 |
right=False, \ |
163 |
top=False, \ |
164 |
bottom=False, \ |
165 |
front=False, \ |
166 |
back=False, \ |
167 |
tol=1.e-8, \ |
168 |
value_of_constraint = None, \ |
169 |
location_of_constraint=None) |
170 |
def doInitialization(self): |
171 |
""" |
172 |
Returns the mask of the location of constraint. |
173 |
""" |
174 |
x=self.domain.getX() |
175 |
self.location_of_constraint=Scalar(0,x.getFunctionSpace()) |
176 |
if self.domain.getDim()==3: |
177 |
x0,x1,x2=x[0],x[1],x[2] |
178 |
if self.left: self.location_of_constraint+=whereZero(x0-inf(x0),self.tol) |
179 |
if self.right: self.location_of_constraint+=whereZero(x0-sup(x0),self.tol) |
180 |
if self.front: self.location_of_constraint+=whereZero(x1-inf(x1),self.tol) |
181 |
if self.back: self.location_of_constraint+=whereZero(x1-sup(x1),self.tol) |
182 |
if self.bottom: self.location_of_constraint+=whereZero(x2-inf(x2),self.tol) |
183 |
if self.top: self.location_of_constraint+=whereZero(x2-sup(x2),self.tol) |
184 |
else: |
185 |
x0,x1=x[0],x[1] |
186 |
if self.left: self.location_of_constraint+=whereZero(x0-inf(x0),self.tol) |
187 |
if self.right: self.location_of_constraint+=whereZero(x0-sup(x0),self.tol) |
188 |
if self.bottom: self.location_of_constraint+=whereZero(x1-inf(x1),self.tol) |
189 |
if self.top: self.location_of_constraint+=whereZero(x1-sup(x1),self.tol) |
190 |
self.value_of_constraint=self.location_of_constraint*self.value |
191 |
|
192 |
class VectorConstrainer(Model): |
193 |
""" |
194 |
Creates a characteristic function for the location of constraints vector value. |
195 |
In the case that the spatial dimension is two, the arguments front and |
196 |
back as well as the third component of each argument is ignored. |
197 |
|
198 |
@ivar domain: domain |
199 |
@ivar left: list of three boolean. left[i]==True sets a constraint for the i-th component at the left face of the domain (x[0]=min x[0]), |
200 |
default [False,False,False] (in). |
201 |
@ivar right: list of three boolean. left[i]==True sets a constraint for the i-th component at the right face of the domain (x[0]=max x[0]), |
202 |
default [False,False,False] (in). |
203 |
@ivar top: list of three boolean. left[i]==True sets a constraint for the i-th component at the top face of the domain (x[1]=min x[1]), |
204 |
default [False,False,False] (in). |
205 |
@ivar bottom: list of three boolean. left[i]==True sets a constraint for the i-th component at the bottom face of the domain (x[1]=min x[1]), |
206 |
default [False,False,False] (in). |
207 |
@ivar front: list of three boolean. left[i]==True sets a constraint for the i-th component at the front face of the domain (x[2]=min x[2]), |
208 |
default [False,False,False] (in). |
209 |
@ivar back: list of three boolean. left[i]==True sets a constraint for the i-th component at the back face of the domain (x[2]=max x[2]), |
210 |
default [False,False,False] (in). |
211 |
@ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in). |
212 |
@ivar location_of_constraint: locations of the constraints (out). |
213 |
@ivar constraint: locations of the constraints (out). |
214 |
|
215 |
""" |
216 |
def __init__(self,debug=False): |
217 |
ParameterSet.__init__(self,debug=debug) |
218 |
self.declareParameter(domain=None, \ |
219 |
value=[0,0,0], \ |
220 |
left=[0,0,0], \ |
221 |
right=[0,0,0], \ |
222 |
top=[0,0,0], \ |
223 |
bottom=[0,0,0], \ |
224 |
front=[0,0,0], \ |
225 |
back=[0,0,0], \ |
226 |
tol=1.e-8, \ |
227 |
value_of_constraint = None, \ |
228 |
location_of_constraint=None) |
229 |
def doInitialization(self): |
230 |
""" |
231 |
sets the location_of_constraint and value_of_constraint to be kept throughout the simulation. |
232 |
""" |
233 |
if self.location_of_constraint==None: |
234 |
x=self.domain.getX() |
235 |
self.location_of_constraint=Vector(0,x.getFunctionSpace()) |
236 |
if self.domain.getDim()==3: |
237 |
x0,x1,x2=x[0],x[1],x[2] |
238 |
left_mask=whereZero(x0-inf(x0),self.tol) |
239 |
if self.left[0]: self.location_of_constraint+=left_mask*[1.,0.,0.] |
240 |
if self.left[1]: self.location_of_constraint+=left_mask*[0.,1.,0.] |
241 |
if self.left[2]: self.location_of_constraint+=left_mask*[0.,0.,1.] |
242 |
right_mask=whereZero(x0-sup(x0),self.tol) |
243 |
if self.right[0]: self.location_of_constraint+=right_mask*[1.,0.,0.] |
244 |
if self.right[1]: self.location_of_constraint+=right_mask*[0.,1.,0.] |
245 |
if self.right[2]: self.location_of_constraint+=right_mask*[0.,0.,1.] |
246 |
front_mask=whereZero(x1-inf(x1),self.tol) |
247 |
if self.front[0]: self.location_of_constraint+=front_mask*[1.,0.,0.] |
248 |
if self.front[1]: self.location_of_constraint+=front_mask*[0.,1.,0.] |
249 |
if self.front[2]: self.location_of_constraint+=front_mask*[0.,0.,1.] |
250 |
back_mask=whereZero(x1-sup(x1),self.tol) |
251 |
if self.back[0]: self.location_of_constraint+=back_mask*[1.,0.,0.] |
252 |
if self.back[1]: self.location_of_constraint+=back_mask*[0.,1.,0.] |
253 |
if self.back[2]: self.location_of_constraint+=back_mask*[0.,0.,1.] |
254 |
bottom_mask=whereZero(x2-inf(x2),self.tol) |
255 |
if self.bottom[0]: self.location_of_constraint+=bottom_mask*[1.,0.,0.] |
256 |
if self.bottom[1]: self.location_of_constraint+=bottom_mask*[0.,1.,0.] |
257 |
if self.bottom[2]: self.location_of_constraint+=bottom_mask*[0.,0.,1.] |
258 |
top_mask=whereZero(x2-sup(x2),self.tol) |
259 |
if self.top[0]: self.location_of_constraint+=top_mask*[1.,0.,0.] |
260 |
if self.top[1]: self.location_of_constraint+=top_mask*[0.,1.,0.] |
261 |
if self.top[2]: self.location_of_constraint+=top_mask*[0.,0.,1.] |
262 |
self.value_of_constraint=self.location_of_constraint*self.value |
263 |
else: |
264 |
x0,x1=x[0],x[1] |
265 |
left_mask=whereZero(x0-inf(x0),self.tol) |
266 |
if self.left[0]: self.location_of_constraint+=left_mask*[1.,0.] |
267 |
if self.left[1]: self.location_of_constraint+=left_mask*[0.,1.] |
268 |
right_mask=whereZero(x0-sup(x0),self.tol) |
269 |
if self.right[0]: self.location_of_constraint+=right_mask*[1.,0.] |
270 |
if self.right[1]: self.location_of_constraint+=right_mask*[0.,1.] |
271 |
bottom_mask=whereZero(x1-inf(x1),self.tol) |
272 |
if self.bottom[0]: self.location_of_constraint+=bottom_mask*[1.,0.] |
273 |
if self.bottom[1]: self.location_of_constraint+=bottom_mask*[0.,1.] |
274 |
top_mask=whereZero(x1-sup(x1),self.tol) |
275 |
if self.top[0]: self.location_of_constraint+=top_mask*[1.,0.] |
276 |
if self.top[1]: self.location_of_constraint+=top_mask*[0.,1.] |
277 |
self.value_of_constraint=self.location_of_constraint*self.value[:2] |
278 |
|
279 |
# vim: expandtab shiftwidth=4: |