/[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 406 by gross, Fri Dec 23 00:39:59 2005 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               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, teh arguments front and back are ignored       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):       def __init__(self,debug=False):
145             Model.__init__(self,debug=debug)             ParameterSet.__init__(self,debug=debug)
146             self.declareParameter(domain=None, \             self.declareParameter(domain=None, \
147                                   left=False, \                                   left=False, \
148                                   right=False, \                                   right=False, \
# Line 81  class ScalarConstrainer(Model): Line 153  class ScalarConstrainer(Model):
153             self._location_of_constraint=None             self._location_of_constraint=None
154    
155       def location_of_constraint(self):       def location_of_constraint(self):
156            """returns the mask of the location of constraint"""            """
157              Returns the mask of the location of constraint.
158              """
159            if self._location_of_constraint==None:            if self._location_of_constraint==None:
160               x=self.domain.getX()               x=self.domain.getX()
161               self._location_of_constraint=Scalar(0,x.getFunctionSpace())               self._location_of_constraint=Scalar(0,x.getFunctionSpace())
162               if self.domain.getDim()==3:               if self.domain.getDim()==3:
163                  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]))
164                  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]))
165                  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]))
166                  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]))
167                  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]))
168                  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]))
169               else:               else:
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.bottom: self._location_of_constraint+=(x[1]-inf(x[1])).whereZero()                  if self.bottom: self._location_of_constraint+=whereZero(x[1]-inf(x[1]))
173                  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]))
174            return self._location_of_constraint            return self._location_of_constraint
175    
176  class VectorConstrainer(Model):  class VectorConstrainer(ParameterSet):
177        """@brief creates a characteristic function for the location of constraints for a scalar value        """
178          Creates a characteristic function for the location of constraints
179                @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.  
180    
181         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
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):        def __init__(self,debug=False):
212             Model.__init__(self,debug=debug)             ParameterSet.__init__(self,debug=debug)
213             self.declareParameter(domain=None, \             self.declareParameter(domain=None, \
214                                   left=[0,0,0],  \                                   left=[0,0,0],  \
215                                   right=[0,0,0],  \                                   right=[0,0,0],  \
# Line 131  class VectorConstrainer(Model): Line 219  class VectorConstrainer(Model):
219                                   back=[0,0,0])                                   back=[0,0,0])
220             self._location_of_constraint=None             self._location_of_constraint=None
221        def location_of_constraint(self):        def location_of_constraint(self):
222            """returns the mask of the location of constraint"""            """
223              Returns the mask of the location of constraint.
224              """
225            if self._location_of_constraint==None:            if self._location_of_constraint==None:
226               x=self.domain.getX()               x=self.domain.getX()
227               self._location_of_constraint=Vector(0,x.getFunctionSpace())               self._location_of_constraint=Vector(0,x.getFunctionSpace())
228               if self.domain.getDim()==3:               if self.domain.getDim()==3:
229                  left_mask=(x[0]-inf(x[0])).whereZero()                  left_mask=whereZero(x[0]-inf(x[0]))
230                  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.]
231                  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.]
232                  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.]
233                  right_mask=(x[0]-sup(x[0])).whereZero()                  right_mask=whereZero(x[0]-sup(x[0]))
234                  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.]
235                  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.]
236                  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.]
237                  front_mask=(x[1]-inf(x[1])).whereZero()                  front_mask=whereZero(x[1]-inf(x[1]))
238                  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.]
239                  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.]
240                  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.]
241                  back_mask=(x[1]-sup(x[1])).whereZero()                  back_mask=whereZero(x[1]-sup(x[1]))
242                  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.]
243                  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.]
244                  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.]
245                  bottom_mask=(x[2]-inf(x[2])).whereZero()                  bottom_mask=whereZero(x[2]-inf(x[2]))
246                  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.]
247                  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.]
248                  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.]
249                  top_mask=(x[2]-sup(x[2])).whereZero()                  top_mask=whereZero(x[2]-sup(x[2]))
250                  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.]
251                  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.]
252                  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.]
253               else:               else:
254                  left_mask=(x[0]-inf(x[0])).whereZero()                  left_mask=whereZero(x[0]-inf(x[0]))
255                  if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.]                  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.]                  if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.]
257                  right_mask=(x[0]-sup(x[0])).whereZero()                  right_mask=whereZero(x[0]-sup(x[0]))
258                  if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.]                  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.]                  if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.]
260                  bottom_mask=(x[1]-inf(x[1])).whereZero()                  bottom_mask=whereZero(x[1]-inf(x[1]))
261                  if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.]                  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.]                  if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.]
263                  top_mask=(x[1]-sup(x[1])).whereZero()                  top_mask=whereZero(x[1]-sup(x[1]))
264                  if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.]                  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.]                  if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.]
266            return self._location_of_constraint            return self._location_of_constraint
267    
268    # vim: expandtab shiftwidth=4:

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

  ViewVC Help
Powered by ViewVC 1.1.26