/[escript]/trunk/modellib/py_src/geometry.py
ViewVC logotype

Contents of /trunk/modellib/py_src/geometry.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 938 - (show annotations)
Thu Jan 25 03:40:54 2007 UTC (16 years, 2 months ago) by gross
File MIME type: text/x-python
File size: 16217 byte(s)
the FinleyReade accepts now gmsh files (use format="gmsh")
and
Simulations are accepting Models only. Moreover, there is a test now
if a all Models targeted by a model in the simulation or a subsimulation
are included in  simulation or a subsimulation. 


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 FinleyReader(ParameterSet):
15 """
16 reads finley mesh file.
17
18 @ivar source: mesh file in finley or gmsh format
19 @type source: C{DataSource}
20 @ivar intergrationOrder: integration order, default -1 (in).
21 @type intergrationOrder: C{int}
22 @ivar reducedIntegrationOrder: reduced integration order, default -1 (in).
23 @type reducedIntegrationOrder: C{int}
24 @ivar optimizeLabeling: switches on optimization of the labeling of the nodes
25 @type optimizeLabeling: C{bool}
26 """
27 def __init__(self,**kwargs):
28 """
29 initializes the object
30 """
31 super(FinleyReader,self).__init__(**kwargs)
32 self.declareParameter(source="none",
33 optimizeLabeling=True,
34 reducedIntegrationOrder=-1,
35 integrationOrder=-1)
36 self.__domain=None
37
38 def domain(self):
39 """
40 returns the domain
41
42 @return: the domain
43 @rtype: L{Domain}
44 """
45 if self.__domain == None:
46 if self.source.fileformat == "fly":
47 self.__domain=finley.ReadMesh(self.source.getLocalFileName(),self.integrationOrder)
48 elif self.source.fileformat == "gmsh":
49 self.__domain=finley.ReadGmsh(self.source.getLocalFileName(),self.integrationOrder,self.reducedIntegrationOrder, self.optimizeLabeling)
50 else:
51 raise TypeError("unknown mesh file format %s."%self.source.fileformat)
52 self.trace("mesh read from %s"%self.source)
53 return self.__domain
54
55
56 class RectangularDomain(ParameterSet):
57 """
58 Generates a mesh over a rectangular domain finley.
59
60 @ivar dim: spatial dimension, default =2 (in).
61 @type dim: spatial dimension
62 @ivar l: spatial lengths, default [1.,1.,1.] (in).
63 @type l: C{list} of C{floats}s
64 @ivar n: number of elements, default [10,10,10] (in).
65 @type n: C{list} of C{int}s
66 @ivar order: element order, default 1 (in).
67 @type order: C{int}
68 @ivar periodic: flags for periodicity, default [False,False,False] (in).
69 @type periodic: C{list} of C{bool}s
70 @ivar intergrationOrder: integration order, default -1 (in).
71 @type intergrationOrder: C{int}
72 """
73 def __init__(self,**kwargs):
74 """
75 initializes the object
76 """
77 super(RectangularDomain,self).__init__(**kwargs)
78 self.declareParameter(dim=2,\
79 l=[1.,1.,1.],\
80 n=[10,10,10], \
81 order=1,\
82 periodic=[False,False,False],
83 integrationOrder=-1)
84 self.__domain=None
85
86 def domain(self):
87 """
88 returns the domain
89
90 @return: the domain
91 @rtype: L{Domain}
92 """
93 if self.__domain==None:
94 if self.dim==2:
95 self.__domain=finley.Rectangle(n0=self.n[0],\
96 n1=self.n[1],\
97 l0=self.l[0],\
98 l1=self.l[1],\
99 order=self.order, \
100 periodic0=self.periodic[0], \
101 periodic1=self.periodic[1], \
102 integrationOrder=self.integrationOrder)
103 else:
104 self.__domain=finley.Brick(n0=self.n[0],\
105 n1=self.n[1],\
106 n2=self.n[2],\
107 l0=self.l[0],\
108 l1=self.l[1],\
109 l2=self.l[2],\
110 order=self.order, \
111 periodic0=self.periodic[0], \
112 periodic1=self.periodic[1], \
113 periodic2=self.periodic[2], \
114 integrationOrder=self.integrationOrder)
115 return self.__domain
116
117 class UpdateGeometry(Model):
118 """
119 applies a displacement field to a domain
120
121 @ivar displacement: displacements applied to the original mesh coordinates (in).
122 @type displacement: L{escript.Vector}
123 @ivar domain: domain
124 @type domain: L{escript.Domain}
125 """
126 def __init__(self,**kwargs):
127 """
128 set-up the object
129 """
130 super(UpdateGeometry, self).__init__(**kwargs)
131 self.declareParameter(domain=None,\
132 displacement=None)
133
134
135 def doInitialization(self):
136 """
137 initialize model
138 """
139 self.__x=self.domain.getX()
140 self.__reset=True
141
142 def doStepPreprocessing(self,dt):
143 """
144 applies the current L{displacement} to mesh nodes if required.
145 """
146 if self.__reset:
147 self.trace("mesh nodes updated.")
148 self.domain.setX(self.__x+self.displacement)
149 self.__reset=False
150
151 def doStep(self,dt):
152 """
153 applies the current L{displacement} to mesh nodes.
154 """
155 self.trace("mesh nodes updated.")
156 self.domain.setX(self.__x+self.displacement)
157 self.__reset=True
158
159 def doStepPostprocessing(self,dt):
160 """
161 marks nodes as beeing updated.
162 """
163 self.__reset=False
164
165 class ScalarConstrainerOverBox(Model):
166 """
167 Creates a characteristic function for the location of constraints
168 for a scalar value and selects the value from an initial value
169 ate these locations.
170
171 In the case that the spatial dimension is two, the arguments front and back are ignored.
172
173 @ivar domain: domain (in).
174 @ivar left: True to set a constraint at the left face of the domain (x[0]=min x[0]), default False (in).
175 @ivar right: True to set a constraint at the left face of the domain (x[0]=max x[0]), default False (in).
176 @ivar top: True to set a constraint at the left face of the domain (x[1]=min x[1]), default False (in).
177 @ivar bottom: True to set a constraint at the left face of the domain (x[1]=max x[1]), default False (in).
178 @ivar front: True to set a constraint at the left face of the domain (x[2]=min x[2]), default False (in).
179 @ivar back: True to set a constraint at the left face of the domain (x[2]=max x[2]), default False (in).
180 @ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
181 """
182 def __init__(self,**kwargs):
183 super(ScalarConstrainerOverBox, self).__init__(**kwargs)
184 self.declareParameter(domain=None, \
185 value=None, \
186 left=False, \
187 right=False, \
188 top=False, \
189 bottom=False, \
190 front=False, \
191 back=False, \
192 tol=1.e-8)
193 self.__value_of_constraint = None
194 self.__location_of_constraint=None
195 def location_of_constraint(self):
196 """
197 return the values used to constrain a solution
198
199 @return: the mask marking the locations of the constraints
200 @rtype: L{escript.Scalar}
201 """
202 if self.__location_of_constraint == None: self.__setOutput()
203 return self.__location_of_constraint
204
205 def value_of_constraint(self):
206 """
207 return the values used to constrain a solution
208
209 @return: values to be used at the locations of the constraints. If
210 L{value} is not given C{None} is rerturned.
211 @rtype: L{escript.Scalar}
212 """
213 if self.__location_of_constraint == None: self.__setOutput()
214 return self.__value_of_constraint
215
216 def __setOutput(self):
217 x=self.domain.getX()
218 self.__location_of_constraint=Scalar(0,x.getFunctionSpace())
219 if self.domain.getDim()==3:
220 x0,x1,x2=x[0],x[1],x[2]
221 if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol)
222 if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol)
223 if self.front: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol)
224 if self.back: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol)
225 if self.bottom: self.__location_of_constraint+=whereZero(x2-inf(x2),self.tol)
226 if self.top: self.__location_of_constraint+=whereZero(x2-sup(x2),self.tol)
227 else:
228 x0,x1=x[0],x[1]
229 if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol)
230 if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol)
231 if self.bottom: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol)
232 if self.top: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol)
233 if self.value:
234 self.__value_of_constraint=self.__location_of_constraint*self.value
235
236 class VectorConstrainerOverBox(Model):
237 """
238 Creates a characteristic function for the location of constraints vector value.
239 In the case that the spatial dimension is two, the arguments front and
240 back as well as the third component of each argument is ignored.
241
242 @ivar domain: domain
243 @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]),
244 default [False,False,False] (in).
245 @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]),
246 default [False,False,False] (in).
247 @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]),
248 default [False,False,False] (in).
249 @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]),
250 default [False,False,False] (in).
251 @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]),
252 default [False,False,False] (in).
253 @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]),
254 default [False,False,False] (in).
255 @ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
256 """
257 def __init__(self, **kwargs):
258 super(VectorConstrainerOverBox, self).__init__(**kwargs)
259 self.declareParameter(domain=None, \
260 value=None, \
261 left=[0,0,0], \
262 right=[0,0,0], \
263 top=[0,0,0], \
264 bottom=[0,0,0], \
265 front=[0,0,0], \
266 back=[0,0,0], \
267 tol=1.e-8)
268 self.__value_of_constraint = None
269 self.__location_of_constraint=None
270
271 def location_of_constraint(self):
272 """
273 return the values used to constrain a solution
274
275 @return: the mask marking the locations of the constraints
276 @rtype: L{escript.Vector}
277 """
278 if self.__location_of_constraint == None: self.__setOutput()
279 return self.__location_of_constraint
280
281 def value_of_constraint(self):
282 """
283 return the values used to constrain a solution
284
285 @return: values to be used at the locations of the constraints. If
286 L{value} is not given C{None} is rerturned.
287 @rtype: L{escript.Vector}
288 """
289 if self.__location_of_constraint == None: self.__setOutput()
290 return self.__value_of_constraint
291
292 def __setOutput(self):
293 x=self.domain.getX()
294 self.__location_of_constraint=Vector(0,x.getFunctionSpace())
295 if self.domain.getDim()==3:
296 x0,x1,x2=x[0],x[1],x[2]
297 left_mask=whereZero(x0-inf(x0),self.tol)
298 if self.left[0]: self.__location_of_constraint+=left_mask*[1.,0.,0.]
299 if self.left[1]: self.__location_of_constraint+=left_mask*[0.,1.,0.]
300 if self.left[2]: self.__location_of_constraint+=left_mask*[0.,0.,1.]
301 right_mask=whereZero(x0-sup(x0),self.tol)
302 if self.right[0]: self.__location_of_constraint+=right_mask*[1.,0.,0.]
303 if self.right[1]: self.__location_of_constraint+=right_mask*[0.,1.,0.]
304 if self.right[2]: self.__location_of_constraint+=right_mask*[0.,0.,1.]
305 front_mask=whereZero(x1-inf(x1),self.tol)
306 if self.front[0]: self.__location_of_constraint+=front_mask*[1.,0.,0.]
307 if self.front[1]: self.__location_of_constraint+=front_mask*[0.,1.,0.]
308 if self.front[2]: self.__location_of_constraint+=front_mask*[0.,0.,1.]
309 back_mask=whereZero(x1-sup(x1),self.tol)
310 if self.back[0]: self.__location_of_constraint+=back_mask*[1.,0.,0.]
311 if self.back[1]: self.__location_of_constraint+=back_mask*[0.,1.,0.]
312 if self.back[2]: self.__location_of_constraint+=back_mask*[0.,0.,1.]
313 bottom_mask=whereZero(x2-inf(x2),self.tol)
314 if self.bottom[0]: self.__location_of_constraint+=bottom_mask*[1.,0.,0.]
315 if self.bottom[1]: self.__location_of_constraint+=bottom_mask*[0.,1.,0.]
316 if self.bottom[2]: self.__location_of_constraint+=bottom_mask*[0.,0.,1.]
317 top_mask=whereZero(x2-sup(x2),self.tol)
318 if self.top[0]: self.__location_of_constraint+=top_mask*[1.,0.,0.]
319 if self.top[1]: self.__location_of_constraint+=top_mask*[0.,1.,0.]
320 if self.top[2]: self.__location_of_constraint+=top_mask*[0.,0.,1.]
321 if self.value:
322 self.__value_of_constraint=self.__location_of_constraint*self.value
323 else:
324 x0,x1=x[0],x[1]
325 left_mask=whereZero(x0-inf(x0),self.tol)
326 if self.left[0]: self.__location_of_constraint+=left_mask*[1.,0.]
327 if self.left[1]: self.__location_of_constraint+=left_mask*[0.,1.]
328 right_mask=whereZero(x0-sup(x0),self.tol)
329 if self.right[0]: self.__location_of_constraint+=right_mask*[1.,0.]
330 if self.right[1]: self.__location_of_constraint+=right_mask*[0.,1.]
331 bottom_mask=whereZero(x1-inf(x1),self.tol)
332 if self.bottom[0]: self.__location_of_constraint+=bottom_mask*[1.,0.]
333 if self.bottom[1]: self.__location_of_constraint+=bottom_mask*[0.,1.]
334 top_mask=whereZero(x1-sup(x1),self.tol)
335 if self.top[0]: self.__location_of_constraint+=top_mask*[1.,0.]
336 if self.top[1]: self.__location_of_constraint+=top_mask*[0.,1.]
337 if self.value:
338 self.__value_of_constraint=self.__location_of_constraint*self.value[:2]
339
340 # vim: expandtab shiftwidth=4:

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26