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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 104 - (show annotations)
Fri Dec 17 07:43:12 2004 UTC (14 years, 4 months ago) by jgs
File MIME type: text/x-python
File size: 6138 byte(s)
*** empty log message ***

1 # $Id$
2
3 ## @file util.py
4
5 """
6 @brief Utility functions for escript
7 """
8
9 import numarray
10 import escript
11 #
12 # escript constants (have to be consistent witj utilC.h
13 #
14 UNKNOWN=-1
15 EPSILON=1.e-15
16 Pi=numarray.pi
17 # some solver options:
18 NO_REORDERING=0
19 MINIMUM_FILL_IN=1
20 NESTED_DISSECTION=2
21 # solver methods
22 DEFAULT_METHOD=0
23 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 # 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 # functions involving the underlying Domain:
58 #
59 def grad(arg,where=None):
60 """
61 @brief returns the spatial gradient of the Data object arg
62
63 @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 """
67 if where==None:
68 return arg.grad()
69 else:
70 return arg.grad(where)
71
72 def integrate(arg):
73 """
74 @brief return the integral if the function represented by Data object arg over its domain.
75
76 @param arg
77 """
78 return arg.integrate()
79
80 def interpolate(arg,where):
81 """
82 @brief interpolates the function represented by Data object arg into the FunctionSpace where.
83
84 @param arg
85 @param where
86 """
87 return arg.interpolate(where)
88
89 # functions returning Data objects:
90
91 def transpose(arg,axis=None):
92 """
93 @brief returns the transpose of the Data object arg.
94
95 @param arg
96 """
97 if isinstance(arg,escript.Data):
98 if axis==None: axis=arg.getRank()/2
99 return arg.transpose(axis)
100 else:
101 if axis==None: axis=arg.rank/2
102 return numarray.transpose(arg,axis=axis)
103
104 def trace(arg):
105 """
106 @brief
107
108 @param arg
109 """
110 if isinstance(arg,escript.Data):
111 return arg.trace()
112 else:
113 return numarray.trace(arg)
114
115 def exp(arg):
116 """
117 @brief
118
119 @param arg
120 """
121 if isinstance(arg,escript.Data):
122 return arg.exp()
123 else:
124 return numarray.exp(arg)
125
126 def sqrt(arg):
127 """
128 @brief
129
130 @param arg
131 """
132 if isinstance(arg,escript.Data):
133 return arg.sqrt()
134 else:
135 return numarray.sqrt(arg)
136
137 def sin(arg):
138 """
139 @brief
140
141 @param arg
142 """
143 if isinstance(arg,escript.Data):
144 return arg.sin()
145 else:
146 return numarray.sin(arg)
147
148 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 def cos(arg):
160 """
161 @brief
162
163 @param arg
164 """
165 if isinstance(arg,escript.Data):
166 return arg.cos()
167 else:
168 return numarray.cos(arg)
169
170 def maxval(arg):
171 """
172 @brief
173
174 @param arg
175 """
176 if isinstance(arg,escript.Data):
177 return arg.maxval()
178 else:
179 return arg.max()
180
181 def minval(arg):
182 """
183 @brief
184
185 @param arg
186 """
187 if isinstance(arg,escript.Data):
188 return arg.minval()
189 else:
190 return arg.max()
191
192 def length(arg):
193 """
194 @brief
195
196 @param arg
197 """
198 if isinstance(arg,escript.Data):
199 if arg.getRank()==1:
200 sum=escript.Scalar(0,arg.getFunctionSpace())
201 for i in range(arg.getShape()[0]):
202 sum+=arg[i]**2
203 return sqrt(sum)
204 else:
205 raise SystemError,"length is not been implemented yet"
206 # return arg.length()
207 else:
208 return sqrt((arg**2).sum())
209
210 def sign(arg):
211 """
212 @brief
213
214 @param arg
215 """
216 if isinstance(arg,escript.Data):
217 return arg.sign()
218 else:
219 return numarray.greater(arg,numarray.zeros(arg.shape))-numarray.less(arg,numarray.zeros(arg.shape))
220
221 # reduction operations:
222
223 def sum(arg):
224 """
225 @brief
226
227 @param arg
228 """
229 return arg.sum()
230
231 def sup(arg):
232 """
233 @brief
234
235 @param arg
236 """
237 if isinstance(arg,escript.Data):
238 return arg.sup()
239 else:
240 return arg.max()
241
242 def inf(arg):
243 """
244 @brief
245
246 @param arg
247 """
248 if isinstance(arg,escript.Data):
249 return arg.inf()
250 else:
251 return arg.min()
252
253 def L2(arg):
254 """
255 @brief returns the L2-norm of the
256
257 @param arg
258 """
259 return arg.L2()
260
261 def Lsup(arg):
262 """
263 @brief
264
265 @param arg
266 """
267 if isinstance(arg,escript.Data):
268 return arg.Lsup()
269 else:
270 return arg.max(numarray.abs(arg))
271
272 def dot(arg1,arg2):
273 """
274 @brief
275
276 @param arg
277 """
278 if isinstance(arg1,escript.Data):
279 return arg1.dot(arg2)
280 elif isinstance(arg1,escript.Data):
281 return arg2.dot(arg1)
282 else:
283 return numarray.dot(arg1,arg2)
284 #
285 # $Log$
286 # Revision 1.6 2004/12/17 07:43:10 jgs
287 # *** empty log message ***
288 #
289 # Revision 1.2.2.5 2004/12/17 00:06:53 gross
290 # mk sets ESYS_ROOT is undefined
291 #
292 # Revision 1.2.2.4 2004/12/07 03:19:51 gross
293 # options for GMRES and PRES20 added
294 #
295 # Revision 1.2.2.3 2004/12/06 04:55:18 gross
296 # function wraper extended
297 #
298 # Revision 1.2.2.2 2004/11/22 05:44:07 gross
299 # a few more unitary functions have been added but not implemented in Data yet
300 #
301 # Revision 1.2.2.1 2004/11/12 06:58:15 gross
302 # 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
303 #
304 # Revision 1.2 2004/10/27 00:23:36 jgs
305 # fixed minor syntax error
306 #
307 # Revision 1.1.1.1 2004/10/26 06:53:56 jgs
308 # initial import of project esys2
309 #
310 # Revision 1.1.2.3 2004/10/26 06:43:48 jgs
311 # committing Lutz's and Paul's changes to brach jgs
312 #
313 # Revision 1.1.4.1 2004/10/20 05:32:51 cochrane
314 # Added incomplete Doxygen comments to files, or merely put the docstrings that already exist into Doxygen form.
315 #
316 # Revision 1.1 2004/08/05 03:58:27 gross
317 # Bug in Assemble_NodeCoordinates fixed
318 #
319 #

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26