/[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 517 by gross, Tue Feb 14 02:25:02 2006 UTC revision 2288 by gross, Tue Feb 24 06:11:48 2009 UTC
# Line 1  Line 1 
1  # $Id$  
2  #  ########################################################
 #      COPYRIGHT ACcESS 2004 -  All Rights Reserved  
 #  
 #   This software is the property of ACcESS.  No part of this code  
 #   may be copied in any form or by any means without the expressed written  
 #   consent of ACcESS.  Copying, use or modification of this software  
 #   by any unauthorised person is illegal unless that  
 #   person has a software license agreement with ACcESS.  
3  #  #
4    # Copyright (c) 2003-2008 by University of Queensland
5    # Earth Systems Science Computational Center (ESSCC)
6    # http://www.uq.edu.au/esscc
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-2008 by University of Queensland
15    Earth Systems Science Computational Center (ESSCC)
16    http://www.uq.edu.au/esscc
17    Primary Business: Queensland, Australia"""
18    __license__="""Licensed under the Open Software License version 3.0
19    http://www.opensource.org/licenses/osl-3.0.php"""
20    __url__="http://www.uq.edu.au/esscc/escript-finley"
21    
22  """  """
23  Utility functions for escript  Utility functions for escript
24    
 @remark:  This module is under construction and is still tested!!!  
   
25  @var __author__: name of author  @var __author__: name of author
26  @var __licence__: licence agreement  @var __copyright__: copyrights
27    @var __license__: licence agreement
28  @var __url__: url entry point on documentation  @var __url__: url entry point on documentation
29  @var __version__: version  @var __version__: version
30  @var __date__: date of the version  @var __date__: date of the version
31    @var EPSILON: smallest positive value with 1.<1.+EPSILON
32    @var DBLE_MAX: largest positive float
33  """  """
34                                                                                                                                                                                                        
35  __author__="Lutz Gross, l.gross@uq.edu.au"  __author__="Lutz Gross, l.gross@uq.edu.au"
 __licence__="contact: esys@access.uq.edu.au"  
 __url__="http://www.iservo.edu.au/esys/escript"  
 __version__="$Revision$"  
 __date__="$Date$"  
36    
37    
38  import math  import math
39  import numarray  import numarray
 import numarray.linear_algebra  
40  import escript  import escript
41  import os  import os
42    from esys.escript import C_GeneralTensorProduct
43    from esys.escript import getVersion
44    from esys.escript import printParallelThreadCounts
45    from esys.escript import listEscriptParams
46    
47  # missing tests:  #=========================================================
48    #   some helpers:
49    #=========================================================
50    def getEpsilon():
51         return escript.getMachinePrecision()
52    EPSILON=getEpsilon()
53    
54  # def pokeShape(arg):  def getMaxFloat():
55  # def pokeDim(arg):       return escript.getMaxFloat()
56  # def commonShape(arg0,arg1):  DBLE_MAX=getMaxFloat()
 # def commonDim(*args):  
 # def testForZero(arg):  
 # def matchType(arg0=0.,arg1=0.):  
 # def matchShape(arg0,arg1):  
57    
 # def reorderComponents(arg,index):  
58    
59  #  def getTagNames(domain):
60  # slicing: get      """
61  #          set      Returns a list of tag names used by the domain.
62  #  
63  # and derivatives      @param domain: a domain object
64        @type domain: L{escript.Domain}
65        @return: a list of tag names used by the domain
66        @rtype: C{list} of C{str}
67        """
68        return [n.strip() for n in domain.showTagNames().split(",") ]
69    
70    def insertTagNames(domain,**kwargs):
71        """
72        Inserts tag names into the domain.
73    
74        @param domain: a domain object
75        @type domain: C{escript.Domain}
76        @keyword <tag_name>: tag key assigned to <tag_name>
77        @type <tag_name>: C{int}
78        """
79        for  k in kwargs:
80             domain.setTagMap(k,kwargs[k])
81    
82    def insertTaggedValues(target,**kwargs):
83        """
84        Inserts tagged values into the target using tag names.
85    
86        @param target: data to be filled by tagged values
87        @type target: L{escript.Data}
88        @keyword <tag_name>: value to be used for <tag_name>
89        @type <tag_name>: C{float} or C{numarray.NumArray}
90        @return: C{target}
91        @rtype: L{escript.Data}
92        """
93        for k in kwargs:
94            target.setTaggedValue(k,kwargs[k])
95        return target
96    
 #=========================================================  
 #   some helpers:  
 #=========================================================  
97  def saveVTK(filename,domain=None,**data):  def saveVTK(filename,domain=None,**data):
98      """      """
99      writes a L{Data} objects into a files using the the VTK XML file format.      Writes L{Data} objects and their mesh into a file using the VTK XML file
100        format.
101    
102      Example:      Example::
103    
104         tmp=Scalar(..)          tmp=Scalar(..)
105         v=Vector(..)          v=Vector(..)
106         saveVTK("solution.xml",temperature=tmp,velovity=v)          saveVTK("solution.vtu", temperature=tmp, velocity=v)
107    
108      tmp and v are written into "solution.xml" where tmp is named "temperature" and v is named "velovity"      C{tmp} and C{v} are written into "solution.vtu" where C{tmp} is named
109        "temperature" and C{v} is named "velocity".
110    
111      @param filename: file name of the output file      @param filename: file name of the output file
112      @type filename: C{str}      @type filename: C{str}
113      @param domain: domain of the L{Data} object. If not specified, the domain of the given L{Data} objects is used.      @param domain: domain of the L{Data} objects. If not specified, the domain
114                       of the given L{Data} objects is used.
115      @type domain: L{escript.Domain}      @type domain: L{escript.Domain}
116      @keyword <name>: writes the assigned value to the VTK file using <name> as identifier.      @keyword <name>: writes the assigned value to the VTK file using <name> as
117      @type <name>: L{Data} object.                       identifier
118      @note: The data objects have to be defined on the same domain. They may not be in the same L{FunctionSpace} but one cannot expect that all L{FunctionSpace} can be mixed. Typically, data on the boundary and data on the interior cannot be mixed.      @type <name>: L{Data} object
119      """      @note: The data objects have to be defined on the same domain. They may not
120      if domain==None:             be in the same L{FunctionSpace} but one cannot expect that all
121         for i in data.keys():             L{FunctionSpace}s can be mixed. Typically, data on the boundary and
122            if not data[i].isEmpty(): domain=data[i].getFunctionSpace().getDomain()             data on the interior cannot be mixed.
123        """
124        new_data={}
125        for n,d in data.items():
126              if not d.isEmpty():
127                fs=d.getFunctionSpace()
128                domain2=fs.getDomain()
129                if fs == escript.Solution(domain2):
130                   new_data[n]=interpolate(d,escript.ContinuousFunction(domain2))
131                elif fs == escript.ReducedSolution(domain2):
132                   new_data[n]=interpolate(d,escript.ReducedContinuousFunction(domain2))
133                else:
134                   new_data[n]=d
135                if domain==None: domain=domain2
136      if domain==None:      if domain==None:
137          raise ValueError,"no domain detected."          raise ValueError,"saveVTK: no domain detected."
138      else:      domain.saveVTK(filename,new_data)
         domain.saveVTK(filename,data)  
139    
140  def saveDX(filename,domain=None,**data):  def saveDX(filename,domain=None,**data):
141      """      """
142      writes a L{Data} objects into a files using the the DX file format.      Writes L{Data} objects into a file using the OpenDX file format.
143    
144      Example:      Example::
145    
146         tmp=Scalar(..)          tmp=Scalar(..)
147         v=Vector(..)          v=Vector(..)
148         saveDX("solution.dx",temperature=tmp,velovity=v)          saveDX("solution.dx", temperature=tmp, velocity=v)
149    
150      tmp and v are written into "solution.dx" where tmp is named "temperature" and v is named "velovity".      C{tmp} and C{v} are written into "solution.dx" where C{tmp} is named
151        "temperature" and C{v} is named "velocity".
152    
153      @param filename: file name of the output file      @param filename: file name of the output file
154      @type filename: C{str}      @type filename: C{str}
155      @param domain: domain of the L{Data} object. If not specified, the domain of the given L{Data} objects is used.      @param domain: domain of the L{Data} objects. If not specified, the domain
156                       of the given L{Data} objects is used.
157      @type domain: L{escript.Domain}      @type domain: L{escript.Domain}
158      @keyword <name>: writes the assigned value to the DX file using <name> as identifier. The identifier can be used to select the data set when data are imported into DX.      @keyword <name>: writes the assigned value to the DX file using <name> as
159      @type <name>: L{Data} object.                       identifier. The identifier can be used to select the data
160      @note: The data objects have to be defined on the same domain. They may not be in the same L{FunctionSpace} but one cannot expect that all L{FunctionSpace} can be mixed. Typically, data on the boundary and data on the interior cannot be mixed.                       set when data are imported into DX.
161      """      @type <name>: L{Data} object
162        @note: The data objects have to be defined on the same domain. They may not
163               be in the same L{FunctionSpace} but one cannot expect that all
164               L{FunctionSpace}s can be mixed. Typically, data on the boundary and
165               data on the interior cannot be mixed.
166        """
167        new_data={}
168        for n,d in data.items():
169              if not d.isEmpty():
170                fs=d.getFunctionSpace()
171                domain2=fs.getDomain()
172                if fs == escript.Solution(domain2):
173                   new_data[n]=interpolate(d,escript.ReducedContinuousFunction(domain2))
174                elif fs == escript.ReducedSolution(domain2):
175                   new_data[n]=interpolate(d,escript.ReducedContinuousFunction(domain2))
176                elif fs == escript.ContinuousFunction(domain2):
177                   new_data[n]=interpolate(d,escript.ReducedContinuousFunction(domain2))
178                else:
179                   new_data[n]=d
180                if domain==None: domain=domain2
181      if domain==None:      if domain==None:
182         for i in data.keys():          raise ValueError,"saveDX: no domain detected."
183            if not data[i].isEmpty(): domain=data[i].getFunctionSpace().getDomain()      domain.saveDX(filename,new_data)
184    
185    def saveESD(datasetName, dataDir=".", domain=None, **data):
186        """
187        Saves L{Data} objects to files and creates an I{escript dataset} (ESD) file
188        for convenient processing/visualisation.
189    
190        Example::
191    
192            tmp = Scalar(..)
193            v = Vector(..)
194            saveESD("solution", "data", temperature=tmp, velocity=v)
195    
196        tmp, v and the domain are saved in native format in the "data"
197        directory and the file "solution.esd" is created that refers to tmp by
198        the name "temperature" and to v by the name "velocity".
199    
200        @param datasetName: name of the dataset, used to name the ESD file
201        @type datasetName: C{str}
202        @param dataDir: optional directory where the data files should be saved
203        @type dataDir: C{str}
204        @param domain: domain of the L{Data} object(s). If not specified, the
205                       domain of the given L{Data} objects is used.
206        @type domain: L{escript.Domain}
207        @keyword <name>: writes the assigned value to the file using <name> as
208                         identifier
209        @type <name>: L{Data} object.
210        @note: The data objects have to be defined on the same domain. They may not
211               be in the same L{FunctionSpace} but one cannot expect that all
212               L{FunctionSpace}s can be mixed. Typically, data on the boundary and
213               data on the interior cannot be mixed.
214        """
215        new_data = {}
216        for n,d in data.items():
217              if not d.isEmpty():
218                fs = d.getFunctionSpace()
219                domain2 = fs.getDomain()
220                if fs == escript.Solution(domain2):
221                   new_data[n]=interpolate(d,escript.ContinuousFunction(domain2))
222                elif fs == escript.ReducedSolution(domain2):
223                   new_data[n]=interpolate(d,escript.ReducedContinuousFunction(domain2))
224                else:
225                   new_data[n]=d
226                if domain==None: domain=domain2
227      if domain==None:      if domain==None:
228          raise ValueError,"no domain detected."          raise ValueError, "saveESD: no domain detected."
229      else:  
230          domain.saveDX(filename,data)      if domain.onMasterProcessor() and not os.path.isdir(dataDir):
231            os.mkdir(dataDir)
232    
233        meshFile = os.path.join(dataDir, datasetName+"_mesh")
234        domain.dump(meshFile + ".nc")
235        outputString = ""
236        if domain.onMasterProcessor():
237            outputString += "#escript datafile V1.0\n"
238            # number of timesteps (currently only 1 is supported)
239            outputString += "T=1\n"
240            # name of the mesh file
241            outputString += "M=%s\n" % meshFile
242            # number of blocks (MPI size)
243            outputString += "N=%d\n" % domain.getMPISize()
244    
245        # now add the variables
246        for varName, d in new_data.items():
247            varFile = os.path.join(dataDir, datasetName+"_"+varName)
248            d.dump(varFile + ".nc")
249            if domain.onMasterProcessor():
250                outputString += "V=%s:%s\n" % (varFile, varName)
251    
252        if domain.onMasterProcessor():
253            esdfile = open(datasetName+".esd", "w")
254            esdfile.write(outputString)
255            esdfile.close()
256    
257  def kronecker(d=3):  def kronecker(d=3):
258     """     """
259     return the kronecker S{delta}-symbol     Returns the kronecker S{delta}-symbol.
260    
261     @param d: dimension or an object that has the C{getDim} method defining the dimension     @param d: dimension or an object that has the C{getDim} method defining the
262                 dimension
263     @type d: C{int}, L{escript.Domain} or L{escript.FunctionSpace}     @type d: C{int}, L{escript.Domain} or L{escript.FunctionSpace}
264     @return: the object u of rank 2 with M{u[i,j]=1} for M{i=j} and M{u[i,j]=0} otherwise     @return: the object u of rank 2 with M{u[i,j]=1} for M{i=j} and M{u[i,j]=0}
265     @rtype d: L{numarray.NumArray} or L{escript.Data} of rank 2.              otherwise
266       @rtype: C{numarray.NumArray} or L{escript.Data} of rank 2
267     """     """
268     return identityTensor(d)     return identityTensor(d)
269    
270  def identity(shape=()):  def identity(shape=()):
271     """     """
272     return the shape x shape identity tensor     Returns the C{shape} x C{shape} identity tensor.
273    
274     @param shape: input shape for the identity tensor     @param shape: input shape for the identity tensor
275     @type shape: C{tuple} of C{int}     @type shape: C{tuple} of C{int}
276     @return: array of shape shape x shape with M{u[i,k]=1} for M{i=k} and M{u[i,k]=0} otherwise for len(shape)=1 and, for len(shape)=2: M{u[i,j,k,l]=1} for M{i=k and j=l} and M{u[i,j,k,l]=0} otherwise.     @return: array whose shape is shape x shape where M{u[i,k]=1} for M{i=k} and
277     @rtype: L{numarray.NumArray} of rank 1, rankk 2 or rank 4.              M{u[i,k]=0} otherwise for len(shape)=1. If len(shape)=2:
278     @raise ValueError: if len(shape)>2.              M{u[i,j,k,l]=1} for M{i=k and j=l} and M{u[i,j,k,l]=0} otherwise.
279       @rtype: C{numarray.NumArray} of rank 1, rank 2 or rank 4
280       @raise ValueError: if len(shape)>2
281     """     """
282     if len(shape)>0:     if len(shape)>0:
283        out=numarray.zeros(shape+shape,numarray.Float)        out=numarray.zeros(shape+shape,numarray.Float64)
284        if len(shape)==1:        if len(shape)==1:
285            for i0 in range(shape[0]):            for i0 in range(shape[0]):
286               out[i0,i0]=1.               out[i0,i0]=1.
# Line 149  def identity(shape=()): Line 296  def identity(shape=()):
296    
297  def identityTensor(d=3):  def identityTensor(d=3):
298     """     """
299     return the dxd identity matrix     Returns the C{d} x C{d} identity matrix.
300    
301     @param d: dimension or an object that has the C{getDim} method defining the dimension     @param d: dimension or an object that has the C{getDim} method defining the
302                 dimension
303     @type d: C{int}, L{escript.Domain} or L{escript.FunctionSpace}     @type d: C{int}, L{escript.Domain} or L{escript.FunctionSpace}
304     @return: the object u of rank 2 with M{u[i,j]=1} for M{i=j} and M{u[i,j]=0} otherwise     @return: the object u of rank 2 with M{u[i,j]=1} for M{i=j} and M{u[i,j]=0}
305     @rtype d: L{numarray.NumArray} or L{escript.Data} of rank 2              otherwise
306       @rtype: C{numarray.NumArray} or L{escript.Data} of rank 2
307     """     """
308     if isinstance(d,escript.FunctionSpace):     if isinstance(d,escript.FunctionSpace):
309         return escript.Data(identity((d.getDim(),)),d)         return escript.Data(identity((d.getDim(),)),d)
# Line 165  def identityTensor(d=3): Line 314  def identityTensor(d=3):
314    
315  def identityTensor4(d=3):  def identityTensor4(d=3):
316     """     """
317     return the dxdxdxd identity tensor     Returns the C{d} x C{d} x C{d} x C{d} identity tensor.
318    
319     @param d: dimension or an object that has the C{getDim} method defining the dimension     @param d: dimension or an object that has the C{getDim} method defining the
320                 dimension
321     @type d: C{int} or any object with a C{getDim} method     @type d: C{int} or any object with a C{getDim} method
322     @return: the object u of rank 4 with M{u[i,j,k,l]=1} for M{i=k and j=l} and M{u[i,j,k,l]=0} otherwise     @return: the object u of rank 4 with M{u[i,j,k,l]=1} for M{i=k and j=l} and
323     @rtype d: L{numarray.NumArray} or L{escript.Data} of rank 4.              M{u[i,j,k,l]=0} otherwise
324       @rtype: C{numarray.NumArray} or L{escript.Data} of rank 4
325     """     """
326     if isinstance(d,escript.FunctionSpace):     if isinstance(d,escript.FunctionSpace):
327         return escript.Data(identity((d.getDim(),d.getDim())),d)         return escript.Data(identity((d.getDim(),d.getDim())),d)
# Line 181  def identityTensor4(d=3): Line 332  def identityTensor4(d=3):
332    
333  def unitVector(i=0,d=3):  def unitVector(i=0,d=3):
334     """     """
335     return a unit vector u of dimension d with nonzero index i:     Returns a unit vector u of dimension d whose non-zero element is at index i.
336    
337     @param i: index     @param i: index for non-zero element
338     @type i: C{int}     @type i: C{int}
339     @param d: dimension or an object that has the C{getDim} method defining the dimension     @param d: dimension or an object that has the C{getDim} method defining the
340                 dimension
341     @type d: C{int}, L{escript.Domain} or L{escript.FunctionSpace}     @type d: C{int}, L{escript.Domain} or L{escript.FunctionSpace}
342     @return: the object u of rank 1 with M{u[j]=1} for M{j=i} and M{u[i]=0} otherwise     @return: the object u of rank 1 with M{u[j]=1} for M{j=index} and M{u[j]=0}
343     @rtype d: L{numarray.NumArray} or L{escript.Data} of rank 1              otherwise
344       @rtype: C{numarray.NumArray} or L{escript.Data} of rank 1
345     """     """
346     return kronecker(d)[i]     return kronecker(d)[i]
347    
# Line 197  def unitVector(i=0,d=3): Line 350  def unitVector(i=0,d=3):
350  #=========================================================================  #=========================================================================
351  def Lsup(arg):  def Lsup(arg):
352      """      """
353      returns the Lsup-norm of argument arg. This is the maximum absolute value over all data points.      Returns the Lsup-norm of argument C{arg}. This is the maximum absolute value
354      This function is equivalent to sup(abs(arg)).      over all data points. This function is equivalent to C{sup(abs(arg))}.
355    
356      @param arg: argument      @param arg: argument
357      @type arg: C{float}, C{int}, L{escript.Data}, L{numarray.NumArray}.      @type arg: C{float}, C{int}, L{escript.Data}, C{numarray.NumArray}
358      @return: maximum value of the absolute value of arg over all components and all data points      @return: maximum value of the absolute value of C{arg}over all components
359                 and all data points
360      @rtype: C{float}      @rtype: C{float}
361      @raise TypeError: if type of arg cannot be processed      @raise TypeError: if type of C{arg}cannot be processed
362      """      """
363      if isinstance(arg,numarray.NumArray):      if isinstance(arg,numarray.NumArray):
364          return sup(abs(arg))          return sup(abs(arg))
# Line 219  def Lsup(arg): Line 373  def Lsup(arg):
373    
374  def sup(arg):  def sup(arg):
375      """      """
376      returns the maximum value over all data points.      Returns the maximum value over all data points.
377    
378      @param arg: argument      @param arg: argument
379      @type arg: C{float}, C{int}, L{escript.Data}, L{numarray.NumArray}.      @type arg: C{float}, C{int}, L{escript.Data}, C{numarray.NumArray}
380      @return: maximum value of arg over all components and all data points      @return: maximum value of C{arg}over all components and all data points
381      @rtype: C{float}      @rtype: C{float}
382      @raise TypeError: if type of arg cannot be processed      @raise TypeError: if type of C{arg}cannot be processed
383      """      """
384      if isinstance(arg,numarray.NumArray):      if isinstance(arg,numarray.NumArray):
385          return arg.max()          return arg.max()
# Line 240  def sup(arg): Line 394  def sup(arg):
394    
395  def inf(arg):  def inf(arg):
396      """      """
397      returns the maximum value over all data points.      Returns the minimum value over all data points.
398    
399      @param arg: argument      @param arg: argument
400      @type arg: C{float}, C{int}, L{escript.Data}, L{numarray.NumArray}.      @type arg: C{float}, C{int}, L{escript.Data}, C{numarray.NumArray}
401      @return : minimum value of arg over all components and all data points      @return: minimum value of C{arg}over all components and all data points
402      @rtype: C{float}      @rtype: C{float}
403      @raise TypeError: if type of arg cannot be processed      @raise TypeError: if type of C{arg}cannot be processed
404      """      """
405      if isinstance(arg,numarray.NumArray):      if isinstance(arg,numarray.NumArray):
406          return arg.min()          return arg.min()
# Line 263  def inf(arg): Line 417  def inf(arg):
417  #=========================================================================  #=========================================================================
418  #   some little helpers  #   some little helpers
419  #=========================================================================  #=========================================================================
420  def pokeShape(arg):  def getRank(arg):
421      """      """
422      identifies the shape of its argument      Identifies the rank of the argument.
423    
424      @param arg: a given object      @param arg: an object whose rank is to be returned
425      @type arg: L{numarray.NumArray},L{escript.Data},C{float}, C{int}, C{Symbol}      @type arg: C{numarray.NumArray}, L{escript.Data}, C{float}, C{int},
426                   C{Symbol}
427        @return: the rank of the argument
428        @rtype: C{int}
429        @raise TypeError: if type of C{arg}cannot be processed
430        """
431    
432        if isinstance(arg,numarray.NumArray):
433            return arg.rank
434        elif isinstance(arg,escript.Data):
435            return arg.getRank()
436        elif isinstance(arg,float):
437            return 0
438        elif isinstance(arg,int):
439            return 0
440        elif isinstance(arg,Symbol):
441            return arg.getRank()
442        else:
443          raise TypeError,"getRank: Unknown argument type."
444    
445    def getShape(arg):
446        """
447        Identifies the shape of the argument.
448    
449        @param arg: an object whose shape is to be returned
450        @type arg: C{numarray.NumArray}, L{escript.Data}, C{float}, C{int},
451                   C{Symbol}
452      @return: the shape of the argument      @return: the shape of the argument
453      @rtype: C{tuple} of C{int}      @rtype: C{tuple} of C{int}
454      @raise TypeError: if type of arg cannot be processed      @raise TypeError: if type of C{arg}cannot be processed
455      """      """
456    
457      if isinstance(arg,numarray.NumArray):      if isinstance(arg,numarray.NumArray):
# Line 285  def pokeShape(arg): Line 465  def pokeShape(arg):
465      elif isinstance(arg,Symbol):      elif isinstance(arg,Symbol):
466          return arg.getShape()          return arg.getShape()
467      else:      else:
468        raise TypeError,"pokeShape: cannot identify shape"        raise TypeError,"getShape: Cannot identify shape"
469    
470  def pokeDim(arg):  def pokeDim(arg):
471      """      """
472      identifies the spatial dimension of its argument      Identifies the spatial dimension of the argument.
473    
474      @param arg: a given object      @param arg: an object whose spatial dimension is to be returned
475      @type arg: any      @type arg: any
476      @return: the spatial dimension of the argument, if available, or C{None}      @return: the spatial dimension of the argument, if available, or C{None}
477      @rtype: C{int} or C{None}      @rtype: C{int} or C{None}
# Line 304  def pokeDim(arg): Line 484  def pokeDim(arg):
484      else:      else:
485          return None          return None
486    
487  def commonShape(arg0,arg1):  def commonShape(arg0, arg1):
488      """      """
489      returns a shape to which arg0 can be extendent from the right and arg1 can be extended from the left.      Returns a shape to which C{arg0} can be extended from the right and C{arg1}
490        can be extended from the left.
491    
492      @param arg0: an object with a shape (see L{pokeShape})      @param arg0: an object with a shape (see L{getShape})
493      @param arg1: an object with a shape (see L{pokeShape})      @param arg1: an object with a shape (see L{getShape})
494      @return: the shape of arg0 or arg1 such that the left port equals the shape of arg0 and the right end equals the shape of arg1.      @return: the shape of C{arg0} or C{arg1} such that the left part equals the
495                 shape of C{arg0} and the right end equals the shape of C{arg1}
496      @rtype: C{tuple} of C{int}      @rtype: C{tuple} of C{int}
497      @raise ValueError: if no shape can be found.      @raise ValueError: if no shape can be found
498      """      """
499      sh0=pokeShape(arg0)      sh0=getShape(arg0)
500      sh1=pokeShape(arg1)      sh1=getShape(arg1)
501      if len(sh0)<len(sh1):      if len(sh0)<len(sh1):
502         if not sh0==sh1[:len(sh0)]:         if not sh0==sh1[:len(sh0)]:
503               raise ValueError,"argument 0 cannot be extended to the shape of argument 1"               raise ValueError,"argument 0 cannot be extended to the shape of argument 1"
# Line 331  def commonShape(arg0,arg1): Line 513  def commonShape(arg0,arg1):
513    
514  def commonDim(*args):  def commonDim(*args):
515      """      """
516      identifies, if possible, the spatial dimension across a set of objects which may or my not have a spatial dimension.      Identifies, if possible, the spatial dimension across a set of objects
517        which may or may not have a spatial dimension.
518    
519      @param *args: given objects      @param args: given objects
520      @return: the spatial dimension of the objects with identifiable dimension (see L{pokeDim}). If none the objects has      @return: the spatial dimension of the objects with identifiable dimension
521               a spatial dimension C{None} is returned.               (see L{pokeDim}). If none of the objects has a spatial dimension
522                 C{None} is returned.
523      @rtype: C{int} or C{None}      @rtype: C{int} or C{None}
524      @raise ValueError: if the objects with identifiable dimension don't have the same spatial dimension.      @raise ValueError: if the objects with identifiable dimension don't have
525                           the same spatial dimension.
526      """      """
527      out=None      out=None
528      for a in args:      for a in args:
# Line 351  def commonDim(*args): Line 536  def commonDim(*args):
536    
537  def testForZero(arg):  def testForZero(arg):
538      """      """
539      test the argument for being identical to Zero      Tests if the argument is identical to zero.
540    
541      @param arg: a given object      @param arg: the object to test for zero
542      @type arg: typically L{numarray.NumArray},L{escript.Data},C{float}, C{int}      @type arg: typically C{numarray.NumArray}, L{escript.Data}, C{float}, C{int}
543      @return : True if the argument is identical to zero.      @return: True if the argument is identical to zero, False otherwise
544      @rtype : C{bool}      @rtype: C{bool}
545      """      """
546      if isinstance(arg,numarray.NumArray):      if isinstance(arg,numarray.NumArray):
547         return not Lsup(arg)>0.         return not Lsup(arg)>0.
# Line 373  def testForZero(arg): Line 558  def testForZero(arg):
558    
559  def matchType(arg0=0.,arg1=0.):  def matchType(arg0=0.,arg1=0.):
560      """      """
561      converting arg0 and arg1 both to the same type L{numarray.NumArray} or L{escript.Data} or, if one of arg0 or arg1 is of type L{Symbol}, the other one to be of type L{numarray.NumArray} or L{escript.Data}.      Converts C{arg0} and C{arg1} both to the same type C{numarray.NumArray} or
562        L{escript.Data} or, if one of C{arg0} or C{arg1} is of type L{Symbol}, the
563        other one to be of type C{numarray.NumArray} or L{escript.Data}.
564    
565      @param arg0: first argument      @param arg0: first argument
566      @type arg0: L{numarray.NumArray},L{escript.Data},C{float}, C{int}, C{Symbol}      @type arg0: C{numarray.NumArray},L{escript.Data},C{float}, C{int}, C{Symbol}
567      @param arg1: second argument      @param arg1: second argument
568      @type arg1: L{numarray.NumArray},L{escript.Data},C{float}, C{int}, C{Symbol}      @type arg1: C{numarray.NumArray},L{escript.Data},C{float}, C{int}, C{Symbol}
569      @return: a tuple representing arg0 and arg1 with the same type or with one of them being a L{Symbol}      @return: a tuple representing C{arg0} and C{arg1} with the same type or
570      @rtype: C{tuple} of two L{numarray.NumArray}, two L{escript.Data}, a C{Symbol} and one of the types L{numarray.NumArray} or L{escript.Data}.                 with one of them being a L{Symbol}
571      @raise TypeError: if type of arg0 or arg1 cannot be processed      @rtype: C{tuple} of two C{numarray.NumArray}, two L{escript.Data},
572                a C{Symbol} and one of the types C{numarray.NumArray} or
573                L{escript.Data}
574        @raise TypeError: if type of C{arg0} or C{arg1} cannot be processed
575      """      """
576      if isinstance(arg0,numarray.NumArray):      if isinstance(arg0,numarray.NumArray):
577         if isinstance(arg1,numarray.NumArray):         if isinstance(arg1,numarray.NumArray):
# Line 389  def matchType(arg0=0.,arg1=0.): Line 579  def matchType(arg0=0.,arg1=0.):
579         elif isinstance(arg1,escript.Data):         elif isinstance(arg1,escript.Data):
580            arg0=escript.Data(arg0,arg1.getFunctionSpace())            arg0=escript.Data(arg0,arg1.getFunctionSpace())
581         elif isinstance(arg1,float):         elif isinstance(arg1,float):
582            arg1=numarray.array(arg1)            arg1=numarray.array(arg1,type=numarray.Float64)
583         elif isinstance(arg1,int):         elif isinstance(arg1,int):
584            arg1=numarray.array(float(arg1))            arg1=numarray.array(float(arg1),type=numarray.Float64)
585         elif isinstance(arg1,Symbol):         elif isinstance(arg1,Symbol):
586            pass            pass
587         else:         else:
588            raise TypeError,"function: Unknown type of second argument."                raise TypeError,"function: Unknown type of second argument."
589      elif isinstance(arg0,escript.Data):      elif isinstance(arg0,escript.Data):
590         if isinstance(arg1,numarray.NumArray):         if isinstance(arg1,numarray.NumArray):
591            arg1=escript.Data(arg1,arg0.getFunctionSpace())            arg1=escript.Data(arg1,arg0.getFunctionSpace())
# Line 408  def matchType(arg0=0.,arg1=0.): Line 598  def matchType(arg0=0.,arg1=0.):
598         elif isinstance(arg1,Symbol):         elif isinstance(arg1,Symbol):
599            pass            pass
600         else:         else:
601            raise TypeError,"function: Unknown type of second argument."                raise TypeError,"function: Unknown type of second argument."
602      elif isinstance(arg0,Symbol):      elif isinstance(arg0,Symbol):
603         if isinstance(arg1,numarray.NumArray):         if isinstance(arg1,numarray.NumArray):
604            pass            pass
605         elif isinstance(arg1,escript.Data):         elif isinstance(arg1,escript.Data):
606            pass            pass
607         elif isinstance(arg1,float):         elif isinstance(arg1,float):
608            arg1=numarray.array(arg1)            arg1=numarray.array(arg1,type=numarray.Float64)
609         elif isinstance(arg1,int):         elif isinstance(arg1,int):
610            arg1=numarray.array(float(arg1))            arg1=numarray.array(float(arg1),type=numarray.Float64)
611         elif isinstance(arg1,Symbol):         elif isinstance(arg1,Symbol):
612            pass            pass
613         else:         else:
614            raise TypeError,"function: Unknown type of second argument."                raise TypeError,"function: Unknown type of second argument."
615      elif isinstance(arg0,float):      elif isinstance(arg0,float):
616         if isinstance(arg1,numarray.NumArray):         if isinstance(arg1,numarray.NumArray):
617            arg0=numarray.array(arg0)            arg0=numarray.array(arg0,type=numarray.Float64)
618         elif isinstance(arg1,escript.Data):         elif isinstance(arg1,escript.Data):
619            arg0=escript.Data(arg0,arg1.getFunctionSpace())            arg0=escript.Data(arg0,arg1.getFunctionSpace())
620         elif isinstance(arg1,float):         elif isinstance(arg1,float):
621            arg0=numarray.array(arg0)            arg0=numarray.array(arg0,type=numarray.Float64)
622            arg1=numarray.array(arg1)            arg1=numarray.array(arg1,type=numarray.Float64)
623         elif isinstance(arg1,int):         elif isinstance(arg1,int):
624            arg0=numarray.array(arg0)            arg0=numarray.array(arg0,type=numarray.Float64)
625            arg1=numarray.array(float(arg1))            arg1=numarray.array(float(arg1),type=numarray.Float64)
626         elif isinstance(arg1,Symbol):         elif isinstance(arg1,Symbol):
627            arg0=numarray.array(arg0)            arg0=numarray.array(arg0,type=numarray.Float64)
628         else:         else:
629            raise TypeError,"function: Unknown type of second argument."                raise TypeError,"function: Unknown type of second argument."
630      elif isinstance(arg0,int):      elif isinstance(arg0,int):
631         if isinstance(arg1,numarray.NumArray):         if isinstance(arg1,numarray.NumArray):
632            arg0=numarray.array(float(arg0))            arg0=numarray.array(float(arg0),type=numarray.Float64)
633         elif isinstance(arg1,escript.Data):         elif isinstance(arg1,escript.Data):
634            arg0=escript.Data(float(arg0),arg1.getFunctionSpace())            arg0=escript.Data(float(arg0),arg1.getFunctionSpace())
635         elif isinstance(arg1,float):         elif isinstance(arg1,float):
636            arg0=numarray.array(float(arg0))            arg0=numarray.array(float(arg0),type=numarray.Float64)
637            arg1=numarray.array(arg1)            arg1=numarray.array(arg1,type=numarray.Float64)
638         elif isinstance(arg1,int):         elif isinstance(arg1,int):
639            arg0=numarray.array(float(arg0))            arg0=numarray.array(float(arg0),type=numarray.Float64)
640            arg1=numarray.array(float(arg1))            arg1=numarray.array(float(arg1),type=numarray.Float64)
641         elif isinstance(arg1,Symbol):         elif isinstance(arg1,Symbol):
642            arg0=numarray.array(float(arg0))            arg0=numarray.array(float(arg0),type=numarray.Float64)
643         else:         else:
644            raise TypeError,"function: Unknown type of second argument."                raise TypeError,"function: Unknown type of second argument."
645      else:      else:
646        raise TypeError,"function: Unknown type of first argument."            raise TypeError,"function: Unknown type of first argument."
647    
648      return arg0,arg1      return arg0,arg1
649    
650  def matchShape(arg0,arg1):  def matchShape(arg0,arg1):
651      """      """
652            Returns a representation of C{arg0} and C{arg1} which have the same shape.
   
     If shape is not given the shape "largest" shape of args is used.  
653    
654      @param args: a given ob      @param arg0: first argument
655      @type arg: typically L{numarray.NumArray},L{escript.Data},C{float}, C{int}      @type arg0: C{numarray.NumArray},L{escript.Data},C{float}, C{int}, L{Symbol}
656      @return: True if the argument is identical to zero.      @param arg1: second argument
657      @rtype: C{list} of C{int}      @type arg1: C{numarray.NumArray},L{escript.Data},C{float}, C{int}, L{Symbol}
658        @return: C{arg0} and C{arg1} where copies are returned when the shape has
659                 to be changed
660        @rtype: C{tuple}
661      """      """
662      sh=commonShape(arg0,arg1)      sh=commonShape(arg0,arg1)
663      sh0=pokeShape(arg0)      sh0=getShape(arg0)
664      sh1=pokeShape(arg1)      sh1=getShape(arg1)
665      if len(sh0)<len(sh):      if len(sh0)<len(sh):
666         return outer(arg0,numarray.ones(sh[len(sh0):],numarray.Float)),arg1         return outer(arg0,numarray.ones(sh[len(sh0):],numarray.Float64)),arg1
667      elif len(sh1)<len(sh):      elif len(sh1)<len(sh):
668         return arg0,outer(arg1,numarray.ones(sh[len(sh1):],numarray.Float))         return arg0,outer(arg1,numarray.ones(sh[len(sh1):],numarray.Float64))
669      else:      else:
670         return arg0,arg1         return arg0,arg1
671    
672  #=========================================================  #=========================================================
673  #   symbolic tool box starts here:  #   symbolic tool box starts here:
674  #=========================================================  #=========================================================
675  class Symbol(object):  class Symbol(object):
676     """     """
677     Symbol class.     Symbol class objects provide the same functionality as C{numarray.NumArray}
678       and L{escript.Data} objects but they do not have a value and therefore
679     Symbol class objects provide the same functionality as L{numarray.NumArray} and L{escript.Data} objects     cannot be plotted or visualized. The main purpose is the possibility to
    but they do not have a value and therefore cannot be plotted or visualize. The main purpose is the possibilty  
680     calculate derivatives with respect to other Symbols used to define a Symbol.     calculate derivatives with respect to other Symbols used to define a Symbol.
681    
682     """     """
683     def __init__(self,shape=(),args=[],dim=None):     def __init__(self,shape=(),args=[],dim=None):
684         """         """
685         Creates an instance of a symbol of a given shape. The symbol may depending on a list of arguments args which may be         Creates an instance of a symbol of a given shape. The symbol may depend
686         symbols or any other object.         on a list of arguments C{args} which may be symbols or any other object.
687    
688         @param arg: the arguments of the symbol.         @param args: the arguments of the symbol
689         @type arg: C{list}         @type args: C{list}
690         @param shape: the shape         @param shape: the shape of the symbol
691         @type shape: C{tuple} of C{int}         @type shape: C{tuple} of C{int}
692         @param dim: spatial dimension of the symbol. If dim=C{None} the spatial dimension is undefined.           @param dim: spatial dimension of the symbol. If dim=C{None} the spatial
693         @type dim: C{None} or C{int}                       dimension is undefined.
694           @type dim: C{None} or C{int}
695    
696         """         """
697         if len(shape)>4:         if len(shape)>4:
698             raise ValueError,"Symbol supports only tensors up to order 4"             raise ValueError,"Symbol only supports tensors up to order 4"
699         self.__args=args         self.__args=args
700         self.__shape=shape         self.__shape=shape
701         self.__dim=dim         self.__dim=dim
702    
703     def getArgument(self,i=None):     def getArgument(self,i=None):
704         """         """
705         returns the i-th argument of the symbol         Returns the i-th argument of the symbol.
706    
707         @param i: index of the argument requested.         @param i: index of the argument requested
708         @type i: C{int} or C{None}         @type i: C{int} or C{None}
709         @raise IndexError: if the requested index does not exist         @raise IndexError: if the requested index does not exist
710         @return: the vlaue of the i-th argument or i is not specified the list of all arguments.         @return: the value of the i-th argument or if i is not specified the
711         @rtype: a single object or a list of objects                  list of all arguments
712           @rtype: a single object or a list of objects
713         """         """
714         if i==None:         if i==None:
715            return self.__args            return self.__args
# Line 527  class Symbol(object): Line 720  class Symbol(object):
720    
721     def getRank(self):     def getRank(self):
722         """         """
723         the rank of the symbol         Returns the rank of the symbol.
724    
725         @return: the rank of the symbol. This is length of the shape         @return: the rank of the symbol. This is length of the shape.
726         @rtype: C{int}         @rtype: C{int}
727         """         """
728         return len(self.getShape())         return len(self.getShape())
729    
730     def getShape(self):     def getShape(self):
731         """         """
732         the shape of the symbol.         Returns the shape of the symbol.
733    
734         @return : the shape of the symbol.         @return: the shape of the symbol
735         @rtype: C{tuple} of C{int}         @rtype: C{tuple} of C{int}
736         """         """
737         return self.__shape         return self.__shape
738    
739     def getDim(self):     def getDim(self):
740         """         """
741         the spatial dimension         Returns the spatial dimension.
742    
743         @return : the spatial dimension         @return: the symbol's spatial dimension
744         @rtype: C{int} if the dimension is defined. Otherwise C{None} is returned.         @rtype: C{int} if the dimension is defined, C{None} otherwise
745         """         """
746         return self.__dim         return self.__dim
747      
748     def __str__(self):     def __str__(self):
749         """         """
750         a string representation of the symbol.         Returns a string representation of the symbol.
751    
752         @return: a string representation of the object         @return: a string representation of the object
753         @rtype: C{str}         @rtype: C{str}
754         """         """
# Line 566  class Symbol(object): Line 760  class Symbol(object):
760         except NotImplementedError:         except NotImplementedError:
761             out="<Symbol %s>"%id(self)             out="<Symbol %s>"%id(self)
762         return out         return out
763          
764     def getSubstitutedArguments(self,argvals):     def getSubstitutedArguments(self,argvals):
765         """         """
766         substitutes symbols in the arguments of this object and returns the result as a list.         Substitutes symbols in the arguments of this object and returns the
767           result as a list.
768    
769         @param argvals: L{Symbols} and their substitutes. The L{Symbol} u in the expression defining this object is replaced by argvals[u].         @param argvals: L{Symbol} and their substitutes. The L{Symbol} u in the
770         @type argvals: C{dict} with keywords of type L{Symbol}.                         expression defining this object is replaced by
771                           argvals[u].
772           @type argvals: C{dict} with keywords of type L{Symbol}
773         @rtype: C{list} of objects         @rtype: C{list} of objects
774         @return: list of the object assigned to the arguments through substitution or for the arguments which are not L{Symbols} the value assigned to the argument at instantiation.         @return: list of the object assigned to the arguments through
775                    substitution or for the arguments which are not L{Symbol}s the
776                    value assigned to the argument at instantiation.
777         """         """
778         out=[]         out=[]
779         for a in self.getArgument():         for a in self.getArgument():
# Line 586  class Symbol(object): Line 785  class Symbol(object):
785    
786     def getDifferentiatedArguments(self,arg):     def getDifferentiatedArguments(self,arg):
787         """         """
788         applifies differentials to the arguments of this object and returns the result as a list.         Applies differentials to the arguments of this object and returns the
789           result as a list.
790    
791         @param arg: the derivative is calculated with respect to arg         @param arg: the derivative is calculated with respect to C{arg}
792         @type arg: typically L{escript.Symbol} but can also be C{float}, L{escript.Data}, L{numarray.NumArray} depending the involved functions and data.         @type arg: typically L{escript.Symbol} but can also be C{float},
793                      L{escript.Data}, C{numarray.NumArray} depending on the
794                      involved functions and data
795         @rtype: C{list} of objects         @rtype: C{list} of objects
796         @return: list of object obtained by calculating the derivatives of the argumenst with respct to arg         @return: list of object obtained by calculating the derivatives of the
797                    arguments with respect to C{arg}
798         """         """
799         out=[]         out=[]
800         for a in self.getArgument():         for a in self.getArgument():
801            if isinstance(a,Symbol):            if isinstance(a,Symbol):
802               out.append(a.substitute(argvals))               out.append(a.substitute(argvals))
803            else:            else:
804                s=pokeShape(s)+arg.getShape()                s=getShape(s)+arg.getShape()
805                if len(s)>0:                if len(s)>0:
806                   out.append(numarray.zeros(s),numarray.Float)                   out.append(numarray.zeros(s),numarray.Float64)
807                else:                else:
808                   out.append(a)                   out.append(a)
809         return out         return out
810    
811     def isAppropriateValue(self,arg):     def isAppropriateValue(self,arg):
812        """        """
813        checks if the given argument arg can be used as a substitution of this object. The method checks        Checks if the given argument C{arg} can be used as a substitution for
814        the shape of arg and, if the spatial dimension is defined, the spatial dimension of arg.            this object. The method checks the shape of C{arg} and, if the spatial
815          dimension is defined, the spatial dimension of C{arg}.
816        @param arg: a given object  
817        @type arg: L{numarray.NumArray},L{escript.Data},C{float}, C{int}, C{Symbol}        @param arg: object to be checked
818        @return: True if arg is a suitbale object to be used for substitution. Otherwise False is returned.        @type arg: C{numarray.NumArray}, L{escript.Data}, C{float}, C{int},
819                     C{Symbol}
820          @return: True if C{arg} is a suitable object to be used for substitution,
821                   False otherwise
822        @rtype: C{bool}        @rtype: C{bool}
823        """        """
824        if isinstance(arg,numarray.NumArray):        if isinstance(arg,numarray.NumArray):
# Line 640  class Symbol(object): Line 846  class Symbol(object):
846    
847     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
848         """         """
849         returns a program code that can be used to evaluate the symbol.         Returns program code that can be used to evaluate the symbol.
850    
851         @param argstrs: gives for each argument a string representing the argument for the evaluation.         @param argstrs: a string for each argument representing the argument
852         @type argstrs: C{list} of C{str}.                         for the evaluation
853         @param format: specifies the format to be used. At the moment only "escript", "str" and "text" are supported.         @type argstrs: C{list} of C{str}
854           @param format: specifies the format to be used. At the moment only
855                          "escript", "str" and "text" are supported.
856         @type format: C{str}         @type format: C{str}
857         @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.         @return: a piece of program code which can be used to evaluate the
858                    expression assuming the values for the arguments are available
859         @rtype: C{str}         @rtype: C{str}
860         @raise NotImplementedError: if no implementation for the given format is available         @raise NotImplementedError: if no implementation for the given format
861                                       is available
862         @note: This method has to be overwritten by subclasses.         @note: This method has to be overwritten by subclasses.
863         """         """
864         raise NotImplementedError,"no code for %s representation available"%format         raise NotImplementedError,"no code for %s representation available"%format
865    
866     def substitute(self,argvals):     def substitute(self,argvals):
867        """          """
868        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
869        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.  
870          The method replaces the L{Symbol} u by argvals[u] in the expression
871          defining this object.
872    
873        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
874        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
875        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
876        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
877          @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
878                  depending on the degree of substitution
879        @note: this method has to be overwritten by a particular L{Symbol}        @note: this method has to be overwritten by a particular L{Symbol}
880        @raise NotImplementedError: if no implementation for the given format is available        @raise NotImplementedError: if no implementation for the given format is
881        @raise TypeError: if a value for a L{Symbol} cannot be substituted.                                    available
882          @raise TypeError: if a value for a L{Symbol} cannot be substituted
883        """        """
884        if argvals.has_key(self):        if argvals.has_key(self):
885           arg=argvals[self]           arg=argvals[self]
# Line 677  class Symbol(object): Line 892  class Symbol(object):
892    
893     def diff(self,arg):     def diff(self,arg):
894         """         """
895         returns the derivative of the symbol with respect to L{Symbol} arg         Returns the derivative of the symbol with respect to L{Symbol} C{arg}.
896    
897         @param arg: the derivative is calculated with respect to arg         @param arg: the derivative is calculated with respect to C{arg}
898         @type arg: typically L{escript.Symbol} but can also be C{float}, L{escript.Data}, L{numarray.NumArray} depending the involved functions and data.         @type arg: typically L{escript.Symbol} but can also be C{float},
899                      L{escript.Data}, C{numarray.NumArray} depending on the
900                      involved functions and data
901         @return: derivative with respect to C{arg}         @return: derivative with respect to C{arg}
902         @rtype: typically L{escript.Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.         @rtype: typically L{escript.Symbol} but other types such as C{float},
903         @note: this method is overwritten by a particular L{Symbol}                 L{escript.Data}, C{numarray.NumArray} are possible
904           @note: this method is overwritten by a particular L{Symbol}.
905         """         """
906         if arg==self:         if arg==self:
907            return identity(self.getShape())            return identity(self.getShape())
908         else:         else:
909            s=self.getShape()+arg.getShape()            s=self.getShape()+arg.getShape()
910            if len(s)>0:            if len(s)>0:
911               return numarray.zeros(s,numarray.Float)               return numarray.zeros(s,numarray.Float64)
912            else:            else:
913               return 0.               return 0.
914    
915     def __neg__(self):     def __neg__(self):
916         """         """
917         returns -self.         Returns -self.
918    
919         @return:  a S{Symbol} representing the negative of the object         @return: a L{Symbol} representing the negative of the object
920         @rtype: L{DependendSymbol}         @rtype: L{DependendSymbol}
921         """         """
922         return self*(-1.)         return self*(-1.)
923    
924     def __pos__(self):     def __pos__(self):
925         """         """
926         returns +self.         Returns +self.
927    
928         @return:  a S{Symbol} representing the positive of the object         @return: a L{Symbol} representing the positive of the object
929         @rtype: L{DependendSymbol}         @rtype: L{DependendSymbol}
930         """         """
931         return self*(1.)         return self*(1.)
932    
933     def __abs__(self):     def __abs__(self):
934         """         """
935         returns a S{Symbol} representing the absolute value of the object.         Returns a L{Symbol} representing the absolute value of the object.
936         """         """
937         return Abs_Symbol(self)         return Abs_Symbol(self)
938    
939     def __add__(self,other):     def __add__(self,other):
940         """         """
941         add another object to this object         Adds another object to this object.
942    
943         @param other: object to be added to this object         @param other: object to be added to this object
944         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
945         @return:  a S{Symbol} representing the sum of this object and C{other}                      C{numarray.NumArray}.
946           @return: a L{Symbol} representing the sum of this object and C{other}
947         @rtype: L{DependendSymbol}         @rtype: L{DependendSymbol}
948         """         """
949         return add(self,other)         return add(self,other)
950    
951     def __radd__(self,other):     def __radd__(self,other):
952         """         """
953         add this object to another object         Adds this object to another object.
954    
955         @param other: object this object is added to         @param other: object to add this object to
956         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
957         @return: a S{Symbol} representing the sum of C{other} and this object object                      C{numarray.NumArray}
958           @return: a L{Symbol} representing the sum of C{other} and this object
959         @rtype: L{DependendSymbol}         @rtype: L{DependendSymbol}
960         """         """
961         return add(other,self)         return add(other,self)
962    
963     def __sub__(self,other):     def __sub__(self,other):
964         """         """
965         subtracts another object from this object         Subtracts another object from this object.
966    
967         @param other: object to be subtracted from this object         @param other: object to be subtracted from this object
968         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
969         @return: a S{Symbol} representing the difference of C{other} and this object                      C{numarray.NumArray}
970           @return: a L{Symbol} representing the difference of C{other} and this
971                    object
972         @rtype: L{DependendSymbol}         @rtype: L{DependendSymbol}
973         """         """
974         return add(self,-other)         return add(self,-other)
975    
976     def __rsub__(self,other):     def __rsub__(self,other):
977         """         """
978         subtracts this object from another object         Subtracts this object from another object.
979    
980         @param other: object this object is been subtracted from         @param other: object this object is to be subtracted from
981         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
982         @return: a S{Symbol} representing the difference of this object and C{other}.                      C{numarray.NumArray}
983           @return: a L{Symbol} representing the difference of this object and
984                    C{other}.
985         @rtype: L{DependendSymbol}         @rtype: L{DependendSymbol}
986         """         """
987         return add(-self,other)         return add(-self,other)
988    
989     def __mul__(self,other):     def __mul__(self,other):
990         """         """
991         multiplies this object with other object         Multiplies this object with another object.
992    
993         @param other: object to be mutiplied by this object         @param other: object to be mutiplied by this object
994         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
995         @return: a S{Symbol} representing the product of the object and C{other}.                      C{numarray.NumArray}
996           @return: a L{Symbol} representing the product of the object and C{other}
997         @rtype: L{DependendSymbol} or 0 if other is identical to zero.         @rtype: L{DependendSymbol} or 0 if other is identical to zero.
998         """         """
999         return mult(self,other)         return mult(self,other)
1000    
1001     def __rmul__(self,other):     def __rmul__(self,other):
1002         """         """
1003         multiplies this object with other object         Multiplies another object by this object.
1004    
1005         @param other: object this object is multiplied with         @param other: object this object is multiplied with
1006         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
1007         @return: a S{Symbol} representing the product of C{other} and the object.                      C{numarray.NumArray}
1008         @rtype: L{DependendSymbol} or 0 if other is identical to zero.         @return: a L{Symbol} representing the product of C{other} and the object
1009           @rtype: L{DependendSymbol} or 0 if other is identical to zero
1010         """         """
1011         return mult(other,self)         return mult(other,self)
1012    
1013     def __div__(self,other):     def __div__(self,other):
1014         """         """
1015         divides this object by other object         Divides this object by another object.
1016    
1017         @param other: object dividing this object         @param other: object dividing this object
1018         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
1019         @return: a S{Symbol} representing the quotient of this object and C{other}                      C{numarray.NumArray}
1020         @rtype: L{DependendSymbol}         @return: a L{Symbol} representing the quotient of this object and
1021                    C{other}
1022           @rtype: L{DependendSymbol}
1023         """         """
1024         return quotient(self,other)         return quotient(self,other)
1025    
1026     def __rdiv__(self,other):     def __rdiv__(self,other):
1027         """         """
1028         divides this object by other object         Divides another object by this object.
1029    
1030         @param other: object dividing this object         @param other: object to be divided by this object
1031         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
1032         @return: a S{Symbol} representing the quotient of C{other} and this object                      C{numarray.NumArray}
1033         @rtype: L{DependendSymbol} or 0 if C{other} is identical to zero.         @return: a L{Symbol} representing the quotient of C{other} and this
1034                    object
1035           @rtype: L{DependendSymbol} or 0 if C{other} is identical to zero
1036         """         """
1037         return quotient(other,self)         return quotient(other,self)
1038    
1039     def __pow__(self,other):     def __pow__(self,other):
1040         """         """
1041         raises this object to the power of other         Raises this object to the power of C{other}.
1042    
1043         @param other: exponent         @param other: exponent
1044         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
1045         @return: a S{Symbol} representing the power of this object to C{other}                      C{numarray.NumArray}
1046         @rtype: L{DependendSymbol} or 1 if C{other} is identical to zero.         @return: a L{Symbol} representing the power of this object to C{other}
1047           @rtype: L{DependendSymbol} or 1 if C{other} is identical to zero
1048         """         """
1049         return power(self,other)         return power(self,other)
1050    
1051     def __rpow__(self,other):     def __rpow__(self,other):
1052         """         """
1053         raises an object to the power of this object         Raises an object to the power of this object.
1054    
1055         @param other: basis         @param other: basis
1056         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
1057         @return: a S{Symbol} representing the power of C{other} to this object                      C{numarray.NumArray}
1058         @rtype: L{DependendSymbol} or 0 if C{other} is identical to zero.         @return: a L{Symbol} representing the power of C{other} to this object
1059           @rtype: L{DependendSymbol} or 0 if C{other} is identical to zero
1060         """         """
1061         return power(other,self)         return power(other,self)
1062    
1063     def __getitem__(self,index):     def __getitem__(self,index):
1064         """         """
1065         returns the slice defined by index         Returns the slice defined by C{index}.
1066    
1067         @param index: defines a         @param index: the slice index
1068         @type index: C{slice} or C{int} or a C{tuple} of them         @type index: C{slice} or C{int} or a C{tuple} of them
1069         @return: a S{Symbol} representing the slice defined by index         @return: a L{Symbol} representing the slice defined by index
1070         @rtype: L{DependendSymbol}         @rtype: L{DependendSymbol}
1071         """         """
1072         return GetSlice_Symbol(self,index)         return GetSlice_Symbol(self,index)
1073    
1074  class DependendSymbol(Symbol):  class DependendSymbol(Symbol):
1075     """     """
1076     DependendSymbol extents L{Symbol} by modifying the == operator to allow two instances to be equal.     DependendSymbol extents L{Symbol} by modifying the == operator to allow two
1077     Two DependendSymbol are equal if they have the same shape, the same arguments and one of them has an unspecified spatial dimension or the spatial dimension is identical       instances to be equal. Two C{DependendSymbol}s are equal if they have the
1078         same shape, the same arguments and one of them has an unspecified spatial
1079     Example:     dimension or the spatial dimension is identical.
1080      
1081     u1=Symbol(shape=(3,4),dim=2,args=[4.])     Example::
1082     u2=Symbol(shape=(3,4),dim=2,args=[4.])  
1083     print u1==u2       u1=Symbol(shape=(3,4),dim=2,args=[4.])
1084     False       u2=Symbol(shape=(3,4),dim=2,args=[4.])
1085           print u1==u2
1086        but         False
1087    
1088     u1=DependendSymbol(shape=(3,4),dim=2,args=[4.])     but::
1089     u2=DependendSymbol(shape=(3,4),dim=2,args=[4.])  
1090     u3=DependendSymbol(shape=(2,),dim=2,args=[4.])         u1=DependendSymbol(shape=(3,4),dim=2,args=[4.])
1091     print u1==u2, u1==u3       u2=DependendSymbol(shape=(3,4),dim=2,args=[4.])
1092     True False       u3=DependendSymbol(shape=(2,),dim=2,args=[4.])
1093         print u1==u2, u1==u3
1094     @note: DependendSymbol should be used as return value of functions with L{Symbol} arguments. This will allow the optimizer to remove redundant function calls.       True False
1095    
1096       @note: DependendSymbol should be used as return value of functions with
1097              L{Symbol} arguments. This will allow the optimizer to remove
1098              redundant function calls.
1099     """     """
1100     def __eq__(self,other):     def __eq__(self,other):
1101        """        """
1102        checks if other equals self        Checks if C{other} equals self.
1103    
1104        @param other: any object        @param other: any object
1105        @return: True if other has the same class like self, and the shape, the spatial diemsnion and the arguments are equal.        @return: True if other has the same class as self and the shape, the
1106                   spatial dimension and the arguments are equal, False otherwise
1107        @rtype: C{bool}        @rtype: C{bool}
1108        """        """
1109        if isinstance(other,DependendSymbol):        if isinstance(other,DependendSymbol):
1110           if self.__class__==other.__class__:             if self.__class__==other.__class__:
1111              if self.getShape()==other.getShape():              if self.getShape()==other.getShape():
1112                if self.getArgument()==other.getArgument():                 if self.getArgument()==other.getArgument():
1113                   if self.getDim()==None or other.getDim()==None or self.getDim()==other.getDim():                    if self.getDim()==None or other.getDim()==None or self.getDim()==other.getDim():
1114                      return True                       return True
1115        return False        return False
1116    
1117     def __ne__(self,other):     def __ne__(self,other):
1118        """        """
1119        checks if other equals self        Checks if C{other} is not equal to self.
1120    
1121        @param other: any object        @param other: any object
1122        @return: Flase if other has the same class like self, and the shape, the spatial diemsnion and the arguments are equal.        @return: False if other has the same class as self and the shape, the
1123                   spatial dimension and the arguments are equal, True otherwise
1124        @rtype: C{bool}        @rtype: C{bool}
1125        """        """
1126        return not self==other        return not self==other
1127  #=========================================================  #=========================================================
1128  #  Unary operations prserving the shape  #  Unary operations preserving the shape
1129  #========================================================  #========================================================
1130  class GetSlice_Symbol(DependendSymbol):  class GetSlice_Symbol(DependendSymbol):
1131     """     """
1132     L{Symbol} representing getting a slice for a L{Symbol}     L{Symbol} representing getting a slice for a L{Symbol}.
1133     """     """
1134     def __init__(self,arg,index):     def __init__(self,arg,index):
1135        """        """
1136        initialization of wherePositive L{Symbol} with argument arg        Initialization of the L{Symbol} with argument C{arg}.
1137        @param arg: argument  
1138        @type arg: L{Symbol}.        @param arg: argument
1139          @type arg: L{Symbol}
1140        @param index: defines index        @param index: defines index
1141        @type index: C{slice} or C{int} or a C{tuple} of them        @type index: C{slice} or C{int} or a C{tuple} of them
1142        @raises IndexError: if length of index is larger than rank of arg or a index start or stop is out of range        @raises IndexError: if length of index is larger than rank of arg or
1143                              index start or stop is out of range
1144        @raises ValueError: if a step is given        @raises ValueError: if a step is given
1145        """        """
1146        if not isinstance(index,tuple): index=(index,)        if not isinstance(index,tuple): index=(index,)
# Line 912  class GetSlice_Symbol(DependendSymbol): Line 1152  class GetSlice_Symbol(DependendSymbol):
1152           ix=index[i]           ix=index[i]
1153           if isinstance(ix,int):           if isinstance(ix,int):
1154              if ix<0 or ix>=arg.getShape()[i]:              if ix<0 or ix>=arg.getShape()[i]:
1155                 raise ValueError,"GetSlice_Symbol: index out of range."                 raise IndexError,"GetSlice_Symbol: index out of range."
1156              index2=index2+(ix,)              index2=index2+(ix,)
1157           else:           else:
1158             if not ix.step==None:             if not ix.step==None:
1159               raise ValueError,"GetSlice_Symbol: steping is not supported."               raise ValueError,"GetSlice_Symbol: stepping is not supported."
1160             if ix.start==None:             if ix.start==None:
1161                s=0                s=0
1162             else:             else:
# Line 939  class GetSlice_Symbol(DependendSymbol): Line 1179  class GetSlice_Symbol(DependendSymbol):
1179    
1180     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1181        """        """
1182        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1183    
1184        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1185        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1186        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
1187          @param format: specifies the format to be used. At the moment only
1188                         "escript", "str" and "text" are supported.
1189        @type format: C{str}        @type format: C{str}
1190        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
1191                   expression assuming the values for the arguments are available
1192        @rtype: C{str}        @rtype: C{str}
1193        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1194                                      is available
1195        """        """
1196        if format=="escript" or format=="str"  or format=="text":        if format=="escript" or format=="str"  or format=="text":
1197           return "%s.__getitem__(%s)"%(argstrs[0],argstrs[1])           return "%s.__getitem__(%s)"%(argstrs[0],argstrs[1])
# Line 956  class GetSlice_Symbol(DependendSymbol): Line 1200  class GetSlice_Symbol(DependendSymbol):
1200    
1201     def substitute(self,argvals):     def substitute(self,argvals):
1202        """        """
1203        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1204        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
1205          defining this object.
1206    
1207        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1208        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1209        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
1210        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
1211        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
1212                  depending on the degree of substitution
1213          @raise TypeError: if a value for a L{Symbol} cannot be substituted
1214        """        """
1215        if argvals.has_key(self):        if argvals.has_key(self):
1216           arg=argvals[self]           arg=argvals[self]
# Line 979  class GetSlice_Symbol(DependendSymbol): Line 1226  class GetSlice_Symbol(DependendSymbol):
1226    
1227  def log10(arg):  def log10(arg):
1228     """     """
1229     returns base-10 logarithm of argument arg     Returns base-10 logarithm of argument C{arg}.
1230    
1231     @param arg: argument     @param arg: argument
1232     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1233     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
1234     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1235       @raises TypeError: if the type of the argument is not expected
1236     """     """
1237     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1238        return numarray.log10(arg)        return numarray.log10(arg)
# Line 1001  def log10(arg): Line 1249  def log10(arg):
1249    
1250  def wherePositive(arg):  def wherePositive(arg):
1251     """     """
1252     returns mask of positive values of argument arg     Returns mask of positive values of argument C{arg}.
1253    
1254     @param arg: argument     @param arg: argument
1255     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}.
1256     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
1257     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1258       @raises TypeError: if the type of the argument is not expected
1259     """     """
1260     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1261        out=numarray.greater(arg,numarray.zeros(arg.shape,numarray.Float))*1.        out=numarray.greater(arg,numarray.zeros(arg.shape,numarray.Float64))*1.
1262        if isinstance(out,float): out=numarray.array(out)        if isinstance(out,float): out=numarray.array(out,type=numarray.Float64)
1263        return out        return out
1264     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1265        return arg._wherePositive()        return arg._wherePositive()
# Line 1031  def wherePositive(arg): Line 1280  def wherePositive(arg):
1280    
1281  class WherePositive_Symbol(DependendSymbol):  class WherePositive_Symbol(DependendSymbol):
1282     """     """
1283     L{Symbol} representing the result of the mask of positive values function     L{Symbol} representing the result of the mask of positive values function.
1284     """     """
1285     def __init__(self,arg):     def __init__(self,arg):
1286        """        """
1287        initialization of wherePositive L{Symbol} with argument arg        Initialization of wherePositive L{Symbol} with argument C{arg}.
1288    
1289        @param arg: argument of function        @param arg: argument of function
1290        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
1291        """        """
1292        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
1293    
1294     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1295        """        """
1296        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1297    
1298        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1299        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1300        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
1301          @param format: specifies the format to be used. At the moment only
1302                         "escript", "str" and "text" are supported.
1303        @type format: C{str}        @type format: C{str}
1304        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
1305                   expression assuming the values for the arguments are available
1306        @rtype: C{str}        @rtype: C{str}
1307        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1308                                      is available
1309        """        """
1310        if isinstance(argstrs,list):        if isinstance(argstrs,list):
1311            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1062  class WherePositive_Symbol(DependendSymb Line 1316  class WherePositive_Symbol(DependendSymb
1316    
1317     def substitute(self,argvals):     def substitute(self,argvals):
1318        """        """
1319        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1320        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
1321          defining this object.
1322    
1323        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1324        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1325        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
1326        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
1327        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
1328                  depending on the degree of substitution
1329          @raise TypeError: if a value for a L{Symbol} cannot be substituted
1330        """        """
1331        if argvals.has_key(self):        if argvals.has_key(self):
1332           arg=argvals[self]           arg=argvals[self]
# Line 1083  class WherePositive_Symbol(DependendSymb Line 1340  class WherePositive_Symbol(DependendSymb
1340    
1341  def whereNegative(arg):  def whereNegative(arg):
1342     """     """
1343     returns mask of positive values of argument arg     Returns mask of negative values of argument C{arg}.
1344    
1345     @param arg: argument     @param arg: argument
1346     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1347     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
1348     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1349       @raises TypeError: if the type of the argument is not expected
1350     """     """
1351     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1352        out=numarray.less(arg,numarray.zeros(arg.shape,numarray.Float))*1.        out=numarray.less(arg,numarray.zeros(arg.shape,numarray.Float64))*1.
1353        if isinstance(out,float): out=numarray.array(out)        if isinstance(out,float): out=numarray.array(out,type=numarray.Float64)
1354        return out        return out
1355     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1356        return arg._whereNegative()        return arg._whereNegative()
# Line 1113  def whereNegative(arg): Line 1371  def whereNegative(arg):
1371    
1372  class WhereNegative_Symbol(DependendSymbol):  class WhereNegative_Symbol(DependendSymbol):
1373     """     """
1374     L{Symbol} representing the result of the mask of positive values function     L{Symbol} representing the result of the mask of negative values function.
1375     """     """
1376     def __init__(self,arg):     def __init__(self,arg):
1377        """        """
1378        initialization of whereNegative L{Symbol} with argument arg        Initialization of whereNegative L{Symbol} with argument C{arg}.
1379    
1380        @param arg: argument of function        @param arg: argument of function
1381        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
1382        """        """
1383        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
1384    
1385     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1386        """        """
1387        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1388    
1389        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1390        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1391        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
1392          @param format: specifies the format to be used. At the moment only
1393                         "escript", "str" and "text" are supported.
1394        @type format: C{str}        @type format: C{str}
1395        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
1396                   expression assuming the values for the arguments are available
1397        @rtype: C{str}        @rtype: C{str}
1398        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1399                                      is available
1400        """        """
1401        if isinstance(argstrs,list):        if isinstance(argstrs,list):
1402            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1144  class WhereNegative_Symbol(DependendSymb Line 1407  class WhereNegative_Symbol(DependendSymb
1407    
1408     def substitute(self,argvals):     def substitute(self,argvals):
1409        """        """
1410        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1411        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
1412          defining this object.
1413    
1414        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1415        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1416        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
1417        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
1418        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
1419                  depending on the degree of substitution
1420          @raise TypeError: if a value for a L{Symbol} cannot be substituted
1421        """        """
1422        if argvals.has_key(self):        if argvals.has_key(self):
1423           arg=argvals[self]           arg=argvals[self]
# Line 1165  class WhereNegative_Symbol(DependendSymb Line 1431  class WhereNegative_Symbol(DependendSymb
1431    
1432  def whereNonNegative(arg):  def whereNonNegative(arg):
1433     """     """
1434     returns mask of non-negative values of argument arg     Returns mask of non-negative values of argument C{arg}.
1435    
1436     @param arg: argument     @param arg: argument
1437     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1438     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
1439     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1440       @raises TypeError: if the type of the argument is not expected
1441     """     """
1442     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1443        out=numarray.greater_equal(arg,numarray.zeros(arg.shape,numarray.Float))*1.        out=numarray.greater_equal(arg,numarray.zeros(arg.shape,numarray.Float64))*1.
1444        if isinstance(out,float): out=numarray.array(out)        if isinstance(out,float): out=numarray.array(out,type=numarray.Float64)
1445        return out        return out
1446     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1447        return arg._whereNonNegative()        return arg._whereNonNegative()
# Line 1195  def whereNonNegative(arg): Line 1462  def whereNonNegative(arg):
1462    
1463  def whereNonPositive(arg):  def whereNonPositive(arg):
1464     """     """
1465     returns mask of non-positive values of argument arg     Returns mask of non-positive values of argument C{arg}.
1466    
1467     @param arg: argument     @param arg: argument
1468     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1469     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
1470     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1471       @raises TypeError: if the type of the argument is not expected
1472     """     """
1473     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1474        out=numarray.less_equal(arg,numarray.zeros(arg.shape,numarray.Float))*1.        out=numarray.less_equal(arg,numarray.zeros(arg.shape,numarray.Float64))*1.
1475        if isinstance(out,float): out=numarray.array(out)        if isinstance(out,float): out=numarray.array(out,type=numarray.Float64)
1476        return out        return out
1477     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1478        return arg._whereNonPositive()        return arg._whereNonPositive()
# Line 1225  def whereNonPositive(arg): Line 1493  def whereNonPositive(arg):
1493    
1494  def whereZero(arg,tol=0.):  def whereZero(arg,tol=0.):
1495     """     """
1496     returns mask of zero entries of argument arg     Returns mask of zero entries of argument C{arg}.
1497    
1498     @param arg: argument     @param arg: argument
1499     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1500     @param tol: tolerance. values with absolute value less then tol are accepted as zero.     @param tol: tolerance. Values with absolute value less than tol are accepted
1501                   as zero.
1502     @type tol: C{float}     @type tol: C{float}
1503     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
1504     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1505       @raises TypeError: if the type of the argument is not expected
1506     """     """
1507     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1508        out=numarray.less_equal(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float))*1.        out=numarray.less_equal(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float64))*1.
1509        if isinstance(out,float): out=numarray.array(out)        if isinstance(out,float): out=numarray.array(out,type=numarray.Float64)
1510        return out        return out
1511     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1512        if tol>0.:        return arg._whereZero(tol)
          return whereNegative(abs(arg)-tol)  
       else:  
          return arg._whereZero()  
1513     elif isinstance(arg,float):     elif isinstance(arg,float):
1514        if abs(arg)<=tol:        if abs(arg)<=tol:
1515          return 1.          return 1.
# Line 1260  def whereZero(arg,tol=0.): Line 1527  def whereZero(arg,tol=0.):
1527    
1528  class WhereZero_Symbol(DependendSymbol):  class WhereZero_Symbol(DependendSymbol):
1529     """     """
1530     L{Symbol} representing the result of the mask of zero entries function     L{Symbol} representing the result of the mask of zero entries function.
1531     """     """
1532     def __init__(self,arg,tol=0.):     def __init__(self,arg,tol=0.):
1533        """        """
1534        initialization of whereZero L{Symbol} with argument arg        Initialization of whereZero L{Symbol} with argument C{arg}.
1535    
1536        @param arg: argument of function        @param arg: argument of function
1537        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
1538        """        """
1539        DependendSymbol.__init__(self,args=[arg,tol],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg,tol],shape=arg.getShape(),dim=arg.getDim())
1540    
1541     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1542        """        """
1543        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1544    
1545        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1546        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1547        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
1548          @param format: specifies the format to be used. At the moment only
1549                         "escript", "str" and "text" are supported.
1550        @type format: C{str}        @type format: C{str}
1551        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
1552                   expression assuming the values for the arguments are available
1553        @rtype: C{str}        @rtype: C{str}
1554        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1555                                      is available
1556        """        """
1557        if format=="escript" or format=="str"  or format=="text":        if format=="escript" or format=="str"  or format=="text":
1558           return "whereZero(%s,tol=%s)"%(argstrs[0],argstrs[1])           return "whereZero(%s,tol=%s)"%(argstrs[0],argstrs[1])
# Line 1289  class WhereZero_Symbol(DependendSymbol): Line 1561  class WhereZero_Symbol(DependendSymbol):
1561    
1562     def substitute(self,argvals):     def substitute(self,argvals):
1563        """        """
1564        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1565        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
1566          defining this object.
1567    
1568        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1569        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1570        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
1571        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
1572        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
1573                  depending on the degree of substitution
1574          @raise TypeError: if a value for a L{Symbol} cannot be substituted
1575        """        """
1576        if argvals.has_key(self):        if argvals.has_key(self):
1577           arg=argvals[self]           arg=argvals[self]
# Line 1310  class WhereZero_Symbol(DependendSymbol): Line 1585  class WhereZero_Symbol(DependendSymbol):
1585    
1586  def whereNonZero(arg,tol=0.):  def whereNonZero(arg,tol=0.):
1587     """     """
1588     returns mask of values different from zero of argument arg     Returns mask of values different from zero of argument C{arg}.
1589    
1590     @param arg: argument     @param arg: argument
1591     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}.
1592     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
1593     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1594       @raise TypeError: if the type of the argument is not expected
1595     """     """
1596     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1597        out=numarray.greater(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float))*1.        out=numarray.greater(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float64))*1.
1598        if isinstance(out,float): out=numarray.array(out)        if isinstance(out,float): out=numarray.array(out,type=numarray.Float64)
1599        return out        return out
1600     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
1601        if tol>0.:        return arg._whereNonZero(tol)
          return 1.-whereZero(arg,tol)  
       else:  
          return arg._whereNonZero()  
1602     elif isinstance(arg,float):     elif isinstance(arg,float):
1603        if abs(arg)>tol:        if abs(arg)>tol:
1604          return 1.          return 1.
# Line 1341  def whereNonZero(arg,tol=0.): Line 1614  def whereNonZero(arg,tol=0.):
1614     else:     else:
1615        raise TypeError,"whereNonZero: Unknown argument type."        raise TypeError,"whereNonZero: Unknown argument type."
1616    
1617    def erf(arg):
1618       """
1619       Returns the error function M{erf} of argument C{arg}.
1620    
1621       @param arg: argument
1622       @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}.
1623       @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
1624               on the type of C{arg}
1625       @raise TypeError: if the type of the argument is not expected
1626       """
1627       if isinstance(arg,escript.Data):
1628          return arg._erf()
1629       else:
1630          raise TypeError,"erf: Unknown argument type."
1631    
1632  def sin(arg):  def sin(arg):
1633     """     """
1634     returns sine of argument arg     Returns sine of argument C{arg}.
1635    
1636     @param arg: argument     @param arg: argument
1637     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}.
1638     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
1639     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1640       @raise TypeError: if the type of the argument is not expected
1641     """     """
1642     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1643        return numarray.sin(arg)        return numarray.sin(arg)
# Line 1365  def sin(arg): Line 1654  def sin(arg):
1654    
1655  class Sin_Symbol(DependendSymbol):  class Sin_Symbol(DependendSymbol):
1656     """     """
1657     L{Symbol} representing the result of the sine function     L{Symbol} representing the result of the sine function.
1658     """     """
1659     def __init__(self,arg):     def __init__(self,arg):
1660        """        """
1661        initialization of sin L{Symbol} with argument arg        Initialization of sin L{Symbol} with argument C{arg}.
1662    
1663        @param arg: argument of function        @param arg: argument of function
1664        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
1665        """        """
1666        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
1667    
1668     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1669        """        """
1670        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1671    
1672        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1673        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1674        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
1675          @param format: specifies the format to be used. At the moment only
1676                         "escript", "str" and "text" are supported.
1677        @type format: C{str}        @type format: C{str}
1678        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
1679                   expression assuming the values for the arguments are available
1680        @rtype: C{str}        @rtype: C{str}
1681        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1682                                      is available
1683        """        """
1684        if isinstance(argstrs,list):        if isinstance(argstrs,list):
1685            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1396  class Sin_Symbol(DependendSymbol): Line 1690  class Sin_Symbol(DependendSymbol):
1690    
1691     def substitute(self,argvals):     def substitute(self,argvals):
1692        """        """
1693        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1694        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
1695          defining this object.
1696    
1697        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1698        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1699        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
1700        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
1701        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
1702                  depending on the degree of substitution
1703          @raise TypeError: if a value for a L{Symbol} cannot be substituted
1704        """        """
1705        if argvals.has_key(self):        if argvals.has_key(self):
1706           arg=argvals[self]           arg=argvals[self]
# Line 1417  class Sin_Symbol(DependendSymbol): Line 1714  class Sin_Symbol(DependendSymbol):
1714    
1715     def diff(self,arg):     def diff(self,arg):
1716        """        """
1717        differential of this object        Differential of this object.
1718    
1719        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
1720        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
1721        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
1722        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
1723                  L{escript.Data}, C{numarray.NumArray} are possible
1724        """        """
1725        if arg==self:        if arg==self:
1726           return identity(self.getShape())           return identity(self.getShape())
# Line 1433  class Sin_Symbol(DependendSymbol): Line 1731  class Sin_Symbol(DependendSymbol):
1731    
1732  def cos(arg):  def cos(arg):
1733     """     """
1734     returns cosine of argument arg     Returns cosine of argument C{arg}.
1735    
1736     @param arg: argument     @param arg: argument
1737     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1738     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
1739     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1740       @raises TypeError: if the type of the argument is not expected
1741     """     """
1742     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1743        return numarray.cos(arg)        return numarray.cos(arg)
# Line 1455  def cos(arg): Line 1754  def cos(arg):
1754    
1755  class Cos_Symbol(DependendSymbol):  class Cos_Symbol(DependendSymbol):
1756     """     """
1757     L{Symbol} representing the result of the cosine function     L{Symbol} representing the result of the cosine function.
1758     """     """
1759     def __init__(self,arg):     def __init__(self,arg):
1760        """        """
1761        initialization of cos L{Symbol} with argument arg        Initialization of cos L{Symbol} with argument C{arg}.
1762    
1763        @param arg: argument of function        @param arg: argument of function
1764        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
1765        """        """
1766        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
1767    
1768     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1769        """        """
1770        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1771    
1772        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1773        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1774        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
1775          @param format: specifies the format to be used. At the moment only
1776                         "escript", "str" and "text" are supported.
1777        @type format: C{str}        @type format: C{str}
1778        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
1779                   expression assuming the values for the arguments are available
1780        @rtype: C{str}        @rtype: C{str}
1781        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1782                                      is available
1783        """        """
1784        if isinstance(argstrs,list):        if isinstance(argstrs,list):
1785            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1486  class Cos_Symbol(DependendSymbol): Line 1790  class Cos_Symbol(DependendSymbol):
1790    
1791     def substitute(self,argvals):     def substitute(self,argvals):
1792        """        """
1793        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1794        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
1795          defining this object.
1796    
1797        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1798        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1799        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
1800        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
1801        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
1802                  depending on the degree of substitution
1803          @raise TypeError: if a value for a L{Symbol} cannot be substituted
1804        """        """
1805        if argvals.has_key(self):        if argvals.has_key(self):
1806           arg=argvals[self]           arg=argvals[self]
# Line 1507  class Cos_Symbol(DependendSymbol): Line 1814  class Cos_Symbol(DependendSymbol):
1814    
1815     def diff(self,arg):     def diff(self,arg):
1816        """        """
1817        differential of this object        Differential of this object.
1818    
1819        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
1820        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
1821        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
1822        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
1823                  L{escript.Data}, C{numarray.NumArray} are possible
1824        """        """
1825        if arg==self:        if arg==self:
1826           return identity(self.getShape())           return identity(self.getShape())
# Line 1523  class Cos_Symbol(DependendSymbol): Line 1831  class Cos_Symbol(DependendSymbol):
1831    
1832  def tan(arg):  def tan(arg):
1833     """     """
1834     returns tangent of argument arg     Returns tangent of argument C{arg}.
1835    
1836     @param arg: argument     @param arg: argument
1837     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1838     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
1839     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1840       @raises TypeError: if the type of the argument is not expected
1841     """     """
1842     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1843        return numarray.tan(arg)        return numarray.tan(arg)
# Line 1545  def tan(arg): Line 1854  def tan(arg):
1854    
1855  class Tan_Symbol(DependendSymbol):  class Tan_Symbol(DependendSymbol):
1856     """     """
1857     L{Symbol} representing the result of the tangent function     L{Symbol} representing the result of the tangent function.
1858     """     """
1859     def __init__(self,arg):     def __init__(self,arg):
1860        """        """
1861        initialization of tan L{Symbol} with argument arg        Initialization of tan L{Symbol} with argument C{arg}.
1862    
1863        @param arg: argument of function        @param arg: argument of function
1864        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
1865        """        """
1866        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
1867    
1868     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1869        """        """
1870        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1871    
1872        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1873        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1874        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
1875          @param format: specifies the format to be used. At the moment only
1876                         "escript", "str" and "text" are supported.
1877        @type format: C{str}        @type format: C{str}
1878        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
1879                   expression assuming the values for the arguments are available
1880        @rtype: C{str}        @rtype: C{str}
1881        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1882                                      is available
1883        """        """
1884        if isinstance(argstrs,list):        if isinstance(argstrs,list):
1885            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1576  class Tan_Symbol(DependendSymbol): Line 1890  class Tan_Symbol(DependendSymbol):
1890    
1891     def substitute(self,argvals):     def substitute(self,argvals):
1892        """        """
1893        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1894        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
1895          defining this object.
1896    
1897        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1898        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1899        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
1900        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
1901        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
1902                  depending on the degree of substitution
1903          @raise TypeError: if a value for a L{Symbol} cannot be substituted
1904        """        """
1905        if argvals.has_key(self):        if argvals.has_key(self):
1906           arg=argvals[self]           arg=argvals[self]
# Line 1597  class Tan_Symbol(DependendSymbol): Line 1914  class Tan_Symbol(DependendSymbol):
1914    
1915     def diff(self,arg):     def diff(self,arg):
1916        """        """
1917        differential of this object        Differential of this object.
1918    
1919        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
1920        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
1921        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
1922        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
1923                  L{escript.Data}, C{numarray.NumArray} are possible
1924        """        """
1925        if arg==self:        if arg==self:
1926           return identity(self.getShape())           return identity(self.getShape())
# Line 1613  class Tan_Symbol(DependendSymbol): Line 1931  class Tan_Symbol(DependendSymbol):
1931    
1932  def asin(arg):  def asin(arg):
1933     """     """
1934     returns inverse sine of argument arg     Returns the inverse sine of argument C{arg}.
1935    
1936     @param arg: argument     @param arg: argument
1937     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1938     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
1939     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1940       @raises TypeError: if the type of the argument is not expected
1941     """     """
1942     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1943        return numarray.arcsin(arg)        return numarray.arcsin(arg)
# Line 1635  def asin(arg): Line 1954  def asin(arg):
1954    
1955  class Asin_Symbol(DependendSymbol):  class Asin_Symbol(DependendSymbol):
1956     """     """
1957     L{Symbol} representing the result of the inverse sine function     L{Symbol} representing the result of the inverse sine function.
1958     """     """
1959     def __init__(self,arg):     def __init__(self,arg):
1960        """        """
1961        initialization of asin L{Symbol} with argument arg        Initialization of asin L{Symbol} with argument C{arg}.
1962    
1963        @param arg: argument of function        @param arg: argument of function
1964        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
1965        """        """
1966        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
1967    
1968     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1969        """        """
1970        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1971    
1972        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1973        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1974        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
1975          @param format: specifies the format to be used. At the moment only
1976                         "escript", "str" and "text" are supported.
1977        @type format: C{str}        @type format: C{str}
1978        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
1979                   expression assuming the values for the arguments are available
1980        @rtype: C{str}        @rtype: C{str}
1981        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1982                                      is available
1983        """        """
1984        if isinstance(argstrs,list):        if isinstance(argstrs,list):
1985            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1666  class Asin_Symbol(DependendSymbol): Line 1990  class Asin_Symbol(DependendSymbol):
1990    
1991     def substitute(self,argvals):     def substitute(self,argvals):
1992        """        """
1993        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1994        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
1995          defining this object.
1996    
1997        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1998        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1999        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2000        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2001        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2002                  depending on the degree of substitution
2003          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2004        """        """
2005        if argvals.has_key(self):        if argvals.has_key(self):
2006           arg=argvals[self]           arg=argvals[self]
# Line 1687  class Asin_Symbol(DependendSymbol): Line 2014  class Asin_Symbol(DependendSymbol):
2014    
2015     def diff(self,arg):     def diff(self,arg):
2016        """        """
2017        differential of this object        Differential of this object.
2018    
2019        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2020        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2021        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2022        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
2023                  L{escript.Data}, C{numarray.NumArray} are possible
2024        """        """
2025        if arg==self:        if arg==self:
2026           return identity(self.getShape())           return identity(self.getShape())
# Line 1703  class Asin_Symbol(DependendSymbol): Line 2031  class Asin_Symbol(DependendSymbol):
2031    
2032  def acos(arg):  def acos(arg):
2033     """     """
2034     returns inverse cosine of argument arg     Returns the inverse cosine of argument C{arg}.
2035    
2036     @param arg: argument     @param arg: argument
2037     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2038     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
2039     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2040       @raises TypeError: if the type of the argument is not expected
2041     """     """
2042     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2043        return numarray.arccos(arg)        return numarray.arccos(arg)
# Line 1725  def acos(arg): Line 2054  def acos(arg):
2054    
2055  class Acos_Symbol(DependendSymbol):  class Acos_Symbol(DependendSymbol):
2056     """     """
2057     L{Symbol} representing the result of the inverse cosine function     L{Symbol} representing the result of the inverse cosine function.
2058     """     """
2059     def __init__(self,arg):     def __init__(self,arg):
2060        """        """
2061        initialization of acos L{Symbol} with argument arg        Initialization of acos L{Symbol} with argument C{arg}.
2062    
2063        @param arg: argument of function        @param arg: argument of function
2064        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2065        """        """
2066        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2067    
2068     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2069        """        """
2070        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2071    
2072        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2073        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2074        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
2075          @param format: specifies the format to be used. At the moment only
2076                         "escript", "str" and "text" are supported.
2077        @type format: C{str}        @type format: C{str}
2078        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
2079                   expression assuming the values for the arguments are available
2080        @rtype: C{str}        @rtype: C{str}
2081        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2082                                      is available
2083        """        """
2084        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2085            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1756  class Acos_Symbol(DependendSymbol): Line 2090  class Acos_Symbol(DependendSymbol):
2090    
2091     def substitute(self,argvals):     def substitute(self,argvals):
2092        """        """
2093        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2094        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
2095          defining this object.
2096    
2097        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2098        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2099        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2100        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2101        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2102                  depending on the degree of substitution
2103          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2104        """        """
2105        if argvals.has_key(self):        if argvals.has_key(self):
2106           arg=argvals[self]           arg=argvals[self]
# Line 1777  class Acos_Symbol(DependendSymbol): Line 2114  class Acos_Symbol(DependendSymbol):
2114    
2115     def diff(self,arg):     def diff(self,arg):
2116        """        """
2117        differential of this object        Differential of this object.
2118    
2119        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2120        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2121        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2122        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
2123                  L{escript.Data}, C{numarray.NumArray} are possible
2124        """        """
2125        if arg==self:        if arg==self:
2126           return identity(self.getShape())           return identity(self.getShape())
# Line 1793  class Acos_Symbol(DependendSymbol): Line 2131  class Acos_Symbol(DependendSymbol):
2131    
2132  def atan(arg):  def atan(arg):
2133     """     """
2134     returns inverse tangent of argument arg     Returns inverse tangent of argument C{arg}.
2135    
2136     @param arg: argument     @param arg: argument
2137     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2138     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
2139     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2140       @raises TypeError: if the type of the argument is not expected
2141     """     """
2142     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2143        return numarray.arctan(arg)        return numarray.arctan(arg)
# Line 1815  def atan(arg): Line 2154  def atan(arg):
2154    
2155  class Atan_Symbol(DependendSymbol):  class Atan_Symbol(DependendSymbol):
2156     """     """
2157     L{Symbol} representing the result of the inverse tangent function     L{Symbol} representing the result of the inverse tangent function.
2158     """     """
2159     def __init__(self,arg):     def __init__(self,arg):
2160        """        """
2161        initialization of atan L{Symbol} with argument arg        Initialization of atan L{Symbol} with argument C{arg}.
2162    
2163        @param arg: argument of function        @param arg: argument of function
2164        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2165        """        """
2166        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2167    
2168     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2169        """        """
2170        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2171    
2172        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2173        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2174        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
2175          @param format: specifies the format to be used. At the moment only
2176                         "escript", "str" and "text" are supported.
2177        @type format: C{str}        @type format: C{str}
2178        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
2179                   expression assuming the values for the arguments are available
2180        @rtype: C{str}        @rtype: C{str}
2181        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2182                                      is available
2183        """        """
2184        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2185            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1846  class Atan_Symbol(DependendSymbol): Line 2190  class Atan_Symbol(DependendSymbol):
2190    
2191     def substitute(self,argvals):     def substitute(self,argvals):
2192        """        """
2193        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2194        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
2195          defining this object.
2196    
2197        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2198        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2199        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2200        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2201        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2202                  depending on the degree of substitution
2203          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2204        """        """
2205        if argvals.has_key(self):        if argvals.has_key(self):
2206           arg=argvals[self]           arg=argvals[self]
# Line 1867  class Atan_Symbol(DependendSymbol): Line 2214  class Atan_Symbol(DependendSymbol):
2214    
2215     def diff(self,arg):     def diff(self,arg):
2216        """        """
2217        differential of this object        Differential of this object.
2218    
2219        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2220        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2221        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2222        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
2223                  L{escript.Data}, C{numarray.NumArray} are possible
2224        """        """
2225        if arg==self:        if arg==self:
2226           return identity(self.getShape())           return identity(self.getShape())
# Line 1883  class Atan_Symbol(DependendSymbol): Line 2231  class Atan_Symbol(DependendSymbol):
2231    
2232  def sinh(arg):  def sinh(arg):
2233     """     """
2234     returns hyperbolic sine of argument arg     Returns the hyperbolic sine of argument C{arg}.
2235    
2236     @param arg: argument     @param arg: argument
2237     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2238     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
2239     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2240       @raises TypeError: if the type of the argument is not expected
2241     """     """
2242     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2243        return numarray.sinh(arg)        return numarray.sinh(arg)
# Line 1905  def sinh(arg): Line 2254  def sinh(arg):
2254    
2255  class Sinh_Symbol(DependendSymbol):  class Sinh_Symbol(DependendSymbol):
2256     """     """
2257     L{Symbol} representing the result of the hyperbolic sine function     L{Symbol} representing the result of the hyperbolic sine function.
2258     """     """
2259     def __init__(self,arg):     def __init__(self,arg):
2260        """        """
2261        initialization of sinh L{Symbol} with argument arg        Initialization of sinh L{Symbol} with argument C{arg}.
2262    
2263        @param arg: argument of function        @param arg: argument of function
2264        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2265        """        """
2266        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2267    
2268     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2269        """        """
2270        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2271    
2272        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2273        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2274        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
2275          @param format: specifies the format to be used. At the moment only
2276                         "escript", "str" and "text" are supported.
2277        @type format: C{str}        @type format: C{str}
2278        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
2279                   expression assuming the values for the arguments are available
2280        @rtype: C{str}        @rtype: C{str}
2281        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2282                                      is available
2283        """        """
2284        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2285            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1936  class Sinh_Symbol(DependendSymbol): Line 2290  class Sinh_Symbol(DependendSymbol):
2290    
2291     def substitute(self,argvals):     def substitute(self,argvals):
2292        """        """
2293        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2294        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
2295          defining this object.
2296    
2297        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2298        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2299        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2300        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2301        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2302                  depending on the degree of substitution
2303          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2304        """        """
2305        if argvals.has_key(self):        if argvals.has_key(self):
2306           arg=argvals[self]           arg=argvals[self]
# Line 1957  class Sinh_Symbol(DependendSymbol): Line 2314  class Sinh_Symbol(DependendSymbol):
2314    
2315     def diff(self,arg):     def diff(self,arg):
2316        """        """
2317        differential of this object        Differential of this object.
2318    
2319        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2320        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2321        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2322        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
2323                  L{escript.Data}, C{numarray.NumArray} are possible
2324        """        """
2325        if arg==self:        if arg==self:
2326           return identity(self.getShape())           return identity(self.getShape())
# Line 1973  class Sinh_Symbol(DependendSymbol): Line 2331  class Sinh_Symbol(DependendSymbol):
2331    
2332  def cosh(arg):  def cosh(arg):
2333     """     """
2334     returns hyperbolic cosine of argument arg     Returns the hyperbolic cosine of argument C{arg}.
2335    
2336     @param arg: argument     @param arg: argument
2337     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2338     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
2339     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2340       @raises TypeError: if the type of the argument is not expected
2341     """     """
2342     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2343        return numarray.cosh(arg)        return numarray.cosh(arg)
# Line 1995  def cosh(arg): Line 2354  def cosh(arg):
2354    
2355  class Cosh_Symbol(DependendSymbol):  class Cosh_Symbol(DependendSymbol):
2356     """     """
2357     L{Symbol} representing the result of the hyperbolic cosine function     L{Symbol} representing the result of the hyperbolic cosine function.
2358     """     """
2359     def __init__(self,arg):     def __init__(self,arg):
2360        """        """
2361        initialization of cosh L{Symbol} with argument arg        Initialization of cosh L{Symbol} with argument C{arg}.
2362    
2363        @param arg: argument of function        @param arg: argument of function
2364        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2365        """        """
2366        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2367    
2368     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2369        """        """
2370        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2371    
2372        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2373        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2374        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
2375          @param format: specifies the format to be used. At the moment only
2376                         "escript", "str" and "text" are supported.
2377        @type format: C{str}        @type format: C{str}
2378        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
2379                   expression assuming the values for the arguments are available
2380        @rtype: C{str}        @rtype: C{str}
2381        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2382                                      is available
2383        """        """
2384        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2385            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2026  class Cosh_Symbol(DependendSymbol): Line 2390  class Cosh_Symbol(DependendSymbol):
2390    
2391     def substitute(self,argvals):     def substitute(self,argvals):
2392        """        """
2393        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2394        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
2395          defining this object.
2396    
2397        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2398        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2399        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2400        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2401        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2402                  depending on the degree of substitution
2403          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2404        """        """
2405        if argvals.has_key(self):        if argvals.has_key(self):
2406           arg=argvals[self]           arg=argvals[self]
# Line 2047  class Cosh_Symbol(DependendSymbol): Line 2414  class Cosh_Symbol(DependendSymbol):
2414    
2415     def diff(self,arg):     def diff(self,arg):
2416        """        """
2417        differential of this object        Differential of this object.
2418    
2419        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2420        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2421        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2422        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
2423                  L{escript.Data}, C{numarray.NumArray} are possible
2424        """        """
2425        if arg==self:        if arg==self:
2426           return identity(self.getShape())           return identity(self.getShape())
# Line 2063  class Cosh_Symbol(DependendSymbol): Line 2431  class Cosh_Symbol(DependendSymbol):
2431    
2432  def tanh(arg):  def tanh(arg):
2433     """     """
2434     returns hyperbolic tangent of argument arg     Returns the hyperbolic tangent of argument C{arg}.
2435    
2436     @param arg: argument     @param arg: argument
2437     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2438     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
2439     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2440       @raises TypeError: if the type of the argument is not expected
2441     """     """
2442     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2443        return numarray.tanh(arg)        return numarray.tanh(arg)
# Line 2085  def tanh(arg): Line 2454  def tanh(arg):
2454    
2455  class Tanh_Symbol(DependendSymbol):  class Tanh_Symbol(DependendSymbol):
2456     """     """
2457     L{Symbol} representing the result of the hyperbolic tangent function     L{Symbol} representing the result of the hyperbolic tangent function.
2458     """     """
2459     def __init__(self,arg):     def __init__(self,arg):
2460        """        """
2461        initialization of tanh L{Symbol} with argument arg        Initialization of tanh L{Symbol} with argument C{arg}.
2462    
2463        @param arg: argument of function        @param arg: argument of function
2464        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2465        """        """
2466        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2467    
2468     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2469        """        """
2470        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2471    
2472        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2473        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2474        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
2475          @param format: specifies the format to be used. At the moment only
2476                         "escript", "str" and "text" are supported.
2477        @type format: C{str}        @type format: C{str}
2478        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
2479                   expression assuming the values for the arguments are available
2480        @rtype: C{str}        @rtype: C{str}
2481        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2482                                      is available
2483        """        """
2484        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2485            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2116  class Tanh_Symbol(DependendSymbol): Line 2490  class Tanh_Symbol(DependendSymbol):
2490    
2491     def substitute(self,argvals):     def substitute(self,argvals):
2492        """        """
2493        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2494        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
2495          defining this object.
2496    
2497        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2498        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2499        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2500        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2501        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2502                  depending on the degree of substitution
2503          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2504        """        """
2505        if argvals.has_key(self):        if argvals.has_key(self):
2506           arg=argvals[self]           arg=argvals[self]
# Line 2137  class Tanh_Symbol(DependendSymbol): Line 2514  class Tanh_Symbol(DependendSymbol):
2514    
2515     def diff(self,arg):     def diff(self,arg):
2516        """        """
2517        differential of this object        Differential of this object.
2518    
2519        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2520        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2521        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2522        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
2523                  L{escript.Data}, C{numarray.NumArray} are possible
2524        """        """
2525        if arg==self:        if arg==self:
2526           return identity(self.getShape())           return identity(self.getShape())
# Line 2153  class Tanh_Symbol(DependendSymbol): Line 2531  class Tanh_Symbol(DependendSymbol):
2531    
2532  def asinh(arg):  def asinh(arg):
2533     """     """
2534     returns inverse hyperbolic sine of argument arg     Returns the inverse hyperbolic sine of argument C{arg}.
2535    
2536     @param arg: argument     @param arg: argument
2537     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2538     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
2539     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2540       @raises TypeError: if the type of the argument is not expected
2541     """     """
2542     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2543        return numarray.arcsinh(arg)        return numarray.arcsinh(arg)
# Line 2175  def asinh(arg): Line 2554  def asinh(arg):
2554    
2555  class Asinh_Symbol(DependendSymbol):  class Asinh_Symbol(DependendSymbol):
2556     """     """
2557     L{Symbol} representing the result of the inverse hyperbolic sine function     L{Symbol} representing the result of the inverse hyperbolic sine function.
2558     """     """
2559     def __init__(self,arg):     def __init__(self,arg):
2560        """        """
2561        initialization of asinh L{Symbol} with argument arg        Initialization of asinh L{Symbol} with argument C{arg}.
2562    
2563        @param arg: argument of function        @param arg: argument of function
2564        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2565        """        """
2566        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2567    
2568     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2569        """        """
2570        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2571    
2572        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2573        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2574        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
2575          @param format: specifies the format to be used. At the moment only
2576                         "escript", "str" and "text" are supported.
2577        @type format: C{str}        @type format: C{str}
2578        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
2579                   expression assuming the values for the arguments are available
2580        @rtype: C{str}        @rtype: C{str}
2581        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2582                                      is available
2583        """        """
2584        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2585            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2206  class Asinh_Symbol(DependendSymbol): Line 2590  class Asinh_Symbol(DependendSymbol):
2590    
2591     def substitute(self,argvals):     def substitute(self,argvals):
2592        """        """
2593        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2594        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
2595          defining this object.
2596    
2597        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2598        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2599        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2600        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2601        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2602                  depending on the degree of substitution
2603          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2604        """        """
2605        if argvals.has_key(self):        if argvals.has_key(self):
2606           arg=argvals[self]           arg=argvals[self]
# Line 2227  class Asinh_Symbol(DependendSymbol): Line 2614  class Asinh_Symbol(DependendSymbol):
2614    
2615     def diff(self,arg):     def diff(self,arg):
2616        """        """
2617        differential of this object        Differential of this object.
2618    
2619        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2620        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2621        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2622        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
2623                  L{escript.Data}, C{numarray.NumArray} are possible
2624        """        """
2625        if arg==self:        if arg==self:
2626           return identity(self.getShape())           return identity(self.getShape())
# Line 2243  class Asinh_Symbol(DependendSymbol): Line 2631  class Asinh_Symbol(DependendSymbol):
2631    
2632  def acosh(arg):  def acosh(arg):
2633     """     """
2634     returns inverse hyperolic cosine of argument arg     Returns the inverse hyperbolic cosine of argument C{arg}.
2635    
2636     @param arg: argument     @param arg: argument
2637     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2638     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
2639     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2640       @raises TypeError: if the type of the argument is not expected
2641     """     """
2642     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2643        return numarray.arccosh(arg)        return numarray.arccosh(arg)
# Line 2265  def acosh(arg): Line 2654  def acosh(arg):
2654    
2655  class Acosh_Symbol(DependendSymbol):  class Acosh_Symbol(DependendSymbol):
2656     """     """
2657     L{Symbol} representing the result of the inverse hyperolic cosine function     L{Symbol} representing the result of the inverse hyperbolic cosine function.
2658     """     """
2659     def __init__(self,arg):     def __init__(self,arg):
2660        """        """
2661        initialization of acosh L{Symbol} with argument arg        Initialization of acosh L{Symbol} with argument C{arg}.
2662    
2663        @param arg: argument of function        @param arg: argument of function
2664        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2665        """        """
2666        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2667    
2668     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2669        """        """
2670        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2671    
2672        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2673        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2674        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
2675          @param format: specifies the format to be used. At the moment only
2676                         "escript", "str" and "text" are supported.
2677        @type format: C{str}        @type format: C{str}
2678        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
2679                   expression assuming the values for the arguments are available
2680        @rtype: C{str}        @rtype: C{str}
2681        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2682                                      is available
2683        """        """
2684        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2685            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2296  class Acosh_Symbol(DependendSymbol): Line 2690  class Acosh_Symbol(DependendSymbol):
2690    
2691     def substitute(self,argvals):     def substitute(self,argvals):
2692        """        """
2693        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2694        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
2695          defining this object.
2696    
2697        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2698        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2699        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2700        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2701        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2702                  depending on the degree of substitution
2703          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2704        """        """
2705        if argvals.has_key(self):        if argvals.has_key(self):
2706           arg=argvals[self]           arg=argvals[self]
# Line 2317  class Acosh_Symbol(DependendSymbol): Line 2714  class Acosh_Symbol(DependendSymbol):
2714    
2715     def diff(self,arg):     def diff(self,arg):
2716        """        """
2717        differential of this object        Differential of this object.
2718    
2719        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2720        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2721        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2722        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
2723                  L{escript.Data}, C{numarray.NumArray} are possible
2724        """        """
2725        if arg==self:        if arg==self:
2726           return identity(self.getShape())           return identity(self.getShape())
# Line 2333  class Acosh_Symbol(DependendSymbol): Line 2731  class Acosh_Symbol(DependendSymbol):
2731    
2732  def atanh(arg):  def atanh(arg):
2733     """     """
2734     returns inverse hyperbolic tangent of argument arg     Returns the inverse hyperbolic tangent of argument C{arg}.
2735    
2736     @param arg: argument     @param arg: argument
2737     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2738     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
2739     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2740       @raises TypeError: if the type of the argument is not expected
2741     """     """
2742     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2743        return numarray.arctanh(arg)        return numarray.arctanh(arg)
# Line 2355  def atanh(arg): Line 2754  def atanh(arg):
2754    
2755  class Atanh_Symbol(DependendSymbol):  class Atanh_Symbol(DependendSymbol):
2756     """     """
2757     L{Symbol} representing the result of the inverse hyperbolic tangent function     L{Symbol} representing the result of the inverse hyperbolic tangent function.
2758     """     """
2759     def __init__(self,arg):     def __init__(self,arg):
2760        """        """
2761        initialization of atanh L{Symbol} with argument arg        Initialization of atanh L{Symbol} with argument C{arg}.
2762    
2763        @param arg: argument of function        @param arg: argument of function
2764        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2765        """        """
2766        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2767    
2768     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2769        """        """
2770        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2771    
2772        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2773        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2774        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
2775          @param format: specifies the format to be used. At the moment only
2776                         "escript", "str" and "text" are supported.
2777        @type format: C{str}        @type format: C{str}
2778        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
2779                   expression assuming the values for the arguments are available
2780        @rtype: C{str}        @rtype: C{str}
2781        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2782                                      is available
2783        """        """
2784        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2785            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2386  class Atanh_Symbol(DependendSymbol): Line 2790  class Atanh_Symbol(DependendSymbol):
2790    
2791     def substitute(self,argvals):     def substitute(self,argvals):
2792        """        """
2793        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2794        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
2795          defining this object.
2796    
2797        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2798        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2799        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2800        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2801        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2802                  depending on the degree of substitution
2803          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2804        """        """
2805        if argvals.has_key(self):        if argvals.has_key(self):
2806           arg=argvals[self]           arg=argvals[self]
# Line 2407  class Atanh_Symbol(DependendSymbol): Line 2814  class Atanh_Symbol(DependendSymbol):
2814    
2815     def diff(self,arg):     def diff(self,arg):
2816        """        """
2817        differential of this object        Differential of this object.
2818    
2819        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2820        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2821        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2822        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
2823                  L{escript.Data}, C{numarray.NumArray} are possible
2824        """        """
2825        if arg==self:        if arg==self:
2826           return identity(self.getShape())           return identity(self.getShape())
# Line 2423  class Atanh_Symbol(DependendSymbol): Line 2831  class Atanh_Symbol(DependendSymbol):
2831    
2832  def exp(arg):  def exp(arg):
2833     """     """
2834     returns exponential of argument arg     Returns M{e} to the power of argument C{arg}.
2835    
2836     @param arg: argument     @param arg: argument
2837     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}.
2838     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
2839     @raises TypeError: if the type of the argument is not expected.             on the type of arg
2840       @raises TypeError: if the type of the argument is not expected
2841     """     """
2842     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2843        return numarray.exp(arg)        return numarray.exp(arg)
# Line 2445  def exp(arg): Line 2854  def exp(arg):
2854    
2855  class Exp_Symbol(DependendSymbol):  class Exp_Symbol(DependendSymbol):
2856     """     """
2857     L{Symbol} representing the result of the exponential function     L{Symbol} representing the result of the exponential function.
2858     """     """
2859     def __init__(self,arg):     def __init__(self,arg):
2860        """        """
2861        initialization of exp L{Symbol} with argument arg        Initialization of exp L{Symbol} with argument C{arg}.
2862    
2863        @param arg: argument of function        @param arg: argument of function
2864        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2865        """        """
2866        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2867    
2868     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2869        """        """
2870        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2871    
2872        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2873        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2874        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
2875          @param format: specifies the format to be used. At the moment only
2876                         "escript", "str" and "text" are supported.
2877        @type format: C{str}        @type format: C{str}
2878        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
2879                   expression assuming the values for the arguments are available
2880        @rtype: C{str}        @rtype: C{str}
2881        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2882                                      is available
2883        """        """
2884        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2885            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2476  class Exp_Symbol(DependendSymbol): Line 2890  class Exp_Symbol(DependendSymbol):
2890    
2891     def substitute(self,argvals):     def substitute(self,argvals):
2892        """        """
2893        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2894        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
2895          defining this object.
2896    
2897        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2898        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2899        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2900        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2901        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2902                  depending on the degree of substitution
2903          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2904        """        """
2905        if argvals.has_key(self):        if argvals.has_key(self):
2906           arg=argvals[self]           arg=argvals[self]
# Line 2497  class Exp_Symbol(DependendSymbol): Line 2914  class Exp_Symbol(DependendSymbol):
2914    
2915     def diff(self,arg):     def diff(self,arg):
2916        """        """
2917        differential of this object        Differential of this object.
2918    
2919        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2920        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2921        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2922        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
2923                  L{escript.Data}, C{numarray.NumArray} are possible
2924        """        """
2925        if arg==self:        if arg==self:
2926           return identity(self.getShape())           return identity(self.getShape())
# Line 2513  class Exp_Symbol(DependendSymbol): Line 2931  class Exp_Symbol(DependendSymbol):
2931    
2932  def sqrt(arg):  def sqrt(arg):
2933     """     """
2934     returns square root of argument arg     Returns the square root of argument C{arg}.
2935    
2936     @param arg: argument     @param arg: argument
2937     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2938     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2939     @raises TypeError: if the type of the argument is not expected.             depending on the type of C{arg}
2940       @raises TypeError: if the type of the argument is not expected
2941     """     """
2942     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2943        return numarray.sqrt(arg)        return numarray.sqrt(arg)
# Line 2535  def sqrt(arg): Line 2954  def sqrt(arg):
2954    
2955  class Sqrt_Symbol(DependendSymbol):  class Sqrt_Symbol(DependendSymbol):
2956     """     """
2957     L{Symbol} representing the result of the square root function     L{Symbol} representing the result of the square root function.
2958     """     """
2959     def __init__(self,arg):     def __init__(self,arg):
2960        """        """
2961        initialization of sqrt L{Symbol} with argument arg        Initialization of sqrt L{Symbol} with argument C{arg}.
2962    
2963        @param arg: argument of function        @param arg: argument of function
2964        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2965        """        """
2966        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2967    
2968     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2969        """        """
2970        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2971    
2972        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2973        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2974        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
2975          @param format: specifies the format to be used. At the moment only
2976                         "escript", "str" and "text" are supported.
2977        @type format: C{str}        @type format: C{str}
2978        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
2979                   expression assuming the values for the arguments are available
2980        @rtype: C{str}        @rtype: C{str}
2981        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2982                                      is available
2983        """        """
2984        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2985            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2566  class Sqrt_Symbol(DependendSymbol): Line 2990  class Sqrt_Symbol(DependendSymbol):
2990    
2991     def substitute(self,argvals):     def substitute(self,argvals):
2992        """        """
2993        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2994        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
2995          defining this object.
2996    
2997        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2998        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2999        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
3000        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
3001        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
3002                  depending on the degree of substitution
3003          @raise TypeError: if a value for a L{Symbol} cannot be substituted
3004        """        """
3005        if argvals.has_key(self):        if argvals.has_key(self):
3006           arg=argvals[self]           arg=argvals[self]
# Line 2587  class Sqrt_Symbol(DependendSymbol): Line 3014  class Sqrt_Symbol(DependendSymbol):
3014    
3015     def diff(self,arg):     def diff(self,arg):
3016        """        """
3017        differential of this object        Differential of this object.
3018    
3019        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
3020        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
3021        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
3022        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
3023                  L{escript.Data}, C{numarray.NumArray} are possible
3024        """        """
3025        if arg==self:        if arg==self:
3026           return identity(self.getShape())           return identity(self.getShape())
# Line 2603  class Sqrt_Symbol(DependendSymbol): Line 3031  class Sqrt_Symbol(DependendSymbol):
3031    
3032  def log(arg):  def log(arg):
3033     """     """
3034     returns natural logarithm of argument arg     Returns the natural logarithm of argument C{arg}.
3035    
3036     @param arg: argument     @param arg: argument
3037     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}.
3038     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
3039     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
3040       @raises TypeError: if the type of the argument is not expected
3041     """     """
3042     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
3043        return numarray.log(arg)        return numarray.log(arg)
# Line 2625  def log(arg): Line 3054  def log(arg):
3054    
3055  class Log_Symbol(DependendSymbol):  class Log_Symbol(DependendSymbol):
3056     """     """
3057     L{Symbol} representing the result of the natural logarithm function     L{Symbol} representing the result of the natural logarithm function.
3058     """     """
3059     def __init__(self,arg):     def __init__(self,arg):
3060        """        """
3061        initialization of log L{Symbol} with argument arg        Initialization of log L{Symbol} with argument C{arg}.
3062    
3063        @param arg: argument of function        @param arg: argument of function
3064        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
3065        """        """
3066        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
3067    
3068     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
3069        """        """
3070        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
3071    
3072        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
3073        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
3074        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
3075          @param format: specifies the format to be used. At the moment only
3076                         "escript", "str" and "text" are supported.
3077        @type format: C{str}        @type format: C{str}
3078        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
3079                   expression assuming the values for the arguments are available
3080        @rtype: C{str}        @rtype: C{str}
3081        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
3082                                      is available
3083        """        """
3084        if isinstance(argstrs,list):        if isinstance(argstrs,list):
3085            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2656  class Log_Symbol(DependendSymbol): Line 3090  class Log_Symbol(DependendSymbol):
3090    
3091     def substitute(self,argvals):     def substitute(self,argvals):
3092        """        """
3093        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
3094        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
3095          defining this object.
3096    
3097        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
3098        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
3099        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
3100        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
3101        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
3102                  depending on the degree of substitution
3103          @raise TypeError: if a value for a L{Symbol} cannot be substituted
3104        """        """
3105        if argvals.has_key(self):        if argvals.has_key(self):
3106           arg=argvals[self]           arg=argvals[self]
# Line 2677  class Log_Symbol(DependendSymbol): Line 3114  class Log_Symbol(DependendSymbol):
3114    
3115     def diff(self,arg):     def diff(self,arg):
3116        """        """
3117        differential of this object        Differential of this object.
3118    
3119        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
3120        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
3121        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
3122        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
3123                  L{escript.Data}, C{numarray.NumArray} are possible
3124        """        """
3125        if arg==self:        if arg==self:
3126           return identity(self.getShape())           return identity(self.getShape())
# Line 2693  class Log_Symbol(DependendSymbol): Line 3131  class Log_Symbol(DependendSymbol):
3131    
3132  def sign(arg):  def sign(arg):
3133     """     """
3134     returns sign of argument arg     Returns the sign of argument C{arg}.
3135    
3136     @param arg: argument     @param arg: argument
3137     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
3138     @rtype:C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending
3139     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
3140       @raises TypeError: if the type of the argument is not expected
3141     """     """
3142     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
3143        return wherePositive(arg)-whereNegative(arg)        return wherePositive(arg)-whereNegative(arg)
# Line 2725  def sign(arg): Line 3164  def sign(arg):
3164    
3165  class Abs_Symbol(DependendSymbol):  class Abs_Symbol(DependendSymbol):
3166     """     """
3167     L{Symbol} representing the result of the absolute value function     L{Symbol} representing the result of the absolute value function.
3168     """     """
3169     def __init__(self,arg):     def __init__(self,arg):
3170        """        """
3171        initialization of abs L{Symbol} with argument arg        Initialization of abs L{Symbol} with argument C{arg}.
3172    
3173        @param arg: argument of function        @param arg: argument of function
3174        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
3175        """        """
3176        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
3177    
3178     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
3179        """        """
3180        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
3181    
3182        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
3183        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
3184        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
3185          @param format: specifies the format to be used. At the moment only
3186                         "escript", "str" and "text" are supported.
3187        @type format: C{str}        @type format: C{str}
3188        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
3189                   expression assuming the values for the arguments are available
3190        @rtype: C{str}        @rtype: C{str}
3191        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
3192                                      is available
3193        """        """
3194        if isinstance(argstrs,list):        if isinstance(argstrs,list):
3195            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2756  class Abs_Symbol(DependendSymbol): Line 3200  class Abs_Symbol(DependendSymbol):
3200    
3201     def substitute(self,argvals):     def substitute(self,argvals):
3202        """        """
3203        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
3204        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
3205          defining this object.
3206    
3207        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
3208        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
3209        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
3210        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
3211        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
3212                  depending on the degree of substitution
3213          @raise TypeError: if a value for a L{Symbol} cannot be substituted
3214        """        """
3215        if argvals.has_key(self):        if argvals.has_key(self):
3216           arg=argvals[self]           arg=argvals[self]
# Line 2777  class Abs_Symbol(DependendSymbol): Line 3224  class Abs_Symbol(DependendSymbol):
3224    
3225     def diff(self,arg):     def diff(self,arg):
3226        """        """
3227        differential of this object        Differential of this object.
3228    
3229        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
3230        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
3231        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
3232        @rtype: typically L{Symbol} but other types such as C{float}, L{escript.Data}, L{numarray.NumArray}  are possible.        @rtype: typically L{Symbol} but other types such as C{float},
3233                  L{escript.Data}, C{numarray.NumArray} are possible
3234        """        """
3235        if arg==self:        if arg==self:
3236           return identity(self.getShape())           return identity(self.getShape())
# Line 2793  class Abs_Symbol(DependendSymbol): Line 3241  class Abs_Symbol(DependendSymbol):
3241    
3242  def minval(arg):  def minval(arg):
3243     """     """
3244     returns minimum value over all components of arg at each data point     Returns the minimum value over all components of C{arg} at each data point.
3245    
3246     @param arg: argument     @param arg: argument
3247     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
3248     @rtype:C{float}, L{escript.Data}, L{Symbol} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol} depending on the type of C{arg}
3249     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected
3250     """     """
3251     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
3252        if arg.rank==0:        if arg.rank==0:
# Line 2818  def minval(arg): Line 3266  def minval(arg):
3266    
3267  class Minval_Symbol(DependendSymbol):  class Minval_Symbol(DependendSymbol):
3268     """     """
3269     L{Symbol} representing the result of the minimum value function     L{Symbol} representing the result of the minimum value function.
3270     """     """
3271     def __init__(self,arg):     def __init__(self,arg):
3272        """        """
3273        initialization of minimum value L{Symbol} with argument arg        Initialization of minimum value L{Symbol} with argument C{arg}.
3274    
3275        @param arg: argument of function        @param arg: argument of function
3276        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
3277        """        """
3278        DependendSymbol.__init__(self,args=[arg],shape=(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=(),dim=arg.getDim())
3279    
3280     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
3281        """        """
3282        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
3283    
3284        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
3285        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
3286        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
3287          @param format: specifies the format to be used. At the moment only
3288                         "escript", "str" and "text" are supported.
3289        @type format: C{str}        @type format: C{str}
3290        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
3291                   expression assuming the values for the arguments are available
3292        @rtype: C{str}        @rtype: C{str}
3293        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
3294                                      is available
3295        """        """
3296        if isinstance(argstrs,list):        if isinstance(argstrs,list):
3297            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2849  class Minval_Symbol(DependendSymbol): Line 3302  class Minval_Symbol(DependendSymbol):
3302    
3303     def substitute(self,argvals):     def substitute(self,argvals):
3304        """        """
3305        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
3306        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
3307          defining this object.
3308    
3309        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
3310        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
3311        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
3312        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
3313        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
3314                  depending on the degree of substitution
3315          @raise TypeError: if a value for a L{Symbol} cannot be substituted
3316        """        """
3317        if argvals.has_key(self):        if argvals.has_key(self):
3318           arg=argvals[self]           arg=argvals[self]
# Line 2870  class Minval_Symbol(DependendSymbol): Line 3326  class Minval_Symbol(DependendSymbol):
3326    
3327  def maxval(arg):  def maxval(arg):
3328     """     """
3329     returns maximum value over all components of arg at each data point     Returns the maximum value over all components of C{arg} at each data point.
3330    
3331     @param arg: argument     @param arg: argument
3332     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
3333     @rtype:C{float}, L{escript.Data}, L{Symbol} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol} depending on the type of C{arg}
3334     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected
3335     """     """
3336     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
3337        if arg.rank==0:        if arg.rank==0:
# Line 2895  def maxval(arg): Line 3351  def maxval(arg):
3351    
3352  class Maxval_Symbol(DependendSymbol):  class Maxval_Symbol(DependendSymbol):
3353     """     """
3354     L{Symbol} representing the result of the maximum value function     L{Symbol} representing the result of the maximum value function.
3355     """     """
3356     def __init__(self,arg):     def __init__(self,arg):
3357        """        """
3358        initialization of maximum value L{Symbol} with argument arg        Initialization of maximum value L{Symbol} with argument C{arg}.
3359    
3360        @param arg: argument of function        @param arg: argument of function
3361        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
3362        """        """
3363        DependendSymbol.__init__(self,args=[arg],shape=(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=(),dim=arg.getDim())
3364    
3365     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
3366        """        """
3367        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
3368    
3369        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
3370        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
3371        @param format: specifies the format to be used. At the moment only "escript" ,"text" and "str" are supported.        @type argstrs: C{str} or a C{list} of length 1 of C{str}
3372          @param format: specifies the format to be used. At the moment only
3373                         "escript", "str" and "text" are supported.
3374        @type format: C{str}        @type format: C{str}
3375        @return: a piece of program code which can be used to evaluate the expression assuming the values for the arguments are available.        @return: a piece of program code which can be used to evaluate the
3376                   expression assuming the values for the arguments are available
3377        @rtype: C{str}        @rtype: C{str}
3378        @raise: NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
3379                                      is available
3380        """        """
3381        if isinstance(argstrs,list):        if isinstance(argstrs,list):
3382            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2926  class Maxval_Symbol(DependendSymbol): Line 3387  class Maxval_Symbol(DependendSymbol):
3387    
3388     def substitute(self,argvals):     def substitute(self,argvals):
3389        """        """
3390        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
3391        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.        The method replaces the L{Symbol} u by argvals[u] in the expression
3392          defining this object.
3393    
3394        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
3395        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
3396        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
3397        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
3398        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
3399                  depending on the degree of substitution
3400          @raise TypeError: if a value for a L{Symbol} cannot be substituted
3401        """        """
3402        if argvals.has_key(self):        if argvals.has_key(self):
3403           arg=argvals[self]           arg=argvals[self]
# Line 2947  class Maxval_Symbol(DependendSymbol): Line 3411  class Maxval_Symbol(DependendSymbol):
3411    
3412  def length(arg):  def length(arg):
3413     """     """
3414     returns length/Euclidean norm of argument arg at each data point     Returns the length (Euclidean norm) of argument C{arg} at each data point.
3415    
3416     @param arg: argument     @param arg: argument
3417     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
3418     @rtype:C{float}, L{escript.Data}, L{Symbol} depending on the type of arg.     @rtype: C{float}, L{escript.Data}, L{Symbol} depending on the type of C{arg}
3419     """     """
3420     return sqrt(inner(arg,arg))     return sqrt(inner(arg,arg))
3421    
3422  def trace(arg,axis_offset=0):  def trace(arg,axis_offset=0):
3423     """     """
3424     returns the trace of arg which the sum of arg[k,k] over k.     Returns the trace of C{arg} which is the sum of C{arg[k,k]} over k.
3425    
3426     @param arg: argument     @param arg: argument
3427     @type arg: L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: L{escript.Data}, L{Symbol}, C{numarray.NumArray}
3428     @param axis_offset: axis_offset to components to sum over. C{axis_offset} must be non-negative and less than the rank of arg +1. The dimensions on component     @param axis_offset: C{axis_offset} to components to sum over. C{axis_offset}
3429                    axis_offset and axis_offset+1 must be equal.                         must be non-negative and less than the rank of C{arg} +1.
3430                           The dimensions of component C{axis_offset} and
3431                           axis_offset+1 must be equal.
3432     @type axis_offset: C{int}     @type axis_offset: C{int}
3433     @return: trace of arg. The rank of the returned object is minus 2 of the rank of arg.     @return: trace of arg. The rank of the returned object is rank of C{arg}
3434     @rtype: L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.              minus 2.
3435       @rtype: L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending on the
3436               type of C{arg}
3437     """     """
3438     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
3439        sh=arg.shape        sh=arg.shape
3440        if len(sh)<2:        if len(sh)<2:
3441          raise ValueError,"trace: rank of argument must be greater than 1"          raise ValueError,"rank of argument must be greater than 1"
3442        if axis_offset<0 or axis_offset>len(sh)-2:        if axis_offset<0 or axis_offset>len(sh)-2:
3443          raise ValueError,"trace: axis_offset must be between 0 and %s"%len(sh)-2          raise ValueError,"axis_offset must be between 0 and %d"%(len(sh)-2)
3444        s1=1        s1=1
3445        for i in range(axis_offset): s1*=sh[i]        for i in range(axis_offset): s1*=sh[i]
3446        s2=1        s2=1
3447        for i in range(axis_offset+2,len(sh)): s2*=sh[i]        for i in range(axis_offset+2,len(sh)): s2*=sh[i]
3448        if not sh[axis_offset] == sh[axis_offset+1]:        if not sh[axis_offset] == sh[axis_offset+1]:
3449          raise ValueError,"trace: dimensions of component %s and %s must match."%(axis_offset.axis_offset+1)          raise ValueError,"dimensions of component %d and %d must match."%(axis_offset,axis_offset+1)
3450        arg_reshaped=numarray.reshape(arg,(s1,sh[axis_offset],sh[axis_offset],s2))        arg_reshaped=numarray.reshape(arg,(s1,sh[axis_offset],sh[axis_offset],s2))
3451        out=numarray.zeros([s1,s2],numarray.Float)        out=numarray.zeros([s1,s2],numarray.Float64)
3452        for i1 in range(s1):        for i1 in range(s1):
3453          for i2 in range(s2):          for i2 in range(s2):
3454              for j in range(sh[axis_offset]): out[i1,i2]+=arg_reshaped[i1,j,j,i2]              for j in range(sh[axis_offset]): out[i1,i2]+=arg_reshaped[i1,j,j,i2]
3455        out.resize(sh[:axis_offset]+sh[axis_offset+2:])        out.resize(sh[:axis_offset]+sh[axis_offset+2:])
3456        return out        return out
3457     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
3458        return escript_trace(arg,axis_offset)        if arg.getRank()<2:
3459            raise ValueError,"rank of argument must be greater than 1"
3460          if axis_offset<0 or axis_offset>arg.getRank()-2:
3461            raise ValueError,"axis_offset must be between 0 and %d"%(arg.getRank()-2)
3462          s=list(arg.getShape())
3463          if not s[axis_offset] == s[axis_offset+1]:
3464            raise ValueError,"dimensions of component %d and %d must match."%(axis_offset,axis_offset+1)
3465          return arg._trace(axis_offset)
3466     elif isinstance(arg,float):     elif isinstance(arg,float):
3467        raise TypeError,"trace: illegal argument type float."        raise TypeError,"illegal argument type float."
3468     elif isinstance(arg,int):     elif isinstance(arg,int):
3469        raise TypeError,"trace: illegal argument type int."        raise TypeError,"illegal argument type int."
3470     elif isinstance(arg,Symbol):     elif isinstance(arg,Symbol):
3471        return Trace_Symbol(arg,axis_offset)        return Trace_Symbol(arg,axis_offset)
3472     else:     else:
3473        raise TypeError,"trace: Unknown argument type."        raise TypeError,"Unknown argument type."
3474    
 def escript_trace(arg,axis_offset): # this should be escript._trace  
       "arg si a Data objects!!!"  
       if arg.getRank()<2:  
         raise ValueError,"escript_trace: rank of argument must be greater than 1"  
       if axis_offset<0 or axis_offset>arg.getRank()-2:  
         raise ValueError,"escript_trace: axis_offset must be between 0 and %s"%arg.getRank()-2  
       s=list(arg.getShape())          
       if not s[axis_offset] == s[axis_offset+1]:  
         raise ValueError,"escript_trace: dimensions of component %s and %s must match."%(axis_offset.axis_offset+1)  
       out=escript.Data(0.,tuple(s[0:axis_offset]+s[axis_offset+2:]),arg.getFunctionSpace())  
       if arg.getRank()==2:  
          for i0 in range(s[0]):  
             out+=arg[i0,i0]  
       elif arg.getRank()==3:  
          if axis_offset==0:  
             for i0 in range(s[0]):  
                   for i2 in range(s[2]):  
                          out[i2]+=arg[i0,i0,i2]  
          elif axis_offset==1:  
             for i0 in range(s[0]):  
                for i1 in range(s[1]):  
                          out[i0]+=arg[i0,i1,i1]  
       elif arg.getRank()==4:  
          if axis_offset==0:  
             for i0 in range(s[0]):  
                   for i2 in range(s[2]):  
                      for i3 in range(s[3]):  
                          out[i2,i3]+=arg[i0,i0,i2,i3]  
          elif axis_offset==1:  
             for i0 in range(s[0]):  
                for i1 in range(s[1]):  
                      for i3 in range(s[3]):  
                          out[i0,i3]+=arg[i0,i1,i1,i3]  
          elif axis_offset==2:  
             for i0 in range(s[0]):  
                for i1 in range(s[1]):  
                   for i2 in range(s[2]):  
                          out[i0,i1]+=arg[i0,i1,i2,i2]  
       return out  
3475  class Trace_Symbol(DependendSymbol):  class Trace_Symbol(DependendSymbol):
3476     """     """
3477     L{Symbol} representing the result of the trace function     L{Symbol} representing the result of the trace function.
3478     """     """
3479     def __init__(self,arg,axis_offset=0):     def __init__(self,arg,axis_offset=0):
3480        """        """
3481        initialization of trace L{Symbol} with argument arg        Initialization of trace L{Symbol} with argument C{arg}.
3482    
3483        @param arg: argument of function        @param arg: argument of function
3484        @type arg: L{Symbol}.        @type arg: L{Symbol}
3485        @param axis_offset: axis_offset to components to sum over. C{axis_offset} must be non-negative and less than the rank of arg +1. The dimensions on component        @param axis_offset: C{axis_offset} to components to sum over.
3486                    axis_offset and axis_offset+1 must be equal.                            C{axis_offset} must be non-negative and less than the
3487                              rank of C{arg} +1. The dimensions on component
3488                              C{axis_offset} and axis_offset+1 must be equal.
3489        @type axis_offset: C{int}        @type axis_offset: C{int}
3490        """        """
3491        if arg.getRank()<2:        if arg.getRank()<2:
3492          raise ValueError,"Trace_Symbol: rank of argument must be greater than 1"          raise ValueError,"rank of argument must be greater than 1"
3493        if axis_offset<0 or axis_offset>arg.getRank()-2:        if axis_offset<0 or axis_offset>arg.getRank()-2:
3494          raise ValueError,"Trace_Symbol: axis_offset must be between 0 and %s"%arg.getRank()-2          raise ValueError,"axis_offset must be between 0 and %d"%(arg.getRank()-2)
3495        s=list(arg.getShape())                s=list(arg.getShape())
3496        if not s[axis_offset] == s[axis_offset+1]:        if not s[axis_offset] == s[axis_offset+1]:
3497          rais