/[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 406 by gross, Fri Dec 23 00:39:59 2005 UTC revision 820 by gross, Mon Aug 28 06:55:36 2006 UTC
# Line 1  Line 1 
1  # $Id$  # $Id$
2    
3    __copyright__="""  Copyright (c) 2006 by ACcESS MNRF
4                        http://www.access.edu.au
5                    Primary Business: Queensland, Australia"""
6    __license__="""Licensed under the Open Software License version 3.0
7                 http://www.opensource.org/licenses/osl-3.0.php"""
8    
9    
10  from esys.escript import *  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(domain=None,\
31                                     displacement=None,\
32                                     integrationOrder=-1)
33    
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             self.__updated=False
48    
49          def doStep(self,dt):
50             """
51             applies the current L{displacement} to mesh nodes.
52             """
53             if self.displacement:
54                  self.domain.setX(self.__x+self.displacement)
55                  self.__update=False
56    
57          def doStepPostprocessing(self,dt):
58             """
59             applies the final L{displacement} to mesh nodes.
60             """
61             if self.displacement:
62                  self.domain.setX(self.__x+self.displacement)
63                  self.__update=False
64    
65    class FinleyReader(Domain):
66         """         """
67         Generates a mesh over a rectangular domain finley.         reads finley mesh file.
68    
69         @ivar filename:         @ivar source: file name of the finley input file
70         @ivar intergrationOrder         @type source: C{str}
        @ivar domain:  
71         """         """
72         def __init__(self,debug=False):         def __init__(self,debug=False):
73             super(FinleyReader,self).__init__(debug=debug)             super(FinleyReader,self).__init__(debug=debug)
74             ParameterSet.__init__(self,debug=debug)             self.declareParameter(source="none")
            self.declareParameter(source="none",\  
                                  integrationOrder=-1)  
            self._domain=None  
75    
76         def domain(self):         def doInitialization(self):
77            if self._domain==None:            self.domain=finley.ReadMesh(self.source,self.integrationOrder)
78                self._domain=finley.ReadMesh(self.source,self.integrationOrder)            self.trace("mesh read from %s"%self.source)          
79                self.trace("mesh read from %s"%self.source)                      super(FinleyReader, self).doInitialization()
           return self._domain  
80                                                
81  class RectangularDomain(ParameterSet):  class RectangularDomain(Domain):
82         """         """
83         Generates a mesh over a rectangular domain finley.         Generates a mesh over a rectangular domain finley.
84    
85         @ivar dim:         @ivar dim: spatial dimension, default =2 (in).
86         @ivar l:         @type dim: spatial dimension
87         @ivar n:         @ivar l: spatial lengths, default [1.,1.,1.] (in).
88         @ivar order:         @type l: C{list} of C{floats}s
89         @ivar periodic:         @ivar n: number of elements, default [10,10,10] (in).
90         @ivar intergration order:         @type n: C{list} of C{int}s
91         @ivar domain:         @ivar order: element order, default 1 (in).
92           @type order: C{int}
93           @ivar periodic: flags for periodicity, default [False,False,False] (in).
94           @type periodic: C{list} of C{bool}s
95         """         """
96         def __init__(self,debug=False):         def __init__(self,debug=False):
97               """
98               initializes the object
99               """
100             super(RectangularDomain,self).__init__(debug=debug)             super(RectangularDomain,self).__init__(debug=debug)
101             self.declareParameter(dim=2,\             self.declareParameter(dim=2,\
102                                   l=[1.,1.,1.],\                                   l=[1.,1.,1.],\
103                                   n=[10,10,10], \                                   n=[10,10,10], \
104                   order=1,\                   order=1,\
105                                   periodic=[False,False,False],\                                   periodic=[False,False,False])
                                  integrationOrder=-1)  
            self._domain=None  
106    
107         def domain(self):         def doInitialization(self):
108            if self._domain==None:             """
109               if self.dim==2:             initializes the object
110                  self._domain=finley.Rectangle(n0=self.n[0],\             """
111               if self.dim==2:
112                    self.domain=finley.Rectangle(n0=self.n[0],\
113                                               n1=self.n[1],\                                               n1=self.n[1],\
114                                               l0=self.l[0],\                                               l0=self.l[0],\
115                                               l1=self.l[1],\                                               l1=self.l[1],\
# Line 59  class RectangularDomain(ParameterSet): Line 117  class RectangularDomain(ParameterSet):
117                                               periodic0=self.periodic[0], \                                               periodic0=self.periodic[0], \
118                                               periodic1=self.periodic[1], \                                               periodic1=self.periodic[1], \
119                                               integrationOrder=self.integrationOrder)                                               integrationOrder=self.integrationOrder)
120               else:             else:
121                  self._domain=finley.Brick(n0=self.n[0],\                  self.__domain=finley.Brick(n0=self.n[0],\
122                                           n1=self.n[1],\                                           n1=self.n[1],\
123                                           n2=self.n[2],\                                           n2=self.n[2],\
124                                           l0=self.l[0],\                                           l0=self.l[0],\
# Line 71  class RectangularDomain(ParameterSet): Line 129  class RectangularDomain(ParameterSet):
129                                           periodic1=self.periodic[1], \                                           periodic1=self.periodic[1], \
130                                           periodic2=self.periodic[2], \                                           periodic2=self.periodic[2], \
131                                           integrationOrder=self.integrationOrder)                                           integrationOrder=self.integrationOrder)
132               super(RectangularDomain, self).doInitialization()
133    
           return self._domain  
