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

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

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

revision 97 by jgs, Tue Dec 14 05:39:33 2004 UTC revision 100 by jgs, Wed Dec 15 03:48:48 2004 UTC
# Line 7  Line 7 
7  """  """
8    
9  import numarray  import numarray
 import escript  
10  #  #
11  #   escript constants (have to be consistent witj utilC.h  #   escript constants:
12  #  #
13    FALSE=0
14    TRUE=1
15  UNKNOWN=-1  UNKNOWN=-1
16  EPSILON=1.e-15  EPSILON=1.e-15
17  Pi=numarray.pi  Pi=3.1415926535897931
18    # matrix types
19    CSC=0  
20    CSR=1
21    LUMPED=10
22  # some solver options:  # some solver options:
23  NO_REORDERING=0  NO_REORDERING=0
24  MINIMUM_FILL_IN=1  MINIMUM_FILL_IN=1
25  NESTED_DISSECTION=2  NESTED_DISSECTION=2
 # solver methods  
26  DEFAULT_METHOD=0  DEFAULT_METHOD=0
27  DIRECT=1  PCG=1
28  CHOLEVSKY=2  CR=2
29  PCG=3  CGS=3
30  CR=4  BICGSTAB=4
31  CGS=5  SSOR=5
32  BICGSTAB=6  ILU0=6
33  SSOR=7  ILUT=7
34  ILU0=8  JACOBI=8
 ILUT=9  
 JACOBI=10  
 GMRES=11  
 PRES20=12  
   
 METHOD_KEY="method"  
 SYMMETRY_KEY="symmetric"  
 TOLERANCE_KEY="tolerance"  
   
