# Diff of /trunk/escript/py_src/util.py

revision 341 by gross, Mon Dec 12 05:26:10 2005 UTC revision 378 by gross, Fri Dec 16 09:02:28 2005 UTC
# Line 24  Utility functions for escript Line 24  Utility functions for escript
24  __author__="Lutz Gross, l.gross@uq.edu.au"  __author__="Lutz Gross, l.gross@uq.edu.au"
25  __licence__="contact: esys@access.uq.edu.au"  __licence__="contact: esys@access.uq.edu.au"
26  __url__="http://www.iservo.edu.au/esys/escript"  __url__="http://www.iservo.edu.au/esys/escript"
27  __version__="\$Revision: 329 \$"  __version__="\$Revision\$"
28  __date__="\$Date\$"  __date__="\$Date\$"
29
30
# Line 45  import os Line 45  import os
45
46  # def maximum(arg0,arg1):  # def maximum(arg0,arg1):
47  # def minimum(arg0,arg1):  # def minimum(arg0,arg1):
48    # def clip(arg,minval,maxval)
49
50  # def transpose(arg,axis=None):  # def transpose(arg,axis=None):
51  # def trace(arg,axis0=0,axis1=1):  # def trace(arg,axis0=0,axis1=1):
# Line 3325  def minimum(*arg): Line 3326  def minimum(*arg):
3326            m=whereNegative(out-a)            m=whereNegative(out-a)
3327            out=m*out+(1.-m)*a            out=m*out+(1.-m)*a
3328      return out      return out
3329
3330    def clip(arg,minval=0.,maxval=1.):
3331        """
3332        cuts the values of arg between minval and maxval
3333
3334        @param arg: argument
3335        @type arg: L{numarray.NumArray}, L{escript.Data}, L{Symbol}, C{int} or C{float}
3336        @param minval: lower range
3337        @type arg: C{float}
3338        @param maxval: uper range
3339        @type arg: C{float}
3340        @return: is on object with all its value between minval and maxval. value of the argument that greater then minval and
3341                 less then maxval are unchanged.
3342        @rtype: L{numarray.NumArray}, L{escript.Data}, L{Symbol}, C{int} or C{float} depending on the input
3343        """
3344        if minval>maxval:
3345           raise ValueError,"minval = %s must be less then maxval %s"%(minval,maxval)
3346        return minimum(maximum(minval,arg),maxval)
3347
3348
3349  def inner(arg0,arg1):  def inner(arg0,arg1):
3350      """      """
# Line 3661  def interpolate(arg,where): Line 3681  def interpolate(arg,where):
3681      @param arg:    interpolant      @param arg:    interpolant
3682      @param where:  FunctionSpace to interpolate to      @param where:  FunctionSpace to interpolate to
3683      """      """
3684      if testForZero(arg):      if isinstance(arg,Symbol):
return 0
elif isinstance(arg,Symbol):
3685         return Interpolated_Symbol(arg,where)         return Interpolated_Symbol(arg,where)
3686      else:      else:
3687         return escript.Data(arg,where)         return escript.Data(arg,where)
# Line 3688  def jump(arg): Line 3706  def jump(arg):
3706                    to be calculated.                    to be calculated.
3707      """      """
3708      d=arg.getDomain()      d=arg.getDomain()
3709      return arg.interpolate(escript.FunctionOnContactOne())-arg.interpolate(escript.FunctionOnContactZero())      return arg.interpolate(escript.FunctionOnContactOne(d))-arg.interpolate(escript.FunctionOnContactZero(d))
3710
3711  #=============================  #=============================
3712  #  #

Legend:
 Removed from v.341 changed lines Added in v.378