134    
135  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  
            """  
            x=self.domain.getX()  
            d=self.domain.getDim()  
            self.location_constrained_value=0  
            x0=x[0]  
            if self.left:  
                self.location_constrained_value=self.location_constrained_value+whereZero(x0-inf(x0))  
            if self.right:  
                self.location_constrained_value=self.location_constrained_value+whereZero(x0-sup(x0))  
            x0=x[d-1]  
            if self.buttom:  
                self.location_constrained_value=self.location_constrained_value+whereZero(x0-inf(x0))  
            if self.top:  
                self.location_constrained_value=self.location_constrained_value+whereZero(x0-sup(x0))  
            if d>2:  
               x0=x[1]  
               if self.front:  
                  self.location_constrained_value=self.location_constrained_value+whereZero(x0-inf(x0))  
               if self.back:  
                  self.location_constrained_value=self.location_constrained_value+whereZero(x0-sup(x0))            
            self.constrain_value=self.value*self.location_constrained_value  
             
 class ScalarConstrainer(ParameterSet):  
136       """       """
137       Creates a characteristic function for the location of constraints       Creates a characteristic function for the location of constraints
138       for a scalar value.       for a scalar value and selects the value from an initial value
139         ate these locations.
140    
141       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.  
142    
143       @ivar domain (in): rectangular domain       @ivar domain: domain (in).
144       @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).
145                 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).
146       @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).
147                 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).
148       @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).
149                 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).
150       @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).
151                 domain (x[1]=max x[1]), default is False       @ivar location_of_constraint: locations of the constraints (out).
152       @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.  
153       """       """
154       def __init__(self,debug=False):       def __init__(self,debug=False):
155             ParameterSet.__init__(self,debug=debug)             ParameterSet.__init__(self,debug=debug)
156             self.declareParameter(domain=None, \             self.declareParameter(domain=None, \
157                                     value=0,  \
158                                   left=False, \                                   left=False, \
159                                   right=False, \                                   right=False, \
160                                   top=False, \                                   top=False, \
161                                   bottom=False, \                                   bottom=False, \
162                                   front=False, \                                   front=False, \
163                                   back=False)                                   back=False, \
164             self._location_of_constraint=None                                   tol=1.e-8, \
165                                     value_of_constraint = None,  \
166                                     location_of_constraint=None)
167               self.location_of_constraint=None
168    
169       def location_of_constraint(self):       def doInitialization(self):
170            """            """
171            Returns the mask of the location of constraint.            Returns the mask of the location of constraint.
172            """            """
173            if self._location_of_constraint==None:            x=self.domain.getX()
174               x=self.domain.getX()            self.location_of_constraint=Scalar(0,x.getFunctionSpace())
175               self._location_of_constraint=Scalar(0,x.getFunctionSpace())            if self.domain.getDim()==3:
176               if self.domain.getDim()==3:                  x0,x1,x2=x[0],x[1],x[2]
177                  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)
178                  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)
179                  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)
180                  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)
181                  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)
182                  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)
183               else:            else:
184                  if self.left: self._location_of_constraint+=whereZero(x[0]-inf(x[0]))                  x0,x1=x[0],x[1]
185                  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)
186                  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)
187                  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)
188            return self._location_of_constraint                  if self.top: self.location_of_constraint+=whereZero(x1-sup(x1),self.tol)
189              self.value_of_constraint=self.location_of_constraint*self.value
190    
191  class VectorConstrainer(ParameterSet):  class VectorConstrainer(Model):
192        """        """
193        Creates a characteristic function for the location of constraints        Creates a characteristic function for the location of constraints vector value.
194        for a scalar value.        In the case that the spatial dimension is two, the arguments front and
195          back as well as the third component of each argument is ignored.
196    
197        @ivar domain (in): rectangular domain        @ivar domain: domain
198        @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]),
199                  constraint for the i-th component at the left                         default [False,False,False] (in).
200                  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]),
201                  default is [False,False,False]                  default [False,False,False] (in).
202        @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]),
203                  constraint for the i-th component at the right                  default [False,False,False] (in).
204                  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]),
205                  default is [False,False,False]                  default [False,False,False] (in).
206        @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]),
207                  constraint for the i-th component at the top                  default [False,False,False] (in).
208                  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]),
209                  default is [False,False,False]                  default [False,False,False] (in).
210        @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).
211                  constraint for the i-th component at the bottom        @ivar location_of_constraint: locations of the constraints (out).
212                  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.  
213    
       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.  
214        """        """
215        def __init__(self,debug=False):        def __init__(self,debug=False):
216             ParameterSet.__init__(self,debug=debug)             ParameterSet.__init__(self,debug=debug)
217             self.declareParameter(domain=None, \             self.declareParameter(domain=None, \
218                                     value=0,  \
219                                   left=[0,0,0],  \                                   left=[0,0,0],  \
220                                   right=[0,0,0],  \                                   right=[0,0,0],  \
221                                   top=[0,0,0],  \                                   top=[0,0,0],  \
222                                   bottom=[0,0,0],  \                                   bottom=[0,0,0],  \
223                                   front=[0,0,0],                                   front=[0,0,0], \
224                                   back=[0,0,0])                                   ack=[0,0,0], \
225             self._location_of_constraint=None                                   tol=1.e-8, \
226        def location_of_constraint(self):                                   value_of_constraint = None,  \
227                                     location_of_constraint=None)
228               self.location_of_constraint=None
229          def doInitialization(self):
230            """            """
231            Returns the mask of the location of constraint.            sets the location_of_constraint and value_of_constraint to be kept throughout the simulation.
232            """            """
233            if self._location_of_constraint==None:            if self.location_of_constraint==None:
234               x=self.domain.getX()               x=self.domain.getX()
235               self._location_of_constraint=Vector(0,x.getFunctionSpace())               self.location_of_constraint=Vector(0,x.getFunctionSpace())
236               if self.domain.getDim()==3:               if self.domain.getDim()==3:
237                  left_mask=whereZero(x[0]-inf(x[0]))                  x0,x1,x2=x[0],x[1],x[2]
238                  if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.,0.]                  left_mask=whereZero(x0-inf(x0),self.tol)
239                  if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.,0.]                  if self.left[0]: self.location_of_constraint+=left_mask*[1.,0.,0.]
240                  if self.left[2]: self._location_of_constraint+=left_mask*[0.,0.,1.]                  if self.left[1]: self.location_of_constraint+=left_mask*[0.,1.,0.]
241                  right_mask=whereZero(x[0]-sup(x[0]))                  if self.left[2]: self.location_of_constraint+=left_mask*[0.,0.,1.]
242                  if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.,0.]                  right_mask=whereZero(x0-sup(x0),self.tol)
243                  if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.,0.]                  if self.right[0]: self.location_of_constraint+=right_mask*[1.,0.,0.]
244                  if self.right[2]: self._location_of_constraint+=right_mask*[0.,0.,1.]                  if self.right[1]: self.location_of_constraint+=right_mask*[0.,1.,0.]
245                  front_mask=whereZero(x[1]-inf(x[1]))                  if self.right[2]: self.location_of_constraint+=right_mask*[0.,0.,1.]
246                  if self.front[0]: self._location_of_constraint+=front_mask*[1.,0.,0.]                  front_mask=whereZero(x1-inf(x1),self.tol)
247                  if self.front[1]: self._location_of_constraint+=front_mask*[0.,1.,0.]                  if self.front[0]: self.location_of_constraint+=front_mask*[1.,0.,0.]
248                  if self.front[2]: self._location_of_constraint+=front_mask*[0.,0.,1.]                  if self.front[1]: self.location_of_constraint+=front_mask*[0.,1.,0.]
249                  back_mask=whereZero(x[1]-sup(x[1]))                  if self.front[2]: self.location_of_constraint+=front_mask*[0.,0.,1.]
250                  if self.back[0]: self._location_of_constraint+=back_mask*[1.,0.,0.]                  back_mask=whereZero(x1-sup(x1),self.tol)
251                  if self.back[1]: self._location_of_constraint+=back_mask*[0.,1.,0.]                  if self.back[0]: self.location_of_constraint+=back_mask*[1.,0.,0.]
252                  if self.back[2]: self._location_of_constraint+=back_mask*[0.,0.,1.]                  if self.back[1]: self.location_of_constraint+=back_mask*[0.,1.,0.]
253                  bottom_mask=whereZero(x[2]-inf(x[2]))                  if self.back[2]: self.location_of_constraint+=back_mask*[0.,0.,1.]
254                  if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.,0.]                  bottom_mask=whereZero(x2-inf(x2),self.tol)
255                  if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.,0.]                  if self.bottom[0]: self.location_of_constraint+=bottom_mask*[1.,0.,0.]
256                  if self.bottom[2]: self._location_of_constraint+=bottom_mask*[0.,0.,1.]                  if self.bottom[1]: self.location_of_constraint+=bottom_mask*[0.,1.,0.]
257                  top_mask=whereZero(x[2]-sup(x[2]))                  if self.bottom[2]: self.location_of_constraint+=bottom_mask*[0.,0.,1.]
258                  if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.,0.]                  top_mask=whereZero(x2-sup(x2),self.tol)
259                  if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.,0.]                  if self.top[0]: self.location_of_constraint+=top_mask*[1.,0.,0.]
260                  if self.top[2]: self._location_of_constraint+=top_mask*[0.,0.,1.]                  if self.top[1]: self.location_of_constraint+=top_mask*[0.,1.,0.]
261                    if self.top[2]: self.location_of_constraint+=top_mask*[0.,0.,1.]
262               else:               else:
263                  left_mask=whereZero(x[0]-inf(x[0]))                  x0,x1=x[0],x[1]
264                  if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.]                  left_mask=whereZero(x0-inf(x0),self.tol)
265                  if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.]                  if self.left[0]: self.location_of_constraint+=left_mask*[1.,0.]
266                  right_mask=whereZero(x[0]-sup(x[0]))                  if self.left[1]: self.location_of_constraint+=left_mask*[0.,1.]
267                  if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.]                  right_mask=whereZero(x0-sup(x0),self.tol)
268                  if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.]                  if self.right[0]: self.location_of_constraint+=right_mask*[1.,0.]
269                  bottom_mask=whereZero(x[1]-inf(x[1]))                  if self.right[1]: self.location_of_constraint+=right_mask*[0.,1.]
270                  if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.]                  bottom_mask=whereZero(x1-inf(x1),self.tol)
271                  if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.]                  if self.bottom[0]: self.location_of_constraint+=bottom_mask*[1.,0.]
272                  top_mask=whereZero(x[1]-sup(x[1]))                  if self.bottom[1]: self.location_of_constraint+=bottom_mask*[0.,1.]
273                  if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.]                  top_mask=whereZero(x1-sup(x1),self.tol)
274                  if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.]                  if self.top[0]: self.location_of_constraint+=top_mask*[1.,0.]
275            return self._location_of_constraint                  if self.top[1]: self.location_of_constraint+=top_mask*[0.,1.]
276              self.value_of_constraint=self.location_of_constraint*self.value
277    
278  # vim: expandtab shiftwidth=4:  # vim: expandtab shiftwidth=4:

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

  ViewVC Help
Powered by ViewVC 1.1.26