/[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

revision 720 by gross, Thu Apr 27 10:16:05 2006 UTC revision 819 by gross, Sun Aug 27 23:07:51 2006 UTC
# Line 11  from esys.escript import * Line 11  from esys.escript import *
11  from esys.escript.modelframe import Model,ParameterSet  from esys.escript.modelframe import Model,ParameterSet
12  from esys import finley  from esys import finley
13    
14  class FinleyReader(ParameterSet):  class Domain(Model):
15          """
16          template L{Model} for a domain.
17          
18          @ivar intergrationOrder: integration order, default -1 (in).
19          @type intergrationOrder: C{int}
20          @ivar displacement: displacements applied to the original mesh coordinates
21          @type displacement: C{None} or L{escript.Vector}
22          @ivar domain: domain (out)
23          @type domain: L{escript.Domain}
24          """
25          def __init__(self,debug=False):
26               """
27               initializes the object
28               """
29               super(Domain, self).__init__(debug=debug)
30               self.declareParameter(displacement=None,\
31                                     integrationOrder=-1)
32    
33               self.__updated=False
34    
35          def doInitialization(self):
36             """
37             applies an initial L{displacement} to the mesh nodes (if not equal to C{None})
38             """
39             self.__x=self.domain.getX()
40             if self.displacement:
41                  self.domain.setX(self.__x+self.displacement)
42            
43          def doStepPreprocessing(self,dt):
44             """
45             applies the final L{displacement} to mesh nodes.
46             """
47             if self.displacement:
48                  self.domain.setX(self.__x+self.displacement)
49                  self.__update=False
50    
51          def doStep(self,dt):
52             """
53             applies the current L{displacement} to mesh nodes.
54             """
55             if self.displacement:
56                  self.domain.setX(self.__x+self.displacement)
57                  self.__update=False
58    
59          def doStepPostprocessing(self,dt):
60             """
61             applies the final L{displacement} to mesh nodes.
62             """
63             if self.displacement:
64                  self.domain.setX(self.__x+self.displacement)
65                  self.__update=False
66    
67    class FinleyReader(Domain):
68         """         """
69         Generates a mesh over a rectangular domain finley.         reads finley mesh file.
70    
71         @ivar filename:         @ivar source: file name of the finley input file
72         @ivar intergrationOrder         @type source: C{str}
        @ivar domain:  
73         """         """
74         def __init__(self,debug=False):         def __init__(self,debug=False):
75             super(FinleyReader,self).__init__(debug=debug)             super(FinleyReader,self).__init__(debug=debug)
76             ParameterSet.__init__(self,debug=debug)             self.declareParameter(source="none")
            self.declareParameter(source="none",\  
                                  integrationOrder=-1)  
            self.__domain=None  
77    
78         def domain(self):         def doInitialization(self):
79            if self.__domain==None:            self.domain=finley.ReadMesh(self.source,self.integrationOrder)
80                self.__domain=finley.ReadMesh(self.source,self.integrationOrder)            self.trace("mesh read from %s"%self.source)          
81                self.trace("mesh read from %s"%self.source)                      super(FinleyReader, self).doInitialization()
           return self.__domain  
82                                                
83  class RectangularDomain(ParameterSet):  class RectangularDomain(Domain):
84         """         """
85         Generates a mesh over a rectangular domain finley.         Generates a mesh over a rectangular domain finley.
86    
87         @ivar dim:         @ivar dim: spatial dimension, default =2 (in).
88         @ivar l:         @type dim: spatial dimension
89         @ivar n:         @ivar l: spatial lengths, default [1.,1.,1.] (in).
90         @ivar order:         @type l: C{list} of C{floats}s
91         @ivar periodic:         @ivar n: number of elements, default [10,10,10] (in).
92         @ivar intergration order:         @type n: C{list} of C{int}s
93         @ivar domain:         @ivar order: element order, default 1 (in).
94           @type order: C{int}
95           @ivar periodic: flags for periodicity, default [False,False,False] (in).
96           @type periodic: C{list} of C{bool}s
97         """         """
98         def __init__(self,debug=False):         def __init__(self,debug=False):
99               """
100               initializes the object
101               """
102             super(RectangularDomain,self).__init__(debug=debug)             super(RectangularDomain,self).__init__(debug=debug)
103             self.declareParameter(dim=2,\             self.declareParameter(dim=2,\
104                                   l=[1.,1.,1.],\                                   l=[1.,1.,1.],\
105                                   n=[10,10,10], \                                   n=[10,10,10], \
106                   order=1,\                   order=1,\
107                                   periodic=[False,False,False],\                                   periodic=[False,False,False])
                                  integrationOrder=-1)  
            self.__domain=None  
108    
109         def domain(self):         def doInitialization(self):
110            if self.__domain==None:             """
111               if self.dim==2:             initializes the object
112                  self.__domain=finley.Rectangle(n0=self.n[0],\             """
113               if self.dim==2:
114                    self.domain=finley.Rectangle(n0=self.n[0],\
115                                               n1=self.n[1],\                                               n1=self.n[1],\
116                                               l0=self.l[0],\                                               l0=self.l[0],\
117                                               l1=self.l[1],\                                               l1=self.l[1],\
# Line 65  class RectangularDomain(ParameterSet): Line 119  class RectangularDomain(ParameterSet):
119                                               periodic0=self.periodic[0], \                                               periodic0=self.periodic[0], \
120                                               periodic1=self.periodic[1], \                                               periodic1=self.periodic[1], \
121                                               integrationOrder=self.integrationOrder)                                               integrationOrder=self.integrationOrder)
122               else:             else:
123                  self.__domain=finley.Brick(n0=self.n[0],\                  self.__domain=finley.Brick(n0=self.n[0],\
124                                           n1=self.n[1],\                                           n1=self.n[1],\
125                                           n2=self.n[2],\                                           n2=self.n[2],\
# Line 77  class RectangularDomain(ParameterSet): Line 131  class RectangularDomain(ParameterSet):
131                                           periodic1=self.periodic[1], \                                           periodic1=self.periodic[1], \
132                                           periodic2=self.periodic[2], \                                           periodic2=self.periodic[2], \
133                                           integrationOrder=self.integrationOrder)                                           integrationOrder=self.integrationOrder)
134               super(RectangularDomain, self).doInitialization()
135    
           return self.__domain  
