/[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 323 by gross, Tue Dec 6 06:18:00 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
7    
8  class RectangularDomain(Model):  class RectangularDomain(Model):
9         """generates a mesh over a rectangular domain finley         """
10           Generates a mesh over a rectangular domain finley.
              dim  
              l  
              n  
              order  
              periodic  
              intergration order  
   
              domain (callable)  
11    
12           @ivar dim:
13           @ivar l:
14           @ivar n:
15           @ivar order:
16           @ivar periodic:
17           @ivar intergration order:
18           @ivar domain (callable):
19         """         """
20         def __init__(self,debug=False):         def __init__(self,debug=False):
21             Model.__init__(self,debug=debug)             Model.__init__(self,debug=debug)
# Line 54  class RectangularDomain(Model): Line 53  class RectangularDomain(Model):
53    
54            return self._domain            return self._domain
55    
56  class ScalarConstrainer(Model):  class ScalarConstrainer(ParameterSet):
57       """@brief creates a characteristic function for the location of constraints for a scalar value       """
58         Creates a characteristic function for the location of constraints
59                @param domain (in) - rectangular domain       for a scalar value.
               @param left (in)  - True to set a constraint at the left face of the domain (x[0]=min x[0]), default is False  
               @param right (in) - True to set a constraint at the left face of the domain (x[0]=max x[0]), default is False  
               @param top (in)  - True to set a constraint at the left face of the domain (x[1]=min x[1]), default is False  
               @param bottom (in) - True to set a constraint at the left face of the domain (x[1]=max x[1]), default is False  
               @param front (in)  - True to set a constraint at the left face of the domain (x[2]=min x[2]), default is False  
               @param back (in) - True to set a constraint at the left face of the domain (x[2]=max x[2]), default is False  
               @param location_of_constraint (out) - object that defines the location of the constraints.  
60    
61         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
62         and back are ignored.
63    
64         @ivar domain (in): rectangular domain
65         @ivar left (in): True to set a constraint at the left face of the
66                   domain (x[0]=min x[0]), default is False
67         @ivar right (in): True to set a constraint at the left face of the
68                   domain (x[0]=max x[0]), default is False
69         @ivar top (in): True to set a constraint at the left face of the
70                   domain (x[1]=min x[1]), default is False
71         @ivar bottom (in): True to set a constraint at the left face of the
72                   domain (x[1]=max x[1]), default is False
73         @ivar front (in): True to set a constraint at the left face of the
74                   domain (x[2]=min x[2]), default is False
75         @ivar back (in): True to set a constraint at the left face of the
76                   domain (x[2]=max x[2]), default is False
77         @ivar location_of_constraint (out): object that defines the location
78                   of the constraints.
79       """       """
80       def __init__(self,debug=False):       def __init__(self,debug=False):
81             Model.__init__(self,debug=debug)             ParameterSet.__init__(self,debug=debug)
82             self.declareParameter(domain=None, \             self.declareParameter(domain=None, \
83                                   left=False, \                                   left=False, \
84                                   right=False, \                                   right=False, \
# Line 81  class ScalarConstrainer(Model): Line 89  class ScalarConstrainer(Model):
89             self._location_of_constraint=None             self._location_of_constraint=None
90    
91       def location_of_constraint(self):       def location_of_constraint(self):
92            """returns the mask of the location of constraint"""            """
93              Returns the mask of the location of constraint.
94              """
95            if self._location_of_constraint==None:            if self._location_of_constraint==None:
96               x=self.domain.getX()               x=self.domain.getX()
97               self._location_of_constraint=Scalar(0,x.getFunctionSpace())               self._location_of_constraint=Scalar(0,x.getFunctionSpace())
98               if self.domain.getDim()==3:               if self.domain.getDim()==3:
99                  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]))
100                  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]))
101                  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]))
102                  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]))
103                  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]))
104                  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]))
105               else:               else:
106                  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]))
107                  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]))
108                  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]))
109                  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]))
110            return self._location_of_constraint            return self._location_of_constraint
111    
112  class VectorConstrainer(Model):  class VectorConstrainer(ParameterSet):
113        """@brief creates a characteristic function for the location of constraints for a scalar value        """
114          Creates a characteristic function for the location of constraints
115                @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.  
116    
117         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
118          @ivar left (in): list of three boolean. left[i]==True sets a
119                    constraint for the i-th component at the left
120                    face of the domain (x[0]=min x[0]),
121                    default is [False,False,False]
122          @ivar right (in): list of three boolean. left[i]==True sets a
123                    constraint for the i-th component at the right
124                    face of the domain (x[0]=max x[0]),
125                    default is [False,False,False]
126          @ivar top (in): list of three boolean. left[i]==True sets a
127                    constraint for the i-th component at the top
128                    face of the domain (x[1]=min x[1]),
129                    default is [False,False,False]
130          @ivar bottom (in): list of three boolean. left[i]==True sets a
131                    constraint for the i-th component at the bottom
132                    face of the domain (x[1]=min x[1]),
133                    default is [False,False,False]
134          @ivar front (in): list of three boolean. left[i]==True sets a
135                    constraint for the i-th component at the front
136                    face of the domain (x[2]=min x[2]),
137                    default is [False,False,False]
138          @ivar back (in): list of three boolean. left[i]==True sets a
139                    constraint for the i-th component at the back
140                    face of the domain (x[2]=max x[2]),
141                    default is [False,False,False]
142          @ivar location_of_constraint (callable): object that defines the location of the constraints for each vector component.
143    
144          In the case that the spatial dimension is two, thh arguments front and
145          back as well as the third component of each argument is ignored.
146        """        """
147        def __init__(self,debug=False):        def __init__(self,debug=False):
148             Model.__init__(self,debug=debug)             ParameterSet.__init__(self,debug=debug)
149             self.declareParameter(domain=None, \             self.declareParameter(domain=None, \
150                                   left=[0,0,0],  \                                   left=[0,0,0],  \
151                                   right=[0,0,0],  \                                   right=[0,0,0],  \
# Line 131  class VectorConstrainer(Model): Line 155  class VectorConstrainer(Model):
155                                   back=[0,0,0])                                   back=[0,0,0])
156             self._location_of_constraint=None             self._location_of_constraint=None
157        def location_of_constraint(self):        def location_of_constraint(self):
158            """returns the mask of the location of constraint"""            """
159              Returns the mask of the location of constraint.
160              """
161            if self._location_of_constraint==None:            if self._location_of_constraint==None:
162               x=self.domain.getX()               x=self.domain.getX()
163               self._location_of_constraint=Vector(0,x.getFunctionSpace())               self._location_of_constraint=Vector(0,x.getFunctionSpace())
164               if self.domain.getDim()==3:               if self.domain.getDim()==3:
165                  left_mask=(x[0]-inf(x[0])).whereZero()                  left_mask=whereZero(x[0]-inf(x[0]))
166                  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.]
167                  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.]
168                  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.]
169                  right_mask=(x[0]-sup(x[0])).whereZero()                  right_mask=whereZero(x[0]-sup(x[0]))
170                  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.]
171                  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.]
172                  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.]
173                  front_mask=(x[1]-inf(x[1])).whereZero()                  front_mask=whereZero(x[1]-inf(x[1]))
174                  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.]
175                  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.]
176                  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.]
177                  back_mask=(x[1]-sup(x[1])).whereZero()                  back_mask=whereZero(x[1]-sup(x[1]))
178                  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.]
179                  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.]
180                  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.]
181                  bottom_mask=(x[2]-inf(x[2])).whereZero()                  bottom_mask=whereZero(x[2]-inf(x[2]))
182                  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.]
183                  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.]
184                  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.]
185                  top_mask=(x[2]-sup(x[2])).whereZero()                  top_mask=whereZero(x[2]-sup(x[2]))
186                  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.]
187                  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.]
188                  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.]
189               else:               else:
190                  left_mask=(x[0]-inf(x[0])).whereZero()                  left_mask=whereZero(x[0]-inf(x[0]))
191                  if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.]                  if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.]
192                  if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.]                  if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.]
193                  right_mask=(x[0]-sup(x[0])).whereZero()                  right_mask=whereZero(x[0]-sup(x[0]))
194                  if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.]                  if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.]
195                  if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.]                  if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.]
196                  bottom_mask=(x[1]-inf(x[1])).whereZero()                  bottom_mask=whereZero(x[1]-inf(x[1]))
197                  if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.]                  if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.]
198                  if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.]                  if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.]
199                  top_mask=(x[1]-sup(x[1])).whereZero()                  top_mask=whereZero(x[1]-sup(x[1]))
200                  if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.]                  if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.]
201                  if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.]                  if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.]
202            return self._location_of_constraint            return self._location_of_constraint
203    
204    # vim: expandtab shiftwidth=4:

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

  ViewVC Help
Powered by ViewVC 1.1.26