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