136    
137  class ConstrainValue(Model):  class ScalarConstrainer(Model):
        """  
        selects values for a given distribution to be used as a constrain. the location of the  
        constrain are he faces of a rectangular domain. This Model is typically used in  
        time dependend problems to fix the values in a given initial condition.  
        """  
        def __init__(self,debug=False):  
            Model.__init__(self,debug=debug)  
            self.declareParameter(domain=None, \  
                                  value=0,  \  
                                  top=True,  \  
                                  bottom=True,\  
                                  front=False, \  
                                  back=False,\  
                                  left=False,\  
                                  right=False,\  
                                  constrain_value = None,  \  
                                  location_constrained_value=None)  
        def doInitialization(self):  
            """  
            initialize time stepping  
            """  
            tol=1.e-8  
            x=self.domain.getX()  
            d=self.domain.getDim()  
            self.location_constrained_value=0  
            x0=x[0]  
            mx=sup(x0)  
            mn=inf(x0)  
            if self.left:  
                self.location_constrained_value=self.location_constrained_value+whereZero(x0-mn,tol*(mx-mn))  
            if self.right:  
                self.location_constrained_value=self.location_constrained_value+whereZero(x0-mx,tol*(mx-mn))  
            x0=x[d-1]  
            mx=sup(x0)  
            mn=inf(x0)  
            if self.bottom:  
                self.location_constrained_value=self.location_constrained_value+whereZero(x0-mn,tol*(mx-mn))  
            if self.top:  
                self.location_constrained_value=self.location_constrained_value+whereZero(x0-mx,tol*(mx-mn))  
            if d>2:  
               x0=x[1]  
               mx=sup(x0)  
               mn=inf(x0)  
               if self.front:  
                  self.location_constrained_value=self.location_constrained_value+whereZero(x0-mn,tol*(mx-mn))  
               if self.back:  
                  self.location_constrained_value=self.location_constrained_value+whereZero(x0-mx,tol*(mx-mn))            
            self.constrain_value=self.value*self.location_constrained_value  
             
 class ScalarConstrainer(ParameterSet):  
