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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 102 - (hide annotations)
Wed Dec 15 07:08:39 2004 UTC (14 years, 11 months ago) by jgs
Original Path: trunk/esys2/escript/py_src/util.py
File MIME type: text/x-python
File size: 4659 byte(s)
*** empty log message ***

1 jgs 82 # $Id$
2    
3     ## @file util.py
4    
5     """
6     @brief Utility functions for escript
7     """
8    
9     import numarray
10 jgs 102 import escript
11 jgs 82 #
12 jgs 102 # escript constants (have to be consistent witj utilC.h
13 jgs 82 #
14     UNKNOWN=-1
15     EPSILON=1.e-15
16 jgs 102 Pi=numarray.pi
17 jgs 82 # some solver options:
18     NO_REORDERING=0
19     MINIMUM_FILL_IN=1
20     NESTED_DISSECTION=2
21 jgs 102 # solver methods
22 jgs 82 DEFAULT_METHOD=0
23 jgs 102 DIRECT=1
24     CHOLEVSKY=2
25     PCG=3
26     CR=4
27     CGS=5
28     BICGSTAB=6
29     SSOR=7
30     ILU0=8
31     ILUT=9
32     JACOBI=10
33     GMRES=11
34     PRES20=12
35    
36     METHOD_KEY="method"
37     SYMMETRY_KEY="symmetric"
38     TOLERANCE_KEY="tolerance"
39    
40 jgs 82 # supported file formats:
41     VRML=1
42     PNG=2
43     JPEG=3
44     JPG=3
45     PS=4
46     OOGL=5
47     BMP=6
48     TIFF=7
49     OPENINVENTOR=8
50     RENDERMAN=9
51     PNM=10
52     #
53     # wrapper for various functions: if the argument has attribute the function name
54     # as an argument it calls the correspong methods. Otherwise the coresponsing numarray
55     # function is called.
56     #
57 jgs 102 # functions involving the underlying Domain:
58     #
59 jgs 82 def grad(arg,where=None):
60     """
61 jgs 102 @brief returns the spatial gradient of the Data object arg
62 jgs 82
63 jgs 102 @param arg: Data object representing the function which gradient to be calculated.
64     @param where: FunctionSpace in which the gradient will be. If None Function(dom) where dom is the
65     domain of the Data object arg.
66 jgs 82 """
67     if where==None:
68     return arg.grad()
69     else:
70     return arg.grad(where)
71    
72     def integrate(arg):
73     """
74 jgs 102 @brief return the integral if the function represented by Data object arg over its domain.
75 jgs 82
76     @param arg
77     """
78     return arg.integrate()
79    
80     def interpolate(arg,where):
81     """
82 jgs 102 @brief interpolates the function represented by Data object arg into the FunctionSpace where.
83 jgs 82
84     @param arg
85     @param where
86     """
87     return arg.interpolate(where)
88    
89 jgs 102 # functions returning Data objects:
90    
91     def transpose(arg,axis=None):
92 jgs 82 """
93 jgs 102 @brief returns the transpose of the Data object arg.
94 jgs 82
95     @param arg
96     """
97 jgs 102 if isinstance(arg,escript.Data):
98     if axis==None: axis=arg.getRank()/2
99     return arg.transpose(axis)
100 jgs 82 else:
101 jgs 102 if axis==None: axis=arg.rank/2
102     return numarray.transpose(arg,axis=axis)
103 jgs 82
104     def trace(arg):
105     """
106     @brief
107    
108     @param arg
109     """
110 jgs 102 if isinstance(arg,escript.Data):
111 jgs 82 return arg.trace()
112     else:
113 jgs 102 return numarray.trace(arg)
114 jgs 82
115     def exp(arg):
116     """
117     @brief
118    
119     @param arg
120     """
121 jgs 102 if isinstance(arg,escript.Data):
122 jgs 82 return arg.exp()
123     else:
124     return numarray.exp(arg)
125    
126     def sqrt(arg):
127     """
128     @brief
129    
130     @param arg
131     """
132 jgs 102 if isinstance(arg,escript.Data):
133 jgs 88 return arg.sqrt()
134     else:
135 jgs 82 return numarray.sqrt(arg)
136    
137     def sin(arg):
138     """
139     @brief
140    
141     @param arg
142     """
143 jgs 102 if isinstance(arg,escript.Data):
144 jgs 82 return arg.sin()
145     else:
146     return numarray.sin(arg)
147    
148 jgs 102 def tan(arg):
149     """
150     @brief
151    
152     @param arg
153     """
154     if isinstance(arg,escript.Data):
155     return arg.tan()
156     else:
157     return numarray.tan(arg)
158    
159 jgs 82 def cos(arg):
160     """
161     @brief
162    
163     @param arg
164     """
165 jgs 102 if isinstance(arg,escript.Data):
166 jgs 82 return arg.cos()
167     else:
168     return numarray.cos(arg)
169    
170     def maxval(arg):
171     """
172     @brief
173    
174     @param arg
175     """
176 jgs 102 if isinstance(arg,escript.Data):
177     return arg.maxval()
178     else:
179     return arg.max()
180 jgs 82
181     def minval(arg):
182     """
183     @brief
184    
185     @param arg
186     """
187 jgs 102 if isinstance(arg,escript.Data):
188     return arg.minval()
189     else:
190     return arg.max()
191 jgs 82
192 jgs 102 def length(arg):
193     """
194     @brief
195    
196     @param arg
197     """
198     if isinstance(arg,escript.Data):
199     return arg.length()
200     else:
201     return sqrt((arg**2).sum())
202    
203     def sign(arg):
204     """
205     @brief
206    
207     @param arg
208     """
209     if isinstance(arg,escript.Data):
210     return arg.sign()
211     else:
212     return numarray.greater(arg,numarray.zeros(arg.shape))-numarray.less(arg,numarray.zeros(arg.shape))
213    
214     # reduction operations:
215    
216     def sum(arg):
217     """
218     @brief
219    
220     @param arg
221     """
222     return arg.sum()
223    
224 jgs 82 def sup(arg):
225     """
226     @brief
227    
228     @param arg
229     """
230 jgs 102 if isinstance(arg,escript.Data):
231     return arg.sup()
232     else:
233     return arg.max()
234 jgs 82
235     def inf(arg):
236     """
237     @brief
238    
239     @param arg
240     """
241 jgs 102 if isinstance(arg,escript.Data):
242     return arg.inf()
243     else:
244     return arg.min()
245 jgs 82
246 jgs 102 def L2(arg):
247 jgs 82 """
248 jgs 102 @brief returns the L2-norm of the
249 jgs 82
250     @param arg
251     """
252 jgs 102 return arg.L2()
253 jgs 82
254 jgs 102 def Lsup(arg):
255 jgs 82 """
256     @brief
257    
258     @param arg
259     """
260 jgs 102 if isinstance(arg,escript.Data):
261     return arg.Lsup()
262     else:
263     return arg.max(numarray.abs(arg))
264 jgs 82
265 jgs 102 def dot(arg1,arg2):
266 jgs 82 """
267     @brief
268    
269     @param arg
270     """
271 jgs 102 if isinstance(arg1,escript.Data):
272     return arg1.dot(arg2)
273     elif isinstance(arg1,escript.Data):
274     return arg2.dot(arg1)
275     else:
276     return numarray.dot(arg1,arg2)

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26