/[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 155 by jgs, Wed Nov 9 02:02:19 2005 UTC revision 1809 by ksteube, Thu Sep 25 06:43:44 2008 UTC
# Line 1  Line 1 
 # $Id$  
1    
2    ########################################################
3    #
4    # Copyright (c) 2003-2008 by University of Queensland
5    # Earth Systems Science Computational Center (ESSCC)
6    # http://www.uq.edu.au/esscc
7    #
8    # Primary Business: Queensland, Australia
9    # Licensed under the Open Software License version 3.0
10    # http://www.opensource.org/licenses/osl-3.0.php
11    #
12    ########################################################
13    
14    __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15    Earth Systems Science Computational Center (ESSCC)
16    http://www.uq.edu.au/esscc
17    Primary Business: Queensland, Australia"""
18    __license__="""Licensed under the Open Software License version 3.0
19    http://www.opensource.org/licenses/osl-3.0.php"""
20    __url__="http://www.uq.edu.au/esscc/escript-finley"
21    
22  from esys.escript import *  from esys.escript import *
23  from esys.escript.modelframe import Model,ParameterSet  from esys.escript.modelframe import Model,ParameterSet
24  from esys import finley  from esys import finley
25    
26  class RectangularDomain(Model):  class FinleyReader(ParameterSet):
27           """
28           reads finley mesh file.
29    
30           @ivar source: mesh file in finley or gmsh format
31           @type source: C{DataSource}
32           @ivar intergrationOrder: integration order, default -1 (in).
33           @type intergrationOrder: C{int}
34           @ivar reducedIntegrationOrder: reduced integration order, default -1 (in).
35           @type reducedIntegrationOrder: C{int}
36           @ivar optimizeLabeling: switches on optimization of the labeling of the nodes
37           @type optimizeLabeling: C{bool}
38           """
39           def __init__(self,**kwargs):
40              """
41              initializes the object
42              """
43              super(FinleyReader,self).__init__(**kwargs)
44              self.declareParameter(source="none",
45                                    dim=None,
46                                    optimizeLabeling=True,
47                                    reducedIntegrationOrder=-1,
48                                    integrationOrder=-1)
49              self.__domain=None
50    
51    
52           def domain(self):
53              """
54              returns the domain
55    
56              @return: the domain
57              @rtype: L{Domain}
58              """
59              if self.__domain == None:
60                 if  self.source.fileformat == "fly":
61                    self.__domain=finley.ReadMesh(self.source.getLocalFileName(),self.integrationOrder)
62                 elif self.source.fileformat == "gmsh":
63                    if self.dim==None:
64                       dim=3
65                    else:
66                       dim=self.dim
67                    self.__domain=finley.ReadGmsh(self.source.getLocalFileName(),dim,self.integrationOrder,self.reducedIntegrationOrder, self.optimizeLabeling)
68                 else:
69                    raise TypeError("unknown mesh file format %s."%self.source.fileformat)
70                 self.trace("mesh read from %s in %s format."%(self.source.getLocalFileName(), self.source.fileformat))          
71              return self.__domain
72    class RectangularDomain(ParameterSet):
73         """         """
74         Generates a mesh over a rectangular domain finley.         Generates a mesh over a rectangular domain finley.
75    
76         @ivar dim:         @ivar dim: spatial dimension, default =2 (in).
77         @ivar l:         @type dim: spatial dimension
78         @ivar n:         @ivar l: spatial lengths, default [1.,1.,1.] (in).
79         @ivar order:         @type l: C{list} of C{floats}s
80         @ivar periodic:         @ivar n: number of elements, default [10,10,10] (in).
81         @ivar intergration order:         @type n: C{list} of C{int}s
82         @ivar domain (callable):         @ivar order: element order, default 1 (in).
83           @type order: C{int}
84           @ivar periodic: flags for periodicity, default [False,False,False] (in).
85           @type periodic: C{list} of C{bool}s
86           @ivar intergrationOrder: integration order, default -1 (in).
87           @type intergrationOrder: C{int}
88         """         """
89         def __init__(self,debug=False):         def __init__(self,**kwargs):
90             Model.__init__(self,debug=debug)             """
91               initializes the object
92               """
93               super(RectangularDomain,self).__init__(**kwargs)
94             self.declareParameter(dim=2,\             self.declareParameter(dim=2,\
95                                   l=[1.,1.,1.],\                                   l=[1.,1.,1.],\
96                                   n=[10,10,10], \                                   n=[10,10,10], \
97                   order=1,\                   order=1,\
98                                   periodic=[False,False,False],\                                   periodic=[False,False,False],
99                                   integrationOrder=-1)                                   integrationOrder=-1)
100             self._domain=None             self.__domain=None
101    
102         def domain(self):         def domain(self):
103            if self._domain==None:             """
104               if self.dim==2:             returns the domain
105                  self._domain=finley.Rectangle(n0=self.n[0],\  
106                                               n1=self.n[1],\             @return: the domain
107                                               l0=self.l[0],\             @rtype: L{Domain}
108                                               l1=self.l[1],\             """
109                                               order=self.order, \             if self.__domain==None:
110                                               periodic0=self.periodic[0], \                if self.dim==2:
111                                               periodic1=self.periodic[1], \                     self.__domain=finley.Rectangle(n0=self.n[0],\
112                                               integrationOrder=self.integrationOrder)                                                  n1=self.n[2],\
113               else:                                                  l0=self.l[0],\
114                  self._domain=finley.Brick(n0=self.n[0],\                                                  l1=self.l[2],\
115                                           n1=self.n[1],\                                                  order=self.order, \
116                                           n2=self.n[2],\                                                  periodic0=self.periodic[0], \
117                                           l0=self.l[0],\                                                  periodic1=self.periodic[2], \
118                                           l1=self.l[1],\                                                  integrationOrder=self.integrationOrder)
119                                           l2=self.l[2],\                else:
120                                           order=self.order, \                     self.__domain=finley.Brick(n0=self.n[0],\
121                                           periodic0=self.periodic[0], \                                              n1=self.n[1],\
122                                           periodic1=self.periodic[1], \                                              n2=self.n[2],\
123                                           periodic2=self.periodic[2], \                                              l0=self.l[0],\
124                                           integrationOrder=self.integrationOrder)                                              l1=self.l[1],\
125                                                l2=self.l[2],\
126            return self._domain                                              order=self.order, \
127                                                periodic0=self.periodic[0], \
128  class ScalarConstrainer(ParameterSet):                                              periodic1=self.periodic[1], \
129       """                                              periodic2=self.periodic[2], \
130       Creates a characteristic function for the location of constraints                                              integrationOrder=self.integrationOrder)
131       for a scalar value.             return self.__domain
132    
133       In the case that the spatial dimension is two, the arguments front  class UpdateGeometry(Model):
134       and back are ignored.        """
135          applies a displacement field to a domain
136       @ivar domain (in): rectangular domain        
137       @ivar left (in): True to set a constraint at the left face of the        @ivar displacement: displacements applied to the original mesh coordinates (in).
138                 domain (x[0]=min x[0]), default is False        @type displacement: L{escript.Vector}
139       @ivar right (in): True to set a constraint at the left face of the        @ivar domain: domain
140                 domain (x[0]=max x[0]), default is False        @type domain: L{escript.Domain}
141       @ivar top (in): True to set a constraint at the left face of the        """
142                 domain (x[1]=min x[1]), default is False        def __init__(self,**kwargs):
143       @ivar bottom (in): True to set a constraint at the left face of the             """
144                 domain (x[1]=max x[1]), default is False             set-up the object
145       @ivar front (in): True to set a constraint at the left face of the             """
146                 domain (x[2]=min x[2]), default is False             super(UpdateGeometry, self).__init__(**kwargs)
147       @ivar back (in): True to set a constraint at the left face of the             self.declareParameter(domain=None,\
148                 domain (x[2]=max x[2]), default is False                                   displacement=None)
149       @ivar location_of_constraint (out): object that defines the location  
150                 of the constraints.  
151       """        def doInitialization(self):
152       def __init__(self,debug=False):           """
153             ParameterSet.__init__(self,debug=debug)           initialize model
154             """
155             self.__x=self.domain.getX()
156             self.__reset=True
157            
158          def doStepPreprocessing(self,dt):
159             """
160             applies the current L{displacement} to mesh nodes if required.
161             """
162             if self.__reset:
163                self.trace("mesh nodes updated.")
164                self.domain.setX(self.__x+self.displacement)
165             self.__reset=False
166    
167          def doStep(self,dt):
168             """
169             applies the current L{displacement} to mesh nodes.
170             """
171             self.trace("mesh nodes updated.")
172             self.domain.setX(self.__x+self.displacement)
173             self.__reset=True
174    
175          def doStepPostprocessing(self,dt):
176             """
177             marks nodes as beeing updated.
178             """
179             self.__reset=False
180    
181    class ConstrainerOverBox(Model):
182          """
183          Creates a characteristic function for the location of constraints
184          for all components of a value and selects the value from an initial value
185          ate these locations.
186    
187          In the case that the spatial dimension is two, the arguments front and back are ignored.
188    
189          @ivar domain: domain (in).
190          @ivar left:  True to set a constraint at the left face of the domain (x[0]=min x[0]), default False (in).
191          @ivar right: True to set a constraint at the left face of the domain (x[0]=max x[0]), default False (in).
192          @ivar top: True to set a constraint at the left face of the domain (x[1]=min x[1]), default False (in).
193          @ivar bottom: True to set a constraint at the left face of the domain (x[1]=max x[1]), default False (in).
194          @ivar front: True to set a constraint at the left face of the domain (x[2]=min x[2]), default False (in).
195          @ivar back: True to set a constraint at the left face of the domain (x[2]=max x[2]), default False (in).
196          @ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
197          """
198          def __init__(self,**kwargs):
199               super(ConstrainerOverBox, self).__init__(**kwargs)
200             self.declareParameter(domain=None, \             self.declareParameter(domain=None, \
201                                     value=None,  \
202                                   left=False, \                                   left=False, \
203                                   right=False, \                                   right=False, \
204                                   top=False, \                                   top=False, \
205                                   bottom=False, \                                   bottom=False, \
206                                   front=False, \                                   front=False, \
207                                   back=False)                                   back=False, \
208             self._location_of_constraint=None                                   tol=1.e-8)
209               self.__value_of_constraint = None
210               self.__location_of_constraint=None
211          def location_of_constraint(self):
212              """
213              return the values used to constrain a solution
214    
215       def location_of_constraint(self):            @return: the mask marking the locations of the constraints
216              @rtype: L{escript.Scalar}
217              """
218              if self.__location_of_constraint == None: self.__setOutput()
219              return self.__location_of_constraint
220            
221          def value_of_constraint(self):
222            """            """
223            Returns the mask of the location of constraint.            return the values used to constrain a solution
224    
225              @return: values to be used at the locations of the constraints. If
226                      L{value} is not given C{None} is rerturned.
227              @rtype: L{escript.Scalar}
228            """            """
229            if self._location_of_constraint==None:            if self.__location_of_constraint == None: self.__setOutput()
230              return self.__value_of_constraint
231            
232          def __setOutput(self):
233              if self.__location_of_constraint == None:
234               x=self.domain.getX()               x=self.domain.getX()
235               self._location_of_constraint=Scalar(0,x.getFunctionSpace())               val=self.value
236                 if isinstance(val, int) or isinstance(val, float):
237                    shape=()
238                 elif isinstance(val, list) or isinstance(val, tuple) :
239                    shape=(len(val),)
240                 elif isinstance(val, numarray.NumArray):
241                     shape=val.shape
242                 elif val == None:
243                      shape=()
244                 else:
245                     shape=val.getShape()
246                 self.__location_of_constraint=Data(0,shape,x.getFunctionSpace())
247               if self.domain.getDim()==3:               if self.domain.getDim()==3:
248                  if self.left: self._location_of_constraint+=(x[0]-inf(x[0])).whereZero()                     x0,x1,x2=x[0],x[1],x[2]
249                  if self.right: self._location_of_constraint+=(x[0]-sup(x[0])).whereZero()                     if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol)
250                  if self.front: self._location_of_constraint+=(x[1]-inf(x[1])).whereZero()                     if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol)
251                  if self.back: self._location_of_constraint+=(x[1]-sup(x[1])).whereZero()                     if self.front: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol)
252                  if self.bottom: self._location_of_constraint+=(x[2]-inf(x[2])).whereZero()                     if self.back: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol)
253                  if self.top: self._location_of_constraint+=(x[2]-sup(x[2])).whereZero()                     if self.bottom: self.__location_of_constraint+=whereZero(x2-inf(x2),self.tol)
254                       if self.top: self.__location_of_constraint+=whereZero(x2-sup(x2),self.tol)
255               else:               else:
256                  if self.left: self._location_of_constraint+=(x[0]-inf(x[0])).whereZero()                     x0,x1=x[0],x[1]
257                  if self.right: self._location_of_constraint+=(x[0]-sup(x[0])).whereZero()                     if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol)
258                  if self.bottom: self._location_of_constraint+=(x[1]-inf(x[1])).whereZero()                     if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol)
259                  if self.top: self._location_of_constraint+=(x[1]-sup(x[1])).whereZero()                     if self.bottom: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol)
260            return self._location_of_constraint                     if self.top: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol)
261                 if not self.value == None:
262  class VectorConstrainer(ParameterSet):                     self.__value_of_constraint=self.__location_of_constraint*self.value
263    class ScalarConstrainerOverBox(Model):
264        """        """
265        Creates a characteristic function for the location of constraints        Creates a characteristic function for the location of constraints
266        for a scalar value.        for a scalar value and selects the value from an initial value
267          ate these locations.
268    
269        @ivar domain (in): rectangular domain        In the case that the spatial dimension is two, the arguments front and back are ignored.
       @ivar 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]  
       @ivar 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]  
       @ivar 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]  
       @ivar 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]  
       @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.  
