/[escript]/trunk/escript/py_src/util.py
ViewVC logotype

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

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

revision 112 by jgs, Thu Jan 27 06:21:59 2005 UTC revision 113 by jgs, Mon Feb 28 07:06:33 2005 UTC
# Line 49  TIFF=7 Line 49  TIFF=7
49  OPENINVENTOR=8  OPENINVENTOR=8
50  RENDERMAN=9  RENDERMAN=9
51  PNM=10  PNM=10
52    
53  #  #
54  # wrapper for various functions: if the argument has attribute the function name  # wrapper for various functions: if the argument has attribute the function name
55  # as an argument it calls the correspong methods. Otherwise the coresponsing numarray  # as an argument it calls the correspong methods. Otherwise the coresponsing numarray
# Line 267  def length(arg): Line 268  def length(arg):
268      else:      else:
269         return sqrt((arg**2).sum())         return sqrt((arg**2).sum())
270    
271    def deviator(arg):
272        """
273        @brief
274    
275        @param arg1
276        """
277        if isinstance(arg,escript.Data):
278            shape=arg.getShape()
279        else:
280            shape=arg.shape
281        if len(shape)!=2:
282              raise ValueError,"Deviator requires rank 2 object"
283        if shape[0]!=shape[1]:
284              raise ValueError,"Deviator requires a square matrix"
285        return arg-1./(shape[0]*1.)*trace(arg)*kronecker(shape[0])
286    
287    def inner(arg1,arg2):
288        """
289        @brief
290    
291        @param arg1, arg2
292        """
293        sum=escript.Scalar(0,arg1.getFunctionSpace())
294        if arg.getRank()==0:
295              return arg1*arg2
296        elif arg.getRank()==1:
297             sum=escript.Scalar(0,arg.getFunctionSpace())
298             for i in range(arg.getShape()[0]):
299                sum+=arg1[i]*arg2[i]
300        elif arg.getRank()==2:
301            sum=escript.Scalar(0,arg.getFunctionSpace())
302            for i in range(arg.getShape()[0]):
303               for j in range(arg.getShape()[1]):
304                  sum+=arg1[i,j]*arg2[i,j]
305        elif arg.getRank()==3:
306            sum=escript.Scalar(0,arg.getFunctionSpace())
307            for i in range(arg.getShape()[0]):
308                for j in range(arg.getShape()[1]):
309                   for k in range(arg.getShape()[2]):
310                      sum+=arg1[i,j,k]*arg2[i,j,k]
311        elif arg.getRank()==4:
312            sum=escript.Scalar(0,arg.getFunctionSpace())
313            for i in range(arg.getShape()[0]):
314               for j in range(arg.getShape()[1]):
315                  for k in range(arg.getShape()[2]):
316                     for l in range(arg.getShape()[3]):
317                        sum+=arg1[i,j,k,l]*arg2[i,j,k,l]
318        else:
319              raise SystemError,"inner is not been implemented yet"
320        return sum
321    
322  def sign(arg):  def sign(arg):
323      """      """
324      @brief      @brief
# Line 352  def dot(arg1,arg2): Line 404  def dot(arg1,arg2):
404         return arg2.dot(arg1)         return arg2.dot(arg1)
405      else:      else:
406         return numarray.dot(arg1,arg2)         return numarray.dot(arg1,arg2)
407    
408    def kronecker(d):
409       return numarray.identity(d)

Legend:
Removed from v.112  
changed lines
  Added in v.113

  ViewVC Help
Powered by ViewVC 1.1.26