138       """       """
139       Creates a characteristic function for the location of constraints       Creates a characteristic function for the location of constraints
140       for a scalar value.       for a scalar value and selects the value from an initial value
141         ate these locations.
142    
143       In the case that the spatial dimension is two, the arguments front       In the case that the spatial dimension is two, the arguments front and back are ignored.
      and back are ignored.  
144    
145       @ivar domain (in): rectangular domain       @ivar domain: domain (in).
146       @ivar left (in): True to set a constraint at the left face of the       @ivar left:  True to set a constraint at the left face of the domain (x[0]=min x[0]), default False (in).
147                 domain (x[0]=min x[0]), default is False       @ivar right: True to set a constraint at the left face of the domain (x[0]=max x[0]), default False (in).
148       @ivar right (in): True to set a constraint at the left face of the       @ivar top: True to set a constraint at the left face of the domain (x[1]=min x[1]), default False (in).
149                 domain (x[0]=max x[0]), default is False       @ivar bottom: True to set a constraint at the left face of the domain (x[1]=max x[1]), default False (in).
150       @ivar top (in): True to set a constraint at the left face of the       @ivar front: True to set a constraint at the left face of the domain (x[2]=min x[2]), default False (in).
151                 domain (x[1]=min x[1]), default is False       @ivar back: True to set a constraint at the left face of the domain (x[2]=max x[2]), default False (in).
152       @ivar bottom (in): True to set a constraint at the left face of the       @ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
153                 domain (x[1]=max x[1]), default is False       @ivar location_of_constraint: locations of the constraints (out).
154       @ivar front (in): True to set a constraint at the left face of the       @ivar constraint: locations of the constraints (out).
                domain (x[2]=min x[2]), default is False  
      @ivar back (in): True to set a constraint at the left face of the  
                domain (x[2]=max x[2]), default is False  
      @ivar location_of_constraint (out): object that defines the location  
                of the constraints.  
