/[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 406 - (hide annotations)
Fri Dec 23 00:39:59 2005 UTC (13 years, 10 months ago) by gross
File MIME type: text/x-python
File size: 13322 byte(s)
bug fixed
1 jgs 127 # $Id$
2    
3    
4 jgs 149 from esys.escript import *
5     from esys.escript.modelframe import Model,ParameterSet
6     from esys import finley
7 jgs 127
8 gross 398 class FinleyReader(ParameterSet):
9 jgs 149 """
10     Generates a mesh over a rectangular domain finley.
11 jgs 147
12 gross 398 @ivar filename:
13     @ivar intergrationOrder
14     @ivar domain:
15     """
16     def __init__(self,debug=False):
17 gross 406 super(FinleyReader,self).__init__(debug=debug)
18     ParameterSet.__init__(self,debug=debug)
19 gross 398 self.declareParameter(source="none",\
20     integrationOrder=-1)
21     self._domain=None
22    
23     def domain(self):
24     if self._domain==None:
25 gross 406 self._domain=finley.ReadMesh(self.source,self.integrationOrder)
26 gross 398 self.trace("mesh read from %s"%self.source)
27 gross 406 return self._domain
28 gross 398
29     class RectangularDomain(ParameterSet):
30     """
31     Generates a mesh over a rectangular domain finley.
32    
33 jgs 149 @ivar dim:
34     @ivar l:
35     @ivar n:
36     @ivar order:
37     @ivar periodic:
38     @ivar intergration order:
39 gross 398 @ivar domain:
40 jgs 147 """
41 jgs 127 def __init__(self,debug=False):
42 gross 406 super(RectangularDomain,self).__init__(debug=debug)
43 jgs 147 self.declareParameter(dim=2,\
44 jgs 127 l=[1.,1.,1.],\
45     n=[10,10,10], \
46     order=1,\
47     periodic=[False,False,False],\
48     integrationOrder=-1)
49 jgs 147 self._domain=None
50 jgs 127
51 jgs 147 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 gross 401 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 jgs 148 class ScalarConstrainer(ParameterSet):
121 jgs 149 """
122     Creates a characteristic function for the location of constraints
123     for a scalar value.
124 jgs 127
125 jgs 149 In the case that the spatial dimension is two, the arguments front
126     and back are ignored.
127 jgs 127
128 jgs 149 @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 jgs 127 """
144     def __init__(self,debug=False):
145 jgs 148 ParameterSet.__init__(self,debug=debug)
146 jgs 127 self.declareParameter(domain=None, \
147 jgs 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 jgs 127
155 jgs 147 def location_of_constraint(self):
156 jgs 149 """
157     Returns the mask of the location of constraint.
158     """
159 jgs 147 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 gross 323 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 jgs 147 else:
170 gross 323 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 jgs 147 return self._location_of_constraint
175    
176 jgs 148 class VectorConstrainer(ParameterSet):
177 jgs 149 """
178     Creates a characteristic function for the location of constraints
179     for a scalar value.
180 jgs 127
181 jgs 149 @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 jgs 127
208 jgs 149 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 jgs 127 """
211     def __init__(self,debug=False):
212 jgs 148 ParameterSet.__init__(self,debug=debug)
213 jgs 127 self.declareParameter(domain=None, \
214 jgs 147 left=[0,0,0], \
215     right=[0,0,0], \
216     top=[0,0,0], \
217     bottom=[0,0,0], \
218 jgs 127 front=[0,0,0],
219 jgs 147 back=[0,0,0])
220     self._location_of_constraint=None
221     def location_of_constraint(self):
222 jgs 149 """
223     Returns the mask of the location of constraint.
224     """
225 jgs 147 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 gross 323 left_mask=whereZero(x[0]-inf(x[0]))
230 jgs 147 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 gross 323 right_mask=whereZero(x[0]-sup(x[0]))
234 jgs 147 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 gross 323 front_mask=whereZero(x[1]-inf(x[1]))
238 jgs 147 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 gross 323 back_mask=whereZero(x[1]-sup(x[1]))
242 jgs 147 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 gross 323 bottom_mask=whereZero(x[2]-inf(x[2]))
246 jgs 147 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 gross 323 top_mask=whereZero(x[2]-sup(x[2]))
250 jgs 147 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 gross 323 left_mask=whereZero(x[0]-inf(x[0]))
255 jgs 147 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 gross 323 right_mask=whereZero(x[0]-sup(x[0]))
258 jgs 147 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 gross 323 bottom_mask=whereZero(x[1]-inf(x[1]))
261 jgs 147 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 gross 323 top_mask=whereZero(x[1]-sup(x[1]))
264 jgs 147 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 jgs 149
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