35  # supported file formats:  # supported file formats:
36  VRML=1  VRML=1
37  PNG=2  PNG=2
# Line 54  PNM=10 Line 49  PNM=10
49  # as an argument it calls the correspong methods. Otherwise the coresponsing numarray  # as an argument it calls the correspong methods. Otherwise the coresponsing numarray
50  # function is called.  # function is called.
51  #  #
52  # functions involving the underlying Domain:  def L2(arg):
53  #      """
54        @brief
55    
56        @param arg
57        """
58        return arg.L2()
59    
60  def grad(arg,where=None):  def grad(arg,where=None):
61      """      """
62      @brief returns the spatial gradient of the Data object arg      @brief
63    
64      @param arg: Data object representing the function which gradient to be calculated.      @param arg
65      @param where: FunctionSpace in which the gradient will be. If None Function(dom) where dom is the      @param where
                   domain of the Data object arg.  
66      """      """
67      if where==None:      if where==None:
68         return arg.grad()         return arg.grad()
# Line 71  def grad(arg,where=None): Line 71  def grad(arg,where=None):
71    
72  def integrate(arg):  def integrate(arg):
73      """      """
74      @brief return the integral if the function represented by Data object arg over its domain.      @brief
75    
76      @param arg      @param arg
77      """      """
# Line 79  def integrate(arg): Line 79  def integrate(arg):
79    
80  def interpolate(arg,where):  def interpolate(arg,where):
81      """      """
82      @brief interpolates the function represented by Data object arg into the FunctionSpace where.      @brief
83    
84      @param arg      @param arg
85      @param where      @param where
86      """      """
87      return arg.interpolate(where)      return arg.interpolate(where)
88    
89  # functions returning Data objects:  def transpose(arg):
   
 def transpose(arg,axis=None):  
90      """      """
91      @brief returns the transpose of the Data object arg.      @brief
92    
93      @param arg      @param arg
94      """      """
95      if isinstance(arg,escript.Data):      if hasattr(arg,"transpose"):
96         if axis==None: axis=arg.getRank()/2         return arg.transpose()
        return arg.transpose(axis)  
97      else:      else:
98         if axis==None: axis=arg.rank/2         return numarray.transpose(arg,axis=None)
        return numarray.transpose(arg,axis=axis)  
99    
100  def trace(arg):  def trace(arg):
101      """      """
# Line 107  def trace(arg): Line 103  def trace(arg):
103    
104      @param arg      @param arg
105      """      """
106      if isinstance(arg,escript.Data):      if hasattr(arg,"trace"):
107         return arg.trace()         return arg.trace()
108      else:      else:
109         return numarray.trace(arg)         return numarray.trace(arg,k=0)
110    
111  def exp(arg):  def exp(arg):
112      """      """
# Line 118  def exp(arg): Line 114  def exp(arg):
114    
115      @param arg      @param arg
116      """      """
117      if isinstance(arg,escript.Data):      if hasattr(arg,"exp"):
118         return arg.exp()         return arg.exp()
119      else:      else:
120         return numarray.exp(arg)         return numarray.exp(arg)
# Line 129  def sqrt(arg): Line 125  def sqrt(arg):
125    
126      @param arg      @param arg
127      """      """
128      if isinstance(arg,escript.Data):      if hasattr(arg,"sqrt"):
129         return arg.sqrt()         return arg.sqrt()
130      else:      else:
131         return numarray.sqrt(arg)         return numarray.sqrt(arg)
# Line 140  def sin(arg): Line 136  def sin(arg):
136    
137      @param arg      @param arg
138      """      """
139      if isinstance(arg,escript.Data):      if hasattr(arg,"sin"):
140         return arg.sin()         return arg.sin()
141      else:      else:
142         return numarray.sin(arg)         return numarray.sin(arg)
143    
 def tan(arg):  
     """  
     @brief  
   
     @param arg  
     """  
     if isinstance(arg,escript.Data):  
        return arg.tan()  
     else:  
        return numarray.tan(arg)  
   
144  def cos(arg):  def cos(arg):
145      """      """
146      @brief      @brief
147    
148      @param arg      @param arg
149      """      """
150      if isinstance(arg,escript.Data):      if hasattr(arg,"cos"):
151         return arg.cos()         return arg.cos()
152      else:      else:
153         return numarray.cos(arg)         return numarray.cos(arg)
# Line 173  def maxval(arg): Line 158  def maxval(arg):
158    
159      @param arg      @param arg
160      """      """
161      if isinstance(arg,escript.Data):      return arg.maxval()
        return arg.maxval()  
     else:  
        return arg.max()  
162    
163  def minval(arg):  def minval(arg):
164      """      """
# Line 184  def minval(arg): Line 166  def minval(arg):
166    
167      @param arg      @param arg
168      """      """
169      if isinstance(arg,escript.Data):      return arg.minval()
        return arg.minval()  
     else:  
        return arg.max()  
   
 def length(arg):  
     """  
     @brief  
   
     @param arg  
     """  
     if isinstance(arg,escript.Data):  
        return arg.length()  
     else:  
        return sqrt((arg**2).sum())  
   
 def sign(arg):  
     """  
     @brief  
   
     @param arg  
     """  
     if isinstance(arg,escript.Data):  
        return arg.sign()  
     else:  
        return numarray.greater(arg,numarray.zeros(arg.shape))-numarray.less(arg,numarray.zeros(arg.shape))  
   
 # reduction operations:  
   
 def sum(arg):  
     """  
     @brief  
   
     @param arg  
     """  
     return arg.sum()  
170    
171  def sup(arg):  def sup(arg):
172      """      """
# Line 227  def sup(arg): Line 174  def sup(arg):
174    
175      @param arg      @param arg
176      """      """
177      if isinstance(arg,escript.Data):      return arg.sup()
        return arg.sup()  
     else:  
        return arg.max()  
178    
179  def inf(arg):  def inf(arg):
180      """      """
# Line 238  def inf(arg): Line 182  def inf(arg):
182    
183      @param arg      @param arg
184      """      """
185      if isinstance(arg,escript.Data):      return arg.inf()
        return arg.inf()  
     else:  
        return arg.min()  
186    
187  def L2(arg):  def Lsup(arg):
188      """      """
189      @brief returns the L2-norm of the      @brief
190    
191      @param arg      @param arg
192      """      """
193      return arg.L2()      return arg.Lsup()
194    
195  def Lsup(arg):  def length(arg):
196      """      """
197      @brief      @brief
198    
199      @param arg      @param arg
200      """      """
201      if isinstance(arg,escript.Data):      return arg.length()
        return arg.Lsup()  
     else:  
        return arg.max(numarray.abs(arg))  
202    
203  def dot(arg1,arg2):  def sign(arg):
204      """      """
205      @brief      @brief
206    
207      @param arg      @param arg
208      """      """
209      if isinstance(arg1,escript.Data):      return arg.sign()
        return arg1.dot(arg2)  
     elif isinstance(arg1,escript.Data):  
        return arg2.dot(arg1)  
     else:  
        return numarray.dot(arg1,arg2)  
210  #  #
211  # $Log$  # $Log$
212  # Revision 1.3  2004/12/14 05:39:26  jgs  # Revision 1.4  2004/12/15 03:48:42  jgs
213  # *** empty log message ***  # *** empty log message ***
214  #  #
 # Revision 1.2.2.4  2004/12/07 03:19:51  gross  
 # options for GMRES and PRES20 added  
 #  
 # Revision 1.2.2.3  2004/12/06 04:55:18  gross  
 # function wraper extended  
 #  
 # Revision 1.2.2.2  2004/11/22 05:44:07  gross  
 # a few more unitary functions have been added but not implemented in Data yet  
 #  
 # Revision 1.2.2.1  2004/11/12 06:58:15  gross  
 # a lot of changes to get the linearPDE class running: most important change is that there is no matrix format exposed to the user anymore. the format is chosen by the Domain according to the solver and symmetry  
 #  
215  # Revision 1.2  2004/10/27 00:23:36  jgs  # Revision 1.2  2004/10/27 00:23:36  jgs
216  # fixed minor syntax error  # fixed minor syntax error
217  #  #

Legend:
Removed from v.97  
changed lines
  Added in v.100

  ViewVC Help
Powered by ViewVC 1.1.26