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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 102 - (show annotations)
Wed Dec 15 07:08:39 2004 UTC (14 years, 10 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 # $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 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 def sup(arg):
225 """
226 @brief
227
228 @param arg
229 """
230 if isinstance(arg,escript.Data):
231 return arg.sup()
232 else:
233 return arg.max()
234
235 def inf(arg):
236 """
237 @brief
238
239 @param arg
240 """
241 if isinstance(arg,escript.Data):
242 return arg.inf()
243 else:
244 return arg.min()
245
246 def L2(arg):
247 """
248 @brief returns the L2-norm of the
249
250 @param arg
251 """
252 return arg.L2()
253
254 def Lsup(arg):
255 """
256 @brief
257
258 @param arg
259 """
260 if isinstance(arg,escript.Data):
261 return arg.Lsup()
262 else:
263 return arg.max(numarray.abs(arg))
264
265 def dot(arg1,arg2):
266 """
267 @brief
268
269 @param arg
270 """
271 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