/[escript]/trunk/modellib/py_src/geometry.py
ViewVC logotype

Diff of /trunk/modellib/py_src/geometry.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/esys2/modellib/py_src/geometry.py revision 147 by jgs, Fri Aug 12 01:45:47 2005 UTC trunk/modellib/py_src/geometry.py revision 490 by gross, Thu Feb 2 07:07:21 2006 UTC
# Line 1  Line 1 
1  # $Id$  # $Id$
2    
3    
4  from escript.escript import *  from esys.escript import *
5  from escript.modelframe import Model  from esys.escript.modelframe import Model,ParameterSet
6  from finley import finley  from esys import finley
   
 class RectangularDomain(Model):  
        """generates a mesh over a rectangular domain finley  
   
              dim  
              l  
              n  
              order  
              periodic  
              intergration order  
7    
8               domain (callable)  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):         def __init__(self,debug=False):
17             Model.__init__(self,debug=debug)             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,\             self.declareParameter(dim=2,\
44                                   l=[1.,1.,1.],\                                   l=[1.,1.,1.],\
45                                   n=[10,10,10], \                                   n=[10,10,10], \
# Line 54  class RectangularDomain(Model): Line 74  class RectangularDomain(Model):
74    
75            return self._domain            return self._domain
76    
77  class ScalarConstrainer(Model):  class ConstrainValue(Model):
78       """@brief creates a characteristic function for the location of constraints for a scalar value         """
79           selects values for a given distribution to be used as a constrain. the location of the
80                @param domain (in) - rectangular domain         constrain are he faces of a rectangular domain. This Model is typically used in
81                @param left (in)  - True to set a constraint at the left face of the domain (x[0]=min x[0]), default is False         time dependend problems to fix the values in a given initial condition.
82                @param right (in) - True to set a constraint at the left face of the domain (x[0]=max x[0]), default is False         """
83                @param top (in)  - True to set a constraint at the left face of the domain (x[1]=min x[1]), default is False         def __init__(self,debug=False):
84                @param bottom (in) - True to set a constraint at the left face of the domain (x[1]=max x[1]), default is False             Model.__init__(self,debug=debug)
85                @param front (in)  - True to set a constraint at the left face of the domain (x[2]=min x[2]), default is False             self.declareParameter(domain=None, \
86                @param back (in) - True to set a constraint at the left face of the domain (x[2]=max x[2]), default is False                                   value=0,  \
87                @param location_of_constraint (out) - object that defines the location of the constraints.                                   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, teh arguments front and back are ignored       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):       def __init__(self,debug=False):
152             Model.__init__(self,debug=debug)             ParameterSet.__init__(self,debug=debug)
153             self.declareParameter(domain=None, \             self.declareParameter(domain=None, \
154                                   left=False, \                                   left=False, \
155                                   right=False, \                                   right=False, \
# Line 81  class ScalarConstrainer(Model): Line 160  class ScalarConstrainer(Model):
160             self._location_of_constraint=None             self._location_of_constraint=None
161    
162       def location_of_constraint(self):       def location_of_constraint(self):
163            """returns the mask of the location of constraint"""            """
164              Returns the mask of the location of constraint.
165              """
166            if self._location_of_constraint==None:            if self._location_of_constraint==None:
167               x=self.domain.getX()               x=self.domain.getX()
168               self._location_of_constraint=Scalar(0,x.getFunctionSpace())               self._location_of_constraint=Scalar(0,x.getFunctionSpace())
169               if self.domain.getDim()==3:               if self.domain.getDim()==3:
170                  if self.left: self._location_of_constraint+=(x[0]-inf(x[0])).whereZero()                  if self.left: self._location_of_constraint+=whereZero(x[0]-inf(x[0]))
171                  if self.right: self._location_of_constraint+=(x[0]-sup(x[0])).whereZero()                  if self.right: self._location_of_constraint+=whereZero(x[0]-sup(x[0]))
172                  if self.front: self._location_of_constraint+=(x[1]-inf(x[1])).whereZero()                  if self.front: self._location_of_constraint+=whereZero(x[1]-inf(x[1]))
173                  if self.back: self._location_of_constraint+=(x[1]-sup(x[1])).whereZero()                  if self.back: self._location_of_constraint+=whereZero(x[1]-sup(x[1]))
174                  if self.bottom: self._location_of_constraint+=(x[2]-inf(x[2])).whereZero()                  if self.bottom: self._location_of_constraint+=whereZero(x[2]-inf(x[2]))
175                  if self.top: self._location_of_constraint+=(x[2]-sup(x[2])).whereZero()                  if self.top: self._location_of_constraint+=whereZero(x[2]-sup(x[2]))
176               else:               else:
177                  if self.left: self._location_of_constraint+=(x[0]-inf(x[0])).whereZero()                  if self.left: self._location_of_constraint+=whereZero(x[0]-inf(x[0]))
178                  if self.right: self._location_of_constraint+=(x[0]-sup(x[0])).whereZero()                  if self.right: self._location_of_constraint+=whereZero(x[0]-sup(x[0]))
179                  if self.bottom: self._location_of_constraint+=(x[1]-inf(x[1])).whereZero()                  if self.bottom: self._location_of_constraint+=whereZero(x[1]-inf(x[1]))
180                  if self.top: self._location_of_constraint+=(x[1]-sup(x[1])).whereZero()                  if self.top: self._location_of_constraint+=whereZero(x[1]-sup(x[1]))
181            return self._location_of_constraint            return self._location_of_constraint
182    
183  class VectorConstrainer(Model):  class VectorConstrainer(ParameterSet):
184        """@brief creates a characteristic function for the location of constraints for a scalar value        """
185          Creates a characteristic function for the location of constraints
186                @param domain (in) - rectangular domain        for a scalar value.
               @param left (in)  - list of three boolean. left[i]==True sets a constraint for the i-th component at the left  
                                   face of the domain (x[0]=min x[0]), default is [False,False,False]  
               @param right (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the right  
                                   face of the domain (x[0]=max x[0]), default is [False,False,False]  
               @param top (in)  - list of three boolean. left[i]==True sets a constraint for the i-th component at the top  
                                   face of the domain (x[1]=min x[1]), default is [False,False,False]  
               @param bottom (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the bottom  
                                   face of the domain (x[1]=min x[1]), default is [False,False,False]  
               @param front (in)  - list of three boolean. left[i]==True sets a constraint for the i-th component at the front  
                                   face of the domain (x[2]=min x[2]), default is [False,False,False]  
               @param back (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the back  
                                   face of the domain (x[2]=max x[2]), default is [False,False,False]  
               @param location_of_constraint (callable) - object that defines the location of the constraints for each vector component.  
187    
188         In the case that the spatial dimension is two, thh arguments front and back as well as the third component of each argument is ignored.        @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):        def __init__(self,debug=False):
219             Model.__init__(self,debug=debug)             ParameterSet.__init__(self,debug=debug)
220             self.declareParameter(domain=None, \             self.declareParameter(domain=None, \
221                                   left=[0,0,0],  \                                   left=[0,0,0],  \
222                                   right=[0,0,0],  \                                   right=[0,0,0],  \
# Line 131  class VectorConstrainer(Model): Line 226  class VectorConstrainer(Model):
226                                   back=[0,0,0])                                   back=[0,0,0])
227             self._location_of_constraint=None             self._location_of_constraint=None
228        def location_of_constraint(self):        def location_of_constraint(self):
229            """returns the mask of the location of constraint"""            """
230              Returns the mask of the location of constraint.
231              """
232            if self._location_of_constraint==None:            if self._location_of_constraint==None:
233               x=self.domain.getX()               x=self.domain.getX()
234               self._location_of_constraint=Vector(0,x.getFunctionSpace())               self._location_of_constraint=Vector(0,x.getFunctionSpace())
235               if self.domain.getDim()==3:               if self.domain.getDim()==3:
236                  left_mask=(x[0]-inf(x[0])).whereZero()                  left_mask=whereZero(x[0]-inf(x[0]))
237                  if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.,0.]                  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.]                  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.]                  if self.left[2]: self._location_of_constraint+=left_mask*[0.,0.,1.]
240                  right_mask=(x[0]-sup(x[0])).whereZero()                  right_mask=whereZero(x[0]-sup(x[0]))
241                  if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.,0.]                  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.]                  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.]                  if self.right[2]: self._location_of_constraint+=right_mask*[0.,0.,1.]
244                  front_mask=(x[1]-inf(x[1])).whereZero()                  front_mask=whereZero(x[1]-inf(x[1]))
245                  if self.front[0]: self._location_of_constraint+=front_mask*[1.,0.,0.]                  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.]                  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.]                  if self.front[2]: self._location_of_constraint+=front_mask*[0.,0.,1.]
248                  back_mask=(x[1]-sup(x[1])).whereZero()                  back_mask=whereZero(x[1]-sup(x[1]))
249                  if self.back[0]: self._location_of_constraint+=back_mask*[1.,0.,0.]                  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.]                  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.]                  if self.back[2]: self._location_of_constraint+=back_mask*[0.,0.,1.]
252                  bottom_mask=(x[2]-inf(x[2])).whereZero()                  bottom_mask=whereZero(x[2]-inf(x[2]))
253                  if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.,0.]                  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.]                  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.]                  if self.bottom[2]: self._location_of_constraint+=bottom_mask*[0.,0.,1.]
256                  top_mask=(x[2]-sup(x[2])).whereZero()                  top_mask=whereZero(x[2]-sup(x[2]))
257                  if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.,0.]                  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.]                  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.]                  if self.top[2]: self._location_of_constraint+=top_mask*[0.,0.,1.]
260               else:               else:
261                  left_mask=(x[0]-inf(x[0])).whereZero()                  left_mask=whereZero(x[0]-inf(x[0]))
262                  if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.]                  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.]                  if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.]
264                  right_mask=(x[0]-sup(x[0])).whereZero()                  right_mask=whereZero(x[0]-sup(x[0]))
265                  if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.]                  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.]                  if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.]
267                  bottom_mask=(x[1]-inf(x[1])).whereZero()                  bottom_mask=whereZero(x[1]-inf(x[1]))
268                  if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.]                  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.]                  if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.]
270                  top_mask=(x[1]-sup(x[1])).whereZero()                  top_mask=whereZero(x[1]-sup(x[1]))
271                  if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.]                  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.]                  if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.]
273            return self._location_of_constraint            return self._location_of_constraint
274    
275    # vim: expandtab shiftwidth=4:

Legend:
Removed from v.147  
changed lines
  Added in v.490

  ViewVC Help
Powered by ViewVC 1.1.26