/[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 149 by jgs, Thu Sep 1 03:31:39 2005 UTC trunk/modellib/py_src/geometry.py revision 406 by gross, Fri Dec 23 00:39:59 2005 UTC
# Line 5  from esys.escript import * Line 5  from esys.escript import *
5  from esys.escript.modelframe import Model,ParameterSet  from esys.escript.modelframe import Model,ParameterSet
6  from esys import finley  from esys import finley
7    
8  class RectangularDomain(Model):  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):
17               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.         Generates a mesh over a rectangular domain finley.
32    
# Line 15  class RectangularDomain(Model): Line 36  class RectangularDomain(Model):
36         @ivar order:         @ivar order:
37         @ivar periodic:         @ivar periodic:
38         @ivar intergration order:         @ivar intergration order:
39         @ivar domain (callable):         @ivar domain:
40         """         """
41         def __init__(self,debug=False):         def __init__(self,debug=False):
42             Model.__init__(self,debug=debug)             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 53  class RectangularDomain(Model): Line 74  class RectangularDomain(Model):
74    
75            return self._domain            return self._domain
76    
77    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  class ScalarConstrainer(ParameterSet):  class ScalarConstrainer(ParameterSet):
121       """       """
122       Creates a characteristic function for the location of constraints       Creates a characteristic function for the location of constraints
# Line 96  class ScalarConstrainer(ParameterSet): Line 160  class ScalarConstrainer(ParameterSet):
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(ParameterSet):  class VectorConstrainer(ParameterSet):
# Line 162  class VectorConstrainer(ParameterSet): Line 226  class VectorConstrainer(ParameterSet):
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

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

  ViewVC Help
Powered by ViewVC 1.1.26