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