/[escript]/trunk/modellib/py_src/geometry.py
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1809 by ksteube, Thu Sep 25 06:43:44 2008 UTC revision 2548 by jfenwick, Mon Jul 20 06:20:06 2009 UTC
# Line 1  Line 1 
1    
2  ########################################################  ########################################################
3  #  #
4  # Copyright (c) 2003-2008 by University of Queensland  # Copyright (c) 2003-2009 by University of Queensland
5  # Earth Systems Science Computational Center (ESSCC)  # Earth Systems Science Computational Center (ESSCC)
6  # http://www.uq.edu.au/esscc  # http://www.uq.edu.au/esscc
7  #  #
# Line 17  http://www.uq.edu.au/esscc Line 17  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__="http://www.uq.edu.au/esscc/escript-finley"  __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 223  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 237  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 305  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 316  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 381  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 392  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 420  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 468  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 482  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 492  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 528  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 579  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 590  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.1809  
changed lines
  Added in v.2548

  ViewVC Help
Powered by ViewVC 1.1.26