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

temp/modellib/py_src/geometry.py revision 1387 by trankine, Fri Jan 11 07:45:26 2008 UTC trunk/modellib/py_src/geometry.py revision 2881 by jfenwick, Thu Jan 28 02:03:15 2010 UTC
# Line 1  Line 1 
1    
2    ########################################################
3  #  #
4  # $Id$  # Copyright (c) 2003-2010 by University of Queensland
5  #  # Earth Systems Science Computational Center (ESSCC)
6  #######################################################  # http://www.uq.edu.au/esscc
 #  
 #           Copyright 2003-2007 by ACceSS MNRF  
 #       Copyright 2007 by University of Queensland  
 #  
 #                http://esscc.uq.edu.au  
 #        Primary Business: Queensland, Australia  
 #  Licensed under the Open Software License version 3.0  
 #     http://www.opensource.org/licenses/osl-3.0.php  
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-2010 by University of Queensland
15  __copyright__="""  Copyright (c) 2006 by ACcESS MNRF  Earth Systems Science Computational Center (ESSCC)
16                      http://www.access.edu.au  http://www.uq.edu.au/esscc
17                  Primary Business: Queensland, Australia"""  Primary Business: Queensland, Australia"""
18  __license__="""Licensed under the Open Software License version 3.0  __license__="""Licensed under the Open Software License version 3.0
19               http://www.opensource.org/licenses/osl-3.0.php"""  http://www.opensource.org/licenses/osl-3.0.php"""
20    __url__="https://launchpad.net/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
# Line 30  class FinleyReader(ParameterSet): Line 27  class FinleyReader(ParameterSet):
27         """         """
28         reads finley mesh file.         reads finley mesh file.
29    
30         @ivar source: mesh file in finley or gmsh format         :ivar source: mesh file in finley or gmsh format
31         @type source: C{DataSource}         :type source: ``DataSource``
32         @ivar intergrationOrder: integration order, default -1 (in).         :ivar intergrationOrder: integration order, default -1 (in).
33         @type intergrationOrder: C{int}         :type intergrationOrder: ``int``
34         @ivar reducedIntegrationOrder: reduced integration order, default -1 (in).         :ivar reducedIntegrationOrder: reduced integration order, default -1 (in).
35         @type reducedIntegrationOrder: C{int}         :type reducedIntegrationOrder: ``int``
36         @ivar optimizeLabeling: switches on optimization of the labeling of the nodes         :ivar optimizeLabeling: switches on optimization of the labeling of the nodes
37         @type optimizeLabeling: C{bool}         :type optimizeLabeling: ``bool``
38         """         """
39         def __init__(self,**kwargs):         def __init__(self,**kwargs):
40            """            """
# Line 56  class FinleyReader(ParameterSet): Line 53  class FinleyReader(ParameterSet):
53            """            """
54            returns the domain            returns the domain
55    
56            @return: the domain            :return: the domain
57            @rtype: L{Domain}            :rtype: `Domain`
58            """            """
59            if self.__domain == None:            if self.__domain == None:
60               if  self.source.fileformat == "fly":               if  self.source.fileformat == "fly":
# Line 76  class RectangularDomain(ParameterSet): Line 73  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: spatial dimension, default =2 (in).         :ivar dim: spatial dimension, default =2 (in).
77         @type dim: spatial dimension         :type dim: spatial dimension
78         @ivar l: spatial lengths, default [1.,1.,1.] (in).         :ivar l: spatial lengths, default [1.,1.,1.] (in).
79         @type l: C{list} of C{floats}s         :type l: ``list`` of ``float``
80         @ivar n: number of elements, default [10,10,10] (in).         :ivar n: number of elements, default [10,10,10] (in).
81         @type n: C{list} of C{int}s         :type n: ``list`` of ``int``
82         @ivar order: element order, default 1 (in).         :ivar order: element order, default 1 (in).
83         @type order: C{int}         :type order: ``int``
84         @ivar periodic: flags for periodicity, default [False,False,False] (in).         :ivar periodic: flags for periodicity, default [False,False,False] (in).
85         @type periodic: C{list} of C{bool}s         :type periodic: ``list`` of ``bool``
86         @ivar intergrationOrder: integration order, default -1 (in).         :ivar intergrationOrder: integration order, default -1 (in).
87         @type intergrationOrder: C{int}         :type intergrationOrder: ``int``
88         """         """
89         def __init__(self,**kwargs):         def __init__(self,**kwargs):
90             """             """
# Line 106  class RectangularDomain(ParameterSet): Line 103  class RectangularDomain(ParameterSet):
103             """             """
104             returns the domain             returns the domain
105    
106             @return: the domain             :return: the domain
107             @rtype: L{Domain}             :rtype: `Domain`
108             """             """
109             if self.__domain==None:             if self.__domain==None:
110                if self.dim==2:                if self.dim==2:
# Line 137  class UpdateGeometry(Model): Line 134  class UpdateGeometry(Model):
134        """        """
135        applies a displacement field to a domain        applies a displacement field to a domain
136                
137        @ivar displacement: displacements applied to the original mesh coordinates (in).        :ivar displacement: displacements applied to the original mesh coordinates (in).
138        @type displacement: L{escript.Vector}        :type displacement: `escript.Vector`
139        @ivar domain: domain        :ivar domain: domain
140        @type domain: L{escript.Domain}        :type domain: `escript.Domain`
141        """        """
142        def __init__(self,**kwargs):        def __init__(self,**kwargs):
143             """             """
# Line 160  class UpdateGeometry(Model): Line 157  class UpdateGeometry(Model):
157                    
158        def doStepPreprocessing(self,dt):        def doStepPreprocessing(self,dt):
159           """           """
160           applies the current L{displacement} to mesh nodes if required.           applies the current `displacement` to mesh nodes if required.
161           """           """
162           if self.__reset:           if self.__reset:
163              self.trace("mesh nodes updated.")              self.trace("mesh nodes updated.")
# Line 169  class UpdateGeometry(Model): Line 166  class UpdateGeometry(Model):
166    
167        def doStep(self,dt):        def doStep(self,dt):
168           """           """
169           applies the current L{displacement} to mesh nodes.           applies the current `displacement` to mesh nodes.
170           """           """
171           self.trace("mesh nodes updated.")           self.trace("mesh nodes updated.")
172           self.domain.setX(self.__x+self.displacement)           self.domain.setX(self.__x+self.displacement)
# Line 189  class ConstrainerOverBox(Model): Line 186  class ConstrainerOverBox(Model):
186    
187        In the case that the spatial dimension is two, the arguments front and back are ignored.        In the case that the spatial dimension is two, the arguments front and back are ignored.
188    
189        @ivar domain: domain (in).        :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).        :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).        :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).        :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).        :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).        :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).        :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).        :ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
197        """        """
198        def __init__(self,**kwargs):        def __init__(self,**kwargs):
199             super(ConstrainerOverBox, self).__init__(**kwargs)             super(ConstrainerOverBox, self).__init__(**kwargs)
# Line 215  class ConstrainerOverBox(Model): Line 212  class ConstrainerOverBox(Model):
212            """            """
213            return the values used to constrain a solution            return the values used to constrain a solution
214    
215            @return: the mask marking the locations of the constraints            :return: the mask marking the locations of the constraints
216            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
217            """            """
218            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
219            return self.__location_of_constraint            return self.__location_of_constraint
# Line 225  class ConstrainerOverBox(Model): Line 222  class ConstrainerOverBox(Model):
222            """            """
223            return the values used to constrain a solution            return the values used to constrain a solution
224    
225            @return: values to be used at the locations of the constraints. If            :return: values to be used at the locations of the constraints. If
226                    L{value} is not given C{None} is rerturned.                    ``value`` is not given ``None`` is rerturned.
227            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
228            """            """
229            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
230            return self.__value_of_constraint            return self.__value_of_constraint
# Line 240  class ConstrainerOverBox(Model): Line 237  class ConstrainerOverBox(Model):
237                  shape=()                  shape=()
238               elif isinstance(val, list) or isinstance(val, tuple) :               elif isinstance(val, list) or isinstance(val, tuple) :
239                  shape=(len(val),)                  shape=(len(val),)
240               elif isinstance(val, numarray.NumArray):               elif isinstance(val, numpy.ndarray):
241                   shape=val.shape                   shape=val.shape
242               elif val == None:               elif val == None:
243                    shape=()                    shape=()
# Line 271  class ScalarConstrainerOverBox(Model): Line 268  class ScalarConstrainerOverBox(Model):
268    
269        In the case that the spatial dimension is two, the arguments front and back are ignored.        In the case that the spatial dimension is two, the arguments front and back are ignored.
270    
271        @ivar domain: domain (in).        :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).        :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).        :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).        :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).        :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).        :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).        :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).        :ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
279        """        """
280        def __init__(self,**kwargs):        def __init__(self,**kwargs):
281             super(ScalarConstrainerOverBox, self).__init__(**kwargs)             super(ScalarConstrainerOverBox, self).__init__(**kwargs)
# Line 297  class ScalarConstrainerOverBox(Model): Line 294  class ScalarConstrainerOverBox(Model):
294            """            """
295            return the values used to constrain a solution            return the values used to constrain a solution
296    
297            @return: the mask marking the locations of the constraints            :return: the mask marking the locations of the constraints
298            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
299            """            """
300            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
301            return self.__location_of_constraint            return self.__location_of_constraint
# Line 307  class ScalarConstrainerOverBox(Model): Line 304  class ScalarConstrainerOverBox(Model):
304            """            """
305            return the values used to constrain a solution            return the values used to constrain a solution
306    
307            @return: values to be used at the locations of the constraints. If            :return: values to be used at the locations of the constraints. If
308                    L{value} is not given C{None} is rerturned.                    ``value`` is not given ``None`` is rerturned.
309            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
310            """            """
311            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
312            return self.__value_of_constraint            return self.__value_of_constraint
# Line 319  class ScalarConstrainerOverBox(Model): Line 316  class ScalarConstrainerOverBox(Model):
316            self.__location_of_constraint=Scalar(0,x.getFunctionSpace())            self.__location_of_constraint=Scalar(0,x.getFunctionSpace())
317            if self.domain.getDim()==3:            if self.domain.getDim()==3:
318                  x0,x1,x2=x[0],x[1],x[2]                  x0,x1,x2=x[0],x[1],x[2]
319                  if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol)                  d=max(sup(x0)-inf(x0), sup(x1)-inf(x1), sup(x2)-inf(x2))
320                  if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol)                  if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol*d)
321                  if self.front: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol)                  if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol*d)
322                  if self.back: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol)                  if self.front: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol*d)
323                  if self.bottom: self.__location_of_constraint+=whereZero(x2-inf(x2),self.tol)                  if self.back: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol*d)
324                  if self.top: self.__location_of_constraint+=whereZero(x2-sup(x2),self.tol)                  if self.bottom: self.__location_of_constraint+=whereZero(x2-inf(x2),self.tol*d)
325                    if self.top: self.__location_of_constraint+=whereZero(x2-sup(x2),self.tol*d)
326            else:            else:
327                  x0,x1=x[0],x[1]                  x0,x1=x[0],x[1]
328                  if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol)                  d=max(sup(x0)-inf(x0), sup(x1)-inf(x1))
329                  if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol)                  if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol*d)
330                  if self.bottom: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol)                  if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol*d)
331                  if self.top: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol)                  if self.bottom: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol*d)
332                    if self.top: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol*d)
333            if not self.value == None:            if not self.value == None:
334                self.__value_of_constraint=self.__location_of_constraint*self.value                self.__value_of_constraint=self.__location_of_constraint*self.value
335    
# Line 340  class VectorConstrainerOverBox(Model): Line 339  class VectorConstrainerOverBox(Model):
339        In the case that the spatial dimension is two, the arguments front and        In the case that the spatial dimension is two, the arguments front and
340        back as well as the third component of each argument is ignored.        back as well as the third component of each argument is ignored.
341    
342        @ivar domain: domain        :ivar domain: domain
343        @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]),        :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]),
344                         default [False,False,False] (in).                         default [False,False,False] (in).
345        @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]),        :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]),
346                  default [False,False,False] (in).                  default [False,False,False] (in).
347        @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]),        :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]),
348                  default [False,False,False] (in).                  default [False,False,False] (in).
349        @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]),        :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]),
350                  default [False,False,False] (in).                  default [False,False,False] (in).
351        @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]),        :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]),
352                  default [False,False,False] (in).                  default [False,False,False] (in).
353        @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]),        :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]),
354                  default [False,False,False] (in).                  default [False,False,False] (in).
355        @ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).        :ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
356        """        """
357        def __init__(self, **kwargs):        def __init__(self, **kwargs):
358             super(VectorConstrainerOverBox, self).__init__(**kwargs)             super(VectorConstrainerOverBox, self).__init__(**kwargs)
# Line 373  class VectorConstrainerOverBox(Model): Line 372  class VectorConstrainerOverBox(Model):
372            """            """
373            return the values used to constrain a solution            return the values used to constrain a solution
374    
375            @return: the mask marking the locations of the constraints            :return: the mask marking the locations of the constraints
376            @rtype: L{escript.Vector}            :rtype: `escript.Vector`
377            """            """
378            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
379            return self.__location_of_constraint            return self.__location_of_constraint
# Line 383  class VectorConstrainerOverBox(Model): Line 382  class VectorConstrainerOverBox(Model):
382            """            """
383            return the values used to constrain a solution            return the values used to constrain a solution
384    
385            @return: values to be used at the locations of the constraints. If            :return: values to be used at the locations of the constraints. If
386                    L{value} is not given C{None} is rerturned.                    ``value`` is not given ``None`` is rerturned.
387            @rtype: L{escript.Vector}            :rtype: `escript.Vector`
388            """            """
389            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
390            return self.__value_of_constraint            return self.__value_of_constraint
# Line 395  class VectorConstrainerOverBox(Model): Line 394  class VectorConstrainerOverBox(Model):
394            self.__location_of_constraint=Vector(0,x.getFunctionSpace())            self.__location_of_constraint=Vector(0,x.getFunctionSpace())
395            if self.domain.getDim()==3:            if self.domain.getDim()==3:
396               x0,x1,x2=x[0],x[1],x[2]               x0,x1,x2=x[0],x[1],x[2]
397               left_mask=whereZero(x0-inf(x0),self.tol)               d=max(sup(x0)-inf(x0), sup(x1)-inf(x1), sup(x2)-inf(x2))
398                 left_mask=whereZero(x0-inf(x0),self.tol*d)
399               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.]
400               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.]
401               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.]
402               right_mask=whereZero(x0-sup(x0),self.tol)               right_mask=whereZero(x0-sup(x0),self.tol*d)
403               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.]
404               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.]
405               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.]
406               front_mask=whereZero(x1-inf(x1),self.tol)               front_mask=whereZero(x1-inf(x1),self.tol*d)
407               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.]
408               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.]
409               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.]
410               back_mask=whereZero(x1-sup(x1),self.tol)               back_mask=whereZero(x1-sup(x1),self.tol*d)
411               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.]
412               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.]
413               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.]
414               bottom_mask=whereZero(x2-inf(x2),self.tol)               bottom_mask=whereZero(x2-inf(x2),self.tol*d)
415               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.]
416               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.]
417               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.]
418               top_mask=whereZero(x2-sup(x2),self.tol)               top_mask=whereZero(x2-sup(x2),self.tol*d)
419               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.]
420               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.]
421               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.]
# Line 423  class VectorConstrainerOverBox(Model): Line 423  class VectorConstrainerOverBox(Model):
423                  self.__value_of_constraint=self.__location_of_constraint*self.value                  self.__value_of_constraint=self.__location_of_constraint*self.value
424            else:            else:
425               x0,x1=x[0],x[1]               x0,x1=x[0],x[1]
426               left_mask=whereZero(x0-inf(x0),self.tol)               d=max(sup(x0)-inf(x0), sup(x1)-inf(x1))
427                 left_mask=whereZero(x0-inf(x0),self.tol*d)
428               if self.left[0]: self.__location_of_constraint+=left_mask*[1.,0.]               if self.left[0]: self.__location_of_constraint+=left_mask*[1.,0.]
429               if self.left[1]: self.__location_of_constraint+=left_mask*[0.,1.]               if self.left[1]: self.__location_of_constraint+=left_mask*[0.,1.]
430               right_mask=whereZero(x0-sup(x0),self.tol)               right_mask=whereZero(x0-sup(x0),self.tol*d)
431               if self.right[0]: self.__location_of_constraint+=right_mask*[1.,0.]               if self.right[0]: self.__location_of_constraint+=right_mask*[1.,0.]
432               if self.right[1]: self.__location_of_constraint+=right_mask*[0.,1.]               if self.right[1]: self.__location_of_constraint+=right_mask*[0.,1.]
433               bottom_mask=whereZero(x1-inf(x1),self.tol)               bottom_mask=whereZero(x1-inf(x1),self.tol*d)
434               if self.bottom[0]: self.__location_of_constraint+=bottom_mask*[1.,0.]               if self.bottom[0]: self.__location_of_constraint+=bottom_mask*[1.,0.]
435               if self.bottom[1]: self.__location_of_constraint+=bottom_mask*[0.,1.]               if self.bottom[1]: self.__location_of_constraint+=bottom_mask*[0.,1.]
436               top_mask=whereZero(x1-sup(x1),self.tol)               top_mask=whereZero(x1-sup(x1),self.tol*d)
437               if self.top[0]: self.__location_of_constraint+=top_mask*[1.,0.]               if self.top[0]: self.__location_of_constraint+=top_mask*[1.,0.]
438               if self.top[1]: self.__location_of_constraint+=top_mask*[0.,1.]               if self.top[1]: self.__location_of_constraint+=top_mask*[0.,1.]
439               if not self.value == None:               if not self.value == None:
# Line 446  class ConstrainerAtBoxVertex(Model): Line 447  class ConstrainerAtBoxVertex(Model):
447    
448        In the case that the spatial dimension is two, the arguments front and back are ignored.        In the case that the spatial dimension is two, the arguments front and back are ignored.
449    
450        @ivar domain: domain (in).        :ivar domain: domain (in).
451        @ivar tol: absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).        :ivar tol: absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).
452        """        """
453        def __init__(self,**kwargs):        def __init__(self,**kwargs):
454             super(ConstrainerAtBoxVertex, self).__init__(**kwargs)             super(ConstrainerAtBoxVertex, self).__init__(**kwargs)
# Line 460  class ConstrainerAtBoxVertex(Model): Line 461  class ConstrainerAtBoxVertex(Model):
461            """            """
462            return the values used to constrain a solution            return the values used to constrain a solution
463    
464            @return: the mask marking the locations of the constraints            :return: the mask marking the locations of the constraints
465            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
466            """            """
467            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
468            return self.__location_of_constraint            return self.__location_of_constraint
# Line 470  class ConstrainerAtBoxVertex(Model): Line 471  class ConstrainerAtBoxVertex(Model):
471            """            """
472            return the values used to constrain a solution            return the values used to constrain a solution
473    
474            @return: values to be used at the locations of the constraints. If            :return: values to be used at the locations of the constraints. If
475                    L{value} is not given C{None} is rerturned.                    ``value`` is not given ``None`` is rerturned.
476            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
477            """            """
478            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
479            return self.__value_of_constraint            return self.__value_of_constraint
# Line 485  class ConstrainerAtBoxVertex(Model): Line 486  class ConstrainerAtBoxVertex(Model):
486                  shape=()                  shape=()
487               elif isinstance(val, list) or isinstance(val, tuple) :               elif isinstance(val, list) or isinstance(val, tuple) :
488                  shape=(len(val),)                  shape=(len(val),)
489               elif isinstance(val, numarray.NumArray):               elif isinstance(val, numpy.ndarray):
490                   shape=val.shape                   shape=val.shape
491               elif val == None:               elif val == None:
492                    shape=()                    shape=()
# Line 495  class ConstrainerAtBoxVertex(Model): Line 496  class ConstrainerAtBoxVertex(Model):
496                     vertex=[inf(x[0]),inf(x[1]),inf(x[2])]                     vertex=[inf(x[0]),inf(x[1]),inf(x[2])]
497               else:               else:
498                     vertex=[inf(x[0]),inf(x[1])]                     vertex=[inf(x[0]),inf(x[1])]
499               self.__location_of_constraint=whereZero(length(x-vertex),self.tol)*numarray.ones(shape)               self.__location_of_constraint=whereZero(length(x-vertex),self.tol)*numpy.ones(shape)
500               if not self.value == None:               if not self.value == None:
501                     self.__value_of_constraint=self.__location_of_constraint*self.value                     self.__value_of_constraint=self.__location_of_constraint*self.value
502  class ScalarConstrainerAtBoxVertex(Model):  class ScalarConstrainerAtBoxVertex(Model):
# Line 506  class ScalarConstrainerAtBoxVertex(Model Line 507  class ScalarConstrainerAtBoxVertex(Model
507    
508        In the case that the spatial dimension is two, the arguments front and back are ignored.        In the case that the spatial dimension is two, the arguments front and back are ignored.
509    
510        @ivar domain: domain (in).        :ivar domain: domain (in).
511        @ivar tol: absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).        :ivar tol: absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).
512        """        """
513        def __init__(self,**kwargs):        def __init__(self,**kwargs):
514             super(ScalarConstrainerAtBoxVertex, self).__init__(**kwargs)             super(ScalarConstrainerAtBoxVertex, self).__init__(**kwargs)
# Line 520  class ScalarConstrainerAtBoxVertex(Model Line 521  class ScalarConstrainerAtBoxVertex(Model
521            """            """
522            return the values used to constrain a solution            return the values used to constrain a solution
523    
524            @return: the mask marking the locations of the constraints            :return: the mask marking the locations of the constraints
525            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
526            """            """
527            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
528            return self.__location_of_constraint            return self.__location_of_constraint
# Line 530  class ScalarConstrainerAtBoxVertex(Model Line 531  class ScalarConstrainerAtBoxVertex(Model
531            """            """
532            return the values used to constrain a solution            return the values used to constrain a solution
533    
534            @return: values to be used at the locations of the constraints. If            :return: values to be used at the locations of the constraints. If
535                    L{value} is not given C{None} is rerturned.                    ``value`` is not given ``None`` is rerturned.
536            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
537            """            """
538            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
539            return self.__value_of_constraint            return self.__value_of_constraint
# Line 554  class VectorConstrainerAtBoxVertex(Model Line 555  class VectorConstrainerAtBoxVertex(Model
555        In the case that the spatial dimension is two, the arguments front and        In the case that the spatial dimension is two, the arguments front and
556        back as well as the third component of each argument is ignored.        back as well as the third component of each argument is ignored.
557    
558        @ivar domain: domain        :ivar domain: domain
559        @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).        :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).
560        @ivar tol: absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).        :ivar tol: absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).
561        """        """
562        def __init__(self, **kwargs):        def __init__(self, **kwargs):
563             super(VectorConstrainerAtBoxVertex, self).__init__(**kwargs)             super(VectorConstrainerAtBoxVertex, self).__init__(**kwargs)
# Line 571  class VectorConstrainerAtBoxVertex(Model Line 572  class VectorConstrainerAtBoxVertex(Model
572            """            """
573            return the values used to constrain a solution            return the values used to constrain a solution
574    
575            @return: the mask marking the locations of the constraints            :return: the mask marking the locations of the constraints
576            @rtype: L{escript.Vector}            :rtype: `escript.Vector`
577            """            """
578            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
579            return self.__location_of_constraint            return self.__location_of_constraint
# Line 581  class VectorConstrainerAtBoxVertex(Model Line 582  class VectorConstrainerAtBoxVertex(Model
582            """            """
583            return the values used to constrain a solution            return the values used to constrain a solution
584    
585            @return: values to be used at the locations of the constraints. If            :return: values to be used at the locations of the constraints. If
586                    L{value} is not given C{None} is rerturned.                    ``value`` is not given ``None`` is rerturned.
587            @rtype: L{escript.Vector}            :rtype: `escript.Vector`
588            """            """
589            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
590            return self.__value_of_constraint            return self.__value_of_constraint
# Line 593  class VectorConstrainerAtBoxVertex(Model Line 594  class VectorConstrainerAtBoxVertex(Model
594            self.__location_of_constraint=Vector(0,x.getFunctionSpace())            self.__location_of_constraint=Vector(0,x.getFunctionSpace())
595            if self.domain.getDim()==3:            if self.domain.getDim()==3:
596               vertex=[inf(x[0]),inf(x[1]),inf(x[2])]               vertex=[inf(x[0]),inf(x[1]),inf(x[2])]
597               msk=numarray.zeros((3,))               msk=numpy.zeros((3,))
598               if self.comp_mask[0]: msk[0]=1               if self.comp_mask[0]: msk[0]=1
599               if self.comp_mask[1]: msk[1]=1               if self.comp_mask[1]: msk[1]=1
600               if self.comp_mask[2]: msk[2]=1               if self.comp_mask[2]: msk[2]=1
601            else:            else:
602               vertex=[inf(x[0]),inf(x[1])]               vertex=[inf(x[0]),inf(x[1])]
603               msk=numarray.zeros((2,))               msk=numpy.zeros((2,))
604               if self.comp_mask[0]: msk[0]=1               if self.comp_mask[0]: msk[0]=1
605               if self.comp_mask[1]: msk[1]=1               if self.comp_mask[1]: msk[1]=1
606            self.__location_of_constraint=whereZero(length(x-vertex),self.tol)*numarray.ones(shape)            self.__location_of_constraint=whereZero(length(x-vertex),self.tol)*numpy.ones(shape)
607            if not self.value == None:            if not self.value == None:
608                  self.__value_of_constraint=self.__location_of_constraint*self.value                  self.__value_of_constraint=self.__location_of_constraint*self.value
609    

Legend:
Removed from v.1387  
changed lines
  Added in v.2881

  ViewVC Help
Powered by ViewVC 1.1.26