/[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 1042 by gross, Mon Mar 19 03:50:34 2007 UTC revision 2169 by caltinay, Wed Dec 17 03:08:58 2008 UTC
# Line 1  Line 1 
1  # $Id$  
2    ########################################################
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
# Line 9  Utility functions for escript Line 28  Utility functions for escript
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"
 __copyright__="""  Copyright (c) 2006 by ACcESS MNRF  
                     http://www.access.edu.au  
                 Primary Business: Queensland, Australia"""  
 __license__="""Licensed under the Open Software License version 3.0  
              http://www.opensource.org/licenses/osl-3.0.php"""  
 __url__="http://www.iservo.edu.au/esys/escript"  
 __version__="$Revision$"  
 __date__="$Date$"  
36    
37    
38  import math  import math
# Line 27  import numarray Line 40  import numarray
40  import escript  import escript
41  import os  import os
42  from esys.escript import C_GeneralTensorProduct  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  #=========================================================  #=========================================================
48  #   some helpers:  #   some helpers:
49  #=========================================================  #=========================================================
50    def getEpsilon():
51         return escript.getMachinePrecision()
52    EPSILON=getEpsilon()
53    
54    def getMaxFloat():
55         return escript.getMaxFloat()
56    DBLE_MAX=getMaxFloat()
57    
58    
59  def getTagNames(domain):  def getTagNames(domain):
60      """      """
61      returns a list of the tag names used by the domain      Returns a list of tag names used by the domain.
62    
       
63      @param domain: a domain object      @param domain: a domain object
64      @type domain: C{escript.Domain}      @type domain: L{escript.Domain}
65      @return: a list of the tag name used by the domain.      @return: a list of tag names used by the domain
66      @rtype: C{list} of C{str}      @rtype: C{list} of C{str}
67      """      """
68      return [n.strip() for n in domain.showTagNames().split(",") ]      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    
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      if domain==None:      @note: The data objects have to be defined on the same domain. They may not
163         for i in data.keys():             be in the same L{FunctionSpace} but one cannot expect that all
164            if not data[i].isEmpty(): domain=data[i].getFunctionSpace().getDomain()             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          raise ValueError,"no domain detected."          raise ValueError,"saveDX: no domain detected."
183      else:      domain.saveDX(filename,new_data)
         domain.saveDX(filename,data)  
184    
185  def kronecker(d=3):  def kronecker(d=3):
186     """     """
187     return the kronecker S{delta}-symbol     Returns the kronecker S{delta}-symbol.
188    
189     @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
190                 dimension
191     @type d: C{int}, L{escript.Domain} or L{escript.FunctionSpace}     @type d: C{int}, L{escript.Domain} or L{escript.FunctionSpace}
192     @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}
193     @rtype: L{numarray.NumArray} or L{escript.Data} of rank 2.              otherwise
194       @rtype: C{numarray.NumArray} or L{escript.Data} of rank 2
195     """     """
196     return identityTensor(d)     return identityTensor(d)
197    
198  def identity(shape=()):  def identity(shape=()):
199     """     """
200     return the shape x shape identity tensor     Returns the C{shape} x C{shape} identity tensor.
201    
202     @param shape: input shape for the identity tensor     @param shape: input shape for the identity tensor
203     @type shape: C{tuple} of C{int}     @type shape: C{tuple} of C{int}
204     @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
205     @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:
206     @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.
207       @rtype: C{numarray.NumArray} of rank 1, rank 2 or rank 4
208       @raise ValueError: if len(shape)>2
209     """     """
210     if len(shape)>0:     if len(shape)>0:
211        out=numarray.zeros(shape+shape,numarray.Float64)        out=numarray.zeros(shape+shape,numarray.Float64)
# Line 137  def identity(shape=()): Line 224  def identity(shape=()):
224    
225  def identityTensor(d=3):  def identityTensor(d=3):
226     """     """
227     return the dxd identity matrix     Returns the C{d} x C{d} identity matrix.
228    
229     @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
230                 dimension
231     @type d: C{int}, L{escript.Domain} or L{escript.FunctionSpace}     @type d: C{int}, L{escript.Domain} or L{escript.FunctionSpace}
232     @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}
233     @rtype: L{numarray.NumArray} or L{escript.Data} of rank 2              otherwise
234       @rtype: C{numarray.NumArray} or L{escript.Data} of rank 2
235     """     """
236     if isinstance(d,escript.FunctionSpace):     if isinstance(d,escript.FunctionSpace):
237         return escript.Data(identity((d.getDim(),)),d)         return escript.Data(identity((d.getDim(),)),d)
# Line 153  def identityTensor(d=3): Line 242  def identityTensor(d=3):
242    
243  def identityTensor4(d=3):  def identityTensor4(d=3):
244     """     """
245     return the dxdxdxd identity tensor     Returns the C{d} x C{d} x C{d} x C{d} identity tensor.
246    
247     @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
248                 dimension
249     @type d: C{int} or any object with a C{getDim} method     @type d: C{int} or any object with a C{getDim} method
250     @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
251     @rtype: L{numarray.NumArray} or L{escript.Data} of rank 4.              M{u[i,j,k,l]=0} otherwise
252       @rtype: C{numarray.NumArray} or L{escript.Data} of rank 4
253     """     """
254     if isinstance(d,escript.FunctionSpace):     if isinstance(d,escript.FunctionSpace):
255         return escript.Data(identity((d.getDim(),d.getDim())),d)         return escript.Data(identity((d.getDim(),d.getDim())),d)
# Line 169  def identityTensor4(d=3): Line 260  def identityTensor4(d=3):
260    
261  def unitVector(i=0,d=3):  def unitVector(i=0,d=3):
262     """     """
263     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.
264    
265     @param i: index     @param i: index for non-zero element
266     @type i: C{int}     @type i: C{int}
267     @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
268                 dimension
269     @type d: C{int}, L{escript.Domain} or L{escript.FunctionSpace}     @type d: C{int}, L{escript.Domain} or L{escript.FunctionSpace}
270     @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}
271     @rtype: L{numarray.NumArray} or L{escript.Data} of rank 1              otherwise
272       @rtype: C{numarray.NumArray} or L{escript.Data} of rank 1
273     """     """
274     return kronecker(d)[i]     return kronecker(d)[i]
275    
# Line 185  def unitVector(i=0,d=3): Line 278  def unitVector(i=0,d=3):
278  #=========================================================================  #=========================================================================
279  def Lsup(arg):  def Lsup(arg):
280      """      """
281      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
282      This function is equivalent to sup(abs(arg)).      over all data points. This function is equivalent to C{sup(abs(arg))}.
283    
284      @param arg: argument      @param arg: argument
285      @type arg: C{float}, C{int}, L{escript.Data}, L{numarray.NumArray}.      @type arg: C{float}, C{int}, L{escript.Data}, C{numarray.NumArray}
286      @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
287                 and all data points
288      @rtype: C{float}      @rtype: C{float}
289      @raise TypeError: if type of arg cannot be processed      @raise TypeError: if type of C{arg}cannot be processed
290      """      """
291      if isinstance(arg,numarray.NumArray):      if isinstance(arg,numarray.NumArray):
292          return sup(abs(arg))          return sup(abs(arg))
# Line 207  def Lsup(arg): Line 301  def Lsup(arg):
301    
302  def sup(arg):  def sup(arg):
303      """      """
304      returns the maximum value over all data points.      Returns the maximum value over all data points.
305    
306      @param arg: argument      @param arg: argument
307      @type arg: C{float}, C{int}, L{escript.Data}, L{numarray.NumArray}.      @type arg: C{float}, C{int}, L{escript.Data}, C{numarray.NumArray}
308      @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
309      @rtype: C{float}      @rtype: C{float}
310      @raise TypeError: if type of arg cannot be processed      @raise TypeError: if type of C{arg}cannot be processed
311      """      """
312      if isinstance(arg,numarray.NumArray):      if isinstance(arg,numarray.NumArray):
313          return arg.max()          return arg.max()
# Line 228  def sup(arg): Line 322  def sup(arg):
322    
323  def inf(arg):  def inf(arg):
324      """      """
325      returns the maximum value over all data points.      Returns the minimum value over all data points.
326    
327      @param arg: argument      @param arg: argument
328      @type arg: C{float}, C{int}, L{escript.Data}, L{numarray.NumArray}.      @type arg: C{float}, C{int}, L{escript.Data}, C{numarray.NumArray}
329      @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
330      @rtype: C{float}      @rtype: C{float}
331      @raise TypeError: if type of arg cannot be processed      @raise TypeError: if type of C{arg}cannot be processed
332      """      """
333      if isinstance(arg,numarray.NumArray):      if isinstance(arg,numarray.NumArray):
334          return arg.min()          return arg.min()
# Line 253  def inf(arg): Line 347  def inf(arg):
347  #=========================================================================  #=========================================================================
348  def getRank(arg):  def getRank(arg):
349      """      """
350      identifies the rank of its argument      Identifies the rank of the argument.
351    
352      @param arg: a given object      @param arg: an object whose rank is to be returned
353      @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},
354                   C{Symbol}
355      @return: the rank of the argument      @return: the rank of the argument
356      @rtype: C{int}      @rtype: C{int}
357      @raise TypeError: if type of arg cannot be processed      @raise TypeError: if type of C{arg}cannot be processed
358      """      """
359    
360      if isinstance(arg,numarray.NumArray):      if isinstance(arg,numarray.NumArray):
# Line 273  def getRank(arg): Line 368  def getRank(arg):
368      elif isinstance(arg,Symbol):      elif isinstance(arg,Symbol):
369          return arg.getRank()          return arg.getRank()
370      else:      else:
371        raise TypeError,"getShape: cannot identify shape"        raise TypeError,"getRank: Unknown argument type."
372    
373  def getShape(arg):  def getShape(arg):
374      """      """
375      identifies the shape of its argument      Identifies the shape of the argument.
376    
377      @param arg: a given object      @param arg: an object whose shape is to be returned
378      @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},
379                   C{Symbol}
380      @return: the shape of the argument      @return: the shape of the argument
381      @rtype: C{tuple} of C{int}      @rtype: C{tuple} of C{int}
382      @raise TypeError: if type of arg cannot be processed      @raise TypeError: if type of C{arg}cannot be processed
383      """      """
384    
385      if isinstance(arg,numarray.NumArray):      if isinstance(arg,numarray.NumArray):
# Line 296  def getShape(arg): Line 393  def getShape(arg):
393      elif isinstance(arg,Symbol):      elif isinstance(arg,Symbol):
394          return arg.getShape()          return arg.getShape()
395      else:      else:
396        raise TypeError,"getShape: cannot identify shape"        raise TypeError,"getShape: Cannot identify shape"
397    
398  def pokeDim(arg):  def pokeDim(arg):
399      """      """
400      identifies the spatial dimension of its argument      Identifies the spatial dimension of the argument.
401    
402      @param arg: a given object      @param arg: an object whose spatial dimension is to be returned
403      @type arg: any      @type arg: any
404      @return: the spatial dimension of the argument, if available, or C{None}      @return: the spatial dimension of the argument, if available, or C{None}
405      @rtype: C{int} or C{None}      @rtype: C{int} or C{None}
# Line 315  def pokeDim(arg): Line 412  def pokeDim(arg):
412      else:      else:
413          return None          return None
414    
415  def commonShape(arg0,arg1):  def commonShape(arg0, arg1):
416      """      """
417      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}
418        can be extended from the left.
419    
420      @param arg0: an object with a shape (see L{getShape})      @param arg0: an object with a shape (see L{getShape})
421      @param arg1: an object with a shape (see L{getShape})      @param arg1: an object with a shape (see L{getShape})
422      @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
423                 shape of C{arg0} and the right end equals the shape of C{arg1}
424      @rtype: C{tuple} of C{int}      @rtype: C{tuple} of C{int}
425      @raise ValueError: if no shape can be found.      @raise ValueError: if no shape can be found
426      """      """
427      sh0=getShape(arg0)      sh0=getShape(arg0)
428      sh1=getShape(arg1)      sh1=getShape(arg1)
# Line 342  def commonShape(arg0,arg1): Line 441  def commonShape(arg0,arg1):
441    
442  def commonDim(*args):  def commonDim(*args):
443      """      """
444      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
445        which may or may not have a spatial dimension.
446    
447      @param args: given objects      @param args: given objects
448      @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
449               a spatial dimension C{None} is returned.               (see L{pokeDim}). If none of the objects has a spatial dimension
450                 C{None} is returned.
451      @rtype: C{int} or C{None}      @rtype: C{int} or C{None}
452      @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
453                           the same spatial dimension.
454      """      """
455      out=None      out=None
456      for a in args:      for a in args:
# Line 362  def commonDim(*args): Line 464  def commonDim(*args):
464    
465  def testForZero(arg):  def testForZero(arg):
466      """      """
467      test the argument for being identical to Zero      Tests if the argument is identical to zero.
468    
469      @param arg: a given object      @param arg: the object to test for zero
470      @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}
471      @return: True if the argument is identical to zero.      @return: True if the argument is identical to zero, False otherwise
472      @rtype: C{bool}      @rtype: C{bool}
473      """      """
474      if isinstance(arg,numarray.NumArray):      if isinstance(arg,numarray.NumArray):
# Line 384  def testForZero(arg): Line 486  def testForZero(arg):
486    
487  def matchType(arg0=0.,arg1=0.):  def matchType(arg0=0.,arg1=0.):
488      """      """
489      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
490        L{escript.Data} or, if one of C{arg0} or C{arg1} is of type L{Symbol}, the
491        other one to be of type C{numarray.NumArray} or L{escript.Data}.
492    
493      @param arg0: first argument      @param arg0: first argument
494      @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}
495      @param arg1: second argument      @param arg1: second argument
496      @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}
497      @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
498      @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}
499      @raise TypeError: if type of arg0 or arg1 cannot be processed      @rtype: C{tuple} of two C{numarray.NumArray}, two L{escript.Data},
500                a C{Symbol} and one of the types C{numarray.NumArray} or
501                L{escript.Data}
502        @raise TypeError: if type of C{arg0} or C{arg1} cannot be processed
503      """      """
504      if isinstance(arg0,numarray.NumArray):      if isinstance(arg0,numarray.NumArray):
505         if isinstance(arg1,numarray.NumArray):         if isinstance(arg1,numarray.NumArray):
# Line 406  def matchType(arg0=0.,arg1=0.): Line 513  def matchType(arg0=0.,arg1=0.):
513         elif isinstance(arg1,Symbol):         elif isinstance(arg1,Symbol):
514            pass            pass
515         else:         else:
516            raise TypeError,"function: Unknown type of second argument."                raise TypeError,"function: Unknown type of second argument."
517      elif isinstance(arg0,escript.Data):      elif isinstance(arg0,escript.Data):
518         if isinstance(arg1,numarray.NumArray):         if isinstance(arg1,numarray.NumArray):
519            arg1=escript.Data(arg1,arg0.getFunctionSpace())            arg1=escript.Data(arg1,arg0.getFunctionSpace())
# Line 419  def matchType(arg0=0.,arg1=0.): Line 526  def matchType(arg0=0.,arg1=0.):
526         elif isinstance(arg1,Symbol):         elif isinstance(arg1,Symbol):
527            pass            pass
528         else:         else:
529            raise TypeError,"function: Unknown type of second argument."                raise TypeError,"function: Unknown type of second argument."
530      elif isinstance(arg0,Symbol):      elif isinstance(arg0,Symbol):
531         if isinstance(arg1,numarray.NumArray):         if isinstance(arg1,numarray.NumArray):
532            pass            pass
# Line 432  def matchType(arg0=0.,arg1=0.): Line 539  def matchType(arg0=0.,arg1=0.):
539         elif isinstance(arg1,Symbol):         elif isinstance(arg1,Symbol):
540            pass            pass
541         else:         else:
542            raise TypeError,"function: Unknown type of second argument."                raise TypeError,"function: Unknown type of second argument."
543      elif isinstance(arg0,float):      elif isinstance(arg0,float):
544         if isinstance(arg1,numarray.NumArray):         if isinstance(arg1,numarray.NumArray):
545            arg0=numarray.array(arg0,type=numarray.Float64)            arg0=numarray.array(arg0,type=numarray.Float64)
# Line 447  def matchType(arg0=0.,arg1=0.): Line 554  def matchType(arg0=0.,arg1=0.):
554         elif isinstance(arg1,Symbol):         elif isinstance(arg1,Symbol):
555            arg0=numarray.array(arg0,type=numarray.Float64)            arg0=numarray.array(arg0,type=numarray.Float64)
556         else:         else:
557            raise TypeError,"function: Unknown type of second argument."                raise TypeError,"function: Unknown type of second argument."
558      elif isinstance(arg0,int):      elif isinstance(arg0,int):
559         if isinstance(arg1,numarray.NumArray):         if isinstance(arg1,numarray.NumArray):
560            arg0=numarray.array(float(arg0),type=numarray.Float64)            arg0=numarray.array(float(arg0),type=numarray.Float64)
# Line 462  def matchType(arg0=0.,arg1=0.): Line 569  def matchType(arg0=0.,arg1=0.):
569         elif isinstance(arg1,Symbol):         elif isinstance(arg1,Symbol):
570            arg0=numarray.array(float(arg0),type=numarray.Float64)            arg0=numarray.array(float(arg0),type=numarray.Float64)
571         else:         else:
572            raise TypeError,"function: Unknown type of second argument."                raise TypeError,"function: Unknown type of second argument."
573      else:      else:
574        raise TypeError,"function: Unknown type of first argument."            raise TypeError,"function: Unknown type of first argument."
575    
576      return arg0,arg1      return arg0,arg1
577    
578  def matchShape(arg0,arg1):  def matchShape(arg0,arg1):
579      """      """
580      return representations of arg0 amd arg1 which ahve the same shape      Returns a representation of C{arg0} and C{arg1} which have the same shape.
581    
582      @param arg0: a given object      @param arg0: first argument
583      @type arg0: L{numarray.NumArray},L{escript.Data},C{float}, C{int}, L{Symbol}      @type arg0: C{numarray.NumArray},L{escript.Data},C{float}, C{int}, L{Symbol}
584      @param arg1: a given object      @param arg1: second argument
585      @type arg1: L{numarray.NumArray},L{escript.Data},C{float}, C{int}, L{Symbol}      @type arg1: C{numarray.NumArray},L{escript.Data},C{float}, C{int}, L{Symbol}
586      @return: C{arg0} and C{arg1} where copies are returned when the shape has to be changed.      @return: C{arg0} and C{arg1} where copies are returned when the shape has
587                 to be changed
588      @rtype: C{tuple}      @rtype: C{tuple}
589      """      """
590      sh=commonShape(arg0,arg1)      sh=commonShape(arg0,arg1)
# Line 486  def matchShape(arg0,arg1): Line 594  def matchShape(arg0,arg1):
594         return outer(arg0,numarray.ones(sh[len(sh0):],numarray.Float64)),arg1         return outer(arg0,numarray.ones(sh[len(sh0):],numarray.Float64)),arg1
595      elif len(sh1)<len(sh):      elif len(sh1)<len(sh):
596         return arg0,outer(arg1,numarray.ones(sh[len(sh1):],numarray.Float64))         return arg0,outer(arg1,numarray.ones(sh[len(sh1):],numarray.Float64))
597      else:      else:
598         return arg0,arg1         return arg0,arg1
599    
600  #=========================================================  #=========================================================
601  #   symbolic tool box starts here:  #   symbolic tool box starts here:
602  #=========================================================  #=========================================================
603  class Symbol(object):  class Symbol(object):
604     """     """
605     Symbol class.     Symbol class objects provide the same functionality as C{numarray.NumArray}
606       and L{escript.Data} objects but they do not have a value and therefore
607     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  
608     calculate derivatives with respect to other Symbols used to define a Symbol.     calculate derivatives with respect to other Symbols used to define a Symbol.
609    
610     """     """
611     def __init__(self,shape=(),args=[],dim=None):     def __init__(self,shape=(),args=[],dim=None):
612         """         """
613         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
614         symbols or any other object.         on a list of arguments C{args} which may be symbols or any other object.
615    
616         @param args: the arguments of the symbol.         @param args: the arguments of the symbol
617         @type args: C{list}         @type args: C{list}
618         @param shape: the shape         @param shape: the shape of the symbol
619         @type shape: C{tuple} of C{int}         @type shape: C{tuple} of C{int}
620         @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
621         @type dim: C{None} or C{int}                       dimension is undefined.
622           @type dim: C{None} or C{int}
623    
624         """         """
625         if len(shape)>4:         if len(shape)>4:
626             raise ValueError,"Symbol supports only tensors up to order 4"             raise ValueError,"Symbol only supports tensors up to order 4"
627         self.__args=args         self.__args=args
628         self.__shape=shape         self.__shape=shape
629         self.__dim=dim         self.__dim=dim
630    
631     def getArgument(self,i=None):     def getArgument(self,i=None):
632         """         """
633         returns the i-th argument of the symbol         Returns the i-th argument of the symbol.
634    
635         @param i: index of the argument requested.         @param i: index of the argument requested
636         @type i: C{int} or C{None}         @type i: C{int} or C{None}
637         @raise IndexError: if the requested index does not exist         @raise IndexError: if the requested index does not exist
638         @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
639         @rtype: a single object or a list of objects                  list of all arguments
640           @rtype: a single object or a list of objects
641         """         """
642         if i==None:         if i==None:
643            return self.__args            return self.__args
# Line 538  class Symbol(object): Line 648  class Symbol(object):
648    
649     def getRank(self):     def getRank(self):
650         """         """
651         the rank of the symbol         Returns the rank of the symbol.
652    
653         @return: the rank of the symbol. This is length of the shape         @return: the rank of the symbol. This is length of the shape.
654         @rtype: C{int}         @rtype: C{int}
655         """         """
656         return len(self.getShape())         return len(self.getShape())
657    
658     def getShape(self):     def getShape(self):
659         """         """
660         the shape of the symbol.         Returns the shape of the symbol.
661    
662         @return: the shape of the symbol.         @return: the shape of the symbol
663         @rtype: C{tuple} of C{int}         @rtype: C{tuple} of C{int}
664         """         """
665         return self.__shape         return self.__shape
666    
667     def getDim(self):     def getDim(self):
668         """         """
669         the spatial dimension         Returns the spatial dimension.
670    
671         @return: the spatial dimension         @return: the symbol's spatial dimension
672         @rtype: C{int} if the dimension is defined. Otherwise C{None} is returned.         @rtype: C{int} if the dimension is defined, C{None} otherwise
673         """         """
674         return self.__dim         return self.__dim
675      
676     def __str__(self):     def __str__(self):
677         """         """
678         a string representation of the symbol.         Returns a string representation of the symbol.
679    
680         @return: a string representation of the object         @return: a string representation of the object
681         @rtype: C{str}         @rtype: C{str}
682         """         """
# Line 577  class Symbol(object): Line 688  class Symbol(object):
688         except NotImplementedError:         except NotImplementedError:
689             out="<Symbol %s>"%id(self)             out="<Symbol %s>"%id(self)
690         return out         return out
691          
692     def getSubstitutedArguments(self,argvals):     def getSubstitutedArguments(self,argvals):
693         """         """
694         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
695           result as a list.
696    
697         @param argvals: L{Symbol} 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
698         @type argvals: C{dict} with keywords of type L{Symbol}.                         expression defining this object is replaced by
699                           argvals[u].
700           @type argvals: C{dict} with keywords of type L{Symbol}
701         @rtype: C{list} of objects         @rtype: C{list} of objects
702         @return: list of the object assigned to the arguments through substitution or for the arguments which are not L{Symbol} the value assigned to the argument at instantiation.         @return: list of the object assigned to the arguments through
703                    substitution or for the arguments which are not L{Symbol}s the
704                    value assigned to the argument at instantiation.
705         """         """
706         out=[]         out=[]
707         for a in self.getArgument():         for a in self.getArgument():
# Line 597  class Symbol(object): Line 713  class Symbol(object):
713    
714     def getDifferentiatedArguments(self,arg):     def getDifferentiatedArguments(self,arg):
715         """         """
716         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
717           result as a list.
718    
719         @param arg: the derivative is calculated with respect to arg         @param arg: the derivative is calculated with respect to C{arg}
720         @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},
721                      L{escript.Data}, C{numarray.NumArray} depending on the
722                      involved functions and data
723         @rtype: C{list} of objects         @rtype: C{list} of objects
724         @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
725                    arguments with respect to C{arg}
726         """         """
727         out=[]         out=[]
728         for a in self.getArgument():         for a in self.getArgument():
# Line 618  class Symbol(object): Line 738  class Symbol(object):
738    
739     def isAppropriateValue(self,arg):     def isAppropriateValue(self,arg):
740        """        """
741        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
742        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
743          dimension is defined, the spatial dimension of C{arg}.
744        @param arg: a given object  
745        @type arg: L{numarray.NumArray},L{escript.Data},C{float}, C{int}, C{Symbol}        @param arg: object to be checked
746        @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},
747                     C{Symbol}
748          @return: True if C{arg} is a suitable object to be used for substitution,
749                   False otherwise
750        @rtype: C{bool}        @rtype: C{bool}
751        """        """
752        if isinstance(arg,numarray.NumArray):        if isinstance(arg,numarray.NumArray):
# Line 651  class Symbol(object): Line 774  class Symbol(object):
774    
775     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
776         """         """
777         returns a program code that can be used to evaluate the symbol.         Returns program code that can be used to evaluate the symbol.
778    
779         @param argstrs: gives for each argument a string representing the argument for the evaluation.         @param argstrs: a string for each argument representing the argument
780         @type argstrs: C{list} of C{str}.                         for the evaluation
781         @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}
782           @param format: specifies the format to be used. At the moment only
783                          "escript", "str" and "text" are supported.
784         @type format: C{str}         @type format: C{str}
785         @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
786                    expression assuming the values for the arguments are available
787         @rtype: C{str}         @rtype: C{str}
788         @raise NotImplementedError: if no implementation for the given format is available         @raise NotImplementedError: if no implementation for the given format
789                                       is available
790         @note: This method has to be overwritten by subclasses.         @note: This method has to be overwritten by subclasses.
791         """         """
792         raise NotImplementedError,"no code for %s representation available"%format         raise NotImplementedError,"no code for %s representation available"%format
793    
794     def substitute(self,argvals):     def substitute(self,argvals):
795        """          """
796        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
797        The method replaces the L{Symbol} u by argvals[u] in the expression defining this object.  
798          The method replaces the L{Symbol} u by argvals[u] in the expression
799          defining this object.
800    
801        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
802        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
803        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
804        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
805          @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
806                  depending on the degree of substitution
807        @note: this method has to be overwritten by a particular L{Symbol}        @note: this method has to be overwritten by a particular L{Symbol}
808        @raise NotImplementedError: if no implementation for the given format is available        @raise NotImplementedError: if no implementation for the given format is
809        @raise TypeError: if a value for a L{Symbol} cannot be substituted.                                    available
810          @raise TypeError: if a value for a L{Symbol} cannot be substituted
811        """        """
812        if argvals.has_key(self):        if argvals.has_key(self):
813           arg=argvals[self]           arg=argvals[self]
# Line 688  class Symbol(object): Line 820  class Symbol(object):
820    
821     def diff(self,arg):     def diff(self,arg):
822         """         """
823         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}.
824    
825         @param arg: the derivative is calculated with respect to arg         @param arg: the derivative is calculated with respect to C{arg}
826         @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},
827                      L{escript.Data}, C{numarray.NumArray} depending on the
828                      involved functions and data
829         @return: derivative with respect to C{arg}         @return: derivative with respect to C{arg}
830         @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},
831         @note: this method is overwritten by a particular L{Symbol}                 L{escript.Data}, C{numarray.NumArray} are possible
832           @note: this method is overwritten by a particular L{Symbol}.
833         """         """
834         if arg==self:         if arg==self:
835            return identity(self.getShape())            return identity(self.getShape())
# Line 707  class Symbol(object): Line 842  class Symbol(object):
842    
843     def __neg__(self):     def __neg__(self):
844         """         """
845         returns -self.         Returns -self.
846    
847         @return:  a L{Symbol} representing the negative of the object         @return: a L{Symbol} representing the negative of the object
848         @rtype: L{DependendSymbol}         @rtype: L{DependendSymbol}
849         """         """
850         return self*(-1.)         return self*(-1.)
851    
852     def __pos__(self):     def __pos__(self):
853         """         """
854         returns +self.         Returns +self.
855    
856         @return:  a L{Symbol} representing the positive of the object         @return: a L{Symbol} representing the positive of the object
857         @rtype: L{DependendSymbol}         @rtype: L{DependendSymbol}
858         """         """
859         return self*(1.)         return self*(1.)
860    
861     def __abs__(self):     def __abs__(self):
862         """         """
863         returns a L{Symbol} representing the absolute value of the object.         Returns a L{Symbol} representing the absolute value of the object.
864         """         """
865         return Abs_Symbol(self)         return Abs_Symbol(self)
866    
867     def __add__(self,other):     def __add__(self,other):
868         """         """
869         add another object to this object         Adds another object to this object.
870    
871         @param other: object to be added to this object         @param other: object to be added to this object
872         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
873         @return:  a L{Symbol} representing the sum of this object and C{other}                      C{numarray.NumArray}.
874           @return: a L{Symbol} representing the sum of this object and C{other}
875         @rtype: L{DependendSymbol}         @rtype: L{DependendSymbol}
876         """         """
877         return add(self,other)         return add(self,other)
878    
879     def __radd__(self,other):     def __radd__(self,other):
880         """         """
881         add this object to another object         Adds this object to another object.
882    
883         @param other: object this object is added to         @param other: object to add this object to
884         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
885         @return: a L{Symbol} representing the sum of C{other} and this object object                      C{numarray.NumArray}
886           @return: a L{Symbol} representing the sum of C{other} and this object
887         @rtype: L{DependendSymbol}         @rtype: L{DependendSymbol}
888         """         """
889         return add(other,self)         return add(other,self)
890    
891     def __sub__(self,other):     def __sub__(self,other):
892         """         """
893         subtracts another object from this object         Subtracts another object from this object.
894    
895         @param other: object to be subtracted from this object         @param other: object to be subtracted from this object
896         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
897         @return: a L{Symbol} representing the difference of C{other} and this object                      C{numarray.NumArray}
898           @return: a L{Symbol} representing the difference of C{other} and this
899                    object
900         @rtype: L{DependendSymbol}         @rtype: L{DependendSymbol}
901         """         """
902         return add(self,-other)         return add(self,-other)
903    
904     def __rsub__(self,other):     def __rsub__(self,other):
905         """         """
906         subtracts this object from another object         Subtracts this object from another object.
907    
908         @param other: object this object is been subtracted from         @param other: object this object is to be subtracted from
909         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
910         @return: a L{Symbol} representing the difference of this object and C{other}.                      C{numarray.NumArray}
911           @return: a L{Symbol} representing the difference of this object and
912                    C{other}.
913         @rtype: L{DependendSymbol}         @rtype: L{DependendSymbol}
914         """         """
915         return add(-self,other)         return add(-self,other)
916    
917     def __mul__(self,other):     def __mul__(self,other):
918         """         """
919         multiplies this object with other object         Multiplies this object with another object.
920    
921         @param other: object to be mutiplied by this object         @param other: object to be mutiplied by this object
922         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
923         @return: a L{Symbol} representing the product of the object and C{other}.                      C{numarray.NumArray}
924           @return: a L{Symbol} representing the product of the object and C{other}
925         @rtype: L{DependendSymbol} or 0 if other is identical to zero.         @rtype: L{DependendSymbol} or 0 if other is identical to zero.
926         """         """
927         return mult(self,other)         return mult(self,other)
928    
929     def __rmul__(self,other):     def __rmul__(self,other):
930         """         """
931         multiplies this object with other object         Multiplies another object by this object.
932    
933         @param other: object this object is multiplied with         @param other: object this object is multiplied with
934         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
935         @return: a L{Symbol} representing the product of C{other} and the object.                      C{numarray.NumArray}
936         @rtype: L{DependendSymbol} or 0 if other is identical to zero.         @return: a L{Symbol} representing the product of C{other} and the object
937           @rtype: L{DependendSymbol} or 0 if other is identical to zero
938         """         """
939         return mult(other,self)         return mult(other,self)
940    
941     def __div__(self,other):     def __div__(self,other):
942         """         """
943         divides this object by other object         Divides this object by another object.
944    
945         @param other: object dividing this object         @param other: object dividing this object
946         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
947         @return: a L{Symbol} representing the quotient of this object and C{other}                      C{numarray.NumArray}
948         @rtype: L{DependendSymbol}         @return: a L{Symbol} representing the quotient of this object and
949                    C{other}
950           @rtype: L{DependendSymbol}
951         """         """
952         return quotient(self,other)         return quotient(self,other)
953    
954     def __rdiv__(self,other):     def __rdiv__(self,other):
955         """         """
956         divides this object by other object         Divides another object by this object.
957    
958         @param other: object dividing this object         @param other: object to be divided by this object
959         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
960         @return: a L{Symbol} representing the quotient of C{other} and this object                      C{numarray.NumArray}
961         @rtype: L{DependendSymbol} or 0 if C{other} is identical to zero.         @return: a L{Symbol} representing the quotient of C{other} and this
962                    object
963           @rtype: L{DependendSymbol} or 0 if C{other} is identical to zero
964         """         """
965         return quotient(other,self)         return quotient(other,self)
966    
967     def __pow__(self,other):     def __pow__(self,other):
968         """         """
969         raises this object to the power of other         Raises this object to the power of C{other}.
970    
971         @param other: exponent         @param other: exponent
972         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
973                        C{numarray.NumArray}
974         @return: a L{Symbol} representing the power of this object to C{other}         @return: a L{Symbol} representing the power of this object to C{other}
975         @rtype: L{DependendSymbol} or 1 if C{other} is identical to zero.         @rtype: L{DependendSymbol} or 1 if C{other} is identical to zero
976         """         """
977         return power(self,other)         return power(self,other)
978    
979     def __rpow__(self,other):     def __rpow__(self,other):
980         """         """
981         raises an object to the power of this object         Raises an object to the power of this object.
982    
983         @param other: basis         @param other: basis
984         @type other: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray}.         @type other: L{escript.Symbol}, C{float}, L{escript.Data},
985                        C{numarray.NumArray}
986         @return: a L{Symbol} representing the power of C{other} to this object         @return: a L{Symbol} representing the power of C{other} to this object
987         @rtype: L{DependendSymbol} or 0 if C{other} is identical to zero.         @rtype: L{DependendSymbol} or 0 if C{other} is identical to zero
988         """         """
989         return power(other,self)         return power(other,self)
990    
991     def __getitem__(self,index):     def __getitem__(self,index):
992         """         """
993         returns the slice defined by index         Returns the slice defined by C{index}.
994    
995         @param index: defines a         @param index: the slice index
996         @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
997         @return: a L{Symbol} representing the slice defined by index         @return: a L{Symbol} representing the slice defined by index
998         @rtype: L{DependendSymbol}         @rtype: L{DependendSymbol}
# Line 852  class Symbol(object): Line 1001  class Symbol(object):
1001    
1002  class DependendSymbol(Symbol):  class DependendSymbol(Symbol):
1003     """     """
1004     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
1005     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
1006         same shape, the same arguments and one of them has an unspecified spatial
1007       dimension or the spatial dimension is identical.
1008    
1009     Example::     Example::
1010      
1011       u1=Symbol(shape=(3,4),dim=2,args=[4.])       u1=Symbol(shape=(3,4),dim=2,args=[4.])
1012       u2=Symbol(shape=(3,4),dim=2,args=[4.])       u2=Symbol(shape=(3,4),dim=2,args=[4.])
1013       print u1==u2       print u1==u2
1014       False       False
1015      
1016     but::     but::
1017    
1018       u1=DependendSymbol(shape=(3,4),dim=2,args=[4.])       u1=DependendSymbol(shape=(3,4),dim=2,args=[4.])
1019       u2=DependendSymbol(shape=(3,4),dim=2,args=[4.])       u2=DependendSymbol(shape=(3,4),dim=2,args=[4.])
1020       u3=DependendSymbol(shape=(2,),dim=2,args=[4.])         u3=DependendSymbol(shape=(2,),dim=2,args=[4.])
1021       print u1==u2, u1==u3       print u1==u2, u1==u3
1022       True False       True False
1023    
1024     @note: DependendSymbol should be used as return value of functions with L{Symbol} arguments. This will allow the optimizer to remove redundant function calls.     @note: DependendSymbol should be used as return value of functions with
1025              L{Symbol} arguments. This will allow the optimizer to remove
1026              redundant function calls.
1027     """     """
1028     def __eq__(self,other):     def __eq__(self,other):
1029        """        """
1030        checks if other equals self        Checks if C{other} equals self.
1031    
1032        @param other: any object        @param other: any object
1033        @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
1034                   spatial dimension and the arguments are equal, False otherwise
1035        @rtype: C{bool}        @rtype: C{bool}
1036        """        """
1037        if isinstance(other,DependendSymbol):        if isinstance(other,DependendSymbol):
1038           if self.__class__==other.__class__:             if self.__class__==other.__class__:
1039              if self.getShape()==other.getShape():              if self.getShape()==other.getShape():
1040                if self.getArgument()==other.getArgument():                 if self.getArgument()==other.getArgument():
1041                   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():
1042                      return True                       return True
1043        return False        return False
1044    
1045     def __ne__(self,other):     def __ne__(self,other):
1046        """        """
1047        checks if other equals self        Checks if C{other} is not equal to self.
1048    
1049        @param other: any object        @param other: any object
1050        @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
1051                   spatial dimension and the arguments are equal, True otherwise
1052        @rtype: C{bool}        @rtype: C{bool}
1053        """        """
1054        return not self==other        return not self==other
1055  #=========================================================  #=========================================================
1056  #  Unary operations prserving the shape  #  Unary operations preserving the shape
1057  #========================================================  #========================================================
1058  class GetSlice_Symbol(DependendSymbol):  class GetSlice_Symbol(DependendSymbol):
1059     """     """
1060     L{Symbol} representing getting a slice for a L{Symbol}     L{Symbol} representing getting a slice for a L{Symbol}.
1061     """     """
1062     def __init__(self,arg,index):     def __init__(self,arg,index):
1063        """        """
1064        initialization of wherePositive L{Symbol} with argument arg        Initialization of the L{Symbol} with argument C{arg}.
1065        @param arg: argument  
1066        @type arg: L{Symbol}.        @param arg: argument
1067          @type arg: L{Symbol}
1068        @param index: defines index        @param index: defines index
1069        @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
1070        @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
1071                              index start or stop is out of range
1072        @raises ValueError: if a step is given        @raises ValueError: if a step is given
1073        """        """
1074        if not isinstance(index,tuple): index=(index,)        if not isinstance(index,tuple): index=(index,)
# Line 923  class GetSlice_Symbol(DependendSymbol): Line 1080  class GetSlice_Symbol(DependendSymbol):
1080           ix=index[i]           ix=index[i]
1081           if isinstance(ix,int):           if isinstance(ix,int):
1082              if ix<0 or ix>=arg.getShape()[i]:              if ix<0 or ix>=arg.getShape()[i]:
1083                 raise ValueError,"GetSlice_Symbol: index out of range."                 raise IndexError,"GetSlice_Symbol: index out of range."
1084              index2=index2+(ix,)              index2=index2+(ix,)
1085           else:           else:
1086             if not ix.step==None:             if not ix.step==None:
1087               raise ValueError,"GetSlice_Symbol: steping is not supported."               raise ValueError,"GetSlice_Symbol: stepping is not supported."
1088             if ix.start==None:             if ix.start==None:
1089                s=0                s=0
1090             else:             else:
# Line 950  class GetSlice_Symbol(DependendSymbol): Line 1107  class GetSlice_Symbol(DependendSymbol):
1107    
1108     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1109        """        """
1110        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1111    
1112        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1113        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1114        @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}
1115          @param format: specifies the format to be used. At the moment only
1116                         "escript", "str" and "text" are supported.
1117        @type format: C{str}        @type format: C{str}
1118        @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
1119                   expression assuming the values for the arguments are available
1120        @rtype: C{str}        @rtype: C{str}
1121        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1122                                      is available
1123        """        """
1124        if format=="escript" or format=="str"  or format=="text":        if format=="escript" or format=="str"  or format=="text":
1125           return "%s.__getitem__(%s)"%(argstrs[0],argstrs[1])           return "%s.__getitem__(%s)"%(argstrs[0],argstrs[1])
# Line 967  class GetSlice_Symbol(DependendSymbol): Line 1128  class GetSlice_Symbol(DependendSymbol):
1128    
1129     def substitute(self,argvals):     def substitute(self,argvals):
1130        """        """
1131        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1132        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
1133          defining this object.
1134    
1135        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1136        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1137        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
1138        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
1139        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
1140                  depending on the degree of substitution
1141          @raise TypeError: if a value for a L{Symbol} cannot be substituted
1142        """        """
1143        if argvals.has_key(self):        if argvals.has_key(self):
1144           arg=argvals[self]           arg=argvals[self]
# Line 990  class GetSlice_Symbol(DependendSymbol): Line 1154  class GetSlice_Symbol(DependendSymbol):
1154    
1155  def log10(arg):  def log10(arg):
1156     """     """
1157     returns base-10 logarithm of argument arg     Returns base-10 logarithm of argument C{arg}.
1158    
1159     @param arg: argument     @param arg: argument
1160     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1161     @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
1162     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1163       @raises TypeError: if the type of the argument is not expected
1164     """     """
1165     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1166        return numarray.log10(arg)        return numarray.log10(arg)
# Line 1012  def log10(arg): Line 1177  def log10(arg):
1177    
1178  def wherePositive(arg):  def wherePositive(arg):
1179     """     """
1180     returns mask of positive values of argument arg     Returns mask of positive values of argument C{arg}.
1181    
1182     @param arg: argument     @param arg: argument
1183     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}.
1184     @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
1185     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1186       @raises TypeError: if the type of the argument is not expected
1187     """     """
1188     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1189        out=numarray.greater(arg,numarray.zeros(arg.shape,numarray.Float64))*1.        out=numarray.greater(arg,numarray.zeros(arg.shape,numarray.Float64))*1.
# Line 1042  def wherePositive(arg): Line 1208  def wherePositive(arg):
1208    
1209  class WherePositive_Symbol(DependendSymbol):  class WherePositive_Symbol(DependendSymbol):
1210     """     """
1211     L{Symbol} representing the result of the mask of positive values function     L{Symbol} representing the result of the mask of positive values function.
1212     """     """
1213     def __init__(self,arg):     def __init__(self,arg):
1214        """        """
1215        initialization of wherePositive L{Symbol} with argument arg        Initialization of wherePositive L{Symbol} with argument C{arg}.
1216    
1217        @param arg: argument of function        @param arg: argument of function
1218        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
1219        """        """
1220        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
1221    
1222     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1223        """        """
1224        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1225    
1226        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1227        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1228        @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}
1229          @param format: specifies the format to be used. At the moment only
1230                         "escript", "str" and "text" are supported.
1231        @type format: C{str}        @type format: C{str}
1232        @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
1233                   expression assuming the values for the arguments are available
1234        @rtype: C{str}        @rtype: C{str}
1235        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1236                                      is available
1237        """        """
1238        if isinstance(argstrs,list):        if isinstance(argstrs,list):
1239            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1073  class WherePositive_Symbol(DependendSymb Line 1244  class WherePositive_Symbol(DependendSymb
1244    
1245     def substitute(self,argvals):     def substitute(self,argvals):
1246        """        """
1247        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1248        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
1249          defining this object.
1250    
1251        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1252        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1253        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
1254        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
1255        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
1256                  depending on the degree of substitution
1257          @raise TypeError: if a value for a L{Symbol} cannot be substituted
1258        """        """
1259        if argvals.has_key(self):        if argvals.has_key(self):
1260           arg=argvals[self]           arg=argvals[self]
# Line 1094  class WherePositive_Symbol(DependendSymb Line 1268  class WherePositive_Symbol(DependendSymb
1268    
1269  def whereNegative(arg):  def whereNegative(arg):
1270     """     """
1271     returns mask of positive values of argument arg     Returns mask of negative values of argument C{arg}.
1272    
1273     @param arg: argument     @param arg: argument
1274     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1275     @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
1276     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1277       @raises TypeError: if the type of the argument is not expected
1278     """     """
1279     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1280        out=numarray.less(arg,numarray.zeros(arg.shape,numarray.Float64))*1.        out=numarray.less(arg,numarray.zeros(arg.shape,numarray.Float64))*1.
# Line 1124  def whereNegative(arg): Line 1299  def whereNegative(arg):
1299    
1300  class WhereNegative_Symbol(DependendSymbol):  class WhereNegative_Symbol(DependendSymbol):
1301     """     """
1302     L{Symbol} representing the result of the mask of positive values function     L{Symbol} representing the result of the mask of negative values function.
1303     """     """
1304     def __init__(self,arg):     def __init__(self,arg):
1305        """        """
1306        initialization of whereNegative L{Symbol} with argument arg        Initialization of whereNegative L{Symbol} with argument C{arg}.
1307    
1308        @param arg: argument of function        @param arg: argument of function
1309        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
1310        """        """
1311        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
1312    
1313     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1314        """        """
1315        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1316    
1317        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1318        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1319        @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}
1320          @param format: specifies the format to be used. At the moment only
1321                         "escript", "str" and "text" are supported.
1322        @type format: C{str}        @type format: C{str}
1323        @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
1324                   expression assuming the values for the arguments are available
1325        @rtype: C{str}        @rtype: C{str}
1326        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1327                                      is available
1328        """        """
1329        if isinstance(argstrs,list):        if isinstance(argstrs,list):
1330            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1155  class WhereNegative_Symbol(DependendSymb Line 1335  class WhereNegative_Symbol(DependendSymb
1335    
1336     def substitute(self,argvals):     def substitute(self,argvals):
1337        """        """
1338        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1339        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
1340          defining this object.
1341    
1342        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1343        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1344        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
1345        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
1346        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
1347                  depending on the degree of substitution
1348          @raise TypeError: if a value for a L{Symbol} cannot be substituted
1349        """        """
1350        if argvals.has_key(self):        if argvals.has_key(self):
1351           arg=argvals[self]           arg=argvals[self]
# Line 1176  class WhereNegative_Symbol(DependendSymb Line 1359  class WhereNegative_Symbol(DependendSymb
1359    
1360  def whereNonNegative(arg):  def whereNonNegative(arg):
1361     """     """
1362     returns mask of non-negative values of argument arg     Returns mask of non-negative values of argument C{arg}.
1363    
1364     @param arg: argument     @param arg: argument
1365     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1366     @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
1367     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1368       @raises TypeError: if the type of the argument is not expected
1369     """     """
1370     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1371        out=numarray.greater_equal(arg,numarray.zeros(arg.shape,numarray.Float64))*1.        out=numarray.greater_equal(arg,numarray.zeros(arg.shape,numarray.Float64))*1.
# Line 1206  def whereNonNegative(arg): Line 1390  def whereNonNegative(arg):
1390    
1391  def whereNonPositive(arg):  def whereNonPositive(arg):
1392     """     """
1393     returns mask of non-positive values of argument arg     Returns mask of non-positive values of argument C{arg}.
1394    
1395     @param arg: argument     @param arg: argument
1396     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1397     @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
1398     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1399       @raises TypeError: if the type of the argument is not expected
1400     """     """
1401     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1402        out=numarray.less_equal(arg,numarray.zeros(arg.shape,numarray.Float64))*1.        out=numarray.less_equal(arg,numarray.zeros(arg.shape,numarray.Float64))*1.
# Line 1236  def whereNonPositive(arg): Line 1421  def whereNonPositive(arg):
1421    
1422  def whereZero(arg,tol=0.):  def whereZero(arg,tol=0.):
1423     """     """
1424     returns mask of zero entries of argument arg     Returns mask of zero entries of argument C{arg}.
1425    
1426     @param arg: argument     @param arg: argument
1427     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1428     @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
1429                   as zero.
1430     @type tol: C{float}     @type tol: C{float}
1431     @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
1432     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1433       @raises TypeError: if the type of the argument is not expected
1434     """     """
1435     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1436        out=numarray.less_equal(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float64))*1.        out=numarray.less_equal(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float64))*1.
# Line 1268  def whereZero(arg,tol=0.): Line 1455  def whereZero(arg,tol=0.):
1455    
1456  class WhereZero_Symbol(DependendSymbol):  class WhereZero_Symbol(DependendSymbol):
1457     """     """
1458     L{Symbol} representing the result of the mask of zero entries function     L{Symbol} representing the result of the mask of zero entries function.
1459     """     """
1460     def __init__(self,arg,tol=0.):     def __init__(self,arg,tol=0.):
1461        """        """
1462        initialization of whereZero L{Symbol} with argument arg        Initialization of whereZero L{Symbol} with argument C{arg}.
1463    
1464        @param arg: argument of function        @param arg: argument of function
1465        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
1466        """        """
1467        DependendSymbol.__init__(self,args=[arg,tol],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg,tol],shape=arg.getShape(),dim=arg.getDim())
1468    
1469     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1470        """        """
1471        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1472    
1473        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1474        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1475        @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}
1476          @param format: specifies the format to be used. At the moment only
1477                         "escript", "str" and "text" are supported.
1478        @type format: C{str}        @type format: C{str}
1479        @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
1480                   expression assuming the values for the arguments are available
1481        @rtype: C{str}        @rtype: C{str}
1482        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1483                                      is available
1484        """        """
1485        if format=="escript" or format=="str"  or format=="text":        if format=="escript" or format=="str"  or format=="text":
1486           return "whereZero(%s,tol=%s)"%(argstrs[0],argstrs[1])           return "whereZero(%s,tol=%s)"%(argstrs[0],argstrs[1])
# Line 1297  class WhereZero_Symbol(DependendSymbol): Line 1489  class WhereZero_Symbol(DependendSymbol):
1489    
1490     def substitute(self,argvals):     def substitute(self,argvals):
1491        """        """
1492        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1493        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
1494          defining this object.
1495    
1496        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1497        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1498        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
1499        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
1500        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
1501                  depending on the degree of substitution
1502          @raise TypeError: if a value for a L{Symbol} cannot be substituted
1503        """        """
1504        if argvals.has_key(self):        if argvals.has_key(self):
1505           arg=argvals[self]           arg=argvals[self]
# Line 1318  class WhereZero_Symbol(DependendSymbol): Line 1513  class WhereZero_Symbol(DependendSymbol):
1513    
1514  def whereNonZero(arg,tol=0.):  def whereNonZero(arg,tol=0.):
1515     """     """
1516     returns mask of values different from zero of argument arg     Returns mask of values different from zero of argument C{arg}.
1517    
1518     @param arg: argument     @param arg: argument
1519     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}.
1520     @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
1521     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1522       @raise TypeError: if the type of the argument is not expected
1523     """     """
1524     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1525        out=numarray.greater(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float64))*1.        out=numarray.greater(abs(arg)-tol,numarray.zeros(arg.shape,numarray.Float64))*1.
# Line 1348  def whereNonZero(arg,tol=0.): Line 1544  def whereNonZero(arg,tol=0.):
1544    
1545  def erf(arg):  def erf(arg):
1546     """     """
1547     returns erf of argument arg     Returns the error function M{erf} of argument C{arg}.
1548    
1549     @param arg: argument     @param arg: argument
1550     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}.
1551     @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
1552     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1553       @raise TypeError: if the type of the argument is not expected
1554     """     """
1555     if isinstance(arg,escript.Data):     if isinstance(arg,escript.Data):
1556        return arg._erf()        return arg._erf()
# Line 1362  def erf(arg): Line 1559  def erf(arg):
1559    
1560  def sin(arg):  def sin(arg):
1561     """     """
1562     returns sine of argument arg     Returns sine of argument C{arg}.
1563    
1564     @param arg: argument     @param arg: argument
1565     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}.
1566     @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
1567     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1568       @raise TypeError: if the type of the argument is not expected
1569     """     """
1570     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1571        return numarray.sin(arg)        return numarray.sin(arg)
# Line 1384  def sin(arg): Line 1582  def sin(arg):
1582    
1583  class Sin_Symbol(DependendSymbol):  class Sin_Symbol(DependendSymbol):
1584     """     """
1585     L{Symbol} representing the result of the sine function     L{Symbol} representing the result of the sine function.
1586     """     """
1587     def __init__(self,arg):     def __init__(self,arg):
1588        """        """
1589        initialization of sin L{Symbol} with argument arg        Initialization of sin L{Symbol} with argument C{arg}.
1590    
1591        @param arg: argument of function        @param arg: argument of function
1592        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
1593        """        """
1594        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
1595    
1596     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1597        """        """
1598        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1599    
1600        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1601        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1602        @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}
1603          @param format: specifies the format to be used. At the moment only
1604                         "escript", "str" and "text" are supported.
1605        @type format: C{str}        @type format: C{str}
1606        @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
1607                   expression assuming the values for the arguments are available
1608        @rtype: C{str}        @rtype: C{str}
1609        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1610                                      is available
1611        """        """
1612        if isinstance(argstrs,list):        if isinstance(argstrs,list):
1613            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1415  class Sin_Symbol(DependendSymbol): Line 1618  class Sin_Symbol(DependendSymbol):
1618    
1619     def substitute(self,argvals):     def substitute(self,argvals):
1620        """        """
1621        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1622        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
1623          defining this object.
1624    
1625        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1626        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1627        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
1628        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
1629        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
1630                  depending on the degree of substitution
1631          @raise TypeError: if a value for a L{Symbol} cannot be substituted
1632        """        """
1633        if argvals.has_key(self):        if argvals.has_key(self):
1634           arg=argvals[self]           arg=argvals[self]
# Line 1436  class Sin_Symbol(DependendSymbol): Line 1642  class Sin_Symbol(DependendSymbol):
1642    
1643     def diff(self,arg):     def diff(self,arg):
1644        """        """
1645        differential of this object        Differential of this object.
1646    
1647        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
1648        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
1649        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
1650        @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},
1651                  L{escript.Data}, C{numarray.NumArray} are possible
1652        """        """
1653        if arg==self:        if arg==self:
1654           return identity(self.getShape())           return identity(self.getShape())
# Line 1452  class Sin_Symbol(DependendSymbol): Line 1659  class Sin_Symbol(DependendSymbol):
1659    
1660  def cos(arg):  def cos(arg):
1661     """     """
1662     returns cosine of argument arg     Returns cosine of argument C{arg}.
1663    
1664     @param arg: argument     @param arg: argument
1665     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1666     @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
1667     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1668       @raises TypeError: if the type of the argument is not expected
1669     """     """
1670     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1671        return numarray.cos(arg)        return numarray.cos(arg)
# Line 1474  def cos(arg): Line 1682  def cos(arg):
1682    
1683  class Cos_Symbol(DependendSymbol):  class Cos_Symbol(DependendSymbol):
1684     """     """
1685     L{Symbol} representing the result of the cosine function     L{Symbol} representing the result of the cosine function.
1686     """     """
1687     def __init__(self,arg):     def __init__(self,arg):
1688        """        """
1689        initialization of cos L{Symbol} with argument arg        Initialization of cos L{Symbol} with argument C{arg}.
1690    
1691        @param arg: argument of function        @param arg: argument of function
1692        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
1693        """        """
1694        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
1695    
1696     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1697        """        """
1698        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1699    
1700        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1701        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1702        @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}
1703          @param format: specifies the format to be used. At the moment only
1704                         "escript", "str" and "text" are supported.
1705        @type format: C{str}        @type format: C{str}
1706        @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
1707                   expression assuming the values for the arguments are available
1708        @rtype: C{str}        @rtype: C{str}
1709        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1710                                      is available
1711        """        """
1712        if isinstance(argstrs,list):        if isinstance(argstrs,list):
1713            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1505  class Cos_Symbol(DependendSymbol): Line 1718  class Cos_Symbol(DependendSymbol):
1718    
1719     def substitute(self,argvals):     def substitute(self,argvals):
1720        """        """
1721        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1722        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
1723          defining this object.
1724    
1725        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1726        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1727        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
1728        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
1729        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
1730                  depending on the degree of substitution
1731          @raise TypeError: if a value for a L{Symbol} cannot be substituted
1732        """        """
1733        if argvals.has_key(self):        if argvals.has_key(self):
1734           arg=argvals[self]           arg=argvals[self]
# Line 1526  class Cos_Symbol(DependendSymbol): Line 1742  class Cos_Symbol(DependendSymbol):
1742    
1743     def diff(self,arg):     def diff(self,arg):
1744        """        """
1745        differential of this object        Differential of this object.
1746    
1747        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
1748        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
1749        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
1750        @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},
1751                  L{escript.Data}, C{numarray.NumArray} are possible
1752        """        """
1753        if arg==self:        if arg==self:
1754           return identity(self.getShape())           return identity(self.getShape())
# Line 1542  class Cos_Symbol(DependendSymbol): Line 1759  class Cos_Symbol(DependendSymbol):
1759    
1760  def tan(arg):  def tan(arg):
1761     """     """
1762     returns tangent of argument arg     Returns tangent of argument C{arg}.
1763    
1764     @param arg: argument     @param arg: argument
1765     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1766     @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
1767     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1768       @raises TypeError: if the type of the argument is not expected
1769     """     """
1770     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1771        return numarray.tan(arg)        return numarray.tan(arg)
# Line 1564  def tan(arg): Line 1782  def tan(arg):
1782    
1783  class Tan_Symbol(DependendSymbol):  class Tan_Symbol(DependendSymbol):
1784     """     """
1785     L{Symbol} representing the result of the tangent function     L{Symbol} representing the result of the tangent function.
1786     """     """
1787     def __init__(self,arg):     def __init__(self,arg):
1788        """        """
1789        initialization of tan L{Symbol} with argument arg        Initialization of tan L{Symbol} with argument C{arg}.
1790    
1791        @param arg: argument of function        @param arg: argument of function
1792        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
1793        """        """
1794        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
1795    
1796     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1797        """        """
1798        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1799    
1800        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1801        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1802        @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}
1803          @param format: specifies the format to be used. At the moment only
1804                         "escript", "str" and "text" are supported.
1805        @type format: C{str}        @type format: C{str}
1806        @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
1807                   expression assuming the values for the arguments are available
1808        @rtype: C{str}        @rtype: C{str}
1809        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1810                                      is available
1811        """        """
1812        if isinstance(argstrs,list):        if isinstance(argstrs,list):
1813            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1595  class Tan_Symbol(DependendSymbol): Line 1818  class Tan_Symbol(DependendSymbol):
1818    
1819     def substitute(self,argvals):     def substitute(self,argvals):
1820        """        """
1821        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1822        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
1823          defining this object.
1824    
1825        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1826        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1827        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
1828        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
1829        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
1830                  depending on the degree of substitution
1831          @raise TypeError: if a value for a L{Symbol} cannot be substituted
1832        """        """
1833        if argvals.has_key(self):        if argvals.has_key(self):
1834           arg=argvals[self]           arg=argvals[self]
# Line 1616  class Tan_Symbol(DependendSymbol): Line 1842  class Tan_Symbol(DependendSymbol):
1842    
1843     def diff(self,arg):     def diff(self,arg):
1844        """        """
1845        differential of this object        Differential of this object.
1846    
1847        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
1848        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
1849        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
1850        @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},
1851                  L{escript.Data}, C{numarray.NumArray} are possible
1852        """        """
1853        if arg==self:        if arg==self:
1854           return identity(self.getShape())           return identity(self.getShape())
# Line 1632  class Tan_Symbol(DependendSymbol): Line 1859  class Tan_Symbol(DependendSymbol):
1859    
1860  def asin(arg):  def asin(arg):
1861     """     """
1862     returns inverse sine of argument arg     Returns the inverse sine of argument C{arg}.
1863    
1864     @param arg: argument     @param arg: argument
1865     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1866     @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
1867     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1868       @raises TypeError: if the type of the argument is not expected
1869     """     """
1870     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1871        return numarray.arcsin(arg)        return numarray.arcsin(arg)
# Line 1654  def asin(arg): Line 1882  def asin(arg):
1882    
1883  class Asin_Symbol(DependendSymbol):  class Asin_Symbol(DependendSymbol):
1884     """     """
1885     L{Symbol} representing the result of the inverse sine function     L{Symbol} representing the result of the inverse sine function.
1886     """     """
1887     def __init__(self,arg):     def __init__(self,arg):
1888        """        """
1889        initialization of asin L{Symbol} with argument arg        Initialization of asin L{Symbol} with argument C{arg}.
1890    
1891        @param arg: argument of function        @param arg: argument of function
1892        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
1893        """        """
1894        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
1895    
1896     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1897        """        """
1898        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1899    
1900        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
1901        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
1902        @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}
1903          @param format: specifies the format to be used. At the moment only
1904                         "escript", "str" and "text" are supported.
1905        @type format: C{str}        @type format: C{str}
1906        @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
1907                   expression assuming the values for the arguments are available
1908        @rtype: C{str}        @rtype: C{str}
1909        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
1910                                      is available
1911        """        """
1912        if isinstance(argstrs,list):        if isinstance(argstrs,list):
1913            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1685  class Asin_Symbol(DependendSymbol): Line 1918  class Asin_Symbol(DependendSymbol):
1918    
1919     def substitute(self,argvals):     def substitute(self,argvals):
1920        """        """
1921        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
1922        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
1923          defining this object.
1924    
1925        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
1926        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
1927        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
1928        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
1929        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
1930                  depending on the degree of substitution
1931          @raise TypeError: if a value for a L{Symbol} cannot be substituted
1932        """        """
1933        if argvals.has_key(self):        if argvals.has_key(self):
1934           arg=argvals[self]           arg=argvals[self]
# Line 1706  class Asin_Symbol(DependendSymbol): Line 1942  class Asin_Symbol(DependendSymbol):
1942    
1943     def diff(self,arg):     def diff(self,arg):
1944        """        """
1945        differential of this object        Differential of this object.
1946    
1947        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
1948        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
1949        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
1950        @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},
1951                  L{escript.Data}, C{numarray.NumArray} are possible
1952        """        """
1953        if arg==self:        if arg==self:
1954           return identity(self.getShape())           return identity(self.getShape())
# Line 1722  class Asin_Symbol(DependendSymbol): Line 1959  class Asin_Symbol(DependendSymbol):
1959    
1960  def acos(arg):  def acos(arg):
1961     """     """
1962     returns inverse cosine of argument arg     Returns the inverse cosine of argument C{arg}.
1963    
1964     @param arg: argument     @param arg: argument
1965     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
1966     @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
1967     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
1968       @raises TypeError: if the type of the argument is not expected
1969     """     """
1970     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
1971        return numarray.arccos(arg)        return numarray.arccos(arg)
# Line 1744  def acos(arg): Line 1982  def acos(arg):
1982    
1983  class Acos_Symbol(DependendSymbol):  class Acos_Symbol(DependendSymbol):
1984     """     """
1985     L{Symbol} representing the result of the inverse cosine function     L{Symbol} representing the result of the inverse cosine function.
1986     """     """
1987     def __init__(self,arg):     def __init__(self,arg):
1988        """        """
1989        initialization of acos L{Symbol} with argument arg        Initialization of acos L{Symbol} with argument C{arg}.
1990    
1991        @param arg: argument of function        @param arg: argument of function
1992        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
1993        """        """
1994        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
1995    
1996     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
1997        """        """
1998        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
1999    
2000        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2001        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2002        @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}
2003          @param format: specifies the format to be used. At the moment only
2004                         "escript", "str" and "text" are supported.
2005        @type format: C{str}        @type format: C{str}
2006        @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
2007                   expression assuming the values for the arguments are available
2008        @rtype: C{str}        @rtype: C{str}
2009        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2010                                      is available
2011        """        """
2012        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2013            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1775  class Acos_Symbol(DependendSymbol): Line 2018  class Acos_Symbol(DependendSymbol):
2018    
2019     def substitute(self,argvals):     def substitute(self,argvals):
2020        """        """
2021        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2022        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
2023          defining this object.
2024    
2025        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2026        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2027        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2028        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2029        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2030                  depending on the degree of substitution
2031          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2032        """        """
2033        if argvals.has_key(self):        if argvals.has_key(self):
2034           arg=argvals[self]           arg=argvals[self]
# Line 1796  class Acos_Symbol(DependendSymbol): Line 2042  class Acos_Symbol(DependendSymbol):
2042    
2043     def diff(self,arg):     def diff(self,arg):
2044        """        """
2045        differential of this object        Differential of this object.
2046    
2047        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2048        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2049        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2050        @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},
2051                  L{escript.Data}, C{numarray.NumArray} are possible
2052        """        """
2053        if arg==self:        if arg==self:
2054           return identity(self.getShape())           return identity(self.getShape())
# Line 1812  class Acos_Symbol(DependendSymbol): Line 2059  class Acos_Symbol(DependendSymbol):
2059    
2060  def atan(arg):  def atan(arg):
2061     """     """
2062     returns inverse tangent of argument arg     Returns inverse tangent of argument C{arg}.
2063    
2064     @param arg: argument     @param arg: argument
2065     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2066     @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
2067     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2068       @raises TypeError: if the type of the argument is not expected
2069     """     """
2070     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2071        return numarray.arctan(arg)        return numarray.arctan(arg)
# Line 1834  def atan(arg): Line 2082  def atan(arg):
2082    
2083  class Atan_Symbol(DependendSymbol):  class Atan_Symbol(DependendSymbol):
2084     """     """
2085     L{Symbol} representing the result of the inverse tangent function     L{Symbol} representing the result of the inverse tangent function.
2086     """     """
2087     def __init__(self,arg):     def __init__(self,arg):
2088        """        """
2089        initialization of atan L{Symbol} with argument arg        Initialization of atan L{Symbol} with argument C{arg}.
2090    
2091        @param arg: argument of function        @param arg: argument of function
2092        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2093        """        """
2094        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2095    
2096     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2097        """        """
2098        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2099    
2100        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2101        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2102        @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}
2103          @param format: specifies the format to be used. At the moment only
2104                         "escript", "str" and "text" are supported.
2105        @type format: C{str}        @type format: C{str}
2106        @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
2107                   expression assuming the values for the arguments are available
2108        @rtype: C{str}        @rtype: C{str}
2109        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2110                                      is available
2111        """        """
2112        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2113            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1865  class Atan_Symbol(DependendSymbol): Line 2118  class Atan_Symbol(DependendSymbol):
2118    
2119     def substitute(self,argvals):     def substitute(self,argvals):
2120        """        """
2121        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2122        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
2123          defining this object.
2124    
2125        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2126        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2127        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2128        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2129        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2130                  depending on the degree of substitution
2131          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2132        """        """
2133        if argvals.has_key(self):        if argvals.has_key(self):
2134           arg=argvals[self]           arg=argvals[self]
# Line 1886  class Atan_Symbol(DependendSymbol): Line 2142  class Atan_Symbol(DependendSymbol):
2142    
2143     def diff(self,arg):     def diff(self,arg):
2144        """        """
2145        differential of this object        Differential of this object.
2146    
2147        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2148        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2149        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2150        @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},
2151                  L{escript.Data}, C{numarray.NumArray} are possible
2152        """        """
2153        if arg==self:        if arg==self:
2154           return identity(self.getShape())           return identity(self.getShape())
# Line 1902  class Atan_Symbol(DependendSymbol): Line 2159  class Atan_Symbol(DependendSymbol):
2159    
2160  def sinh(arg):  def sinh(arg):
2161     """     """
2162     returns hyperbolic sine of argument arg     Returns the hyperbolic sine of argument C{arg}.
2163    
2164     @param arg: argument     @param arg: argument
2165     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2166     @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
2167     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2168       @raises TypeError: if the type of the argument is not expected
2169     """     """
2170     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2171        return numarray.sinh(arg)        return numarray.sinh(arg)
# Line 1924  def sinh(arg): Line 2182  def sinh(arg):
2182    
2183  class Sinh_Symbol(DependendSymbol):  class Sinh_Symbol(DependendSymbol):
2184     """     """
2185     L{Symbol} representing the result of the hyperbolic sine function     L{Symbol} representing the result of the hyperbolic sine function.
2186     """     """
2187     def __init__(self,arg):     def __init__(self,arg):
2188        """        """
2189        initialization of sinh L{Symbol} with argument arg        Initialization of sinh L{Symbol} with argument C{arg}.
2190    
2191        @param arg: argument of function        @param arg: argument of function
2192        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2193        """        """
2194        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2195    
2196     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2197        """        """
2198        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2199    
2200        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2201        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2202        @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}
2203          @param format: specifies the format to be used. At the moment only
2204                         "escript", "str" and "text" are supported.
2205        @type format: C{str}        @type format: C{str}
2206        @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
2207                   expression assuming the values for the arguments are available
2208        @rtype: C{str}        @rtype: C{str}
2209        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2210                                      is available
2211        """        """
2212        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2213            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 1955  class Sinh_Symbol(DependendSymbol): Line 2218  class Sinh_Symbol(DependendSymbol):
2218    
2219     def substitute(self,argvals):     def substitute(self,argvals):
2220        """        """
2221        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2222        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
2223          defining this object.
2224    
2225        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2226        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2227        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2228        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2229        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2230                  depending on the degree of substitution
2231          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2232        """        """
2233        if argvals.has_key(self):        if argvals.has_key(self):
2234           arg=argvals[self]           arg=argvals[self]
# Line 1976  class Sinh_Symbol(DependendSymbol): Line 2242  class Sinh_Symbol(DependendSymbol):
2242    
2243     def diff(self,arg):     def diff(self,arg):
2244        """        """
2245        differential of this object        Differential of this object.
2246    
2247        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2248        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2249        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2250        @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},
2251                  L{escript.Data}, C{numarray.NumArray} are possible
2252        """        """
2253        if arg==self:        if arg==self:
2254           return identity(self.getShape())           return identity(self.getShape())
# Line 1992  class Sinh_Symbol(DependendSymbol): Line 2259  class Sinh_Symbol(DependendSymbol):
2259    
2260  def cosh(arg):  def cosh(arg):
2261     """     """
2262     returns hyperbolic cosine of argument arg     Returns the hyperbolic cosine of argument C{arg}.
2263    
2264     @param arg: argument     @param arg: argument
2265     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2266     @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
2267     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2268       @raises TypeError: if the type of the argument is not expected
2269     """     """
2270     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2271        return numarray.cosh(arg)        return numarray.cosh(arg)
# Line 2014  def cosh(arg): Line 2282  def cosh(arg):
2282    
2283  class Cosh_Symbol(DependendSymbol):  class Cosh_Symbol(DependendSymbol):
2284     """     """
2285     L{Symbol} representing the result of the hyperbolic cosine function     L{Symbol} representing the result of the hyperbolic cosine function.
2286     """     """
2287     def __init__(self,arg):     def __init__(self,arg):
2288        """        """
2289        initialization of cosh L{Symbol} with argument arg        Initialization of cosh L{Symbol} with argument C{arg}.
2290    
2291        @param arg: argument of function        @param arg: argument of function
2292        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2293        """        """
2294        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2295    
2296     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2297        """        """
2298        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2299    
2300        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2301        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2302        @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}
2303          @param format: specifies the format to be used. At the moment only
2304                         "escript", "str" and "text" are supported.
2305        @type format: C{str}        @type format: C{str}
2306        @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
2307                   expression assuming the values for the arguments are available
2308        @rtype: C{str}        @rtype: C{str}
2309        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2310                                      is available
2311        """        """
2312        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2313            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2045  class Cosh_Symbol(DependendSymbol): Line 2318  class Cosh_Symbol(DependendSymbol):
2318    
2319     def substitute(self,argvals):     def substitute(self,argvals):
2320        """        """
2321        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2322        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
2323          defining this object.
2324    
2325        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2326        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2327        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2328        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2329        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2330                  depending on the degree of substitution
2331          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2332        """        """
2333        if argvals.has_key(self):        if argvals.has_key(self):
2334           arg=argvals[self]           arg=argvals[self]
# Line 2066  class Cosh_Symbol(DependendSymbol): Line 2342  class Cosh_Symbol(DependendSymbol):
2342    
2343     def diff(self,arg):     def diff(self,arg):
2344        """        """
2345        differential of this object        Differential of this object.
2346    
2347        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2348        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2349        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2350        @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},
2351                  L{escript.Data}, C{numarray.NumArray} are possible
2352        """        """
2353        if arg==self:        if arg==self:
2354           return identity(self.getShape())           return identity(self.getShape())
# Line 2082  class Cosh_Symbol(DependendSymbol): Line 2359  class Cosh_Symbol(DependendSymbol):
2359    
2360  def tanh(arg):  def tanh(arg):
2361     """     """
2362     returns hyperbolic tangent of argument arg     Returns the hyperbolic tangent of argument C{arg}.
2363    
2364     @param arg: argument     @param arg: argument
2365     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2366     @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
2367     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2368       @raises TypeError: if the type of the argument is not expected
2369     """     """
2370     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2371        return numarray.tanh(arg)        return numarray.tanh(arg)
# Line 2104  def tanh(arg): Line 2382  def tanh(arg):
2382    
2383  class Tanh_Symbol(DependendSymbol):  class Tanh_Symbol(DependendSymbol):
2384     """     """
2385     L{Symbol} representing the result of the hyperbolic tangent function     L{Symbol} representing the result of the hyperbolic tangent function.
2386     """     """
2387     def __init__(self,arg):     def __init__(self,arg):
2388        """        """
2389        initialization of tanh L{Symbol} with argument arg        Initialization of tanh L{Symbol} with argument C{arg}.
2390    
2391        @param arg: argument of function        @param arg: argument of function
2392        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2393        """        """
2394        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2395    
2396     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2397        """        """
2398        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2399    
2400        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2401        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2402        @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}
2403          @param format: specifies the format to be used. At the moment only
2404                         "escript", "str" and "text" are supported.
2405        @type format: C{str}        @type format: C{str}
2406        @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
2407                   expression assuming the values for the arguments are available
2408        @rtype: C{str}        @rtype: C{str}
2409        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2410                                      is available
2411        """        """
2412        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2413            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2135  class Tanh_Symbol(DependendSymbol): Line 2418  class Tanh_Symbol(DependendSymbol):
2418    
2419     def substitute(self,argvals):     def substitute(self,argvals):
2420        """        """
2421        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2422        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
2423          defining this object.
2424    
2425        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2426        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2427        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2428        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2429        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2430                  depending on the degree of substitution
2431          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2432        """        """
2433        if argvals.has_key(self):        if argvals.has_key(self):
2434           arg=argvals[self]           arg=argvals[self]
# Line 2156  class Tanh_Symbol(DependendSymbol): Line 2442  class Tanh_Symbol(DependendSymbol):
2442    
2443     def diff(self,arg):     def diff(self,arg):
2444        """        """
2445        differential of this object        Differential of this object.
2446    
2447        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2448        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2449        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2450        @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},
2451                  L{escript.Data}, C{numarray.NumArray} are possible
2452        """        """
2453        if arg==self:        if arg==self:
2454           return identity(self.getShape())           return identity(self.getShape())
# Line 2172  class Tanh_Symbol(DependendSymbol): Line 2459  class Tanh_Symbol(DependendSymbol):
2459    
2460  def asinh(arg):  def asinh(arg):
2461     """     """
2462     returns inverse hyperbolic sine of argument arg     Returns the inverse hyperbolic sine of argument C{arg}.
2463    
2464     @param arg: argument     @param arg: argument
2465     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2466     @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
2467     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2468       @raises TypeError: if the type of the argument is not expected
2469     """     """
2470     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2471        return numarray.arcsinh(arg)        return numarray.arcsinh(arg)
# Line 2194  def asinh(arg): Line 2482  def asinh(arg):
2482    
2483  class Asinh_Symbol(DependendSymbol):  class Asinh_Symbol(DependendSymbol):
2484     """     """
2485     L{Symbol} representing the result of the inverse hyperbolic sine function     L{Symbol} representing the result of the inverse hyperbolic sine function.
2486     """     """
2487     def __init__(self,arg):     def __init__(self,arg):
2488        """        """
2489        initialization of asinh L{Symbol} with argument arg        Initialization of asinh L{Symbol} with argument C{arg}.
2490    
2491        @param arg: argument of function        @param arg: argument of function
2492        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2493        """        """
2494        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2495    
2496     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2497        """        """
2498        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2499    
2500        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2501        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2502        @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}
2503          @param format: specifies the format to be used. At the moment only
2504                         "escript", "str" and "text" are supported.
2505        @type format: C{str}        @type format: C{str}
2506        @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
2507                   expression assuming the values for the arguments are available
2508        @rtype: C{str}        @rtype: C{str}
2509        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2510                                      is available
2511        """        """
2512        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2513            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2225  class Asinh_Symbol(DependendSymbol): Line 2518  class Asinh_Symbol(DependendSymbol):
2518    
2519     def substitute(self,argvals):     def substitute(self,argvals):
2520        """        """
2521        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2522        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
2523          defining this object.
2524    
2525        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2526        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2527        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2528        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2529        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2530                  depending on the degree of substitution
2531          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2532        """        """
2533        if argvals.has_key(self):        if argvals.has_key(self):
2534           arg=argvals[self]           arg=argvals[self]
# Line 2246  class Asinh_Symbol(DependendSymbol): Line 2542  class Asinh_Symbol(DependendSymbol):
2542    
2543     def diff(self,arg):     def diff(self,arg):
2544        """        """
2545        differential of this object        Differential of this object.
2546    
2547        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2548        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2549        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2550        @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},
2551                  L{escript.Data}, C{numarray.NumArray} are possible
2552        """        """
2553        if arg==self:        if arg==self:
2554           return identity(self.getShape())           return identity(self.getShape())
# Line 2262  class Asinh_Symbol(DependendSymbol): Line 2559  class Asinh_Symbol(DependendSymbol):
2559    
2560  def acosh(arg):  def acosh(arg):
2561     """     """
2562     returns inverse hyperolic cosine of argument arg     Returns the inverse hyperbolic cosine of argument C{arg}.
2563    
2564     @param arg: argument     @param arg: argument
2565     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2566     @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
2567     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2568       @raises TypeError: if the type of the argument is not expected
2569     """     """
2570     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2571        return numarray.arccosh(arg)        return numarray.arccosh(arg)
# Line 2284  def acosh(arg): Line 2582  def acosh(arg):
2582    
2583  class Acosh_Symbol(DependendSymbol):  class Acosh_Symbol(DependendSymbol):
2584     """     """
2585     L{Symbol} representing the result of the inverse hyperolic cosine function     L{Symbol} representing the result of the inverse hyperbolic cosine function.
2586     """     """
2587     def __init__(self,arg):     def __init__(self,arg):
2588        """        """
2589        initialization of acosh L{Symbol} with argument arg        Initialization of acosh L{Symbol} with argument C{arg}.
2590    
2591        @param arg: argument of function        @param arg: argument of function
2592        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2593        """        """
2594        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2595    
2596     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2597        """        """
2598        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2599    
2600        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2601        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2602        @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}
2603          @param format: specifies the format to be used. At the moment only
2604                         "escript", "str" and "text" are supported.
2605        @type format: C{str}        @type format: C{str}
2606        @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
2607                   expression assuming the values for the arguments are available
2608        @rtype: C{str}        @rtype: C{str}
2609        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2610                                      is available
2611        """        """
2612        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2613            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2315  class Acosh_Symbol(DependendSymbol): Line 2618  class Acosh_Symbol(DependendSymbol):
2618    
2619     def substitute(self,argvals):     def substitute(self,argvals):
2620        """        """
2621        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2622        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
2623          defining this object.
2624    
2625        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2626        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2627        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2628        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2629        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2630                  depending on the degree of substitution
2631          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2632        """        """
2633        if argvals.has_key(self):        if argvals.has_key(self):
2634           arg=argvals[self]           arg=argvals[self]
# Line 2336  class Acosh_Symbol(DependendSymbol): Line 2642  class Acosh_Symbol(DependendSymbol):
2642    
2643     def diff(self,arg):     def diff(self,arg):
2644        """        """
2645        differential of this object        Differential of this object.
2646    
2647        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2648        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2649        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2650        @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},
2651                  L{escript.Data}, C{numarray.NumArray} are possible
2652        """        """
2653        if arg==self:        if arg==self:
2654           return identity(self.getShape())           return identity(self.getShape())
# Line 2352  class Acosh_Symbol(DependendSymbol): Line 2659  class Acosh_Symbol(DependendSymbol):
2659    
2660  def atanh(arg):  def atanh(arg):
2661     """     """
2662     returns inverse hyperbolic tangent of argument arg     Returns the inverse hyperbolic tangent of argument C{arg}.
2663    
2664     @param arg: argument     @param arg: argument
2665     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2666     @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
2667     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2668       @raises TypeError: if the type of the argument is not expected
2669     """     """
2670     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2671        return numarray.arctanh(arg)        return numarray.arctanh(arg)
# Line 2374  def atanh(arg): Line 2682  def atanh(arg):
2682    
2683  class Atanh_Symbol(DependendSymbol):  class Atanh_Symbol(DependendSymbol):
2684     """     """
2685     L{Symbol} representing the result of the inverse hyperbolic tangent function     L{Symbol} representing the result of the inverse hyperbolic tangent function.
2686     """     """
2687     def __init__(self,arg):     def __init__(self,arg):
2688        """        """
2689        initialization of atanh L{Symbol} with argument arg        Initialization of atanh L{Symbol} with argument C{arg}.
2690    
2691        @param arg: argument of function        @param arg: argument of function
2692        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2693        """        """
2694        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2695    
2696     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2697        """        """
2698        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2699    
2700        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2701        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2702        @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}
2703          @param format: specifies the format to be used. At the moment only
2704                         "escript", "str" and "text" are supported.
2705        @type format: C{str}        @type format: C{str}
2706        @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
2707                   expression assuming the values for the arguments are available
2708        @rtype: C{str}        @rtype: C{str}
2709        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2710                                      is available
2711        """        """
2712        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2713            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2405  class Atanh_Symbol(DependendSymbol): Line 2718  class Atanh_Symbol(DependendSymbol):
2718    
2719     def substitute(self,argvals):     def substitute(self,argvals):
2720        """        """
2721        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2722        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
2723          defining this object.
2724    
2725        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2726        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2727        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2728        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2729        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2730                  depending on the degree of substitution
2731          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2732        """        """
2733        if argvals.has_key(self):        if argvals.has_key(self):
2734           arg=argvals[self]           arg=argvals[self]
# Line 2426  class Atanh_Symbol(DependendSymbol): Line 2742  class Atanh_Symbol(DependendSymbol):
2742    
2743     def diff(self,arg):     def diff(self,arg):
2744        """        """
2745        differential of this object        Differential of this object.
2746    
2747        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2748        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2749        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2750        @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},
2751                  L{escript.Data}, C{numarray.NumArray} are possible
2752        """        """
2753        if arg==self:        if arg==self:
2754           return identity(self.getShape())           return identity(self.getShape())
# Line 2442  class Atanh_Symbol(DependendSymbol): Line 2759  class Atanh_Symbol(DependendSymbol):
2759    
2760  def exp(arg):  def exp(arg):
2761     """     """
2762     returns exponential of argument arg     Returns M{e} to the power of argument C{arg}.
2763    
2764     @param arg: argument     @param arg: argument
2765     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}.
2766     @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
2767     @raises TypeError: if the type of the argument is not expected.             on the type of arg
2768       @raises TypeError: if the type of the argument is not expected
2769     """     """
2770     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2771        return numarray.exp(arg)        return numarray.exp(arg)
# Line 2464  def exp(arg): Line 2782  def exp(arg):
2782    
2783  class Exp_Symbol(DependendSymbol):  class Exp_Symbol(DependendSymbol):
2784     """     """
2785     L{Symbol} representing the result of the exponential function     L{Symbol} representing the result of the exponential function.
2786     """     """
2787     def __init__(self,arg):     def __init__(self,arg):
2788        """        """
2789        initialization of exp L{Symbol} with argument arg        Initialization of exp L{Symbol} with argument C{arg}.
2790    
2791        @param arg: argument of function        @param arg: argument of function
2792        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2793        """        """
2794        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2795    
2796     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2797        """        """
2798        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2799    
2800        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2801        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2802        @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}
2803          @param format: specifies the format to be used. At the moment only
2804                         "escript", "str" and "text" are supported.
2805        @type format: C{str}        @type format: C{str}
2806        @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
2807                   expression assuming the values for the arguments are available
2808        @rtype: C{str}        @rtype: C{str}
2809        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2810                                      is available
2811        """        """
2812        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2813            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2495  class Exp_Symbol(DependendSymbol): Line 2818  class Exp_Symbol(DependendSymbol):
2818    
2819     def substitute(self,argvals):     def substitute(self,argvals):
2820        """        """
2821        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2822        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
2823          defining this object.
2824    
2825        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2826        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2827        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2828        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2829        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2830                  depending on the degree of substitution
2831          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2832        """        """
2833        if argvals.has_key(self):        if argvals.has_key(self):
2834           arg=argvals[self]           arg=argvals[self]
# Line 2516  class Exp_Symbol(DependendSymbol): Line 2842  class Exp_Symbol(DependendSymbol):
2842    
2843     def diff(self,arg):     def diff(self,arg):
2844        """        """
2845        differential of this object        Differential of this object.
2846    
2847        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2848        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2849        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2850        @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},
2851                  L{escript.Data}, C{numarray.NumArray} are possible
2852        """        """
2853        if arg==self:        if arg==self:
2854           return identity(self.getShape())           return identity(self.getShape())
# Line 2532  class Exp_Symbol(DependendSymbol): Line 2859  class Exp_Symbol(DependendSymbol):
2859    
2860  def sqrt(arg):  def sqrt(arg):
2861     """     """
2862     returns square root of argument arg     Returns the square root of argument C{arg}.
2863    
2864     @param arg: argument     @param arg: argument
2865     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
2866     @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}
2867     @raises TypeError: if the type of the argument is not expected.             depending on the type of C{arg}
2868       @raises TypeError: if the type of the argument is not expected
2869     """     """
2870     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2871        return numarray.sqrt(arg)        return numarray.sqrt(arg)
# Line 2554  def sqrt(arg): Line 2882  def sqrt(arg):
2882    
2883  class Sqrt_Symbol(DependendSymbol):  class Sqrt_Symbol(DependendSymbol):
2884     """     """
2885     L{Symbol} representing the result of the square root function     L{Symbol} representing the result of the square root function.
2886     """     """
2887     def __init__(self,arg):     def __init__(self,arg):
2888        """        """
2889        initialization of sqrt L{Symbol} with argument arg        Initialization of sqrt L{Symbol} with argument C{arg}.
2890    
2891        @param arg: argument of function        @param arg: argument of function
2892        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2893        """        """
2894        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2895    
2896     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2897        """        """
2898        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2899    
2900        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
2901        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
2902        @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}
2903          @param format: specifies the format to be used. At the moment only
2904                         "escript", "str" and "text" are supported.
2905        @type format: C{str}        @type format: C{str}
2906        @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
2907                   expression assuming the values for the arguments are available
2908        @rtype: C{str}        @rtype: C{str}
2909        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
2910                                      is available
2911        """        """
2912        if isinstance(argstrs,list):        if isinstance(argstrs,list):
2913            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2585  class Sqrt_Symbol(DependendSymbol): Line 2918  class Sqrt_Symbol(DependendSymbol):
2918    
2919     def substitute(self,argvals):     def substitute(self,argvals):
2920        """        """
2921        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
2922        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
2923          defining this object.
2924    
2925        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
2926        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
2927        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
2928        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
2929        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
2930                  depending on the degree of substitution
2931          @raise TypeError: if a value for a L{Symbol} cannot be substituted
2932        """        """
2933        if argvals.has_key(self):        if argvals.has_key(self):
2934           arg=argvals[self]           arg=argvals[self]
# Line 2606  class Sqrt_Symbol(DependendSymbol): Line 2942  class Sqrt_Symbol(DependendSymbol):
2942    
2943     def diff(self,arg):     def diff(self,arg):
2944        """        """
2945        differential of this object        Differential of this object.
2946    
2947        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
2948        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
2949        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
2950        @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},
2951                  L{escript.Data}, C{numarray.NumArray} are possible
2952        """        """
2953        if arg==self:        if arg==self:
2954           return identity(self.getShape())           return identity(self.getShape())
# Line 2622  class Sqrt_Symbol(DependendSymbol): Line 2959  class Sqrt_Symbol(DependendSymbol):
2959    
2960  def log(arg):  def log(arg):
2961     """     """
2962     returns natural logarithm of argument arg     Returns the natural logarithm of argument C{arg}.
2963    
2964     @param arg: argument     @param arg: argument
2965     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}.
2966     @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
2967     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
2968       @raises TypeError: if the type of the argument is not expected
2969     """     """
2970     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
2971        return numarray.log(arg)        return numarray.log(arg)
# Line 2644  def log(arg): Line 2982  def log(arg):
2982    
2983  class Log_Symbol(DependendSymbol):  class Log_Symbol(DependendSymbol):
2984     """     """
2985     L{Symbol} representing the result of the natural logarithm function     L{Symbol} representing the result of the natural logarithm function.
2986     """     """
2987     def __init__(self,arg):     def __init__(self,arg):
2988        """        """
2989        initialization of log L{Symbol} with argument arg        Initialization of log L{Symbol} with argument C{arg}.
2990    
2991        @param arg: argument of function        @param arg: argument of function
2992        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
2993        """        """
2994        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
2995    
2996     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
2997        """        """
2998        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
2999    
3000        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
3001        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
3002        @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}
3003          @param format: specifies the format to be used. At the moment only
3004                         "escript", "str" and "text" are supported.
3005        @type format: C{str}        @type format: C{str}
3006        @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
3007                   expression assuming the values for the arguments are available
3008        @rtype: C{str}        @rtype: C{str}
3009        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
3010                                      is available
3011        """        """
3012        if isinstance(argstrs,list):        if isinstance(argstrs,list):
3013            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2675  class Log_Symbol(DependendSymbol): Line 3018  class Log_Symbol(DependendSymbol):
3018    
3019     def substitute(self,argvals):     def substitute(self,argvals):
3020        """        """
3021        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
3022        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
3023          defining this object.
3024    
3025        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
3026        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
3027        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
3028        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
3029        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
3030                  depending on the degree of substitution
3031          @raise TypeError: if a value for a L{Symbol} cannot be substituted
3032        """        """
3033        if argvals.has_key(self):        if argvals.has_key(self):
3034           arg=argvals[self]           arg=argvals[self]
# Line 2696  class Log_Symbol(DependendSymbol): Line 3042  class Log_Symbol(DependendSymbol):
3042    
3043     def diff(self,arg):     def diff(self,arg):
3044        """        """
3045        differential of this object        Differential of this object.
3046    
3047        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
3048        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
3049        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
3050        @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},
3051                  L{escript.Data}, C{numarray.NumArray} are possible
3052        """        """
3053        if arg==self:        if arg==self:
3054           return identity(self.getShape())           return identity(self.getShape())
# Line 2712  class Log_Symbol(DependendSymbol): Line 3059  class Log_Symbol(DependendSymbol):
3059    
3060  def sign(arg):  def sign(arg):
3061     """     """
3062     returns sign of argument arg     Returns the sign of argument C{arg}.
3063    
3064     @param arg: argument     @param arg: argument
3065     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
3066     @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
3067     @raises TypeError: if the type of the argument is not expected.             on the type of C{arg}
3068       @raises TypeError: if the type of the argument is not expected
3069     """     """
3070     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
3071        return wherePositive(arg)-whereNegative(arg)        return wherePositive(arg)-whereNegative(arg)
# Line 2744  def sign(arg): Line 3092  def sign(arg):
3092    
3093  class Abs_Symbol(DependendSymbol):  class Abs_Symbol(DependendSymbol):
3094     """     """
3095     L{Symbol} representing the result of the absolute value function     L{Symbol} representing the result of the absolute value function.
3096     """     """
3097     def __init__(self,arg):     def __init__(self,arg):
3098        """        """
3099        initialization of abs L{Symbol} with argument arg        Initialization of abs L{Symbol} with argument C{arg}.
3100    
3101        @param arg: argument of function        @param arg: argument of function
3102        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
3103        """        """
3104        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=arg.getShape(),dim=arg.getDim())
3105    
3106     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
3107        """        """
3108        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
3109    
3110        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
3111        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
3112        @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}
3113          @param format: specifies the format to be used. At the moment only
3114                         "escript", "str" and "text" are supported.
3115        @type format: C{str}        @type format: C{str}
3116        @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
3117                   expression assuming the values for the arguments are available
3118        @rtype: C{str}        @rtype: C{str}
3119        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
3120                                      is available
3121        """        """
3122        if isinstance(argstrs,list):        if isinstance(argstrs,list):
3123            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2775  class Abs_Symbol(DependendSymbol): Line 3128  class Abs_Symbol(DependendSymbol):
3128    
3129     def substitute(self,argvals):     def substitute(self,argvals):
3130        """        """
3131        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
3132        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
3133          defining this object.
3134    
3135        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
3136        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
3137        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
3138        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
3139        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
3140                  depending on the degree of substitution
3141          @raise TypeError: if a value for a L{Symbol} cannot be substituted
3142        """        """
3143        if argvals.has_key(self):        if argvals.has_key(self):
3144           arg=argvals[self]           arg=argvals[self]
# Line 2796  class Abs_Symbol(DependendSymbol): Line 3152  class Abs_Symbol(DependendSymbol):
3152    
3153     def diff(self,arg):     def diff(self,arg):
3154        """        """
3155        differential of this object        Differential of this object.
3156    
3157        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
3158        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
3159        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
3160        @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},
3161                  L{escript.Data}, C{numarray.NumArray} are possible
3162        """        """
3163        if arg==self:        if arg==self:
3164           return identity(self.getShape())           return identity(self.getShape())
# Line 2812  class Abs_Symbol(DependendSymbol): Line 3169  class Abs_Symbol(DependendSymbol):
3169    
3170  def minval(arg):  def minval(arg):
3171     """     """
3172     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.
3173    
3174     @param arg: argument     @param arg: argument
3175     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
3176     @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}
3177     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected
3178     """     """
3179     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
3180        if arg.rank==0:        if arg.rank==0:
# Line 2837  def minval(arg): Line 3194  def minval(arg):
3194    
3195  class Minval_Symbol(DependendSymbol):  class Minval_Symbol(DependendSymbol):
3196     """     """
3197     L{Symbol} representing the result of the minimum value function     L{Symbol} representing the result of the minimum value function.
3198     """     """
3199     def __init__(self,arg):     def __init__(self,arg):
3200        """        """
3201        initialization of minimum value L{Symbol} with argument arg        Initialization of minimum value L{Symbol} with argument C{arg}.
3202    
3203        @param arg: argument of function        @param arg: argument of function
3204        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
3205        """        """
3206        DependendSymbol.__init__(self,args=[arg],shape=(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=(),dim=arg.getDim())
3207    
3208     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
3209        """        """
3210        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
3211    
3212        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
3213        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
3214        @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}
3215          @param format: specifies the format to be used. At the moment only
3216                         "escript", "str" and "text" are supported.
3217        @type format: C{str}        @type format: C{str}
3218        @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
3219                   expression assuming the values for the arguments are available
3220        @rtype: C{str}        @rtype: C{str}
3221        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
3222                                      is available
3223        """        """
3224        if isinstance(argstrs,list):        if isinstance(argstrs,list):
3225            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2868  class Minval_Symbol(DependendSymbol): Line 3230  class Minval_Symbol(DependendSymbol):
3230    
3231     def substitute(self,argvals):     def substitute(self,argvals):
3232        """        """
3233        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
3234        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
3235          defining this object.
3236    
3237        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
3238        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
3239        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
3240        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
3241        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
3242                  depending on the degree of substitution
3243          @raise TypeError: if a value for a L{Symbol} cannot be substituted
3244        """        """
3245        if argvals.has_key(self):        if argvals.has_key(self):
3246           arg=argvals[self]           arg=argvals[self]
# Line 2889  class Minval_Symbol(DependendSymbol): Line 3254  class Minval_Symbol(DependendSymbol):
3254    
3255  def maxval(arg):  def maxval(arg):
3256     """     """
3257     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.
3258    
3259     @param arg: argument     @param arg: argument
3260     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
3261     @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}
3262     @raises TypeError: if the type of the argument is not expected.     @raises TypeError: if the type of the argument is not expected
3263     """     """
3264     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
3265        if arg.rank==0:        if arg.rank==0:
# Line 2914  def maxval(arg): Line 3279  def maxval(arg):
3279    
3280  class Maxval_Symbol(DependendSymbol):  class Maxval_Symbol(DependendSymbol):
3281     """     """
3282     L{Symbol} representing the result of the maximum value function     L{Symbol} representing the result of the maximum value function.
3283     """     """
3284     def __init__(self,arg):     def __init__(self,arg):
3285        """        """
3286        initialization of maximum value L{Symbol} with argument arg        Initialization of maximum value L{Symbol} with argument C{arg}.
3287    
3288        @param arg: argument of function        @param arg: argument of function
3289        @type arg: typically L{Symbol}.        @type arg: typically L{Symbol}
3290        """        """
3291        DependendSymbol.__init__(self,args=[arg],shape=(),dim=arg.getDim())        DependendSymbol.__init__(self,args=[arg],shape=(),dim=arg.getDim())
3292    
3293     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
3294        """        """
3295        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
3296    
3297        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
3298        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
3299        @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}
3300          @param format: specifies the format to be used. At the moment only
3301                         "escript", "str" and "text" are supported.
3302        @type format: C{str}        @type format: C{str}
3303        @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
3304                   expression assuming the values for the arguments are available
3305        @rtype: C{str}        @rtype: C{str}
3306        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
3307                                      is available
3308        """        """
3309        if isinstance(argstrs,list):        if isinstance(argstrs,list):
3310            argstrs=argstrs[0]            argstrs=argstrs[0]
# Line 2945  class Maxval_Symbol(DependendSymbol): Line 3315  class Maxval_Symbol(DependendSymbol):
3315    
3316     def substitute(self,argvals):     def substitute(self,argvals):
3317        """        """
3318        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
3319        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
3320          defining this object.
3321    
3322        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
3323        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
3324        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
3325        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
3326        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
3327                  depending on the degree of substitution
3328          @raise TypeError: if a value for a L{Symbol} cannot be substituted
3329        """        """
3330        if argvals.has_key(self):        if argvals.has_key(self):
3331           arg=argvals[self]           arg=argvals[self]
# Line 2966  class Maxval_Symbol(DependendSymbol): Line 3339  class Maxval_Symbol(DependendSymbol):
3339    
3340  def length(arg):  def length(arg):
3341     """     """
3342     returns length/Euclidean norm of argument arg at each data point     Returns the length (Euclidean norm) of argument C{arg} at each data point.
3343    
3344     @param arg: argument     @param arg: argument
3345     @type arg: C{float}, L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: C{float}, L{escript.Data}, L{Symbol}, C{numarray.NumArray}
3346     @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}
3347     """     """
3348     return sqrt(inner(arg,arg))     return sqrt(inner(arg,arg))
3349    
3350  def trace(arg,axis_offset=0):  def trace(arg,axis_offset=0):
3351     """     """
3352     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.
3353    
3354     @param arg: argument     @param arg: argument
3355     @type arg: L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: L{escript.Data}, L{Symbol}, C{numarray.NumArray}
3356     @param axis_offset: C{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}
3357                    C{axis_offset} and axis_offset+1 must be equal.                         must be non-negative and less than the rank of C{arg} +1.
3358                           The dimensions of component C{axis_offset} and
3359                           axis_offset+1 must be equal.
3360     @type axis_offset: C{int}     @type axis_offset: C{int}
3361     @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}
3362     @rtype: L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.              minus 2.
3363       @rtype: L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending on the
3364               type of C{arg}
3365     """     """
3366     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
3367        sh=arg.shape        sh=arg.shape
3368        if len(sh)<2:        if len(sh)<2:
3369          raise ValueError,"rank of argument must be greater than 1"          raise ValueError,"rank of argument must be greater than 1"
3370        if axis_offset<0 or axis_offset>len(sh)-2:        if axis_offset<0 or axis_offset>len(sh)-2:
3371          raise ValueError,"axis_offset must be between 0 and %s"%len(sh)-2          raise ValueError,"axis_offset must be between 0 and %s"%len(sh)-2
# Line 3006  def trace(arg,axis_offset=0): Line 3383  def trace(arg,axis_offset=0):
3383        out.resize(sh[:axis_offset]+sh[axis_offset+2:])        out.resize(sh[:axis_offset]+sh[axis_offset+2:])
3384        return out        return out
3385     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
3386        if arg.getRank()<2:        if arg.getRank()<2:
3387          raise ValueError,"rank of argument must be greater than 1"          raise ValueError,"rank of argument must be greater than 1"
3388        if axis_offset<0 or axis_offset>arg.getRank()-2:        if axis_offset<0 or axis_offset>arg.getRank()-2:
3389          raise ValueError,"axis_offset must be between 0 and %s"%arg.getRank()-2          raise ValueError,"axis_offset must be between 0 and %s"%arg.getRank()-2
3390        s=list(arg.getShape())                s=list(arg.getShape())
3391        if not s[axis_offset] == s[axis_offset+1]:        if not s[axis_offset] == s[axis_offset+1]:
3392          raise ValueError,"dimensions of component %s and %s must match."%(axis_offset.axis_offset+1)          raise ValueError,"dimensions of component %s and %s must match."%(axis_offset.axis_offset+1)
3393        return arg._trace(axis_offset)        return arg._trace(axis_offset)
# Line 3025  def trace(arg,axis_offset=0): Line 3402  def trace(arg,axis_offset=0):
3402    
3403  class Trace_Symbol(DependendSymbol):  class Trace_Symbol(DependendSymbol):
3404     """     """
3405     L{Symbol} representing the result of the trace function     L{Symbol} representing the result of the trace function.
3406     """     """
3407     def __init__(self,arg,axis_offset=0):     def __init__(self,arg,axis_offset=0):
3408        """        """
3409        initialization of trace L{Symbol} with argument arg        Initialization of trace L{Symbol} with argument C{arg}.
3410    
3411        @param arg: argument of function        @param arg: argument of function
3412        @type arg: L{Symbol}.        @type arg: L{Symbol}
3413        @param axis_offset: C{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.
3414                    C{axis_offset} and axis_offset+1 must be equal.                            C{axis_offset} must be non-negative and less than the
3415                              rank of C{arg} +1. The dimensions on component
3416                              C{axis_offset} and axis_offset+1 must be equal.
3417        @type axis_offset: C{int}        @type axis_offset: C{int}
3418        """        """
3419        if arg.getRank()<2:        if arg.getRank()<2:
3420          raise ValueError,"rank of argument must be greater than 1"          raise ValueError,"rank of argument must be greater than 1"
3421        if axis_offset<0 or axis_offset>arg.getRank()-2:        if axis_offset<0 or axis_offset>arg.getRank()-2:
3422          raise ValueError,"axis_offset must be between 0 and %s"%arg.getRank()-2          raise ValueError,"axis_offset must be between 0 and %s"%arg.getRank()-2
3423        s=list(arg.getShape())                s=list(arg.getShape())
3424        if not s[axis_offset] == s[axis_offset+1]:        if not s[axis_offset] == s[axis_offset+1]:
3425          raise ValueError,"dimensions of component %s and %s must match."%(axis_offset.axis_offset+1)          raise ValueError,"dimensions of component %s and %s must match."%(axis_offset.axis_offset+1)
3426        super(Trace_Symbol,self).__init__(args=[arg,axis_offset],shape=tuple(s[0:axis_offset]+s[axis_offset+2:]),dim=arg.getDim())        super(Trace_Symbol,self).__init__(args=[arg,axis_offset],shape=tuple(s[0:axis_offset]+s[axis_offset+2:]),dim=arg.getDim())
3427    
3428     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
3429        """        """
3430        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
3431    
3432        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
3433        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
3434        @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}
3435          @param format: specifies the format to be used. At the moment only
3436                         "escript", "str" and "text" are supported.
3437        @type format: C{str}        @type format: C{str}
3438        @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
3439                   expression assuming the values for the arguments are available
3440        @rtype: C{str}        @rtype: C{str}
3441        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
3442                                      is available
3443        """        """
3444        if format=="escript" or format=="str"  or format=="text":        if format=="escript" or format=="str"  or format=="text":
3445           return "trace(%s,axis_offset=%s)"%(argstrs[0],argstrs[1])           return "trace(%s,axis_offset=%s)"%(argstrs[0],argstrs[1])
# Line 3064  class Trace_Symbol(DependendSymbol): Line 3448  class Trace_Symbol(DependendSymbol):
3448    
3449     def substitute(self,argvals):     def substitute(self,argvals):
3450        """        """
3451        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
3452        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
3453          defining this object.
3454    
3455        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
3456        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
3457        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
3458        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
3459        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
3460                  depending on the degree of substitution
3461          @raise TypeError: if a value for a L{Symbol} cannot be substituted
3462        """        """
3463        if argvals.has_key(self):        if argvals.has_key(self):
3464           arg=argvals[self]           arg=argvals[self]
# Line 3085  class Trace_Symbol(DependendSymbol): Line 3472  class Trace_Symbol(DependendSymbol):
3472    
3473     def diff(self,arg):     def diff(self,arg):
3474        """        """
3475        differential of this object        Differential of this object.
3476    
3477        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
3478        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
3479        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
3480        @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},
3481                  L{escript.Data}, C{numarray.NumArray} are possible
3482        """        """
3483        if arg==self:        if arg==self:
3484           return identity(self.getShape())           return identity(self.getShape())
# Line 3099  class Trace_Symbol(DependendSymbol): Line 3487  class Trace_Symbol(DependendSymbol):
3487    
3488  def transpose(arg,axis_offset=None):  def transpose(arg,axis_offset=None):
3489     """     """
3490     returns the transpose of arg by swaping the first C{axis_offset} and the last rank-axis_offset components.     Returns the transpose of C{arg} by swapping the first C{axis_offset} and the
3491       last C{rank-axis_offset} components.
3492    
3493     @param arg: argument     @param arg: argument
3494     @type arg: L{escript.Data}, L{Symbol}, L{numarray.NumArray}, C{float}, C{int}     @type arg: L{escript.Data}, L{Symbol}, C{numarray.NumArray}, C{float}, C{int}
3495     @param axis_offset: the first C{axis_offset} components are swapped with rest. If C{axis_offset} must be non-negative and less or equal the rank of arg.     @param axis_offset: the first C{axis_offset} components are swapped with the
3496                         if C{axis_offset} is not present C{int(r/2)} where r is the rank of arg is used.                         rest. C{axis_offset} must be non-negative and less or
3497                           equal to the rank of C{arg}. If C{axis_offset} is not
3498                           present C{int(r/2)} where r is the rank of C{arg} is
3499                           used.
3500     @type axis_offset: C{int}     @type axis_offset: C{int}
3501     @return: transpose of arg     @return: transpose of C{arg}
3502     @rtype: L{escript.Data}, L{Symbol}, L{numarray.NumArray},C{float}, C{int} depending on the type of arg.     @rtype: L{escript.Data}, L{Symbol}, C{numarray.NumArray}, C{float}, C{int}
3503               depending on the type of C{arg}
3504     """     """
3505     if isinstance(arg,numarray.NumArray):     if isinstance(arg,numarray.NumArray):
3506        if axis_offset==None: axis_offset=int(arg.rank/2)        if axis_offset==None: axis_offset=int(arg.rank/2)
# Line 3119  def transpose(arg,axis_offset=None): Line 3512  def transpose(arg,axis_offset=None):
3512          raise ValueError,"axis_offset must be between 0 and %s"%r          raise ValueError,"axis_offset must be between 0 and %s"%r
3513        return arg._transpose(axis_offset)        return arg._transpose(axis_offset)
3514     elif isinstance(arg,float):     elif isinstance(arg,float):
3515        if not ( axis_offset==0 or axis_offset==None):        if not ( axis_offset==0 or axis_offset==None):
3516          raise ValueError,"axis_offset must be 0 for float argument"          raise ValueError,"axis_offset must be 0 for float argument"
3517        return arg        return arg
3518     elif isinstance(arg,int):     elif isinstance(arg,int):
3519        if not ( axis_offset==0 or axis_offset==None):        if not ( axis_offset==0 or axis_offset==None):
3520          raise ValueError,"axis_offset must be 0 for int argument"          raise ValueError,"axis_offset must be 0 for int argument"
3521        return float(arg)        return float(arg)
3522     elif isinstance(arg,Symbol):     elif isinstance(arg,Symbol):
# Line 3134  def transpose(arg,axis_offset=None): Line 3527  def transpose(arg,axis_offset=None):
3527    
3528  class Transpose_Symbol(DependendSymbol):  class Transpose_Symbol(DependendSymbol):
3529     """     """
3530     L{Symbol} representing the result of the transpose function     L{Symbol} representing the result of the transpose function.
3531     """     """
3532     def __init__(self,arg,axis_offset=None):     def __init__(self,arg,axis_offset=None):
3533        """        """
3534        initialization of transpose L{Symbol} with argument arg        Initialization of transpose L{Symbol} with argument C{arg}.
3535    
3536        @param arg: argument of function        @param arg: argument of function
3537        @type arg: L{Symbol}.        @type arg: L{Symbol}
3538        @param axis_offset: the first C{axis_offset} components are swapped with rest. If C{axis_offset} must be non-negative and less or equal the rank of arg.        @param axis_offset: the first C{axis_offset} components are swapped with
3539                         if C{axis_offset} is not present C{int(r/2)} where r is the rank of arg is used.                            the rest. C{axis_offset} must be non-negative and
3540                              less than or equal to the rank of C{arg}. If
3541                              C{axis_offset} is not present C{int(r/2)} where r is
3542                              the rank of C{arg} is used.
3543        @type axis_offset: C{int}        @type axis_offset: C{int}
3544        """        """
3545        if axis_offset==None: axis_offset=int(arg.getRank()/2)        if axis_offset==None: axis_offset=int(arg.getRank()/2)
# Line 3154  class Transpose_Symbol(DependendSymbol): Line 3550  class Transpose_Symbol(DependendSymbol):
3550    
3551     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):
3552        """        """
3553        returns a program code that can be used to evaluate the symbol.        Returns program code that can be used to evaluate the symbol.
3554    
3555        @param argstrs: gives for each argument a string representing the argument for the evaluation.        @param argstrs: a string for each argument representing the argument
3556        @type argstrs: C{str} or a C{list} of length 1 of C{str}.                        for the evaluation
3557        @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}
3558          @param format: specifies the format to be used. At the moment only
3559                         "escript", "str" and "text" are supported.
3560        @type format: C{str}        @type format: C{str}
3561        @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
3562                   expression assuming the values for the arguments are available
3563        @rtype: C{str}        @rtype: C{str}
3564        @raise NotImplementedError: if the requested format is not available        @raise NotImplementedError: if no implementation for the given format
3565                                      is available
3566        """        """
3567        if format=="escript" or format=="str"  or format=="text":        if format=="escript" or format=="str"  or format=="text":
3568           return "transpose(%s,axis_offset=%s)"%(argstrs[0],argstrs[1])           return "transpose(%s,axis_offset=%s)"%(argstrs[0],argstrs[1])
# Line 3171  class Transpose_Symbol(DependendSymbol): Line 3571  class Transpose_Symbol(DependendSymbol):
3571    
3572     def substitute(self,argvals):     def substitute(self,argvals):
3573        """        """
3574        assigns new values to symbols in the definition of the symbol.        Assigns new values to symbols in the definition of the symbol.
3575        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
3576          defining this object.
3577    
3578        @param argvals: new values assigned to symbols        @param argvals: new values assigned to symbols
3579        @type argvals: C{dict} with keywords of type L{Symbol}.        @type argvals: C{dict} with keywords of type L{Symbol}
3580        @return: result of the substitution process. Operations are executed as much as possible.        @return: result of the substitution process. Operations are executed as
3581        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, L{numarray.NumArray} depending on the degree of substitution                 much as possible.
3582        @raise TypeError: if a value for a L{Symbol} cannot be substituted.        @rtype: L{escript.Symbol}, C{float}, L{escript.Data}, C{numarray.NumArray}
3583                  depending on the degree of substitution
3584          @raise TypeError: if a value for a L{Symbol} cannot be substituted
3585        """        """
3586        if argvals.has_key(self):        if argvals.has_key(self):
3587           arg=argvals[self]           arg=argvals[self]
# Line 3192  class Transpose_Symbol(DependendSymbol): Line 3595  class Transpose_Symbol(DependendSymbol):
3595    
3596     def diff(self,arg):     def diff(self,arg):
3597        """        """
3598        differential of this object        Differential of this object.
3599    
3600        @param arg: the derivative is calculated with respect to arg        @param arg: the derivative is calculated with respect to C{arg}
3601        @type arg: L{escript.Symbol}        @type arg: L{escript.Symbol}
3602        @return: derivative with respect to C{arg}        @return: derivative with respect to C{arg}
3603        @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},
3604                  L{escript.Data}, C{numarray.NumArray} are possible
3605        """        """
3606        if arg==self:        if arg==self:
3607           return identity(self.getShape())           return identity(self.getShape())
# Line 3206  class Transpose_Symbol(DependendSymbol): Line 3610  class Transpose_Symbol(DependendSymbol):
3610    
3611  def swap_axes(arg,axis0=0,axis1=1):  def swap_axes(arg,axis0=0,axis1=1):
3612     """     """
3613     returns the swap of arg by swaping the components axis0 and axis1     Returns the swap of C{arg} by swapping the components C{axis0} and C{axis1}.
3614    
3615     @param arg: argument     @param arg: argument
3616     @type arg: L{escript.Data}, L{Symbol}, L{numarray.NumArray}.     @type arg: L{escript.Data}, L{Symbol}, C{numarray.NumArray}
3617     @param axis0: axis. C{axis0} must be non-negative and less than the rank of arg.     @param axis0: first axis. C{axis0} must be non-negative and less than the
3618                     rank of C{arg}.
3619     @type axis0: C{int}     @type axis0: C{int}
3620     @param axis1: axis. C{axis1} must be non-negative and less than the rank of arg.     @param axis1: second axis. C{axis1} must be non-negative and less than the
3621                     rank of C{arg}.
3622     @type axis1: C{int}     @type axis1: C{int}
3623     @return: C{arg} with swaped components     @return: C{arg} with swapped components
3624     @rtype: L{escript.Data}, L{Symbol}, L{numarray.NumArray} depending on the type of arg.     @rtype: L{escript.Data}, L{Symbol}, C{numarray.NumArray} depending on the
3625               type of C{arg}
3626     """     """
3627     if axis0 > axis1:     if axis0 > axis1:
3628        axis0,axis1=axis1,axis0        axis0,axis1=axis1,axis0
# Line 3224  def swap_axes(arg,axis0=0,axis1=1): Line 3631  def swap_axes(arg,axis0=0,axis1=1):
3631     elif isinstance(arg,escript.Data):     elif isinstance(arg,escript.Data):
3632        return arg._swap_axes(axis0,axis1)        return arg._swap_axes(axis0,axis1)
3633     elif isinstance(arg,float):     elif isinstance(arg,float):
3634        raise TyepError,"float argument is not supported."        raise TypeError,"float argument is not supported."
3635     elif isinstance(arg,int):     elif isinstance(arg,int):
3636        raise TyepError,"int argument is not supported."        raise TypeError,"int argument is not supported."
3637     elif isinstance(arg,Symbol):     elif isinstance(arg,Symbol):
3638        return SwapAxes_Symbol(arg,axis0,axis1)        return SwapAxes_Symbol(arg,axis0,axis1)
3639     else:     else:
# Line 3234  def swap_axes(arg,axis0=0,axis1=1):