7 |
""" |
""" |
8 |
|
|
9 |
import numarray |
import numarray |
10 |
|
import escript |
11 |
# |
# |
12 |
# escript constants: |
# escript constants (have to be consistent witj utilC.h |
13 |
# |
# |
|
FALSE=0 |
|
|
TRUE=1 |
|
14 |
UNKNOWN=-1 |
UNKNOWN=-1 |
15 |
EPSILON=1.e-15 |
EPSILON=1.e-15 |
16 |
Pi=3.1415926535897931 |
Pi=numarray.pi |
|
# matrix types |
|
|
CSC=0 |
|
|
CSR=1 |
|
|
LUMPED=10 |
|
17 |
# some solver options: |
# some solver options: |
18 |
NO_REORDERING=0 |
NO_REORDERING=0 |
19 |
MINIMUM_FILL_IN=1 |
MINIMUM_FILL_IN=1 |
20 |
NESTED_DISSECTION=2 |
NESTED_DISSECTION=2 |
21 |
|
# solver methods |
22 |
DEFAULT_METHOD=0 |
DEFAULT_METHOD=0 |
23 |
PCG=1 |
DIRECT=1 |
24 |
CR=2 |
CHOLEVSKY=2 |
25 |
CGS=3 |
PCG=3 |
26 |
BICGSTAB=4 |
CR=4 |
27 |
SSOR=5 |
CGS=5 |
28 |
ILU0=6 |
BICGSTAB=6 |
29 |
ILUT=7 |
SSOR=7 |
30 |
JACOBI=8 |
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: |
# supported file formats: |
41 |
VRML=1 |
VRML=1 |
42 |
PNG=2 |
PNG=2 |
54 |
# as an argument it calls the correspong methods. Otherwise the coresponsing numarray |
# as an argument it calls the correspong methods. Otherwise the coresponsing numarray |
55 |
# function is called. |
# function is called. |
56 |
# |
# |
57 |
def L2(arg): |
# functions involving the underlying Domain: |
58 |
""" |
# |
|
@brief |
|
|
|
|
|
@param arg |
|
|
""" |
|
|
return arg.L2() |
|
|
|
|
59 |
def grad(arg,where=None): |
def grad(arg,where=None): |
60 |
""" |
""" |
61 |
@brief |
@brief returns the spatial gradient of the Data object arg |
62 |
|
|
63 |
@param arg |
@param arg: Data object representing the function which gradient to be calculated. |
64 |
@param where |
@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: |
if where==None: |
68 |
return arg.grad() |
return arg.grad() |
71 |
|
|
72 |
def integrate(arg): |
def integrate(arg): |
73 |
""" |
""" |
74 |
@brief |
@brief return the integral if the function represented by Data object arg over its domain. |
75 |
|
|
76 |
@param arg |
@param arg |
77 |
""" |
""" |
79 |
|
|
80 |
def interpolate(arg,where): |
def interpolate(arg,where): |
81 |
""" |
""" |
82 |
@brief |
@brief interpolates the function represented by Data object arg into the FunctionSpace where. |
83 |
|
|
84 |
@param arg |
@param arg |
85 |
@param where |
@param where |
86 |
""" |
""" |
87 |
return arg.interpolate(where) |
return arg.interpolate(where) |
88 |
|
|
89 |
def transpose(arg): |
# functions returning Data objects: |
90 |
|
|
91 |
|
def transpose(arg,axis=None): |
92 |
""" |
""" |
93 |
@brief |
@brief returns the transpose of the Data object arg. |
94 |
|
|
95 |
@param arg |
@param arg |
96 |
""" |
""" |
97 |
if hasattr(arg,"transpose"): |
if isinstance(arg,escript.Data): |
98 |
return arg.transpose() |
if axis==None: axis=arg.getRank()/2 |
99 |
|
return arg.transpose(axis) |
100 |
else: |
else: |
101 |
return numarray.transpose(arg,axis=None) |
if axis==None: axis=arg.rank/2 |
102 |
|
return numarray.transpose(arg,axis=axis) |
103 |
|
|
104 |
def trace(arg): |
def trace(arg): |
105 |
""" |
""" |
107 |
|
|
108 |
@param arg |
@param arg |
109 |
""" |
""" |
110 |
if hasattr(arg,"trace"): |
if isinstance(arg,escript.Data): |
111 |
return arg.trace() |
return arg.trace() |
112 |
else: |
else: |
113 |
return numarray.trace(arg,k=0) |
return numarray.trace(arg) |
114 |
|
|
115 |
def exp(arg): |
def exp(arg): |
116 |
""" |
""" |
118 |
|
|
119 |
@param arg |
@param arg |
120 |
""" |
""" |
121 |
if hasattr(arg,"exp"): |
if isinstance(arg,escript.Data): |
122 |
return arg.exp() |
return arg.exp() |
123 |
else: |
else: |
124 |
return numarray.exp(arg) |
return numarray.exp(arg) |
129 |
|
|
130 |
@param arg |
@param arg |
131 |
""" |
""" |
132 |
if hasattr(arg,"sqrt"): |
if isinstance(arg,escript.Data): |
133 |
return arg.sqrt() |
return arg.sqrt() |
134 |
else: |
else: |
135 |
return numarray.sqrt(arg) |
return numarray.sqrt(arg) |
136 |
|
|
137 |
def sin(arg): |
def sin(arg): |
140 |
|
|
141 |
@param arg |
@param arg |
142 |
""" |
""" |
143 |
if hasattr(arg,"sin"): |
if isinstance(arg,escript.Data): |
144 |
return arg.sin() |
return arg.sin() |
145 |
else: |
else: |
146 |
return numarray.sin(arg) |
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): |
def cos(arg): |
160 |
""" |
""" |
161 |
@brief |
@brief |
162 |
|
|
163 |
@param arg |
@param arg |
164 |
""" |
""" |
165 |
if hasattr(arg,"cos"): |
if isinstance(arg,escript.Data): |
166 |
return arg.cos() |
return arg.cos() |
167 |
else: |
else: |
168 |
return numarray.cos(arg) |
return numarray.cos(arg) |
173 |
|
|
174 |
@param arg |
@param arg |
175 |
""" |
""" |
176 |
return arg.maxval() |
if isinstance(arg,escript.Data): |
177 |
|
return arg.maxval() |
178 |
|
else: |
179 |
|
return arg.max() |
180 |
|
|
181 |
def minval(arg): |
def minval(arg): |
182 |
""" |
""" |
184 |
|
|
185 |
@param arg |
@param arg |
186 |
""" |
""" |
187 |
return arg.minval() |
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): |
def sup(arg): |
232 |
""" |
""" |
234 |
|
|
235 |
@param arg |
@param arg |
236 |
""" |
""" |
237 |
return arg.sup() |
if isinstance(arg,escript.Data): |
238 |
|
return arg.sup() |
239 |
|
else: |
240 |
|
return arg.max() |
241 |
|
|
242 |
def inf(arg): |
def inf(arg): |
243 |
""" |
""" |
245 |
|
|
246 |
@param arg |
@param arg |
247 |
""" |
""" |
248 |
return arg.inf() |
if isinstance(arg,escript.Data): |
249 |
|
return arg.inf() |
250 |
|
else: |
251 |
|
return arg.min() |
252 |
|
|
253 |
def Lsup(arg): |
def L2(arg): |
254 |
""" |
""" |
255 |
@brief |
@brief returns the L2-norm of the |
256 |
|
|
257 |
@param arg |
@param arg |
258 |
""" |
""" |
259 |
return arg.Lsup() |
return arg.L2() |
260 |
|
|
261 |
def length(arg): |
def Lsup(arg): |
262 |
""" |
""" |
263 |
@brief |
@brief |
264 |
|
|
265 |
@param arg |
@param arg |
266 |
""" |
""" |
267 |
return arg.length() |
if isinstance(arg,escript.Data): |
268 |
|
return arg.Lsup() |
269 |
|
else: |
270 |
|
return arg.max(numarray.abs(arg)) |
271 |
|
|
272 |
def sign(arg): |
def dot(arg1,arg2): |
273 |
""" |
""" |
274 |
@brief |
@brief |
275 |
|
|
276 |
@param arg |
@param arg |
277 |
""" |
""" |
278 |
return arg.sign() |
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$ |
# $Log$ |
286 |
# Revision 1.1 2004/10/26 06:53:56 jgs |
# Revision 1.6 2004/12/17 07:43:10 jgs |
287 |
# Initial revision |
# *** 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 |
# Revision 1.1.2.3 2004/10/26 06:43:48 jgs |
311 |
# committing Lutz's and Paul's changes to brach jgs |
# committing Lutz's and Paul's changes to brach jgs |