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