/[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 628 - (hide annotations)
Thu Mar 23 02:27:57 2006 UTC (13 years, 7 months ago) by elspeth
File MIME type: text/x-python
File size: 13812 byte(s)
Copyright information added.

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 398 class FinleyReader(ParameterSet):
15 jgs 149 """
16     Generates a mesh over a rectangular domain finley.
17 jgs 147
18 gross 398 @ivar filename:
19     @ivar intergrationOrder
20     @ivar domain:
21     """
22     def __init__(self,debug=False):
23 gross 406 super(FinleyReader,self).__init__(debug=debug)
24     ParameterSet.__init__(self,debug=debug)
25 gross 398 self.declareParameter(source="none",\
26     integrationOrder=-1)
27     self._domain=None
28    
29     def domain(self):
30     if self._domain==None:
31 gross 406 self._domain=finley.ReadMesh(self.source,self.integrationOrder)
32 gross 398 self.trace("mesh read from %s"%self.source)
33 gross 406 return self._domain
34 gross 398
35     class RectangularDomain(ParameterSet):
36     """
37     Generates a mesh over a rectangular domain finley.
38    
39 jgs 149 @ivar dim:
40     @ivar l:
41     @ivar n:
42     @ivar order:
43     @ivar periodic:
44     @ivar intergration order:
45 gross 398 @ivar domain:
46 jgs 147 """
47 jgs 127 def __init__(self,debug=False):
48 gross 406 super(RectangularDomain,self).__init__(debug=debug)
49 jgs 147 self.declareParameter(dim=2,\
50 jgs 127 l=[1.,1.,1.],\
51     n=[10,10,10], \
52     order=1,\
53     periodic=[False,False,False],\
54     integrationOrder=-1)
55 jgs 147 self._domain=None
56 jgs 127
57 jgs 147 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 gross 401 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 gross 490 tol=1.e-8
106 gross 401 x=self.domain.getX()
107     d=self.domain.getDim()
108     self.location_constrained_value=0
109     x0=x[0]
110 gross 490 mx=sup(x0)
111     mn=inf(x0)
112 gross 401 if self.left:
113 gross 490 self.location_constrained_value=self.location_constrained_value+whereZero(x0-mn,tol*(mx-mn))
114 gross 401 if self.right:
115 gross 490 self.location_constrained_value=self.location_constrained_value+whereZero(x0-mx,tol*(mx-mn))
116 gross 401 x0=x[d-1]
117 gross 490 mx=sup(x0)
118     mn=inf(x0)
119 gross 407 if self.bottom:
120 gross 490 self.location_constrained_value=self.location_constrained_value+whereZero(x0-mn,tol*(mx-mn))
121 gross 401 if self.top:
122 gross 490 self.location_constrained_value=self.location_constrained_value+whereZero(x0-mx,tol*(mx-mn))
123 gross 401 if d>2:
124     x0=x[1]
125 gross 490 mx=sup(x0)
126     mn=inf(x0)
127 gross 401 if self.front:
128 gross 490 self.location_constrained_value=self.location_constrained_value+whereZero(x0-mn,tol*(mx-mn))
129 gross 401 if self.back:
130 gross 490 self.location_constrained_value=self.location_constrained_value+whereZero(x0-mx,tol*(mx-mn))
131 gross 401 self.constrain_value=self.value*self.location_constrained_value
132    
133 jgs 148 class ScalarConstrainer(ParameterSet):
134 jgs 149 """
135     Creates a characteristic function for the location of constraints
136     for a scalar value.
137 jgs 127
138 jgs 149 In the case that the spatial dimension is two, the arguments front
139     and back are ignored.
140 jgs 127
141 jgs 149 @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 jgs 127 """
157     def __init__(self,debug=False):
158 jgs 148 ParameterSet.__init__(self,debug=debug)
159 jgs 127 self.declareParameter(domain=None, \
160 jgs 147 left=False, \
161     right=False, \
162     top=False, \
163     bottom=False, \
164     front=False, \
165     back=False)
166     self._location_of_constraint=None
167 jgs 127
168 jgs 147 def location_of_constraint(self):
169 jgs 149 """
170     Returns the mask of the location of constraint.
171     """
172 jgs 147 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 gross 323 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 jgs 147 else:
183 gross 323 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 jgs 147 return self._location_of_constraint
188    
189 jgs 148 class VectorConstrainer(ParameterSet):
190 jgs 149 """
191     Creates a characteristic function for the location of constraints
192     for a scalar value.
193 jgs 127
194 jgs 149 @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 jgs 127
221 jgs 149 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 jgs 127 """
224     def __init__(self,debug=False):
225 jgs 148 ParameterSet.__init__(self,debug=debug)
226 jgs 127 self.declareParameter(domain=None, \
227 jgs 147 left=[0,0,0], \
228     right=[0,0,0], \
229     top=[0,0,0], \
230     bottom=[0,0,0], \
231 jgs 127 front=[0,0,0],
232 jgs 147 back=[0,0,0])
233     self._location_of_constraint=None
234     def location_of_constraint(self):
235 jgs 149 """
236     Returns the mask of the location of constraint.
237     """
238 jgs 147 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 gross 323 left_mask=whereZero(x[0]-inf(x[0]))
243 jgs 147 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 gross 323 right_mask=whereZero(x[0]-sup(x[0]))
247 jgs 147 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 gross 323 front_mask=whereZero(x[1]-inf(x[1]))
251 jgs 147 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 gross 323 back_mask=whereZero(x[1]-sup(x[1]))
255 jgs 147 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 gross 323 bottom_mask=whereZero(x[2]-inf(x[2]))
259 jgs 147 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 gross 323 top_mask=whereZero(x[2]-sup(x[2]))
263 jgs 147 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 gross 323 left_mask=whereZero(x[0]-inf(x[0]))
268 jgs 147 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 gross 323 right_mask=whereZero(x[0]-sup(x[0]))
271 jgs 147 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 gross 323 bottom_mask=whereZero(x[1]-inf(x[1]))
274 jgs 147 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 gross 323 top_mask=whereZero(x[1]-sup(x[1]))
277 jgs 147 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 jgs 149
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