# Diff of /trunk/modellib/py_src/geometry.py

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 2455 by jfenwick, Wed Jun 3 03:29:07 2009 UTC
# Line 1  Line 1
1
2    ########################################################
3  #  #
4  # \$Id\$  # Copyright (c) 2003-2008 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
7  #  #
8  #######################################################  # Primary Business: Queensland, Australia
11  #  #
12    ########################################################
13
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
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 226  class ConstrainerOverBox(Model): Line 223  class ConstrainerOverBox(Model):
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.                    C{value} is not given C{None} is rerturned.
227            @rtype: L{escript.Scalar}            @rtype: L{escript.Scalar}
228            """            """
229            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
# 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 308  class ScalarConstrainerOverBox(Model): Line 305  class ScalarConstrainerOverBox(Model):
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.                    C{value} is not given C{None} is rerturned.
309            @rtype: L{escript.Scalar}            @rtype: L{escript.Scalar}
310            """            """
311            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
# 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 384  class VectorConstrainerOverBox(Model): Line 383  class VectorConstrainerOverBox(Model):
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.                    C{value} is not given C{None} is rerturned.
387            @rtype: L{escript.Vector}            @rtype: L{escript.Vector}
388            """            """
389            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
# 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]
# 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]
439               if not self.value == None:               if not self.value == None:
# Line 471  class ConstrainerAtBoxVertex(Model): Line 472  class ConstrainerAtBoxVertex(Model):
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.                    C{value} is not given C{None} is rerturned.
476            @rtype: L{escript.Scalar}            @rtype: L{escript.Scalar}
477            """            """
478            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
# 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 531  class ScalarConstrainerAtBoxVertex(Model Line 532  class ScalarConstrainerAtBoxVertex(Model
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.                    C{value} is not given C{None} is rerturned.
536            @rtype: L{escript.Scalar}            @rtype: L{escript.Scalar}
537            """            """
538            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
# Line 582  class VectorConstrainerAtBoxVertex(Model Line 583  class VectorConstrainerAtBoxVertex(Model
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.                    C{value} is not given C{None} is rerturned.
587            @rtype: L{escript.Vector}            @rtype: L{escript.Vector}
588            """            """
589            if self.__location_of_constraint == None: self.__setOutput()            if self.__location_of_constraint == None: self.__setOutput()
# 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,))
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,))