155       """       """
156       def __init__(self,debug=False):       def __init__(self,debug=False):
157             ParameterSet.__init__(self,debug=debug)             ParameterSet.__init__(self,debug=debug)
158             self.declareParameter(domain=None, \             self.declareParameter(domain=None, \
159                                     value=0,  \
160                                   left=False, \                                   left=False, \
161                                   right=False, \                                   right=False, \
162                                   top=False, \                                   top=False, \
163                                   bottom=False, \                                   bottom=False, \
164                                   front=False, \                                   front=False, \
165                                   back=False)                                   back=False, \
166                                     tol=1.e-8, \
167                                     constraint_value = None,  \
168                                     location_constrained_value=None)
169             self._location_of_constraint=None             self._location_of_constraint=None
170    
171       def location_of_constraint(self):       def doInitialization(self):
172            """            """
173            Returns the mask of the location of constraint.            Returns the mask of the location of constraint.
174            """            """
175            if self._location_of_constraint==None:            x=self.domain.getX()
176               x=self.domain.getX()            self._location_of_constraint=Scalar(0,x.getFunctionSpace())
177               self._location_of_constraint=Scalar(0,x.getFunctionSpace())            if self.domain.getDim()==3:
178               if self.domain.getDim()==3:                  x0,x1,x2=x[0],x[1],x[2]
179                  if self.left: self._location_of_constraint+=whereZero(x[0]-inf(x[0]))                  if self.left: self._location_of_constraint+=whereZero(x0-inf(x0),self.tol)
180                  if self.right: self._location_of_constraint+=whereZero(x[0]-sup(x[0]))                  if self.right: self._location_of_constraint+=whereZero(x0-sup(x0),self.tol)
181                  if self.front: self._location_of_constraint+=whereZero(x[1]-inf(x[1]))                  if self.front: self._location_of_constraint+=whereZero(x1-inf(x1),self.tol)
182                  if self.back: self._location_of_constraint+=whereZero(x[1]-sup(x[1]))                  if self.back: self._location_of_constraint+=whereZero(x1-sup(x1),self.tol)
183                  if self.bottom: self._location_of_constraint+=whereZero(x[2]-inf(x[2]))                  if self.bottom: self._location_of_constraint+=whereZero(x2-inf(x2),self.tol)
184                  if self.top: self._location_of_constraint+=whereZero(x[2]-sup(x[2]))                  if self.top: self._location_of_constraint+=whereZero(x2-sup(x2),self.tol)
185               else:            else:
186                  if self.left: self._location_of_constraint+=whereZero(x[0]-inf(x[0]))                  x0,x1=x[0],x[1]
187                  if self.right: self._location_of_constraint+=whereZero(x[0]-sup(x[0]))                  if self.left: self._location_of_constraint+=whereZero(x0-inf(x0),self.tol)
188                  if self.bottom: self._location_of_constraint+=whereZero(x[1]-inf(x[1]))                  if self.right: self._location_of_constraint+=whereZero(x0-sup(x0),self.tol)
189                  if self.top: self._location_of_constraint+=whereZero(x[1]-sup(x[1]))                  if self.bottom: self._location_of_constraint+=whereZero(x1-inf(x1),self.tol)
190            return self._location_of_constraint                  if self.top: self._location_of_constraint+=whereZero(x1-sup(x1),self.tol)
191              self.constraint_value=self.location_constrained_value*self.value
192    
193  class VectorConstrainer(ParameterSet):  class VectorConstrainer(Model):
194        """        """
195        Creates a characteristic function for the location of constraints        Creates a characteristic function for the location of constraints vector value.
196        for a scalar value.        In the case that the spatial dimension is two, the arguments front and
197          back as well as the third component of each argument is ignored.
198    
199        @ivar domain (in): rectangular domain        @ivar domain: domain
200        @ivar left (in): list of three boolean. left[i]==True sets a        @ivar left: 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]),
201                  constraint for the i-th component at the left                         default [False,False,False] (in).
202                  face of the domain (x[0]=min x[0]),        @ivar right: 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]),
203                  default is [False,False,False]                  default [False,False,False] (in).
204        @ivar right (in): list of three boolean. left[i]==True sets a        @ivar top: 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]),
205                  constraint for the i-th component at the right                  default [False,False,False] (in).
206                  face of the domain (x[0]=max x[0]),        @ivar bottom: 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]),
207                  default is [False,False,False]                  default [False,False,False] (in).
208        @ivar top (in): list of three boolean. left[i]==True sets a        @ivar front: 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]),
209                  constraint for the i-th component at the top                  default [False,False,False] (in).
210                  face of the domain (x[1]=min x[1]),        @ivar back: 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]),
211                  default is [False,False,False]                  default [False,False,False] (in).
212        @ivar bottom (in): list of three boolean. left[i]==True sets a        @ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
213                  constraint for the i-th component at the bottom        @ivar location_of_constraint: locations of the constraints (out).
214                  face of the domain (x[1]=min x[1]),        @ivar constraint: locations of the constraints (out).
                 default is [False,False,False]  
       @ivar 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]  
       @ivar 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]  
       @ivar location_of_constraint (callable): object that defines the location of the constraints for each vector component.  
215    
       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.  