270    
271        In the case that the spatial dimension is two, thh arguments front and        @ivar domain: domain (in).
272          @ivar left:  True to set a constraint at the left face of the domain (x[0]=min x[0]), default False (in).
273          @ivar right: True to set a constraint at the left face of the domain (x[0]=max x[0]), default False (in).
274          @ivar top: True to set a constraint at the left face of the domain (x[1]=min x[1]), default False (in).
275          @ivar bottom: True to set a constraint at the left face of the domain (x[1]=max x[1]), default False (in).
276          @ivar front: True to set a constraint at the left face of the domain (x[2]=min x[2]), default False (in).
277          @ivar back: True to set a constraint at the left face of the domain (x[2]=max x[2]), default False (in).
278          @ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
279          """
280          def __init__(self,**kwargs):
281               super(ScalarConstrainerOverBox, self).__init__(**kwargs)
282               self.declareParameter(domain=None, \
283                                     value=None,  \
284                                     left=False, \
285                                     right=False, \
286                                     top=False, \
287                                     bottom=False, \
288                                     front=False, \
289                                     back=False, \
290                                     tol=1.e-8)
291               self.__value_of_constraint = None
292               self.__location_of_constraint=None
293          def location_of_constraint(self):
294              """
295              return the values used to constrain a solution
296    
297              @return: the mask marking the locations of the constraints
298              @rtype: L{escript.Scalar}
299              """
300              if self.__location_of_constraint == None: self.__setOutput()
301              return self.__location_of_constraint
302            
303          def value_of_constraint(self):
304              """
305              return the values used to constrain a solution
306    
307              @return: values to be used at the locations of the constraints. If
308                      L{value} is not given C{None} is rerturned.
309              @rtype: L{escript.Scalar}
310              """
311              if self.__location_of_constraint == None: self.__setOutput()
312              return self.__value_of_constraint
313            
314          def __setOutput(self):
315              x=self.domain.getX()
316              self.__location_of_constraint=Scalar(0,x.getFunctionSpace())
317              if self.domain.getDim()==3:
318                    x0,x1,x2=x[0],x[1],x[2]
319                    if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol)
320                    if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol)
321                    if self.front: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol)
322                    if self.back: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol)
323                    if self.bottom: self.__location_of_constraint+=whereZero(x2-inf(x2),self.tol)
324                    if self.top: self.__location_of_constraint+=whereZero(x2-sup(x2),self.tol)
325              else:
326                    x0,x1=x[0],x[1]
327                    if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol)
328                    if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol)
329                    if self.bottom: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol)
330                    if self.top: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol)
331              if not self.value == None:
332                  self.__value_of_constraint=self.__location_of_constraint*self.value
333    
334    class VectorConstrainerOverBox(Model):
335          """
336          Creates a characteristic function for the location of constraints vector value.
337          In the case that the spatial dimension is two, the arguments front and
338        back as well as the third component of each argument is ignored.        back as well as the third component of each argument is ignored.
339    
340          @ivar domain: domain
341          @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]),
342                           default [False,False,False] (in).
343          @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]),
344                    default [False,False,False] (in).
345          @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]),
346                    default [False,False,False] (in).
347          @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]),
348                    default [False,False,False] (in).
349          @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]),
350                    default [False,False,False] (in).
351          @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]),
352                    default [False,False,False] (in).
353          @ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
354        """        """
355        def __init__(self,debug=False):        def __init__(self, **kwargs):
356             ParameterSet.__init__(self,debug=debug)             super(VectorConstrainerOverBox, self).__init__(**kwargs)
357             self.declareParameter(domain=None, \             self.declareParameter(domain=None, \
358                                   left=[0,0,0],  \                                   value=None,  \
359                                   right=[0,0,0],  \                                   left=[False ,False ,False ],  \
360                                   top=[0,0,0],  \                                   right=[False ,False ,False ],  \
361                                   bottom=[0,0,0],  \                                   top=[False ,False ,False ],  \
362                                   front=[0,0,0],                                   bottom=[False ,False ,False ],  \
363                                   back=[0,0,0])                                   front=[False ,False ,False ], \
364             self._location_of_constraint=None                                   back=[False ,False ,False ], \
365                                     tol=1.e-8)
366               self.__value_of_constraint = None
367               self.__location_of_constraint=None
368    
369        def location_of_constraint(self):        def location_of_constraint(self):
370            """            """
371            Returns the mask of the location of constraint.            return the values used to constrain a solution
372    
373              @return: the mask marking the locations of the constraints
374              @rtype: L{escript.Vector}
375              """
376              if self.__location_of_constraint == None: self.__setOutput()
377              return self.__location_of_constraint
378            
379          def value_of_constraint(self):
380              """
381              return the values used to constrain a solution
382    
383              @return: values to be used at the locations of the constraints. If
384                      L{value} is not given C{None} is rerturned.
385              @rtype: L{escript.Vector}
386            """            """
387            if self._location_of_constraint==None:            if self.__location_of_constraint == None: self.__setOutput()
388              return self.__value_of_constraint
389            
390          def __setOutput(self):
391              x=self.domain.getX()
392              self.__location_of_constraint=Vector(0,x.getFunctionSpace())
393              if self.domain.getDim()==3:
394                 x0,x1,x2=x[0],x[1],x[2]
395                 left_mask=whereZero(x0-inf(x0),self.tol)
396                 if self.left[0]: self.__location_of_constraint+=left_mask*[1.,0.,0.]
397                 if self.left[1]: self.__location_of_constraint+=left_mask*[0.,1.,0.]
398                 if self.left[2]: self.__location_of_constraint+=left_mask*[0.,0.,1.]
399                 right_mask=whereZero(x0-sup(x0),self.tol)
400                 if self.right[0]: self.__location_of_constraint+=right_mask*[1.,0.,0.]
401                 if self.right[1]: self.__location_of_constraint+=right_mask*[0.,1.,0.]
402                 if self.right[2]: self.__location_of_constraint+=right_mask*[0.,0.,1.]
403                 front_mask=whereZero(x1-inf(x1),self.tol)
404                 if self.front[0]: self.__location_of_constraint+=front_mask*[1.,0.,0.]
405                 if self.front[1]: self.__location_of_constraint+=front_mask*[0.,1.,0.]
406                 if self.front[2]: self.__location_of_constraint+=front_mask*[0.,0.,1.]
407                 back_mask=whereZero(x1-sup(x1),self.tol)
408                 if self.back[0]: self.__location_of_constraint+=back_mask*[1.,0.,0.]
409                 if self.back[1]: self.__location_of_constraint+=back_mask*[0.,1.,0.]
410                 if self.back[2]: self.__location_of_constraint+=back_mask*[0.,0.,1.]
411                 bottom_mask=whereZero(x2-inf(x2),self.tol)
412                 if self.bottom[0]: self.__location_of_constraint+=bottom_mask*[1.,0.,0.]
413                 if self.bottom[1]: self.__location_of_constraint+=bottom_mask*[0.,1.,0.]
414                 if self.bottom[2]: self.__location_of_constraint+=bottom_mask*[0.,0.,1.]
415                 top_mask=whereZero(x2-sup(x2),self.tol)
416                 if self.top[0]: self.__location_of_constraint+=top_mask*[1.,0.,0.]
417                 if self.top[1]: self.__location_of_constraint+=top_mask*[0.,1.,0.]
418                 if self.top[2]: self.__location_of_constraint+=top_mask*[0.,0.,1.]
419                 if not self.value == None:
420                    self.__value_of_constraint=self.__location_of_constraint*self.value
421              else:
422                 x0,x1=x[0],x[1]
423                 left_mask=whereZero(x0-inf(x0),self.tol)
424                 if self.left[0]: self.__location_of_constraint+=left_mask*[1.,0.]
425                 if self.left[1]: self.__location_of_constraint+=left_mask*[0.,1.]
426                 right_mask=whereZero(x0-sup(x0),self.tol)
427                 if self.right[0]: self.__location_of_constraint+=right_mask*[1.,0.]
428                 if self.right[1]: self.__location_of_constraint+=right_mask*[0.,1.]
429                 bottom_mask=whereZero(x1-inf(x1),self.tol)
430                 if self.bottom[0]: self.__location_of_constraint+=bottom_mask*[1.,0.]
431                 if self.bottom[1]: self.__location_of_constraint+=bottom_mask*[0.,1.]
432                 top_mask=whereZero(x1-sup(x1),self.tol)
433                 if self.top[0]: self.__location_of_constraint+=top_mask*[1.,0.]
434                 if self.top[1]: self.__location_of_constraint+=top_mask*[0.,1.]
435                 if not self.value == None:
436                    self.__value_of_constraint=self.__location_of_constraint*self.value[:2]
437    
438    class ConstrainerAtBoxVertex(Model):
439          """
440          Creates a characteristic function for the location of constraints
441          for all components of a value and selects the value from an initial value
442          ate these locations.
443    
444          In the case that the spatial dimension is two, the arguments front and back are ignored.
445    
446          @ivar domain: domain (in).
447          @ivar tol: absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).
448          """
449          def __init__(self,**kwargs):
450               super(ConstrainerAtBoxVertex, self).__init__(**kwargs)
451               self.declareParameter(domain=None, \
452                                     value=None,  \
453                                     tol=1.e-8)
454               self.__value_of_constraint = None
455               self.__location_of_constraint=None
456          def location_of_constraint(self):
457              """
458              return the values used to constrain a solution
459    
460              @return: the mask marking the locations of the constraints
461              @rtype: L{escript.Scalar}
462              """
463              if self.__location_of_constraint == None: self.__setOutput()
464              return self.__location_of_constraint
465            
466          def value_of_constraint(self):
467              """
468              return the values used to constrain a solution
469    
470              @return: values to be used at the locations of the constraints. If
471                      L{value} is not given C{None} is rerturned.
472              @rtype: L{escript.Scalar}
473              """
474              if self.__location_of_constraint == None: self.__setOutput()
475              return self.__value_of_constraint
476            
477          def __setOutput(self):
478              if self.__location_of_constraint == None:
479               x=self.domain.getX()               x=self.domain.getX()
480               self._location_of_constraint=Vector(0,x.getFunctionSpace())               val=self.value
481                 if isinstance(val, int) or isinstance(val, float):
482                    shape=()
483                 elif isinstance(val, list) or isinstance(val, tuple) :
484                    shape=(len(val),)
485                 elif isinstance(val, numarray.NumArray):
486                     shape=val.shape
487                 elif val == None:
488                      shape=()
489                 else:
490                     shape=val.getShape()
491               if self.domain.getDim()==3:               if self.domain.getDim()==3:
492                  left_mask=(x[0]-inf(x[0])).whereZero()                     vertex=[inf(x[0]),inf(x[1]),inf(x[2])]
                 if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.,0.]  
                 if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.,0.]  
                 if self.left[2]: self._location_of_constraint+=left_mask*[0.,0.,1.]  
                 right_mask=(x[0]-sup(x[0])).whereZero()  
                 if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.,0.]  
                 if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.,0.]  
                 if self.right[2]: self._location_of_constraint+=right_mask*[0.,0.,1.]  
                 front_mask=(x[1]-inf(x[1])).whereZero()  
                 if self.front[0]: self._location_of_constraint+=front_mask*[1.,0.,0.]  
                 if self.front[1]: self._location_of_constraint+=front_mask*[0.,1.,0.]  
                 if self.front[2]: self._location_of_constraint+=front_mask*[0.,0.,1.]  
                 back_mask=(x[1]-sup(x[1])).whereZero()  
                 if self.back[0]: self._location_of_constraint+=back_mask*[1.,0.,0.]  
                 if self.back[1]: self._location_of_constraint+=back_mask*[0.,1.,0.]  
                 if self.back[2]: self._location_of_constraint+=back_mask*[0.,0.,1.]  
                 bottom_mask=(x[2]-inf(x[2])).whereZero()  
                 if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.,0.]  
                 if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.,0.]  
                 if self.bottom[2]: self._location_of_constraint+=bottom_mask*[0.,0.,1.]  
                 top_mask=(x[2]-sup(x[2])).whereZero()  
                 if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.,0.]  
                 if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.,0.]  
                 if self.top[2]: self._location_of_constraint+=top_mask*[0.,0.,1.]  
