/[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 3259 by jfenwick, Mon Oct 11 01:48:14 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
24  from esys import finley  import esys.finley
25    
26  class FinleyReader(ParameterSet):  class DomainReader(ParameterSet):
27    #class DudleyReader(ParameterSet):
28         """         """
        reads finley mesh file.  
   
        @ivar source: mesh file in finley or gmsh format  
        @type source: C{DataSource}  
        @ivar intergrationOrder: integration order, default -1 (in).  
        @type intergrationOrder: C{int}  
        @ivar reducedIntegrationOrder: reduced integration order, default -1 (in).  
        @type reducedIntegrationOrder: C{int}  
        @ivar optimizeLabeling: switches on optimization of the labeling of the nodes  
        @type optimizeLabeling: C{bool}  
29         """         """
30         def __init__(self,**kwargs):         def __init__(self,domainmodule=None, **kwargs):
31            """            """
32            initializes the object            initializes the object
33            """            """
34            super(FinleyReader,self).__init__(**kwargs)            super(DudleyReader,self).__init__(**kwargs)
35            self.declareParameter(source="none",            self.declareParameter(source="none",
36                                  dim=None,                                  dim=None,
37                                  optimizeLabeling=True,                                  optimizeLabeling=True,
38                                  reducedIntegrationOrder=-1,                                  reducedIntegrationOrder=-1,
39                                  integrationOrder=-1)                                  integrationOrder=-1)
40          if domainmodule==None:
41            domainmodule=esys.finley
42          self.__domainModule=domainmodule
43            self.__domain=None            self.__domain=None
44    
45    
# Line 56  class FinleyReader(ParameterSet): Line 47  class FinleyReader(ParameterSet):
47            """            """
48            returns the domain            returns the domain
49    
50            @return: the domain            :return: the domain
51            @rtype: L{Domain}            :rtype: `Domain`
52            """            """
53            if self.__domain == None:            if self.__domain == None:
54               if  self.source.fileformat == "fly":               if  self.source.fileformat == "fly":
55                  self.__domain=finley.ReadMesh(self.source.getLocalFileName(),self.integrationOrder)                  self.__domain=self.__domainmodule.ReadMesh(self.source.getLocalFileName(),self.integrationOrder)
56               elif self.source.fileformat == "gmsh":               elif self.source.fileformat == "gmsh":
57                  if self.dim==None:                  if self.dim==None:
58                     dim=3                     dim=3
59                  else:                  else:
60                     dim=self.dim                     dim=self.dim
61                  self.__domain=finley.ReadGmsh(self.source.getLocalFileName(),dim,self.integrationOrder,self.reducedIntegrationOrder, self.optimizeLabeling)                  self.__domain=self.__domainmodule.ReadGmsh(self.source.getLocalFileName(),dim,self.integrationOrder,self.reducedIntegrationOrder, self.optimizeLabeling)
62               else:               else:
63                  raise TypeError("unknown mesh file format %s."%self.source.fileformat)                  raise TypeError("unknown mesh file format %s."%self.source.fileformat)
64               self.trace("mesh read from %s in %s format."%(self.source.getLocalFileName(), self.source.fileformat))                         self.trace("mesh read from %s in %s format."%(self.source.getLocalFileName(), self.source.fileformat))          
65            return self.__domain            return self.__domain
66            
67    class FinleyReader(DomainReader):
68        def __init__(self, **kw):
69            super().__init__(esys.finley, kw)
70            
71  class RectangularDomain(ParameterSet):  class RectangularDomain(ParameterSet):
72         """         """
73         Generates a mesh over a rectangular domain finley.         Generates a mesh over a rectangular domain.
74    
75         @ivar dim: spatial dimension, default =2 (in).         :ivar dim: spatial dimension, default =2 (in).
76         @type dim: spatial dimension         :type dim: spatial dimension
77         @ivar l: spatial lengths, default [1.,1.,1.] (in).         :ivar l: spatial lengths, default [1.,1.,1.] (in).
78         @type l: C{list} of C{floats}s         :type l: ``list`` of ``float``
79         @ivar n: number of elements, default [10,10,10] (in).         :ivar n: number of elements, default [10,10,10] (in).
80         @type n: C{list} of C{int}s         :type n: ``list`` of ``int``
81         @ivar order: element order, default 1 (in).         :ivar order: element order, default 1 (in).
82         @type order: C{int}         :type order: ``int``
83         @ivar periodic: flags for periodicity, default [False,False,False] (in).         :ivar periodic: flags for periodicity, default [False,False,False] (in).
84         @type periodic: C{list} of C{bool}s         :type periodic: ``list`` of ``bool``
85         @ivar intergrationOrder: integration order, default -1 (in).         :ivar intergrationOrder: integration order, default -1 (in).
86         @type intergrationOrder: C{int}         :type intergrationOrder: ``int``
87         """         """
88         def __init__(self,**kwargs):         def __init__(self,domainmodule=None,**kwargs):
89             """             """
90             initializes the object             initializes the object
91             """             """
# Line 101  class RectangularDomain(ParameterSet): Line 97  class RectangularDomain(ParameterSet):
97                                   periodic=[False,False,False],                                   periodic=[False,False,False],
98                                   integrationOrder=-1)                                   integrationOrder=-1)
99             self.__domain=None             self.__domain=None
100           self.__domainModule=domainmodule
101           if self.__domainModule==None:
102            self.__domainModule=esys.finley
103    
104         def domain(self):         def domain(self):
105             """             """
106             returns the domain             returns the domain
107    
108             @return: the domain             :return: the domain
109             @rtype: L{Domain}             :rtype: `Domain`
110             """             """
111             if self.__domain==None:             if self.__domain==None:
112                if self.dim==2:                if self.dim==2:
113                     self.__domain=finley.Rectangle(n0=self.n[0],\                     self.__domain=self.__domainModule.Rectangle(n0=self.n[0],\
114                                                  n1=self.n[2],\                                                  n1=self.n[2],\
115                                                  l0=self.l[0],\                                                  l0=self.l[0],\
116                                                  l1=self.l[2],\                                                  l1=self.l[2],\
# Line 120  class RectangularDomain(ParameterSet): Line 119  class RectangularDomain(ParameterSet):
119                                                  periodic1=self.periodic[2], \                                                  periodic1=self.periodic[2], \
120                                                  integrationOrder=self.integrationOrder)                                                  integrationOrder=self.integrationOrder)
121                else:                else:
122                     self.__domain=finley.Brick(n0=self.n[0],\                     self.__domain=self__domainModule.Brick(n0=self.n[0],\
123                                              n1=self.n[1],\                                              n1=self.n[1],\
124                                              n2=self.n[2],\                                              n2=self.n[2],\
125                                              l0=self.l[0],\                                              l0=self.l[0],\
# Line 137  class UpdateGeometry(Model): Line 136  class UpdateGeometry(Model):
136        """        """
137        applies a displacement field to a domain        applies a displacement field to a domain
138                
139        @ivar displacement: displacements applied to the original mesh coordinates (in).        :ivar displacement: displacements applied to the original mesh coordinates (in).
140        @type displacement: L{escript.Vector}        :type displacement: `escript.Vector`
141        @ivar domain: domain        :ivar domain: domain
142        @type domain: L{escript.Domain}        :type domain: `escript.Domain`
143        """        """
144        def __init__(self,**kwargs):        def __init__(self,**kwargs):
145             """             """
# Line 160  class UpdateGeometry(Model): Line 159  class UpdateGeometry(Model):
159                    
160        def doStepPreprocessing(self,dt):        def doStepPreprocessing(self,dt):
161           """           """
162           applies the current L{displacement} to mesh nodes if required.           applies the current `displacement` to mesh nodes if required.
163           """           """
164           if self.__reset:           if self.__reset:
165              self.trace("mesh nodes updated.")              self.trace("mesh nodes updated.")
# Line 169  class UpdateGeometry(Model): Line 168  class UpdateGeometry(Model):
168    
169        def doStep(self,dt):        def doStep(self,dt):
170           """           """
171           applies the current L{displacement} to mesh nodes.           applies the current `displacement` to mesh nodes.
172           """           """
173           self.trace("mesh nodes updated.")           self.trace("mesh nodes updated.")
174           self.domain.setX(self.__x+self.displacement)           self.domain.setX(self.__x+self.displacement)
# Line 189  class ConstrainerOverBox(Model): Line 188  class ConstrainerOverBox(Model):
188    
189        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.
190    
191        @ivar domain: domain (in).        :ivar domain: domain (in).
192        @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).
193        @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).
194        @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).
195        @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).
196        @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).
197        @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).
198        @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).
199        """        """
200        def __init__(self,**kwargs):        def __init__(self,**kwargs):
201             super(ConstrainerOverBox, self).__init__(**kwargs)             super(ConstrainerOverBox, self).__init__(**kwargs)
# Line 215  class ConstrainerOverBox(Model): Line 214  class ConstrainerOverBox(Model):
214            """            """
215            return the values used to constrain a solution            return the values used to constrain a solution
216    
217            @return: the mask marking the locations of the constraints            :return: the mask marking the locations of the constraints
218            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
219            """            """
220            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
221            return self.__location_of_constraint            return self.__location_of_constraint
# Line 225  class ConstrainerOverBox(Model): Line 224  class ConstrainerOverBox(Model):
224            """            """
225            return the values used to constrain a solution            return the values used to constrain a solution
226    
227            @return: values to be used at the locations of the constraints. If            :return: values to be used at the locations of the constraints. If
228                    L{value} is not given C{None} is rerturned.                    ``value`` is not given ``None`` is rerturned.
229            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
230            """            """
231            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
232            return self.__value_of_constraint            return self.__value_of_constraint
# Line 240  class ConstrainerOverBox(Model): Line 239  class ConstrainerOverBox(Model):
239                  shape=()                  shape=()
240               elif isinstance(val, list) or isinstance(val, tuple) :               elif isinstance(val, list) or isinstance(val, tuple) :
241                  shape=(len(val),)                  shape=(len(val),)
242               elif isinstance(val, numarray.NumArray):               elif isinstance(val, numpy.ndarray):
243                   shape=val.shape                   shape=val.shape
244               elif val == None:               elif val == None:
245                    shape=()                    shape=()
# Line 271  class ScalarConstrainerOverBox(Model): Line 270  class ScalarConstrainerOverBox(Model):
270    
271        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.
272    
273        @ivar domain: domain (in).        :ivar domain: domain (in).
274        @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).
275        @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).
276        @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).
277        @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).
278        @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).
279        @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).
280        @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).
281        """        """
282        def __init__(self,**kwargs):        def __init__(self,**kwargs):
283             super(ScalarConstrainerOverBox, self).__init__(**kwargs)             super(ScalarConstrainerOverBox, self).__init__(**kwargs)
# Line 297  class ScalarConstrainerOverBox(Model): Line 296  class ScalarConstrainerOverBox(Model):
296            """            """
297            return the values used to constrain a solution            return the values used to constrain a solution
298    
299            @return: the mask marking the locations of the constraints            :return: the mask marking the locations of the constraints
300            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
301            """            """
302            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
303            return self.__location_of_constraint            return self.__location_of_constraint
# Line 307  class ScalarConstrainerOverBox(Model): Line 306  class ScalarConstrainerOverBox(Model):
306            """            """
307            return the values used to constrain a solution            return the values used to constrain a solution
308    
309            @return: values to be used at the locations of the constraints. If            :return: values to be used at the locations of the constraints. If
310                    L{value} is not given C{None} is rerturned.                    ``value`` is not given ``None`` is rerturned.
311            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
312            """            """
313            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
314            return self.__value_of_constraint            return self.__value_of_constraint
# Line 319  class ScalarConstrainerOverBox(Model): Line 318  class ScalarConstrainerOverBox(Model):
318            self.__location_of_constraint=Scalar(0,x.getFunctionSpace())            self.__location_of_constraint=Scalar(0,x.getFunctionSpace())
319            if self.domain.getDim()==3:            if self.domain.getDim()==3:
320                  x0,x1,x2=x[0],x[1],x[2]                  x0,x1,x2=x[0],x[1],x[2]
321                  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))
322                  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)
323                  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)
324                  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)
325                  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)
326                  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)
327                    if self.top: self.__location_of_constraint+=whereZero(x2-sup(x2),self.tol*d)
328            else:            else:
329                  x0,x1=x[0],x[1]                  x0,x1=x[0],x[1]
330                  if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol)                  d=max(sup(x0)-inf(x0), sup(x1)-inf(x1))
331                  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)
332                  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)
333                  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)
334                    if self.top: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol*d)
335            if not self.value == None:            if not self.value == None:
336                self.__value_of_constraint=self.__location_of_constraint*self.value                self.__value_of_constraint=self.__location_of_constraint*self.value
337    
# Line 340  class VectorConstrainerOverBox(Model): Line 341  class VectorConstrainerOverBox(Model):
341        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
342        back as well as the third component of each argument is ignored.        back as well as the third component of each argument is ignored.
343    
344        @ivar domain: domain        :ivar domain: domain
345        @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]),
346                         default [False,False,False] (in).                         default [False,False,False] (in).
347        @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]),
348                  default [False,False,False] (in).                  default [False,False,False] (in).
349        @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]),
350                  default [False,False,False] (in).                  default [False,False,False] (in).
351        @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]),
352                  default [False,False,False] (in).                  default [False,False,False] (in).
353        @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]),
354                  default [False,False,False] (in).                  default [False,False,False] (in).
355        @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]),
356                  default [False,False,False] (in).                  default [False,False,False] (in).
357        @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).
358        """        """
359        def __init__(self, **kwargs):        def __init__(self, **kwargs):
360             super(VectorConstrainerOverBox, self).__init__(**kwargs)             super(VectorConstrainerOverBox, self).__init__(**kwargs)
# Line 373  class VectorConstrainerOverBox(Model): Line 374  class VectorConstrainerOverBox(Model):
374            """            """
375            return the values used to constrain a solution            return the values used to constrain a solution
376    
377            @return: the mask marking the locations of the constraints            :return: the mask marking the locations of the constraints
378            @rtype: L{escript.Vector}            :rtype: `escript.Vector`
379            """            """
380            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
381            return self.__location_of_constraint            return self.__location_of_constraint
# Line 383  class VectorConstrainerOverBox(Model): Line 384  class VectorConstrainerOverBox(Model):
384            """            """
385            return the values used to constrain a solution            return the values used to constrain a solution
386    
387            @return: values to be used at the locations of the constraints. If            :return: values to be used at the locations of the constraints. If
388                    L{value} is not given C{None} is rerturned.                    ``value`` is not given ``None`` is rerturned.
389            @rtype: L{escript.Vector}            :rtype: `escript.Vector`
390            """            """
391            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
392            return self.__value_of_constraint            return self.__value_of_constraint
# Line 395  class VectorConstrainerOverBox(Model): Line 396  class VectorConstrainerOverBox(Model):
396            self.__location_of_constraint=Vector(0,x.getFunctionSpace())            self.__location_of_constraint=Vector(0,x.getFunctionSpace())
397            if self.domain.getDim()==3:            if self.domain.getDim()==3:
398               x0,x1,x2=x[0],x[1],x[2]               x0,x1,x2=x[0],x[1],x[2]
399               left_mask=whereZero(x0-inf(x0),self.tol)               d=max(sup(x0)-inf(x0), sup(x1)-inf(x1), sup(x2)-inf(x2))
400                 left_mask=whereZero(x0-inf(x0),self.tol*d)
401               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.]
402               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.]
403               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.]
404               right_mask=whereZero(x0-sup(x0),self.tol)               right_mask=whereZero(x0-sup(x0),self.tol*d)
405               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.]
406               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.]
407               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.]
408               front_mask=whereZero(x1-inf(x1),self.tol)               front_mask=whereZero(x1-inf(x1),self.tol*d)
409               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.]
410               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.]
411               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.]
412               back_mask=whereZero(x1-sup(x1),self.tol)               back_mask=whereZero(x1-sup(x1),self.tol*d)
413               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.]
414               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.]
415               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.]
416               bottom_mask=whereZero(x2-inf(x2),self.tol)               bottom_mask=whereZero(x2-inf(x2),self.tol*d)
417               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.]
418               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.]
419               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.]
420               top_mask=whereZero(x2-sup(x2),self.tol)               top_mask=whereZero(x2-sup(x2),self.tol*d)
421               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.]
422               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.]
423               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 425  class VectorConstrainerOverBox(Model):
425                  self.__value_of_constraint=self.__location_of_constraint*self.value                  self.__value_of_constraint=self.__location_of_constraint*self.value
426            else:            else:
427               x0,x1=x[0],x[1]               x0,x1=x[0],x[1]
428               left_mask=whereZero(x0-inf(x0),self.tol)               d=max(sup(x0)-inf(x0), sup(x1)-inf(x1))
429                 left_mask=whereZero(x0-inf(x0),self.tol*d)
430               if self.left[0]: self.__location_of_constraint+=left_mask*[1.,0.]               if self.left[0]: self.__location_of_constraint+=left_mask*[1.,0.]
431               if self.left[1]: self.__location_of_constraint+=left_mask*[0.,1.]               if self.left[1]: self.__location_of_constraint+=left_mask*[0.,1.]
432               right_mask=whereZero(x0-sup(x0),self.tol)               right_mask=whereZero(x0-sup(x0),self.tol*d)
433               if self.right[0]: self.__location_of_constraint+=right_mask*[1.,0.]               if self.right[0]: self.__location_of_constraint+=right_mask*[1.,0.]
434               if self.right[1]: self.__location_of_constraint+=right_mask*[0.,1.]               if self.right[1]: self.__location_of_constraint+=right_mask*[0.,1.]
435               bottom_mask=whereZero(x1-inf(x1),self.tol)               bottom_mask=whereZero(x1-inf(x1),self.tol*d)
436               if self.bottom[0]: self.__location_of_constraint+=bottom_mask*[1.,0.]               if self.bottom[0]: self.__location_of_constraint+=bottom_mask*[1.,0.]
437               if self.bottom[1]: self.__location_of_constraint+=bottom_mask*[0.,1.]               if self.bottom[1]: self.__location_of_constraint+=bottom_mask*[0.,1.]
438               top_mask=whereZero(x1-sup(x1),self.tol)               top_mask=whereZero(x1-sup(x1),self.tol*d)
439               if self.top[0]: self.__location_of_constraint+=top_mask*[1.,0.]               if self.top[0]: self.__location_of_constraint+=top_mask*[1.,0.]
440               if self.top[1]: self.__location_of_constraint+=top_mask*[0.,1.]               if self.top[1]: self.__location_of_constraint+=top_mask*[0.,1.]
441               if not self.value == None:               if not self.value == None:
# Line 446  class ConstrainerAtBoxVertex(Model): Line 449  class ConstrainerAtBoxVertex(Model):
449    
450        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.
451    
452        @ivar domain: domain (in).        :ivar domain: domain (in).
453        @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).
454        """        """
455        def __init__(self,**kwargs):        def __init__(self,**kwargs):
456             super(ConstrainerAtBoxVertex, self).__init__(**kwargs)             super(ConstrainerAtBoxVertex, self).__init__(**kwargs)
# Line 460  class ConstrainerAtBoxVertex(Model): Line 463  class ConstrainerAtBoxVertex(Model):
463            """            """
464            return the values used to constrain a solution            return the values used to constrain a solution
465    
466            @return: the mask marking the locations of the constraints            :return: the mask marking the locations of the constraints
467            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
468            """            """
469            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
470            return self.__location_of_constraint            return self.__location_of_constraint
# Line 470  class ConstrainerAtBoxVertex(Model): Line 473  class ConstrainerAtBoxVertex(Model):
473            """            """
474            return the values used to constrain a solution            return the values used to constrain a solution
475    
476            @return: values to be used at the locations of the constraints. If            :return: values to be used at the locations of the constraints. If
477                    L{value} is not given C{None} is rerturned.                    ``value`` is not given ``None`` is rerturned.
478            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
479            """            """
480            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
481            return self.__value_of_constraint            return self.__value_of_constraint
# Line 485  class ConstrainerAtBoxVertex(Model): Line 488  class ConstrainerAtBoxVertex(Model):
488                  shape=()                  shape=()
489               elif isinstance(val, list) or isinstance(val, tuple) :               elif isinstance(val, list) or isinstance(val, tuple) :
490                  shape=(len(val),)                  shape=(len(val),)
491               elif isinstance(val, numarray.NumArray):               elif isinstance(val, numpy.ndarray):
492                   shape=val.shape                   shape=val.shape
493               elif val == None:               elif val == None:
494                    shape=()                    shape=()
# Line 495  class ConstrainerAtBoxVertex(Model): Line 498  class ConstrainerAtBoxVertex(Model):
498                     vertex=[inf(x[0]),inf(x[1]),inf(x[2])]                     vertex=[inf(x[0]),inf(x[1]),inf(x[2])]
499               else:               else:
500                     vertex=[inf(x[0]),inf(x[1])]                     vertex=[inf(x[0]),inf(x[1])]
501               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)
502               if not self.value == None:               if not self.value == None:
503                     self.__value_of_constraint=self.__location_of_constraint*self.value                     self.__value_of_constraint=self.__location_of_constraint*self.value
504  class ScalarConstrainerAtBoxVertex(Model):  class ScalarConstrainerAtBoxVertex(Model):
# Line 506  class ScalarConstrainerAtBoxVertex(Model Line 509  class ScalarConstrainerAtBoxVertex(Model
509    
510        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.
511    
512        @ivar domain: domain (in).        :ivar domain: domain (in).
513        @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).
514        """        """
515        def __init__(self,**kwargs):        def __init__(self,**kwargs):
516             super(ScalarConstrainerAtBoxVertex, self).__init__(**kwargs)             super(ScalarConstrainerAtBoxVertex, self).__init__(**kwargs)
# Line 520  class ScalarConstrainerAtBoxVertex(Model Line 523  class ScalarConstrainerAtBoxVertex(Model
523            """            """
524            return the values used to constrain a solution            return the values used to constrain a solution
525    
526            @return: the mask marking the locations of the constraints            :return: the mask marking the locations of the constraints
527            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
528            """            """
529            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
530            return self.__location_of_constraint            return self.__location_of_constraint
# Line 530  class ScalarConstrainerAtBoxVertex(Model Line 533  class ScalarConstrainerAtBoxVertex(Model
533            """            """
534            return the values used to constrain a solution            return the values used to constrain a solution
535    
536            @return: values to be used at the locations of the constraints. If            :return: values to be used at the locations of the constraints. If
537                    L{value} is not given C{None} is rerturned.                    ``value`` is not given ``None`` is rerturned.
538            @rtype: L{escript.Scalar}            :rtype: `escript.Scalar`
539            """            """
540            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
541            return self.__value_of_constraint            return self.__value_of_constraint
# Line 554  class VectorConstrainerAtBoxVertex(Model Line 557  class VectorConstrainerAtBoxVertex(Model
557        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
558        back as well as the third component of each argument is ignored.        back as well as the third component of each argument is ignored.
559    
560        @ivar domain: domain        :ivar domain: domain
561        @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).
562        @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).
563        """        """
564        def __init__(self, **kwargs):        def __init__(self, **kwargs):
565             super(VectorConstrainerAtBoxVertex, self).__init__(**kwargs)             super(VectorConstrainerAtBoxVertex, self).__init__(**kwargs)
# Line 571  class VectorConstrainerAtBoxVertex(Model Line 574  class VectorConstrainerAtBoxVertex(Model
574            """            """
575            return the values used to constrain a solution            return the values used to constrain a solution
576    
577            @return: the mask marking the locations of the constraints            :return: the mask marking the locations of the constraints
578            @rtype: L{escript.Vector}            :rtype: `escript.Vector`
579            """            """
580            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
581            return self.__location_of_constraint            return self.__location_of_constraint
# Line 581  class VectorConstrainerAtBoxVertex(Model Line 584  class VectorConstrainerAtBoxVertex(Model
584            """            """
585            return the values used to constrain a solution            return the values used to constrain a solution
586    
587            @return: values to be used at the locations of the constraints. If            :return: values to be used at the locations of the constraints. If
588                    L{value} is not given C{None} is rerturned.                    ``value`` is not given ``None`` is rerturned.
589            @rtype: L{escript.Vector}            :rtype: `escript.Vector`
590            """            """
591            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
592            return self.__value_of_constraint            return self.__value_of_constraint
# Line 593  class VectorConstrainerAtBoxVertex(Model Line 596  class VectorConstrainerAtBoxVertex(Model
596            self.__location_of_constraint=Vector(0,x.getFunctionSpace())            self.__location_of_constraint=Vector(0,x.getFunctionSpace())
597            if self.domain.getDim()==3:            if self.domain.getDim()==3:
598               vertex=[inf(x[0]),inf(x[1]),inf(x[2])]               vertex=[inf(x[0]),inf(x[1]),inf(x[2])]
599               msk=numarray.zeros((3,))               msk=numpy.zeros((3,))
600               if self.comp_mask[0]: msk[0]=1               if self.comp_mask[0]: msk[0]=1
601               if self.comp_mask[1]: msk[1]=1               if self.comp_mask[1]: msk[1]=1
602               if self.comp_mask[2]: msk[2]=1               if self.comp_mask[2]: msk[2]=1
603            else:            else:
604               vertex=[inf(x[0]),inf(x[1])]               vertex=[inf(x[0]),inf(x[1])]
605               msk=numarray.zeros((2,))               msk=numpy.zeros((2,))
606               if self.comp_mask[0]: msk[0]=1               if self.comp_mask[0]: msk[0]=1
607               if self.comp_mask[1]: msk[1]=1               if self.comp_mask[1]: msk[1]=1
608            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)
609            if not self.value == None:            if not self.value == None:
610                  self.__value_of_constraint=self.__location_of_constraint*self.value                  self.__value_of_constraint=self.__location_of_constraint*self.value
611    

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

  ViewVC Help
Powered by ViewVC 1.1.26