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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 820 - (hide annotations)
Mon Aug 28 06:55:36 2006 UTC (13 years, 1 month ago) by gross
File MIME type: text/x-python
File size: 13961 byte(s)
make the modelframe test run
1 jgs 127 # $Id$
2    
3 elspeth 628 __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 jgs 127
9 elspeth 628
10 jgs 149 from esys.escript import *
11     from esys.escript.modelframe import Model,ParameterSet
12     from esys import finley
13 jgs 127
14 gross 819 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 gross 820 self.declareParameter(domain=None,\
31     displacement=None,\
32 gross 819 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.domain.setX(self.__x+self.displacement)
42    
43     def doStepPreprocessing(self,dt):
44     """
45     applies the final L{displacement} to mesh nodes.
46     """
47 gross 820 self.__updated=False
48 gross 819
49     def doStep(self,dt):
50     """
51     applies the current L{displacement} to mesh nodes.
52     """
53     if self.displacement:
54     self.domain.setX(self.__x+self.displacement)
55     self.__update=False
56    
57     def doStepPostprocessing(self,dt):
58     """
59     applies the final L{displacement} to mesh nodes.
60     """
61     if self.displacement:
62     self.domain.setX(self.__x+self.displacement)
63     self.__update=False
64    
65     class FinleyReader(Domain):
66 jgs 149 """
67 gross 819 reads finley mesh file.
68 jgs 147
69 gross 819 @ivar source: file name of the finley input file
70     @type source: C{str}
71 gross 398 """
72     def __init__(self,debug=False):
73 gross 406 super(FinleyReader,self).__init__(debug=debug)
74 gross 819 self.declareParameter(source="none")
75 gross 398
76 gross 819 def doInitialization(self):
77     self.domain=finley.ReadMesh(self.source,self.integrationOrder)
78     self.trace("mesh read from %s"%self.source)
79     super(FinleyReader, self).doInitialization()
80 gross 398
81 gross 819 class RectangularDomain(Domain):
82 gross 398 """
83     Generates a mesh over a rectangular domain finley.
84    
85 gross 819 @ivar dim: spatial dimension, default =2 (in).
86     @type dim: spatial dimension
87     @ivar l: spatial lengths, default [1.,1.,1.] (in).
88     @type l: C{list} of C{floats}s
89     @ivar n: number of elements, default [10,10,10] (in).
90     @type n: C{list} of C{int}s
91     @ivar order: element order, default 1 (in).
92     @type order: C{int}
93     @ivar periodic: flags for periodicity, default [False,False,False] (in).
94     @type periodic: C{list} of C{bool}s
95 jgs 147 """
96 jgs 127 def __init__(self,debug=False):
97 gross 819 """
98     initializes the object
99     """
100 gross 406 super(RectangularDomain,self).__init__(debug=debug)
101 jgs 147 self.declareParameter(dim=2,\
102 jgs 127 l=[1.,1.,1.],\
103     n=[10,10,10], \
104     order=1,\
105 gross 819 periodic=[False,False,False])
106 jgs 127
107 gross 819 def doInitialization(self):
108     """
109     initializes the object
110     """
111     if self.dim==2:
112     self.domain=finley.Rectangle(n0=self.n[0],\
113 jgs 147 n1=self.n[1],\
114     l0=self.l[0],\
115     l1=self.l[1],\
116     order=self.order, \
117     periodic0=self.periodic[0], \
118     periodic1=self.periodic[1], \
119     integrationOrder=self.integrationOrder)
120 gross 819 else:
121 gross 720 self.__domain=finley.Brick(n0=self.n[0],\
122 jgs 147 n1=self.n[1],\
123     n2=self.n[2],\
124     l0=self.l[0],\
125     l1=self.l[1],\
126     l2=self.l[2],\
127     order=self.order, \
128     periodic0=self.periodic[0], \
129     periodic1=self.periodic[1], \
130     periodic2=self.periodic[2], \
131     integrationOrder=self.integrationOrder)
132 gross 819 super(RectangularDomain, self).doInitialization()
133 jgs 147
134    
135 gross 819 class ScalarConstrainer(Model):
136 jgs 149 """
137     Creates a characteristic function for the location of constraints
138 gross 819 for a scalar value and selects the value from an initial value
139     ate these locations.
140 jgs 127
141 gross 819 In the case that the spatial dimension is two, the arguments front and back are ignored.
142 jgs 127
143 gross 819 @ivar domain: domain (in).
144     @ivar left: True to set a constraint at the left face of the domain (x[0]=min x[0]), default False (in).
145     @ivar right: True to set a constraint at the left face of the domain (x[0]=max x[0]), default False (in).
146     @ivar top: True to set a constraint at the left face of the domain (x[1]=min x[1]), default False (in).
147     @ivar bottom: True to set a constraint at the left face of the domain (x[1]=max x[1]), default False (in).
148     @ivar front: True to set a constraint at the left face of the domain (x[2]=min x[2]), default False (in).
149     @ivar back: True to set a constraint at the left face of the domain (x[2]=max x[2]), default False (in).
150     @ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
151     @ivar location_of_constraint: locations of the constraints (out).
152     @ivar constraint: locations of the constraints (out).
153 jgs 127 """
154     def __init__(self,debug=False):
155 jgs 148 ParameterSet.__init__(self,debug=debug)
156 jgs 127 self.declareParameter(domain=None, \
157 gross 819 value=0, \
158 jgs 147 left=False, \
159     right=False, \
160     top=False, \
161     bottom=False, \
162     front=False, \
163 gross 819 back=False, \
164     tol=1.e-8, \
165 gross 820 value_of_constraint = None, \
166     location_of_constraint=None)
167     self.location_of_constraint=None
168 jgs 127
169 gross 819 def doInitialization(self):
170 jgs 149 """
171     Returns the mask of the location of constraint.
172     """
173 gross 819 x=self.domain.getX()
174 gross 820 self.location_of_constraint=Scalar(0,x.getFunctionSpace())
175 gross 819 if self.domain.getDim()==3:
176     x0,x1,x2=x[0],x[1],x[2]
177 gross 820 if self.left: self.location_of_constraint+=whereZero(x0-inf(x0),self.tol)
178     if self.right: self.location_of_constraint+=whereZero(x0-sup(x0),self.tol)
179     if self.front: self.location_of_constraint+=whereZero(x1-inf(x1),self.tol)
180     if self.back: self.location_of_constraint+=whereZero(x1-sup(x1),self.tol)
181     if self.bottom: self.location_of_constraint+=whereZero(x2-inf(x2),self.tol)
182     if self.top: self.location_of_constraint+=whereZero(x2-sup(x2),self.tol)
183 gross 819 else:
184     x0,x1=x[0],x[1]
185 gross 820 if self.left: self.location_of_constraint+=whereZero(x0-inf(x0),self.tol)
186     if self.right: self.location_of_constraint+=whereZero(x0-sup(x0),self.tol)
187     if self.bottom: self.location_of_constraint+=whereZero(x1-inf(x1),self.tol)
188     if self.top: self.location_of_constraint+=whereZero(x1-sup(x1),self.tol)
189     self.value_of_constraint=self.location_of_constraint*self.value
190 jgs 147
191 gross 819 class VectorConstrainer(Model):
192 jgs 149 """
193 gross 819 Creates a characteristic function for the location of constraints vector value.
194     In the case that the spatial dimension is two, the arguments front and
195     back as well as the third component of each argument is ignored.
196 jgs 127
197 gross 819 @ivar domain: domain
198     @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]),
199     default [False,False,False] (in).
200     @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]),
201     default [False,False,False] (in).
202     @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]),
203     default [False,False,False] (in).
204     @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]),
205     default [False,False,False] (in).
206     @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]),
207     default [False,False,False] (in).
208     @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]),
209     default [False,False,False] (in).
210     @ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
211     @ivar location_of_constraint: locations of the constraints (out).
212     @ivar constraint: locations of the constraints (out).
213 jgs 127
214     """
215     def __init__(self,debug=False):
216 jgs 148 ParameterSet.__init__(self,debug=debug)
217 jgs 127 self.declareParameter(domain=None, \
218 gross 819 value=0, \
219 jgs 147 left=[0,0,0], \
220     right=[0,0,0], \
221     top=[0,0,0], \
222     bottom=[0,0,0], \
223 gross 819 front=[0,0,0], \
224     ack=[0,0,0], \
225     tol=1.e-8, \
226 gross 820 value_of_constraint = None, \
227     location_of_constraint=None)
228     self.location_of_constraint=None
229 gross 819 def doInitialization(self):
230 jgs 149 """
231 gross 820 sets the location_of_constraint and value_of_constraint to be kept throughout the simulation.
232 jgs 149 """
233 gross 820 if self.location_of_constraint==None:
234 jgs 147 x=self.domain.getX()
235 gross 820 self.location_of_constraint=Vector(0,x.getFunctionSpace())
236 jgs 147 if self.domain.getDim()==3:
237 gross 819 x0,x1,x2=x[0],x[1],x[2]
238     left_mask=whereZero(x0-inf(x0),self.tol)
239 gross 820 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 gross 819 right_mask=whereZero(x0-sup(x0),self.tol)
243 gross 820 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 gross 819 front_mask=whereZero(x1-inf(x1),self.tol)
247 gross 820 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 gross 819 back_mask=whereZero(x1-sup(x1),self.tol)
251 gross 820 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 gross 819 bottom_mask=whereZero(x2-inf(x2),self.tol)
255 gross 820 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 gross 819 top_mask=whereZero(x2-sup(x2),self.tol)
259 gross 820 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 jgs 147 else:
263 gross 819 x0,x1=x[0],x[1]
264     left_mask=whereZero(x0-inf(x0),self.tol)
265 gross 820 if self.left[0]: self.location_of_constraint+=left_mask*[1.,0.]
266     if self.left[1]: self.location_of_constraint+=left_mask*[0.,1.]
267 gross 819 right_mask=whereZero(x0-sup(x0),self.tol)
268 gross 820 if self.right[0]: self.location_of_constraint+=right_mask*[1.,0.]
269     if self.right[1]: self.location_of_constraint+=right_mask*[0.,1.]
270 gross 819 bottom_mask=whereZero(x1-inf(x1),self.tol)
271 gross 820 if self.bottom[0]: self.location_of_constraint+=bottom_mask*[1.,0.]
272     if self.bottom[1]: self.location_of_constraint+=bottom_mask*[0.,1.]
273 gross 819 top_mask=whereZero(x1-sup(x1),self.tol)
274 gross 820 if self.top[0]: self.location_of_constraint+=top_mask*[1.,0.]
275     if self.top[1]: self.location_of_constraint+=top_mask*[0.,1.]
276     self.value_of_constraint=self.location_of_constraint*self.value
277 jgs 149
278     # 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