493               else:               else:
494                  left_mask=(x[0]-inf(x[0])).whereZero()                     vertex=[inf(x[0]),inf(x[1])]
495                  if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.]               self.__location_of_constraint=whereZero(length(x-vertex),self.tol)*numarray.ones(shape)
496                  if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.]               if not self.value == None:
497                  right_mask=(x[0]-sup(x[0])).whereZero()                     self.__value_of_constraint=self.__location_of_constraint*self.value
498                  if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.]  class ScalarConstrainerAtBoxVertex(Model):
499                  if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.]        """
500                  bottom_mask=(x[1]-inf(x[1])).whereZero()        Creates a characteristic function for the location of constraints
501                  if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.]        for a scalar value and selects the value from an initial value
502                  if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.]        ate these locations.
503                  top_mask=(x[1]-sup(x[1])).whereZero()  
504                  if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.]        In the case that the spatial dimension is two, the arguments front and back are ignored.
505                  if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.]  
506            return self._location_of_constraint        @ivar domain: domain (in).
507          @ivar tol: absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).
508          """
509          def __init__(self,**kwargs):
510               super(ScalarConstrainerAtBoxVertex, self).__init__(**kwargs)
511               self.declareParameter(domain=None, \
512                                     value=None,  \
513                                     tol=1.e-8)
514               self.__value_of_constraint = None
515               self.__location_of_constraint=None
516          def location_of_constraint(self):
517              """
518              return the values used to constrain a solution
519    
520              @return: the mask marking the locations of the constraints
521              @rtype: L{escript.Scalar}
522              """
523              if self.__location_of_constraint == None: self.__setOutput()
524              return self.__location_of_constraint
525            
526          def value_of_constraint(self):
527              """
528              return the values used to constrain a solution
529    
530              @return: values to be used at the locations of the constraints. If
531                      L{value} is not given C{None} is rerturned.
532              @rtype: L{escript.Scalar}
533              """
534              if self.__location_of_constraint == None: self.__setOutput()
535              return self.__value_of_constraint
536            
537          def __setOutput(self):
538              x=self.domain.getX()
539              self.__location_of_constraint=Scalar(0,x.getFunctionSpace())
540              if self.domain.getDim()==3:
541                       vertex=[inf(x[0]),inf(x[1]),inf(x[2])]
542              else:
543                     vertex=[inf(x[0]),inf(x[1])]
544              self.__location_of_constraint=whereZero(length(x-vertex),self.tol)
545              if not self.value == None:
546                  self.__value_of_constraint=self.__location_of_constraint*self.value
547    
548    class VectorConstrainerAtBoxVertex(Model):
549          """
550          Creates a characteristic function for the location of constraints vector value.
551          In the case that the spatial dimension is two, the arguments front and
552          back as well as the third component of each argument is ignored.
553    
554          @ivar domain: domain
555          @ivar comp_mask: list of three boolean. comp_mask[i]==True sets a constraint for the i-th component at the left, front, bottom vertex, default [False,False,False] (in).
556          @ivar tol: absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).
557          """
558          def __init__(self, **kwargs):
559               super(VectorConstrainerAtBoxVertex, self).__init__(**kwargs)
560               self.declareParameter(domain=None, \
561                                     value=None,  \
562                                     comp_mask=[False, False, False],
563                                     tol=1.e-8)
564               self.__value_of_constraint = None
565               self.__location_of_constraint=None
566    
567          def location_of_constraint(self):
568              """
569              return the values used to constrain a solution
570    
571              @return: the mask marking the locations of the constraints
572              @rtype: L{escript.Vector}
573              """
574              if self.__location_of_constraint == None: self.__setOutput()
575              return self.__location_of_constraint
576            
577          def value_of_constraint(self):
578              """
579              return the values used to constrain a solution
580    
581              @return: values to be used at the locations of the constraints. If
582                      L{value} is not given C{None} is rerturned.
583              @rtype: L{escript.Vector}
584              """
585              if self.__location_of_constraint == None: self.__setOutput()
586              return self.__value_of_constraint
587            
588          def __setOutput(self):
589              x=self.domain.getX()
590              self.__location_of_constraint=Vector(0,x.getFunctionSpace())
591              if self.domain.getDim()==3:
592                 vertex=[inf(x[0]),inf(x[1]),inf(x[2])]
593                 msk=numarray.zeros((3,))
594                 if self.comp_mask[0]: msk[0]=1
595                 if self.comp_mask[1]: msk[1]=1
596                 if self.comp_mask[2]: msk[2]=1
597              else:
598                 vertex=[inf(x[0]),inf(x[1])]
599                 msk=numarray.zeros((2,))
600                 if self.comp_mask[0]: msk[0]=1
601                 if self.comp_mask[1]: msk[1]=1
602              self.__location_of_constraint=whereZero(length(x-vertex),self.tol)*numarray.ones(shape)
603              if not self.value == None:
604                    self.__value_of_constraint=self.__location_of_constraint*self.value
605    
 # vim: expandtab shiftwidth=4:  

Legend:
Removed from v.155  
changed lines
  Added in v.1809

  ViewVC Help
Powered by ViewVC 1.1.26