/[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 406 - (show annotations)
Fri Dec 23 00:39:59 2005 UTC (13 years, 9 months ago) by gross
File MIME type: text/x-python
File size: 13322 byte(s)
bug fixed
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 x=self.domain.getX()
100 d=self.domain.getDim()
101 self.location_constrained_value=0
102 x0=x[0]
103 if self.left:
104 self.location_constrained_value=self.location_constrained_value+whereZero(x0-inf(x0))
105 if self.right:
106 self.location_constrained_value=self.location_constrained_value+whereZero(x0-sup(x0))
107 x0=x[d-1]
108 if self.buttom:
109 self.location_constrained_value=self.location_constrained_value+whereZero(x0-inf(x0))
110 if self.top:
111 self.location_constrained_value=self.location_constrained_value+whereZero(x0-sup(x0))
112 if d>2:
113 x0=x[1]
114 if self.front:
115 self.location_constrained_value=self.location_constrained_value+whereZero(x0-inf(x0))
116 if self.back:
117 self.location_constrained_value=self.location_constrained_value+whereZero(x0-sup(x0))
118 self.constrain_value=self.value*self.location_constrained_value
119
120 class ScalarConstrainer(ParameterSet):
121 """
122 Creates a characteristic function for the location of constraints
123 for a scalar value.
124
125 In the case that the spatial dimension is two, the arguments front
126 and back are ignored.
127
128 @ivar domain (in): rectangular domain
129 @ivar left (in): True to set a constraint at the left face of the
130 domain (x[0]=min x[0]), default is False
131 @ivar right (in): True to set a constraint at the left face of the
132 domain (x[0]=max x[0]), default is False
133 @ivar top (in): True to set a constraint at the left face of the
134 domain (x[1]=min x[1]), default is False
135 @ivar bottom (in): True to set a constraint at the left face of the
136 domain (x[1]=max x[1]), default is False
137 @ivar front (in): True to set a constraint at the left face of the
138 domain (x[2]=min x[2]), default is False
139 @ivar back (in): True to set a constraint at the left face of the
140 domain (x[2]=max x[2]), default is False
141 @ivar location_of_constraint (out): object that defines the location
142 of the constraints.
143 """
144 def __init__(self,debug=False):
145 ParameterSet.__init__(self,debug=debug)
146 self.declareParameter(domain=None, \
147 left=False, \
148 right=False, \
149 top=False, \
150 bottom=False, \
151 front=False, \
152 back=False)
153 self._location_of_constraint=None
154
155 def location_of_constraint(self):
156 """
157 Returns the mask of the location of constraint.
158 """
159 if self._location_of_constraint==None:
160 x=self.domain.getX()
161 self._location_of_constraint=Scalar(0,x.getFunctionSpace())
162 if self.domain.getDim()==3:
163 if self.left: self._location_of_constraint+=whereZero(x[0]-inf(x[0]))
164 if self.right: self._location_of_constraint+=whereZero(x[0]-sup(x[0]))
165 if self.front: self._location_of_constraint+=whereZero(x[1]-inf(x[1]))
166 if self.back: self._location_of_constraint+=whereZero(x[1]-sup(x[1]))
167 if self.bottom: self._location_of_constraint+=whereZero(x[2]-inf(x[2]))
168 if self.top: self._location_of_constraint+=whereZero(x[2]-sup(x[2]))
169 else:
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.bottom: self._location_of_constraint+=whereZero(x[1]-inf(x[1]))
173 if self.top: self._location_of_constraint+=whereZero(x[1]-sup(x[1]))
174 return self._location_of_constraint
175
176 class VectorConstrainer(ParameterSet):
177 """
178 Creates a characteristic function for the location of constraints
179 for a scalar value.
180
181 @ivar domain (in): rectangular domain
182 @ivar left (in): list of three boolean. left[i]==True sets a
183 constraint for the i-th component at the left
184 face of the domain (x[0]=min x[0]),
185 default is [False,False,False]
186 @ivar right (in): list of three boolean. left[i]==True sets a
187 constraint for the i-th component at the right
188 face of the domain (x[0]=max x[0]),
189 default is [False,False,False]
190 @ivar top (in): list of three boolean. left[i]==True sets a
191 constraint for the i-th component at the top
192 face of the domain (x[1]=min x[1]),
193 default is [False,False,False]
194 @ivar bottom (in): list of three boolean. left[i]==True sets a
195 constraint for the i-th component at the bottom
196 face of the domain (x[1]=min x[1]),
197 default is [False,False,False]
198 @ivar front (in): list of three boolean. left[i]==True sets a
199 constraint for the i-th component at the front
200 face of the domain (x[2]=min x[2]),
201 default is [False,False,False]
202 @ivar back (in): list of three boolean. left[i]==True sets a
203 constraint for the i-th component at the back
204 face of the domain (x[2]=max x[2]),
205 default is [False,False,False]
206 @ivar location_of_constraint (callable): object that defines the location of the constraints for each vector component.
207
208 In the case that the spatial dimension is two, thh arguments front and
209 back as well as the third component of each argument is ignored.
210 """
211 def __init__(self,debug=False):
212 ParameterSet.__init__(self,debug=debug)
213 self.declareParameter(domain=None, \
214 left=[0,0,0], \
215 right=[0,0,0], \
216 top=[0,0,0], \
217 bottom=[0,0,0], \
218 front=[0,0,0],
219 back=[0,0,0])
220 self._location_of_constraint=None
221 def location_of_constraint(self):
222 """
223 Returns the mask of the location of constraint.
224 """
225 if self._location_of_constraint==None:
226 x=self.domain.getX()
227 self._location_of_constraint=Vector(0,x.getFunctionSpace())
228 if self.domain.getDim()==3:
229 left_mask=whereZero(x[0]-inf(x[0]))
230 if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.,0.]
231 if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.,0.]
232 if self.left[2]: self._location_of_constraint+=left_mask*[0.,0.,1.]
233 right_mask=whereZero(x[0]-sup(x[0]))
234 if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.,0.]
235 if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.,0.]
236 if self.right[2]: self._location_of_constraint+=right_mask*[0.,0.,1.]
237 front_mask=whereZero(x[1]-inf(x[1]))
238 if self.front[0]: self._location_of_constraint+=front_mask*[1.,0.,0.]
239 if self.front[1]: self._location_of_constraint+=front_mask*[0.,1.,0.]
240 if self.front[2]: self._location_of_constraint+=front_mask*[0.,0.,1.]
241 back_mask=whereZero(x[1]-sup(x[1]))
242 if self.back[0]: self._location_of_constraint+=back_mask*[1.,0.,0.]
243 if self.back[1]: self._location_of_constraint+=back_mask*[0.,1.,0.]
244 if self.back[2]: self._location_of_constraint+=back_mask*[0.,0.,1.]
245 bottom_mask=whereZero(x[2]-inf(x[2]))
246 if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.,0.]
247 if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.,0.]
248 if self.bottom[2]: self._location_of_constraint+=bottom_mask*[0.,0.,1.]
249 top_mask=whereZero(x[2]-sup(x[2]))
250 if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.,0.]
251 if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.,0.]
252 if self.top[2]: self._location_of_constraint+=top_mask*[0.,0.,1.]
253 else:
254 left_mask=whereZero(x[0]-inf(x[0]))
255 if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.]
256 if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.]
257 right_mask=whereZero(x[0]-sup(x[0]))
258 if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.]
259 if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.]
260 bottom_mask=whereZero(x[1]-inf(x[1]))
261 if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.]
262 if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.]
263 top_mask=whereZero(x[1]-sup(x[1]))
264 if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.]
265 if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.]
266 return self._location_of_constraint
267
268 # 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