216        """        """
217        def __init__(self,debug=False):        def __init__(self,debug=False):
218             ParameterSet.__init__(self,debug=debug)             ParameterSet.__init__(self,debug=debug)
219             self.declareParameter(domain=None, \             self.declareParameter(domain=None, \
220                                     value=0,  \
221                                   left=[0,0,0],  \                                   left=[0,0,0],  \
222                                   right=[0,0,0],  \                                   right=[0,0,0],  \
223                                   top=[0,0,0],  \                                   top=[0,0,0],  \
224                                   bottom=[0,0,0],  \                                   bottom=[0,0,0],  \
225                                   front=[0,0,0],                                   front=[0,0,0], \
226                                   back=[0,0,0])                                   ack=[0,0,0], \
227                                     tol=1.e-8, \
228                                     constraint_value = None,  \
229                                     location_constrained_value=None)
230             self._location_of_constraint=None             self._location_of_constraint=None
231        def location_of_constraint(self):        def doInitialization(self):
232            """            """
233            Returns the mask of the location of constraint.            sets the location_constrained_value and constraint_value to be kept throughout the simulation.
234            """            """
235            if self._location_of_constraint==None:            if self._location_of_constraint==None:
236               x=self.domain.getX()               x=self.domain.getX()
237               self._location_of_constraint=Vector(0,x.getFunctionSpace())               self._location_of_constraint=Vector(0,x.getFunctionSpace())
238               if self.domain.getDim()==3:               if self.domain.getDim()==3:
239                  left_mask=whereZero(x[0]-inf(x[0]))                  x0,x1,x2=x[0],x[1],x[2]
240                    left_mask=whereZero(x0-inf(x0),self.tol)
241                  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.]
242                  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.]
243                  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.]
244                  right_mask=whereZero(x[0]-sup(x[0]))                  right_mask=whereZero(x0-sup(x0),self.tol)
245                  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.]
246                  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.]
247                  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.]
248                  front_mask=whereZero(x[1]-inf(x[1]))                  front_mask=whereZero(x1-inf(x1),self.tol)
249                  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.]
250                  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.]
251                  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.]
252                  back_mask=whereZero(x[1]-sup(x[1]))                  back_mask=whereZero(x1-sup(x1),self.tol)
253                  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.]
254                  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.]
255                  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.]
256                  bottom_mask=whereZero(x[2]-inf(x[2]))                  bottom_mask=whereZero(x2-inf(x2),self.tol)
257                  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.]
258                  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.]
259                  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.]
260                  top_mask=whereZero(x[2]-sup(x[2]))                  top_mask=whereZero(x2-sup(x2),self.tol)
261                  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.]
262                  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.]
263                  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.]
264               else:               else:
265                  left_mask=whereZero(x[0]-inf(x[0]))                  x0,x1=x[0],x[1]
266                    left_mask=whereZero(x0-inf(x0),self.tol)
267                  if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.]                  if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.]
268                  if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.]                  if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.]
269                  right_mask=whereZero(x[0]-sup(x[0]))                  right_mask=whereZero(x0-sup(x0),self.tol)
270                  if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.]                  if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.]
271                  if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.]                  if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.]
272                  bottom_mask=whereZero(x[1]-inf(x[1]))                  bottom_mask=whereZero(x1-inf(x1),self.tol)
273                  if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.]                  if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.]
274                  if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.]                  if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.]
275                  top_mask=whereZero(x[1]-sup(x[1]))                  top_mask=whereZero(x1-sup(x1),self.tol)
276                  if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.]                  if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.]
277                  if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.]                  if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.]
278            return self._location_of_constraint            self.constraint_value=self.location_constrained_value*self.value
279    
280  # vim: expandtab shiftwidth=4:  # vim: expandtab shiftwidth=4:

Legend:
Removed from v.720  
changed lines
  Added in v.819

  ViewVC Help
Powered by ViewVC 1.1.26