/[escript]/trunk/escriptcore/test/python/test_linearPDEs.py
ViewVC logotype

Contents of /trunk/escriptcore/test/python/test_linearPDEs.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4005 - (show annotations)
Fri Sep 28 06:09:03 2012 UTC (7 years ago) by caltinay
Original Path: trunk/escript/test/python/test_linearPDEs.py
File MIME type: text/x-python
File size: 197895 byte(s)
test fixes, doco updates, annoyance removals.

1 # -*- coding: utf-8 -*-
2
3 ##############################################################################
4 #
5 # Copyright (c) 2003-2012 by University of Queensland
6 # http://www.uq.edu.au
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
13 # Development since 2012 by School of Earth Sciences
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2003-2012 by University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 """
25 Test suite for linearPDEs class
26
27 """
28
29 __author__="Lutz Gross, l.gross@uq.edu.au"
30
31 from esys.escript.util import Lsup,kronecker,interpolate,whereZero, outer, swap_axes
32 from esys.escript import Function,FunctionOnBoundary,FunctionOnContactZero,Solution,ReducedSolution,Vector,ContinuousFunction,Scalar, ReducedFunction,ReducedFunctionOnBoundary,ReducedFunctionOnContactZero,Data, Tensor4, Tensor, getEscriptParamInt
33 from esys.escript.linearPDEs import LinearPDE,IllegalCoefficientValue,Poisson, IllegalCoefficientFunctionSpace, TransportPDE, IllegalCoefficient, Helmholtz, LameEquation, SolverOptions
34 import numpy
35 import unittest
36
37 class Test_linearPDEs(unittest.TestCase):
38 TOL=1.e-6
39 SOLVER_TOL=1.e-10
40 DEBUG=False
41 VERBOSE=False
42 def check(self,arg,ref_arg,tol=None):
43 """
44 checks if arg and ref_arg are nearly identical using the `Lsup`
45 """
46 if tol==None: tol=self.TOL
47 return Lsup(arg-ref_arg)<=tol*Lsup(ref_arg)
48
49 class Test_LameEquation(Test_linearPDEs):
50
51 def test_config(self):
52 mypde=LameEquation(self.domain,debug=self.DEBUG)
53 d=self.domain.getDim()
54 self.assertEqual((mypde.getNumEquations(), mypde.getNumSolutions(), mypde.getSolverOptions().isSymmetric()),(d,d,True),"set up incorrect")
55
56 def test_setCoefficient_q(self):
57 mypde=LameEquation(self.domain,debug=self.DEBUG)
58 x=self.domain.getX()
59 mypde.setValue(q=x)
60
61 q_ref=interpolate(x,Solution(self.domain))
62 self.assertTrue(self.check(mypde.getCoefficient("A"),0),"A is not 0")
63 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
64 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
65 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
66 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
67 self.assertTrue(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
68 self.assertTrue(mypde.getCoefficient("y").isEmpty(),"y is not empty")
69 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
70 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
71 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
72 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
73 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
74 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
75 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
76 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
77 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
78 if self.domain.supportsContactElements():
79 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
80 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
81 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
82 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
83 self.assertTrue(self.check(mypde.getCoefficient("q"),q_ref),"q is not empty")
84 self.assertTrue(mypde.getCoefficient("r").isEmpty(),"r is not empty")
85
86 def test_setCoefficient_r(self):
87 mypde=LameEquation(self.domain,debug=self.DEBUG)
88 x=self.domain.getX()
89 mypde.setValue(r=x)
90
91 r_ref=interpolate(x,Solution(self.domain))
92 self.assertTrue(self.check(mypde.getCoefficient("A"),0),"A is not 0")
93 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
94 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
95 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
96 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
97 self.assertTrue(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
98 self.assertTrue(mypde.getCoefficient("y").isEmpty(),"y is not empty")
99 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
100 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
101 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
102 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
103 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
104 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
105 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
106 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
107 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
108 if self.domain.supportsContactElements():
109 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
110 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
111 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
112 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
113 self.assertTrue(self.check(mypde.getCoefficient("r"),r_ref),"r is nor x")
114 self.assertTrue(mypde.getCoefficient("q").isEmpty(),"q is not empty")
115
116
117 def test_setCoefficient_F(self):
118 mypde=LameEquation(self.domain,debug=self.DEBUG)
119 x=self.domain.getX()
120 mypde.setValue(F=x)
121
122 Y_ref=interpolate(x,Function(self.domain))
123 self.assertTrue(self.check(mypde.getCoefficient("A"),0),"A is not 0")
124 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
125 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
126 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
127 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
128 self.assertTrue(self.check(mypde.getCoefficient("Y"),Y_ref),"Y is not x")
129 self.assertTrue(mypde.getCoefficient("y").isEmpty(),"y is not empty")
130 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
131 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
132 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
133 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
134 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
135 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
136 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
137 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
138 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
139 if self.domain.supportsContactElements():
140 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
141 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
142 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
143 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
144 self.assertTrue(mypde.getCoefficient("q").isEmpty(),"q is not empty")
145 self.assertTrue(mypde.getCoefficient("r").isEmpty(),"r is not empty")
146
147 def test_setCoefficient_f(self):
148 mypde=LameEquation(self.domain,debug=self.DEBUG)
149 x=self.domain.getX()
150 mypde.setValue(f=x)
151
152 y_ref=interpolate(x,FunctionOnBoundary(self.domain))
153 self.assertTrue(self.check(mypde.getCoefficient("A"),0),"A is not 0")
154 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
155 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
156 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
157 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
158 self.assertTrue(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
159 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
160 self.assertTrue(self.check(mypde.getCoefficient("y"),y_ref),"d is not x[0]")
161 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
162 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
163 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
164 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
165 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
166 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"X_reduced is not empty")
167 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
168 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
169 if self.domain.supportsContactElements():
170 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
171 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
172 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
173 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
174 self.assertTrue(mypde.getCoefficient("q").isEmpty(),"q is not empty")
175 self.assertTrue(mypde.getCoefficient("r").isEmpty(),"r is not empty")
176
177 def test_setCoefficient_sigma(self):
178 mypde=LameEquation(self.domain,debug=self.DEBUG)
179 x=self.domain.getX()
180 mypde.setValue(sigma=outer(x,x))
181
182 X_ref=interpolate(outer(x,x),Function(self.domain))
183 self.assertTrue(self.check(mypde.getCoefficient("A"),0),"A is not 0")
184 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
185 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
186 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
187 self.assertTrue(self.check(mypde.getCoefficient("X"),X_ref),"X is not x X x")
188 self.assertTrue(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
189 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
190 self.assertTrue(mypde.getCoefficient("y").isEmpty(),"y is not empty")
191 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
192 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
193 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
194 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
195 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
196 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"X_reduced is not empty")
197 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
198 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
199 if self.domain.supportsContactElements():
200 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
201 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
202 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
203 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
204 self.assertTrue(mypde.getCoefficient("q").isEmpty(),"q is not empty")
205 self.assertTrue(mypde.getCoefficient("r").isEmpty(),"r is not empty")
206
207 def test_setCoefficient_lambda(self):
208 mypde=LameEquation(self.domain,debug=self.DEBUG)
209 x=self.domain.getX()
210 mypde.setValue(lame_lambda=x[0])
211
212
213 k3=kronecker(Function(self.domain))
214 k3Xk3=outer(k3,k3)
215 A_ref=x[0]*k3Xk3
216
217 self.assertTrue(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
218 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
219 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
220 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
221 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
222 self.assertTrue(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
223 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
224 self.assertTrue(mypde.getCoefficient("y").isEmpty(),"y is not empty")
225 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
226 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
227 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
228 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
229 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
230 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
231 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
232 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
233 if self.domain.supportsContactElements():
234 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
235 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
236 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
237 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
238 self.assertTrue(mypde.getCoefficient("q").isEmpty(),"q is not empty")
239 self.assertTrue(mypde.getCoefficient("r").isEmpty(),"r is not empty")
240
241 def test_setCoefficient_mu(self):
242 mypde=LameEquation(self.domain,debug=self.DEBUG)
243 x=self.domain.getX()
244 mypde.setValue(lame_mu=x[0])
245
246
247 k3=kronecker(Function(self.domain))
248 k3Xk3=outer(k3,k3)
249 A_ref=x[0]*(swap_axes(k3Xk3,0,3)+swap_axes(k3Xk3,1,3))
250
251 self.assertTrue(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
252 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
253 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
254 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
255 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
256 self.assertTrue(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
257 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
258 self.assertTrue(mypde.getCoefficient("y").isEmpty(),"y is not empty")
259 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
260 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
261 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
262 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
263 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
264 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
265 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
266 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
267 if self.domain.supportsContactElements():
268 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
269 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
270 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
271 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
272 self.assertTrue(mypde.getCoefficient("q").isEmpty(),"q is not empty")
273 self.assertTrue(mypde.getCoefficient("r").isEmpty(),"r is not empty")
274
275 def test_setCoefficient_lambdamu(self):
276 mypde=LameEquation(self.domain,debug=self.DEBUG)
277 x=self.domain.getX()
278 mypde.setValue(lame_lambda=x[0], lame_mu=x[1])
279
280 k3=kronecker(Function(self.domain))
281 k3Xk3=outer(k3,k3)
282 A_ref=x[0]*k3Xk3+x[1]*(swap_axes(k3Xk3,0,3)+swap_axes(k3Xk3,1,3))
283
284 self.assertTrue(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
285 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
286 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
287 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
288 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
289 self.assertTrue(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
290 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
291 self.assertTrue(mypde.getCoefficient("y").isEmpty(),"y is not empty")
292 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
293 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
294 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
295 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
296 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
297 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
298 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
299 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
300 if self.domain.supportsContactElements():
301 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
302 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
303 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
304 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
305 self.assertTrue(mypde.getCoefficient("q").isEmpty(),"q is not empty")
306 self.assertTrue(mypde.getCoefficient("r").isEmpty(),"r is not empty")
307
308 def test_solve(self):
309 d=self.domain.getDim()
310 mypde=LameEquation(self.domain)
311 cf=ContinuousFunction(self.domain)
312 x=cf.getX()
313 u_ex=x
314 msk=Vector(0.,cf)
315 for i in range(d): msk[i]=whereZero(x[i])
316 mypde.setValue(q=msk,r=u_ex,lame_mu=3,lame_lambda=50,f=(2*3+50*d)*FunctionOnBoundary(self.domain).getNormal())
317
318 u=mypde.getSolution()
319 self.assertTrue(self.check(u,u_ex,10*self.TOL),"incorrect solution")
320
321 class Test_Helmholtz(Test_linearPDEs):
322
323 def test_config(self):
324 mypde=Helmholtz(self.domain,debug=self.DEBUG)
325 self.assertEqual((mypde.getNumEquations(), mypde.getNumSolutions(), mypde.getSolverOptions().isSymmetric()),(1,1,True),"set up incorrect")
326 def test_setCoefficient_q(self):
327 mypde=Helmholtz(self.domain,debug=self.DEBUG)
328 x=self.domain.getX()
329 mypde.setValue(q=whereZero(x[0]))
330
331 q_ref=interpolate(whereZero(x[0]),Solution(self.domain))
332 A_ref=kronecker(self.domain)
333
334 self.assertTrue(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
335 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
336 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
337 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
338 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
339 self.assertTrue(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
340 self.assertTrue(mypde.getCoefficient("y").isEmpty(),"y is not empty")
341 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
342 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
343 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
344 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
345 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
346 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
347 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
348 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
349 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
350 if self.domain.supportsContactElements():
351 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
352 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
353 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
354 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
355 self.assertTrue(self.check(mypde.getCoefficient("q"),q_ref),"q is not empty")
356 self.assertTrue(mypde.getCoefficient("r").isEmpty(),"r is not empty")
357
358 def test_setCoefficient_r(self):
359 mypde=Helmholtz(self.domain,debug=self.DEBUG)
360 x=self.domain.getX()
361 mypde.setValue(r=x[0])
362
363 r_ref=interpolate(x[0],Solution(self.domain))
364 A_ref=kronecker(self.domain)
365 self.assertTrue(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
366 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
367 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
368 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
369 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
370 self.assertTrue(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
371 self.assertTrue(mypde.getCoefficient("y").isEmpty(),"y is not empty")
372 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
373 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
374 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
375 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
376 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
377 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
378 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
379 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
380 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
381 if self.domain.supportsContactElements():
382 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
383 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
384 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
385 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
386 self.assertTrue(self.check(mypde.getCoefficient("r"),r_ref),"r is nor x[0]")
387 self.assertTrue(mypde.getCoefficient("q").isEmpty(),"q is not empty")
388
389
390 def test_setCoefficient_f(self):
391 mypde=Helmholtz(self.domain,debug=self.DEBUG)
392 x=self.domain.getX()
393 mypde.setValue(f=x[0])
394
395 Y_ref=interpolate(x[0],Function(self.domain))
396 A_ref=kronecker(self.domain)
397 self.assertTrue(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
398 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
399 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
400 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
401 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
402 self.assertTrue(self.check(mypde.getCoefficient("Y"),Y_ref),"Y is not x[0]")
403 self.assertTrue(mypde.getCoefficient("y").isEmpty(),"y is not empty")
404 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
405 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
406 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
407 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
408 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
409 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
410 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
411 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
412 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
413 if self.domain.supportsContactElements():
414 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
415 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
416 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
417 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
418 self.assertTrue(mypde.getCoefficient("q").isEmpty(),"q is not empty")
419 self.assertTrue(mypde.getCoefficient("r").isEmpty(),"r is not empty")
420
421 def test_setCoefficient_alpha(self):
422 mypde=Helmholtz(self.domain,debug=self.DEBUG)
423 x=self.domain.getX()
424 mypde.setValue(alpha=x[0])
425
426 d_ref=interpolate(x[0],FunctionOnBoundary(self.domain))
427 A_ref=kronecker(self.domain)
428 self.assertTrue(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
429 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
430 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
431 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
432 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
433 self.assertTrue(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
434 self.assertTrue(mypde.getCoefficient("y").isEmpty(),"y is not empty")
435 self.assertTrue(self.check(mypde.getCoefficient("d"),d_ref),"d is not x[0]")
436 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
437 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
438 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
439 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
440 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
441 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"X_reduced is not empty")
442 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
443 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
444 if self.domain.supportsContactElements():
445 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
446 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
447 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
448 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
449 self.assertTrue(mypde.getCoefficient("q").isEmpty(),"q is not empty")
450 self.assertTrue(mypde.getCoefficient("r").isEmpty(),"r is not empty")
451
452 def test_setCoefficient_g(self):
453 mypde=Helmholtz(self.domain,debug=self.DEBUG)
454 x=self.domain.getX()
455 mypde.setValue(g=x[0])
456
457 y_ref=interpolate(x[0],FunctionOnBoundary(self.domain))
458 A_ref=kronecker(self.domain)
459 self.assertTrue(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
460 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
461 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
462 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
463 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
464 self.assertTrue(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
465 self.assertTrue(self.check(mypde.getCoefficient("y"),y_ref),"y is not x[0]")
466 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
467 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
468 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
469 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
470 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
471 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
472 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
473 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
474 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
475 if self.domain.supportsContactElements():
476 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
477 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
478 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
479 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
480 self.assertTrue(mypde.getCoefficient("q").isEmpty(),"q is not empty")
481 self.assertTrue(mypde.getCoefficient("r").isEmpty(),"r is not empty")
482
483 def test_setCoefficient_omega(self):
484 mypde=Helmholtz(self.domain,debug=self.DEBUG)
485 x=self.domain.getX()
486 mypde.setValue(omega=x[0])
487
488 D_ref=interpolate(x[0],Function(self.domain))
489 A_ref=kronecker(self.domain)
490 self.assertTrue(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
491 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
492 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
493 self.assertTrue(self.check(mypde.getCoefficient("D"),D_ref),"D is not x[0]")
494 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
495 self.assertTrue(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
496 self.assertTrue(mypde.getCoefficient("y").isEmpty(),"y is not empty")
497 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
498 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
499 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
500 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
501 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
502 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
503 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
504 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
505 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
506 if self.domain.supportsContactElements():
507 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
508 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
509 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
510 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
511 self.assertTrue(mypde.getCoefficient("q").isEmpty(),"q is not empty")
512 self.assertTrue(mypde.getCoefficient("r").isEmpty(),"r is not empty")
513
514 def test_solve(self):
515 d=self.domain.getDim()
516 cf=ContinuousFunction(self.domain)
517 u_ex=Scalar(1.,cf)
518 mypde=Helmholtz(self.domain)
519 mypde.setValue(f=3,omega=3,alpha=2,g=2)
520 u=mypde.getSolution()
521 self.assertTrue(self.check(u,u_ex,10*self.TOL),"incorrect solution")
522
523 class Test_Poisson(Test_linearPDEs):
524
525 def test_config(self):
526 mypde=Poisson(self.domain,debug=self.DEBUG)
527 self.assertEqual((mypde.getNumEquations(), mypde.getNumSolutions(), mypde.getSolverOptions().isSymmetric()),(1,1,True),"set up incorrect")
528 def test_setCoefficient_q(self):
529 mypde=Poisson(self.domain,debug=self.DEBUG)
530 x=self.domain.getX()
531 q_ref=interpolate(whereZero(x[0]),Solution(self.domain))
532 A_ref=kronecker(self.domain)
533 mypde.setValue(q=whereZero(x[0]))
534 self.assertTrue(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
535 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
536 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
537 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
538 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
539 self.assertTrue(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
540 self.assertTrue(mypde.getCoefficient("y").isEmpty(),"y is not empty")
541 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
542 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
543 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
544 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
545 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
546 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
547 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
548 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
549 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
550 if self.domain.supportsContactElements():
551 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
552 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
553 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
554 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
555 self.assertTrue(self.check(mypde.getCoefficient("q"),q_ref),"q is not empty")
556 self.assertTrue(mypde.getCoefficient("r").isEmpty(),"r is not empty")
557 def test_setCoefficient_f(self):
558 mypde=Poisson(self.domain,debug=self.DEBUG)
559 x=self.domain.getX()
560 Y_ref=interpolate(x[0],Function(self.domain))
561 A_ref=kronecker(self.domain)
562 mypde.setValue(f=x[0])
563 self.assertTrue(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
564 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
565 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
566 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
567 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
568 self.assertTrue(self.check(mypde.getCoefficient("Y"),Y_ref),"Y is not x[0]")
569 self.assertTrue(mypde.getCoefficient("y").isEmpty(),"y is not empty")
570 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
571 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
572 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
573 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
574 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
575 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
576 self.assertTrue(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
577 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
578 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
579 if self.domain.supportsContactElements():
580 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
581 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
582 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
583 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
584 self.assertTrue(mypde.getCoefficient("q").isEmpty(),"q is not empty")
585 self.assertTrue(mypde.getCoefficient("r").isEmpty(),"r is not empty")
586 def test_setCoefficient_f_reduced(self):
587 mypde=Poisson(self.domain,debug=self.DEBUG)
588 x=self.domain.getX()
589 Y_ref=interpolate(x[0],ReducedFunction(self.domain))
590 A_ref=kronecker(self.domain)
591 mypde.setValue(f_reduced=x[0])
592 self.assertTrue(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
593 self.assertTrue(mypde.getCoefficient("B").isEmpty(),"B is not empty")
594 self.assertTrue(mypde.getCoefficient("C").isEmpty(),"C is not empty")
595 self.assertTrue(mypde.getCoefficient("D").isEmpty(),"D is not empty")
596 self.assertTrue(mypde.getCoefficient("X").isEmpty(),"X is not empty")
597 self.assertTrue(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
598 self.assertTrue(mypde.getCoefficient("y").isEmpty(),"y is not empty")
599 self.assertTrue(mypde.getCoefficient("d").isEmpty(),"d is not empty")
600 self.assertTrue(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
601 self.assertTrue(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
602 self.assertTrue(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
603 self.assertTrue(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
604 self.assertTrue(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
605 self.assertTrue(self.check(mypde.getCoefficient("Y_reduced"),Y_ref),"Y_reduced is not x[0]")
606 self.assertTrue(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
607 self.assertTrue(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
608 if self.domain.supportsContactElements():
609 self.assertTrue(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
610 self.assertTrue(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
611 self.assertTrue(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
612 self.assertTrue(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
613 self.assertTrue(mypde.getCoefficient("q").isEmpty(),"q is not empty")
614 self.assertTrue(mypde.getCoefficient("r").isEmpty(),"r is not empty")
615 def test_solve(self):
616 d=self.domain.getDim()
617 cf=ContinuousFunction(self.domain)
618 x=cf.getX()
619 #construct exact solution:
620 u_ex=Scalar(1.,cf)
621 for i in range(d):
622 u_ex*=x[i]*(2.-x[i])
623 #construct mask:
624 msk=Scalar(0.,cf)
625 for i in range(d):
626 msk+=whereZero(x[i])
627 #construct right hand side
628 f=Scalar(0,cf)
629 for i in range(d):
630 f_p=Scalar(1,cf)
631 for j in range(d):
632 if i==j:
633 f_p*=2.
634 else:
635 f_p*=x[j]*(2-x[j])
636 f+=f_p
637 mypde=Poisson(self.domain)
638 mypde.setValue(f=f,q=msk)
639 u=mypde.getSolution()
640 self.assertTrue(self.check(u,u_ex,10*self.TOL),"incorrect solution")
641
642 class Test_LinearPDE_noLumping(Test_linearPDEs):
643 N=4
644 def test_SolverOptions(self):
645 so=SolverOptions()
646
647 self.assertTrue(so.getSmoother() == 28, "initial Smoother is wrong.")
648 self.assertRaises(ValueError,so.setSmoother,-1)
649 so.setSmoother(so.GAUSS_SEIDEL)
650 self.assertTrue(so.getSmoother() == 28, "Gauss-Seidel smoother is not set.")
651 so.setSmoother(so.JACOBI)
652 self.assertTrue(so.getSmoother() == 10, "Jacobi smoother is not set.")
653
654 self.assertTrue(so.getLevelMax() == 100, "initial LevelMax is wrong.")
655 self.assertRaises(ValueError,so.setLevelMax,-1)
656 so.setLevelMax(20)
657 self.assertTrue(so.getLevelMax() == 20, "LevelMax is wrong.")
658
659 self.assertTrue(so.getCoarseningThreshold() == 0.25, "initial CoarseningThreshold is wrong.")
660 self.assertRaises(ValueError,so.setCoarseningThreshold,-1)
661 so.setCoarseningThreshold(0.1)
662 self.assertTrue(so.getCoarseningThreshold() == 0.1, "CoarseningThreshold is wrong.")
663
664 self.assertTrue(so.getMinCoarseMatrixSize() == 500, "initial Minimum Coarse Matrix Size is wrong.")
665 self.assertRaises(ValueError,so.setMinCoarseMatrixSize,-1)
666 so.setMinCoarseMatrixSize(1000)
667 self.assertTrue(so.getMinCoarseMatrixSize() == 1000, "Minimum Coarse Matrix Size is wrong.")
668
669 self.assertTrue(so.getNumSweeps() == 1, "initial Sweeps is wrong.")
670 self.assertRaises(ValueError,so.setNumSweeps,-1)
671 so.setNumSweeps(3)
672 self.assertTrue(so.getNumSweeps() == 3, "Sweeps is wrong.")
673
674 self.assertTrue(so.getNumPreSweeps() == 1, "initial PreSweeps is wrong.")
675 self.assertRaises(ValueError,so.setNumPreSweeps,-1)
676 so.setNumPreSweeps(4)
677 self.assertTrue(so.getNumPreSweeps() == 4, "PreSweeps is wrong.")
678
679 self.assertTrue(so.getNumPostSweeps() == 1, "initial PostSweeps is wrong.")
680 self.assertRaises(ValueError,so.setNumPostSweeps,-1)
681 so.setNumPostSweeps(5)
682 self.assertTrue(so.getNumPostSweeps() == 5, "PostSweeps is wrong.")
683
684 self.assertTrue(so.getTolerance() == 1.e-8, "initial Tolerance is wrong.")
685 self.assertRaises(ValueError,so.setTolerance,-1)
686 so.setTolerance(0.2)
687 self.assertTrue(so.getTolerance() == 0.2, "Tolerance is wrong.")
688
689 self.assertTrue(so.getAbsoluteTolerance() == 0., "initial AbsoluteTolerance is wrong.")
690 self.assertRaises(ValueError,so.setAbsoluteTolerance,-1)
691 so.setAbsoluteTolerance(0.3)
692 self.assertTrue(so.getAbsoluteTolerance() == 0.3, "AbsoluteTolerance is wrong.")
693
694 self.assertTrue(so.getInnerTolerance() == 0.9, "initial InnerTolerance is wrong.")
695 self.assertRaises(ValueError,so.setInnerTolerance,-1)
696 so.setInnerTolerance(0.4)
697 self.assertTrue(so.getInnerTolerance() == 0.4, "InnerTolerance is wrong.")
698
699 self.assertTrue(so.getDropTolerance() == 0.01, "initial DropTolerance is wrong.")
700 self.assertRaises(ValueError,so.setDropTolerance,-1)
701 so.setDropTolerance(0.5)
702 self.assertTrue(so.getDropTolerance() == 0.5, "DropDropTolerance is wrong.")
703
704 self.assertTrue(so.getDropStorage() == 2., "initial DropStorage is wrong.")
705 self.assertRaises(ValueError,so.setDropStorage,-1)
706 so.setDropStorage(10)
707 self.assertTrue(so.getDropStorage() == 10, "DropStorage is wrong.")
708
709 self.assertTrue(so.getRelaxationFactor() == 0.3, "initial RelaxationFactor is wrong.")
710 self.assertRaises(ValueError,so.setRelaxationFactor,-1)
711 so.setRelaxationFactor(0.1)
712 self.assertTrue(so.getRelaxationFactor() == 0.1, "Relaxation is wrong.")
713
714
715 self.assertTrue(so.getIterMax() == 100000, "initial IterMax is wrong.")
716 self.assertRaises(ValueError,so.setIterMax,0)
717 so.setIterMax(11)
718 self.assertTrue(so.getIterMax() == 11, "IterMax is wrong.")
719
720 self.assertTrue(so.getInnerIterMax() == 10, "initial InnerIterMax is wrong.")
721 self.assertRaises(ValueError,so.setInnerIterMax,0)
722 so.setInnerIterMax(12)
723 self.assertTrue(so.getInnerIterMax() == 12, "InnerIterMax is wrong.")
724
725 self.assertTrue(so.getTruncation() == 20, "initial Truncation is wrong.")
726 self.assertRaises(ValueError,so.setTruncation,0)
727 so.setTruncation(13)
728 self.assertTrue(so.getTruncation() == 13, "Truncation is wrong.")
729
730 self.assertTrue(so.getRestart() == None, "initial Truncation is wrong.")
731 self.assertRaises(ValueError,so.setTruncation,0)
732 so.setRestart(14)
733 self.assertTrue(so.getRestart() == 14, "Truncation is wrong.")
734 so.setRestart(None)
735 self.assertTrue(so.getRestart() == None, "Truncation is wrong.")
736
737 self.assertTrue(not so.isVerbose(), "initial verbosity flag is wrong.")
738 so.setVerbosityOn()
739 self.assertTrue(so.isVerbose(), "verbosity (1) flag is wrong.")
740 so.setVerbosityOff()
741 self.assertTrue(not so.isVerbose(), "verbosity (2) flag is wrong.")
742 so.setVerbosity(verbose=True)
743 self.assertTrue(so.isVerbose(), "verbosity (3) flag is wrong.")
744 so.setVerbosity(verbose=False)
745 self.assertTrue(not so.isVerbose(), "verbosity (4) flag is wrong.")
746
747 self.assertTrue(not so.isSymmetric(), "initial symmetry flag is wrong.")
748 so.setSymmetryOn()
749 self.assertTrue(so.isSymmetric(), "symmetry (1) flag is wrong.")
750 so.setSymmetryOff()
751 self.assertTrue(not so.isSymmetric(), "symmetry (2) flag is wrong.")
752 so.setSymmetry(flag=True)
753 self.assertTrue(so.isSymmetric(), "symmetry (3) flag is wrong.")
754 so.setSymmetry(flag=False)
755 self.assertTrue(not so.isSymmetric(), "symmetry (4) flag is wrong.")
756
757 self.assertTrue(so.adaptInnerTolerance(), "initial InnerToleranceAdaption flag is wrong.")
758 so.setInnerToleranceAdaptionOn()
759 self.assertTrue(so.adaptInnerTolerance(), "InnerToleranceAdaption (1) flag is wrong.")
760 so.setInnerToleranceAdaptionOff()
761 self.assertTrue(not so.adaptInnerTolerance(), "InnerToleranceAdaption (2) flag is wrong.")
762 so.setInnerToleranceAdaption(adapt=True)
763 self.assertTrue(so.adaptInnerTolerance(), "InnerToleranceAdaption (3) flag is wrong.")
764 so.setInnerToleranceAdaption(adapt=False)
765 self.assertTrue(not so.adaptInnerTolerance(), "InnerToleranceAdaption (4) flag is wrong.")
766
767 self.assertTrue(not so.acceptConvergenceFailure(), "initial acceptConvergenceFailure flag is wrong.")
768 so.setAcceptanceConvergenceFailureOn()
769 self.assertTrue(so.acceptConvergenceFailure(), "acceptConvergenceFailure (1) flag is wrong.")
770 so.setAcceptanceConvergenceFailureOff()
771 self.assertTrue(not so.acceptConvergenceFailure(), "acceptConvergenceFailure (2) flag is wrong.")
772 so.setAcceptanceConvergenceFailure(accept=True)
773 self.assertTrue(so.acceptConvergenceFailure(), "acceptConvergenceFailure (3) flag is wrong.")
774 so.setAcceptanceConvergenceFailure(accept=False)
775 self.assertTrue(not so.acceptConvergenceFailure(), "acceptConvergenceFailure (4) flag is wrong.")
776
777 self.assertTrue(so.getReordering() == 30, "initial Reordering is wrong.")
778 self.assertRaises(ValueError,so.setReordering,-1)
779 so.setReordering(so.NO_REORDERING)
780 self.assertTrue(so.getReordering() == 17, "NO_REORDERING is not set.")
781 so.setReordering(so.MINIMUM_FILL_IN)
782 self.assertTrue(so.getReordering() == 18, "MINIMUM_FILL_IN is not set.")
783 so.setReordering(so.NESTED_DISSECTION)
784 self.assertTrue(so.getReordering() == 19, "NESTED_DISSECTION is not set.")
785 so.setReordering(so.DEFAULT_REORDERING)
786 self.assertTrue(so.getReordering() == 30, "DEFAULT_REORDERING is not set.")
787
788 self.assertTrue(so.getPackage() == 0, "initial solver package is wrong.")
789 self.assertRaises(ValueError,so.setPackage,-1)
790 so.setPackage(so.PASO)
791 self.assertTrue(so.getPackage() == 21, "PASO is not set.")
792 so.setPackage(so.SUPER_LU)
793 self.assertTrue(so.getPackage() == 31, "SUPER_LU is not set.")
794 so.setPackage(so.PASTIX)
795 self.assertTrue(so.getPackage() == 32, "PASTIX is not set.")
796 so.setPackage(so.MKL)
797 self.assertTrue(so.getPackage() == 15, "MKL is not set.")
798 so.setPackage(so.UMFPACK)
799 self.assertTrue(so.getPackage() == 16, "UMFPACK is not set.")
800 so.setPackage(so.TRILINOS)
801 self.assertTrue(so.getPackage() == 24, "TRILINOS is not set.")
802
803 self.assertTrue(so.getSolverMethod() == 0, "initial SolverMethod is wrong.")
804 self.assertRaises(ValueError,so.setSolverMethod,-1)
805 so.setSolverMethod(so.DIRECT)
806 self.assertTrue(so.getSolverMethod() == 1, "DIRECT is not set.")
807 so.setSolverMethod(so.CHOLEVSKY)
808 self.assertTrue(so.getSolverMethod() == 2, "CHOLEVSKY is not set.")
809 so.setSolverMethod(so.PCG)
810 self.assertTrue(so.getSolverMethod() == 3, "PCG is not set.")
811 so.setSolverMethod(so.CR)
812 self.assertTrue(so.getSolverMethod() == 4, "CR is not set.")
813 so.setSolverMethod(so.CGS)
814 self.assertTrue(so.getSolverMethod() == 5, "CGS is not set.")
815 so.setSolverMethod(so.BICGSTAB)
816 self.assertTrue(so.getSolverMethod() == 6, "BICGSTAB is not set.")
817 so.setSolverMethod(so.GMRES)
818 self.assertTrue(so.getSolverMethod() == 11, "GMRES is not set.")
819 so.setSolverMethod(so.PRES20)
820 self.assertTrue(so.getSolverMethod() == 12, "PRES20 is not set.")
821 so.setSolverMethod(so.LUMPING)
822 self.assertTrue(so.getSolverMethod() == 13, "LUMPING is not set.")
823 so.setSolverMethod(so.ITERATIVE)
824 self.assertTrue(so.getSolverMethod() == 20, "ITERATIVE is not set.")
825 so.setSolverMethod(so.NONLINEAR_GMRES)
826 self.assertTrue(so.getSolverMethod() == 25, "NONLINEAR_GMRES is not set.")
827 so.setSolverMethod(so.TFQMR)
828 self.assertTrue(so.getSolverMethod() == 26, "TFQMR is not set.")
829 so.setSolverMethod(so.MINRES)
830 self.assertTrue(so.getSolverMethod() == 27, "MINRES is not set.")
831 so.setSolverMethod(so.DEFAULT)
832 self.assertTrue(so.getSolverMethod() == 0, "DEFAULT is not set.")
833
834 self.assertTrue(so.getPreconditioner() == 10, "initial Preconditioner is wrong.")
835 self.assertRaises(ValueError,so.setPreconditioner,-1)
836 so.setPreconditioner(so.ILU0)
837 self.assertTrue(so.getPreconditioner() == 8, "ILU0 is not set.")
838 so.setPreconditioner(so.ILUT)
839 self.assertTrue(so.getPreconditioner() == 9, "ILUT is not set.")
840 so.setPreconditioner(so.JACOBI)
841 self.assertTrue(so.getPreconditioner() == 10, "JACOBI is not set.")
842 if getEscriptParamInt('DISABLE_AMG', 0):
843 print("AMG test disabled on MPI build")
844 else:
845 so.setPreconditioner(so.AMG)
846 self.assertTrue(so.getPreconditioner() == 22, "AMG is not set.")
847 so.setPreconditioner(so.REC_ILU)
848 self.assertTrue(so.getPreconditioner() == 23, "REC_ILU is not set.")
849 so.setPreconditioner(so.GAUSS_SEIDEL)
850 self.assertTrue(so.getPreconditioner() == 28, "GAUSS_SEIDEL is not set.")
851 so.setPreconditioner(so.RILU)
852 self.assertTrue(so.getPreconditioner() == 29, "RILU is not set.")
853 so.setPreconditioner(so.AMLI)
854 self.assertTrue(so.getPreconditioner() == 38, "AMLI is not set.")
855 so.setPreconditioner(so.NO_PRECONDITIONER)
856 self.assertTrue(so.getPreconditioner() == 36, "NO_PRECONDITIONER is not set.")
857
858 self.assertTrue(so.getCoarsening() == 0, "initial Coarseningr is wrong.")
859 self.assertRaises(ValueError,so.setCoarsening,-1)
860 so.setCoarsening(so.YAIR_SHAPIRA_COARSENING)
861 self.assertTrue(so.getCoarsening() == 33, "YAIR_SHAPIRA_COARSENING is not set.")
862 so.setCoarsening(so.RUGE_STUEBEN_COARSENING)
863 self.assertTrue(so.getCoarsening() == 34, "RUGE_STUEBEN_COARSENING is not set.")
864 so.setCoarsening(so.AGGREGATION_COARSENING)
865 self.assertTrue(so.getCoarsening() == 35, "AGREGATION_COARSENING is not set.")
866 so.setCoarsening(so.STANDARD_COARSENING)
867 self.assertTrue(so.getCoarsening() == 39, "STANDARD_COARSENING is not set.")
868 so.setCoarsening(so.DEFAULT)
869 self.assertTrue(so.getCoarsening() == 0, "DEFAULT is not set.")
870
871 self.assertTrue(so.getDiagnostics("num_iter") == None, "initial num_iter is wrong.")
872 self.assertTrue(so.getDiagnostics("num_inner_iter") == None, "initial num_inner_iter is wrong.")
873 self.assertTrue(so.getDiagnostics("time") == None, "initial time is wrong.")
874 self.assertTrue(so.getDiagnostics("set_up_time") == None, "initial set_up_time is wrong.")
875 self.assertTrue(so.getDiagnostics("residual_norm") == None, "initial residual_norm is wrong.")
876 self.assertTrue(so.getDiagnostics("converged") == None, "initial converged is wrong.")
877 self.assertTrue(so.hasConverged() == None, "initial convergence flag is wrong.")
878 self.assertTrue(so.getDiagnostics("cum_num_inner_iter") == 0, "initial cum_num_inner_iter is wrong.")
879 self.assertTrue(so.getDiagnostics("cum_num_iter") == 0, "initial cum_num_iter is wrong.")
880 self.assertTrue(so.getDiagnostics("cum_time") ==0, "initial cum_time is wrong.")
881 self.assertTrue(so.getDiagnostics("cum_set_up_time") == 0, "initial cum_set_up_time is wrong.")
882
883 so._updateDiagnostics("num_iter",1)
884 so._updateDiagnostics("num_inner_iter",2)
885 so._updateDiagnostics("time",3)
886 so._updateDiagnostics("set_up_time",4)
887 so._updateDiagnostics("residual_norm",5)
888 so._updateDiagnostics("converged",True)
889
890 self.assertTrue(so.getDiagnostics("num_iter") == 1, "num_iter is wrong.")
891 self.assertTrue(so.getDiagnostics("num_inner_iter") == 2, "num_inner_iter is wrong.")
892 self.assertTrue(so.getDiagnostics("time") == 3, "time is wrong.")
893 self.assertTrue(so.getDiagnostics("set_up_time") == 4, "set_up_time is wrong.")
894 self.assertTrue(so.getDiagnostics("residual_norm") == 5, "residual_norm is wrong.")
895 self.assertTrue(so.getDiagnostics("converged"), "converged is wrong.")
896 self.assertTrue(so.hasConverged(), "convergence flag is wrong.")
897 self.assertTrue(so.getDiagnostics("cum_num_inner_iter") == 2, "cum_num_inner_iter is wrong.")
898 self.assertTrue(so.getDiagnostics("cum_num_iter") == 1, "cum_num_iter is wrong.")
899 self.assertTrue(so.getDiagnostics("cum_time") ==3, "cum_time is wrong.")
900 self.assertTrue(so.getDiagnostics("cum_set_up_time") == 4, "cum_set_up_time is wrong.")
901
902 so.resetDiagnostics()
903 self.assertTrue(so.getDiagnostics("num_iter") == None, "initial num_iter is wrong.")
904 self.assertTrue(so.getDiagnostics("num_inner_iter") == None, "initial num_inner_iter is wrong.")
905 self.assertTrue(so.getDiagnostics("time") == None, "initial time is wrong.")
906 self.assertTrue(so.getDiagnostics("set_up_time") == None, "initial set_up_time is wrong.")
907 self.assertTrue(so.getDiagnostics("residual_norm") == None, "initial residual_norm is wrong.")
908 self.assertTrue(so.getDiagnostics("converged") == None, "initial converged is wrong.")
909 self.assertTrue(so.hasConverged() == None, "initial convergence flag is wrong")
910 self.assertTrue(so.getDiagnostics("cum_num_inner_iter") == 2, "cum_num_inner_iter is wrong.")
911 self.assertTrue(so.getDiagnostics("cum_num_iter") == 1, "cum_num_iter is wrong.")
912 self.assertTrue(so.getDiagnostics("cum_time") ==3, "cum_time is wrong.")
913 self.assertTrue(so.getDiagnostics("cum_set_up_time") == 4, "cum_set_up_time is wrong.")
914
915 so._updateDiagnostics("num_iter",10)
916 so._updateDiagnostics("num_inner_iter",20)
917 so._updateDiagnostics("time",30)
918 so._updateDiagnostics("set_up_time",40)
919 so._updateDiagnostics("residual_norm",50)
920 so._updateDiagnostics("converged",False)
921
922 self.assertTrue(so.getDiagnostics("num_iter") == 10, "num_iter is wrong.")
923 self.assertTrue(so.getDiagnostics("num_inner_iter") == 20, "num_inner_iter is wrong.")
924 self.assertTrue(so.getDiagnostics("time") == 30, "time is wrong.")
925 self.assertTrue(so.getDiagnostics("set_up_time") == 40, "set_up_time is wrong.")
926 self.assertTrue(so.getDiagnostics("residual_norm") == 50, "residual_norm is wrong.")
927 self.assertTrue(not so.getDiagnostics("converged"), "converged is wrong.")
928 self.assertTrue(not so.hasConverged(), "convergence flag is wrong.")
929 self.assertTrue(so.getDiagnostics("cum_num_inner_iter") == 22, "cum_num_inner_iter is wrong.")
930 self.assertTrue(so.getDiagnostics("cum_num_iter") == 11, "cum_num_iter is wrong.")
931 self.assertTrue(so.getDiagnostics("cum_time") ==33, "cum_time is wrong.")
932 self.assertTrue(so.getDiagnostics("cum_set_up_time") == 44, "cum_set_up_time is wrong.")
933
934 so.resetDiagnostics(all=True)
935 self.assertTrue(so.getDiagnostics("num_iter") == None, "initial num_iter is wrong.")
936 self.assertTrue(so.getDiagnostics("num_inner_iter") == None, "initial num_inner_iter is wrong.")
937 self.assertTrue(so.getDiagnostics("time") == None, "initial time is wrong.")
938 self.assertTrue(so.getDiagnostics("set_up_time") == None, "initial set_up_time is wrong.")
939 self.assertTrue(so.getDiagnostics("residual_norm") == None, "initial residual_norm is wrong.")
940 self.assertTrue(so.getDiagnostics("converged") == None, "initial converged is wrong.")
941 self.assertTrue(so.hasConverged() == None, "initial convergence flag is wrong.")
942 self.assertTrue(so.getDiagnostics("cum_num_inner_iter") == 0, "initial cum_num_inner_iter is wrong.")
943 self.assertTrue(so.getDiagnostics("cum_num_iter") == 0, "initial cum_num_iter is wrong.")
944 self.assertTrue(so.getDiagnostics("cum_time") ==0, "initial cum_time is wrong.")
945 self.assertTrue(so.getDiagnostics("cum_set_up_time") == 0, "initial cum_set_up_time is wrong.")
946
947 def test_setCoefficient_WithIllegalFunctionSpace(self):
948 mypde=LinearPDE(self.domain,debug=self.DEBUG)
949 self.assertRaises(IllegalCoefficientFunctionSpace, mypde.setValue, C=Vector(0.,FunctionOnBoundary(self.domain)))
950
951 def test_setCoefficient_WithWrongName(self):
952 mypde=LinearPDE(self.domain,debug=self.DEBUG)
953 self.assertRaises(IllegalCoefficient, mypde.setValue, ROMA=0.)
954
955 def test_resetCoefficient_WithWrongShape(self):
956 mypde=LinearPDE(self.domain,numEquations=2,debug=self.DEBUG)
957 self.assertRaises(IllegalCoefficientValue, mypde.setValue, C=0.)
958
959 def test_reducedOn(self):
960 mypde=LinearPDE(self.domain,debug=self.DEBUG)
961 x=self.domain.getX()
962 mypde.setReducedOrderOn()
963 mypde.setValue(A=kronecker(self.domain),D=x[0],Y=x[0])
964 u=mypde.getSolution()
965 self.assertTrue(self.check(u,1.),'solution is wrong.')
966
967 def test_attemptToChangeOrderAfterDefinedCoefficient(self):
968 mypde=LinearPDE(self.domain,debug=self.DEBUG)
969 mypde.setValue(D=1.)
970 self.assertRaises(RuntimeError, mypde.setReducedOrderOn)
971
972 def test_reducedOnConfig(self):
973 mypde=LinearPDE(self.domain,debug=self.DEBUG)
974 mypde.setReducedOrderOn()
975 self.assertEqual((mypde.getFunctionSpaceForSolution(), mypde.getFunctionSpaceForEquation()),(ReducedSolution(self.domain),ReducedSolution(self.domain)),"reduced function spaces expected.")
976 #
977 # set coefficients for scalars:
978 #
979 def test_setCoefficient_A_Scalar(self):
980 d=self.domain.getDim()
981 mypde=LinearPDE(self.domain,debug=self.DEBUG)
982 mypde.setValue(A=numpy.ones((d,d)))
983 coeff=mypde.getCoefficient("A")
984 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,d),Function(self.domain),1,1))
985 def test_setCoefficient_B_Scalar(self):
986 d=self.domain.getDim()
987 mypde=LinearPDE(self.domain,debug=self.DEBUG)
988 mypde.setValue(B=numpy.ones((d,)))
989 coeff=mypde.getCoefficient("B")
990 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,),Function(self.domain),1,1))
991 def test_setCoefficient_C_Scalar(self):
992 d=self.domain.getDim()
993 mypde=LinearPDE(self.domain,debug=self.DEBUG)
994 mypde.setValue(C=numpy.ones((d,)))
995 coeff=mypde.getCoefficient("C")
996 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,),Function(self.domain),1,1))
997 def test_setCoefficient_D_Scalar(self):
998 d=self.domain.getDim()
999 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1000 mypde.setValue(D=1.)
1001 coeff=mypde.getCoefficient("D")
1002 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),Function(self.domain),1,1))
1003 def test_setCoefficient_X_Scalar(self):
1004 d=self.domain.getDim()
1005 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1006 mypde.setValue(X=numpy.ones((d,)))
1007 coeff=mypde.getCoefficient("X")
1008 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((d,),Function(self.domain),1))
1009 def test_setCoefficient_Y_Scalar(self):
1010 d=self.domain.getDim()
1011 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1012 mypde.setValue(Y=1.)
1013 coeff=mypde.getCoefficient("Y")
1014 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),Function(self.domain),1))
1015 def test_setCoefficient_y_Scalar(self):
1016 d=self.domain.getDim()
1017 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1018 mypde.setValue(y=1.)
1019 coeff=mypde.getCoefficient("y")
1020 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),FunctionOnBoundary(self.domain),1))
1021 def test_setCoefficient_d_Scalar(self):
1022 d=self.domain.getDim()
1023 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1024 mypde.setValue(d=1.)
1025 coeff=mypde.getCoefficient("d")
1026 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),FunctionOnBoundary(self.domain),1,1))
1027 def test_setCoefficient_d_contact_Scalar(self):
1028 if self.domain.supportsContactElements():
1029 d=self.domain.getDim()
1030 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1031 mypde.setValue(d_contact=1.)
1032 coeff=mypde.getCoefficient("d_contact")
1033 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),FunctionOnContactZero(self.domain),1,1))
1034 def test_setCoefficient_y_contact_Scalar(self):
1035 d=self.domain.getDim()
1036 if self.domain.supportsContactElements():
1037 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1038 mypde.setValue(y_contact=1.)
1039 coeff=mypde.getCoefficient("y_contact")
1040 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),FunctionOnContactZero(self.domain),1))
1041 def test_setCoefficient_A_reduced_Scalar(self):
1042 d=self.domain.getDim()
1043 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1044 mypde.setValue(A_reduced=numpy.ones((d,d)))
1045 coeff=mypde.getCoefficient("A_reduced")
1046 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,d),ReducedFunction(self.domain),1,1))
1047 def test_setCoefficient_B_reduced_Scalar(self):
1048 d=self.domain.getDim()
1049 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1050 mypde.setValue(B_reduced=numpy.ones((d,)))
1051 coeff=mypde.getCoefficient("B_reduced")
1052 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1,1))
1053 def test_setCoefficient_C_reduced_Scalar(self):
1054 d=self.domain.getDim()
1055 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1056 mypde.setValue(C_reduced=numpy.ones((d,)))
1057 coeff=mypde.getCoefficient("C_reduced")
1058 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1,1))
1059 def test_setCoefficient_D_reduced_Scalar(self):
1060 d=self.domain.getDim()
1061 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1062 mypde.setValue(D_reduced=1.)
1063 coeff=mypde.getCoefficient("D_reduced")
1064 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),ReducedFunction(self.domain),1,1))
1065 def test_setCoefficient_X_reduced_Scalar(self):
1066 d=self.domain.getDim()
1067 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1068 mypde.setValue(X_reduced=numpy.ones((d,)))
1069 coeff=mypde.getCoefficient("X_reduced")
1070 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1))
1071 def test_setCoefficient_Y_reduced_Scalar(self):
1072 d=self.domain.getDim()
1073 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1074 mypde.setValue(Y_reduced=1.)
1075 coeff=mypde.getCoefficient("Y_reduced")
1076 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),ReducedFunction(self.domain),1))
1077 def test_setCoefficient_y_reduced_Scalar(self):
1078 d=self.domain.getDim()
1079 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1080 mypde.setValue(y_reduced=1.)
1081 coeff=mypde.getCoefficient("y_reduced")
1082 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),ReducedFunctionOnBoundary(self.domain),1))
1083 def test_setCoefficient_d_reduced_Scalar(self):
1084 d=self.domain.getDim()
1085 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1086 mypde.setValue(d_reduced=1.)
1087 coeff=mypde.getCoefficient("d_reduced")
1088 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),ReducedFunctionOnBoundary(self.domain),1,1))
1089 def test_setCoefficient_d_contact_reduced_Scalar(self):
1090 if self.domain.supportsContactElements():
1091 d=self.domain.getDim()
1092 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1093 mypde.setValue(d_contact_reduced=1.)
1094 coeff=mypde.getCoefficient("d_contact_reduced")
1095 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),ReducedFunctionOnContactZero(self.domain),1,1))
1096 def test_setCoefficient_y_contact_reduced_Scalar(self):
1097 if self.domain.supportsContactElements():
1098 d=self.domain.getDim()
1099 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1100 mypde.setValue(y_contact_reduced=1.)
1101 coeff=mypde.getCoefficient("y_contact_reduced")
1102 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),ReducedFunctionOnContactZero(self.domain),1))
1103 def test_setCoefficient_r_Scalar(self):
1104 d=self.domain.getDim()
1105 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1106 mypde.setValue(r=1.)
1107 coeff=mypde.getCoefficient("r")
1108 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((),Solution(self.domain),1))
1109 def test_setCoefficient_q_Scalar(self):
1110 d=self.domain.getDim()
1111 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1112 mypde.setValue(q=1.)
1113 coeff=mypde.getCoefficient("q")
1114 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((),Solution(self.domain),1))
1115 def test_setCoefficient_r_Scalar_reducedOn(self):
1116 d=self.domain.getDim()
1117 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1118 mypde.setReducedOrderOn()
1119 mypde.setValue(r=1.)
1120 coeff=mypde.getCoefficient("r")
1121 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((),ReducedSolution(self.domain),1))
1122 def test_setCoefficient_q_Scalar_reducedOn(self):
1123 d=self.domain.getDim()
1124 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1125 mypde.setReducedOrderOn()
1126 mypde.setValue(q=1.)
1127 coeff=mypde.getCoefficient("q")
1128 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((),ReducedSolution(self.domain),1))
1129
1130 def test_setCoefficient_A_reduced_Scalar_usingA(self):
1131 d=self.domain.getDim()
1132 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1133 mypde.setValue(A=Data(numpy.ones((d,d)),ReducedFunction(self.domain)))
1134 coeff=mypde.getCoefficient("A_reduced")
1135 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,d),ReducedFunction(self.domain),1,1))
1136 def test_setCoefficient_B_reduced_Scalar_usingB(self):
1137 d=self.domain.getDim()
1138 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1139 mypde.setValue(B=Data(numpy.ones((d,)),ReducedFunction(self.domain)))
1140 coeff=mypde.getCoefficient("B_reduced")
1141 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1,1))
1142 def test_setCoefficient_C_reduced_Scalar_usingC(self):
1143 d=self.domain.getDim()
1144 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1145 mypde.setValue(C=Data(numpy.ones((d,)),ReducedFunction(self.domain)))
1146 coeff=mypde.getCoefficient("C_reduced")
1147 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1,1))
1148 def test_setCoefficient_D_reduced_Scalar_usingD(self):
1149 d=self.domain.getDim()
1150 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1151 mypde.setValue(D=Scalar(1.,ReducedFunction(self.domain)))
1152 coeff=mypde.getCoefficient("D_reduced")
1153 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),ReducedFunction(self.domain),1,1))
1154 def test_setCoefficient_X_reduced_Scalar_usingX(self):
1155 d=self.domain.getDim()
1156 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1157 mypde.setValue(X_reduced=Data(numpy.ones((d,)),ReducedFunction(self.domain)))
1158 coeff=mypde.getCoefficient("X_reduced")
1159 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1))
1160 def test_setCoefficient_Y_reduced_Scalar_usingY(self):
1161 d=self.domain.getDim()
1162 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1163 mypde.setValue(Y=Scalar(1.,ReducedFunction(self.domain)))
1164 coeff=mypde.getCoefficient("Y_reduced")
1165 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),ReducedFunction(self.domain),1))
1166 def test_setCoefficient_y_reduced_Scalar_using_y(self):
1167 d=self.domain.getDim()
1168 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1169 mypde.setValue(y=Scalar(1.,ReducedFunctionOnBoundary(self.domain)))
1170 coeff=mypde.getCoefficient("y_reduced")
1171 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),ReducedFunctionOnBoundary(self.domain),1))
1172 def test_setCoefficient_d_reduced_Scalar_using_d(self):
1173 d=self.domain.getDim()
1174 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1175 mypde.setValue(d=Scalar(1.,ReducedFunctionOnBoundary(self.domain)))
1176 coeff=mypde.getCoefficient("d_reduced")
1177 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),ReducedFunctionOnBoundary(self.domain),1,1))
1178 def test_setCoefficient_d_contact_reduced_Scalar_using_d_contact(self):
1179 if self.domain.supportsContactElements():
1180 d=self.domain.getDim()
1181 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1182 mypde.setValue(d_contact=Scalar(1.,ReducedFunctionOnContactZero(self.domain)))
1183 coeff=mypde.getCoefficient("d_contact_reduced")
1184 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),ReducedFunctionOnContactZero(self.domain),1,1))
1185 def test_setCoefficient_y_contact_reduced_Scalar_using_y_contact(self):
1186 if self.domain.supportsContactElements():
1187 d=self.domain.getDim()
1188 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1189 mypde.setValue(y_contact=Scalar(1.,ReducedFunctionOnContactZero(self.domain)))
1190 coeff=mypde.getCoefficient("y_contact_reduced")
1191 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),ReducedFunctionOnContactZero(self.domain),1))
1192 #
1193 # set coefficients for systems:
1194 #
1195 def test_setCoefficient_A_System(self):
1196 d=self.domain.getDim()
1197 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1198 mypde.setValue(A=numpy.ones((self.N,d,self.N,d)))
1199 coeff=mypde.getCoefficient("A")
1200 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,d,self.N,d),Function(self.domain),self.N,self.N))
1201 def test_setCoefficient_B_System(self):
1202 d=self.domain.getDim()
1203 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1204 mypde.setValue(B=numpy.ones((self.N,d,self.N)))
1205 coeff=mypde.getCoefficient("B")
1206 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,d,self.N),Function(self.domain),self.N,self.N))
1207 def test_setCoefficient_C_System(self):
1208 d=self.domain.getDim()
1209 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1210 mypde.setValue(C=numpy.ones((self.N,self.N,d)))
1211 coeff=mypde.getCoefficient("C")
1212 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N,d),Function(self.domain),self.N,self.N))
1213 def test_setCoefficient_D_System(self):
1214 d=self.domain.getDim()
1215 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1216 mypde.setValue(D=numpy.ones((self.N,self.N)))
1217 coeff=mypde.getCoefficient("D")
1218 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),Function(self.domain),self.N,self.N))
1219 def test_setCoefficient_X_System(self):
1220 d=self.domain.getDim()
1221 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1222 mypde.setValue(X=numpy.ones((self.N,d)))
1223 coeff=mypde.getCoefficient("X")
1224 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,d),Function(self.domain),self.N))
1225 def test_setCoefficient_Y_System(self):
1226 d=self.domain.getDim()
1227 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1228 mypde.setValue(Y=numpy.ones((self.N,)))
1229 coeff=mypde.getCoefficient("Y")
1230 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),Function(self.domain),self.N))
1231 def test_setCoefficient_y_System(self):
1232 d=self.domain.getDim()
1233 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1234 mypde.setValue(y=numpy.ones((self.N,)))
1235 coeff=mypde.getCoefficient("y")
1236 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),FunctionOnBoundary(self.domain),self.N))
1237 def test_setCoefficient_d_System(self):
1238 d=self.domain.getDim()
1239 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1240 mypde.setValue(d=numpy.ones((self.N,self.N)))
1241 coeff=mypde.getCoefficient("d")
1242 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),FunctionOnBoundary(self.domain),self.N,self.N))
1243 def test_setCoefficient_d_contact_System(self):
1244 if self.domain.supportsContactElements():
1245 d=self.domain.getDim()
1246 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1247 mypde.setValue(d_contact=numpy.ones((self.N,self.N)))
1248 coeff=mypde.getCoefficient("d_contact")
1249 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),FunctionOnContactZero(self.domain),self.N,self.N))
1250 def test_setCoefficient_y_contact_System(self):
1251 if self.domain.supportsContactElements():
1252 d=self.domain.getDim()
1253 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1254 mypde.setValue(y_contact=numpy.ones((self.N,)))
1255 coeff=mypde.getCoefficient("y_contact")
1256 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),FunctionOnContactZero(self.domain),self.N))
1257 def test_setCoefficient_A_reduced_System(self):
1258 d=self.domain.getDim()
1259 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1260 mypde.setValue(A_reduced=numpy.ones((self.N,d,self.N,d)))
1261 coeff=mypde.getCoefficient("A_reduced")
1262 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,d,self.N,d),ReducedFunction(self.domain),self.N,self.N))
1263 def test_setCoefficient_B_reduced_System(self):
1264 d=self.domain.getDim()
1265 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1266 mypde.setValue(B_reduced=numpy.ones((self.N,d,self.N)))
1267 coeff=mypde.getCoefficient("B_reduced")
1268 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,d,self.N),ReducedFunction(self.domain),self.N,self.N))
1269 def test_setCoefficient_C_reduced_System(self):
1270 d=self.domain.getDim()
1271 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1272 mypde.setValue(C_reduced=numpy.ones((self.N,self.N,d)))
1273 coeff=mypde.getCoefficient("C_reduced")
1274 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N,d),ReducedFunction(self.domain),self.N,self.N))
1275 def test_setCoefficient_D_System_reduced(self):
1276 d=self.domain.getDim()
1277 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1278 mypde.setValue(D_reduced=numpy.ones((self.N,self.N)))
1279 coeff=mypde.getCoefficient("D_reduced")
1280 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),ReducedFunction(self.domain),self.N,self.N))
1281 def test_setCoefficient_X_System_reduced(self):
1282 d=self.domain.getDim()
1283 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1284 mypde.setValue(X_reduced=numpy.ones((self.N,d)))
1285 coeff=mypde.getCoefficient("X_reduced")
1286 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,d),ReducedFunction(self.domain),self.N))
1287 def test_setCoefficient_Y_System_reduced(self):
1288 d=self.domain.getDim()
1289 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1290 mypde.setValue(Y_reduced=numpy.ones((self.N,)))
1291 coeff=mypde.getCoefficient("Y_reduced")
1292 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),ReducedFunction(self.domain),self.N))
1293 def test_setCoefficient_y_System_reduced(self):
1294 d=self.domain.getDim()
1295 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1296 mypde.setValue(y_reduced=numpy.ones((self.N,)))
1297 coeff=mypde.getCoefficient("y_reduced")
1298 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),ReducedFunctionOnBoundary(self.domain),self.N))
1299 def test_setCoefficient_d_reduced_System(self):
1300 d=self.domain.getDim()
1301 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1302 mypde.setValue(d_reduced=numpy.ones((self.N,self.N)))
1303 coeff=mypde.getCoefficient("d_reduced")
1304 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),ReducedFunctionOnBoundary(self.domain),self.N,self.N))
1305 def test_setCoefficient_d_contact_reduced_System(self):
1306 if self.domain.supportsContactElements():
1307 d=self.domain.getDim()
1308 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1309 mypde.setValue(d_contact_reduced=numpy.ones((self.N,self.N)))
1310 coeff=mypde.getCoefficient("d_contact_reduced")
1311 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),ReducedFunctionOnContactZero(self.domain),self.N,self.N))
1312 def test_setCoefficient_y_contact_reduced_System(self):
1313 if self.domain.supportsContactElements():
1314 d=self.domain.getDim()
1315 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1316 mypde.setValue(y_contact_reduced=numpy.ones((self.N,)))
1317 coeff=mypde.getCoefficient("y_contact_reduced")
1318 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),ReducedFunctionOnContactZero(self.domain),self.N))
1319 def test_setCoefficient_r_System(self):
1320 d=self.domain.getDim()
1321 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1322 mypde.setValue(r=numpy.ones((self.N,)))
1323 coeff=mypde.getCoefficient("r")
1324 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((self.N,),Solution(self.domain),self.N))
1325 def test_setCoefficient_q_System(self):
1326 d=self.domain.getDim()
1327 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1328 mypde.setValue(q=numpy.ones((self.N,)))
1329 coeff=mypde.getCoefficient("q")
1330 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((self.N,),Solution(self.domain),self.N))
1331 def test_setCoefficient_r_System_reducedOn(self):
1332 d=self.domain.getDim()
1333 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1334 mypde.setReducedOrderOn()
1335 mypde.setValue(r=numpy.ones((self.N,)))
1336 coeff=mypde.getCoefficient("r")
1337 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((self.N,),ReducedSolution(self.domain),self.N))
1338 def test_setCoefficient_q_System_reducedOn(self):
1339 d=self.domain.getDim()
1340 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1341 mypde.setReducedOrderOn()
1342 mypde.setValue(q=numpy.ones((self.N,)))
1343 coeff=mypde.getCoefficient("q")
1344 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((self.N,),ReducedSolution(self.domain),self.N))
1345
1346 def test_setCoefficient_A_reduced_System_using_A(self):
1347 d=self.domain.getDim()
1348 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1349 mypde.setValue(A=Data(numpy.ones((self.N,d,self.N,d)),ReducedFunction(self.domain)))
1350 coeff=mypde.getCoefficient("A_reduced")
1351 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,d,self.N,d),ReducedFunction(self.domain),self.N,self.N))
1352 def test_setCoefficient_B_reduced_System_using_B(self):
1353 d=self.domain.getDim()
1354 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1355 mypde.setValue(B=Data(numpy.ones((self.N,d,self.N)),ReducedFunction(self.domain)))
1356 coeff=mypde.getCoefficient("B_reduced")
1357 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,d,self.N),ReducedFunction(self.domain),self.N,self.N))
1358 def test_setCoefficient_C_reduced_System_using_C(self):
1359 d=self.domain.getDim()
1360 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1361 mypde.setValue(C=Data(numpy.ones((self.N,self.N,d)),ReducedFunction(self.domain)))
1362 coeff=mypde.getCoefficient("C_reduced")
1363 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N,d),ReducedFunction(self.domain),self.N,self.N))
1364 def test_setCoefficient_D_System_reduced_using_D(self):
1365 d=self.domain.getDim()
1366 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1367 mypde.setValue(D=Data(numpy.ones((self.N,self.N)),ReducedFunction(self.domain)))
1368 coeff=mypde.getCoefficient("D_reduced")
1369 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),ReducedFunction(self.domain),self.N,self.N))
1370 def test_setCoefficient_X_System_reduced_using_X(self):
1371 d=self.domain.getDim()
1372 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1373 mypde.setValue(X=Data(numpy.ones((self.N,d)),ReducedFunction(self.domain)))
1374 coeff=mypde.getCoefficient("X_reduced")
1375 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,d),ReducedFunction(self.domain),self.N))
1376 def test_setCoefficient_Y_System_reduced_using_Y(self):
1377 d=self.domain.getDim()
1378 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1379 mypde.setValue(Y=Data(numpy.ones((self.N,)),ReducedFunction(self.domain)))
1380 coeff=mypde.getCoefficient("Y_reduced")
1381 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),ReducedFunction(self.domain),self.N))
1382 def test_setCoefficient_y_reduced_System_using_y(self):
1383 d=self.domain.getDim()
1384 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1385 mypde.setValue(y=Data(numpy.ones((self.N,)),ReducedFunctionOnBoundary(self.domain)))
1386 coeff=mypde.getCoefficient("y_reduced")
1387 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),ReducedFunctionOnBoundary(self.domain),self.N))
1388 def test_setCoefficient_d_reduced_System_using_d(self):
1389 d=self.domain.getDim()
1390 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1391 mypde.setValue(d=Data(numpy.ones((self.N,self.N)),ReducedFunctionOnBoundary(self.domain)))
1392 coeff=mypde.getCoefficient("d_reduced")
1393 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),ReducedFunctionOnBoundary(self.domain),self.N,self.N))
1394 def test_setCoefficient_d_contact_reduced_System_using_d_contact(self):
1395 if self.domain.supportsContactElements():
1396 d=self.domain.getDim()
1397 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1398 mypde.setValue(d_contact=Data(numpy.ones((self.N,self.N)),ReducedFunctionOnContactZero(self.domain)))
1399 coeff=mypde.getCoefficient("d_contact_reduced")
1400 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),ReducedFunctionOnContactZero(self.domain),self.N,self.N))
1401 def test_setCoefficient_y_contact_reduced_System_using_y_contact(self):
1402 if self.domain.supportsContactElements():
1403 d=self.domain.getDim()
1404 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1405 mypde.setValue(y_contact=Data(numpy.ones((self.N,)),ReducedFunctionOnContactZero(self.domain)))
1406 coeff=mypde.getCoefficient("y_contact_reduced")
1407 self.assertEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),ReducedFunctionOnContactZero(self.domain),self.N))
1408 def test_resetCoefficient_HomogeneousConstraint(self):
1409 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1410 x=self.domain.getX()
1411 mypde.setValue(A=kronecker(self.domain),Y=1.,q=whereZero(x[0]))
1412 u1=mypde.getSolution()
1413 mypde.setValue(Y=2.)
1414 u2=mypde.getSolution()
1415 self.assertTrue(self.check(u2,2*u1),'solution is wrong.')
1416
1417 def test_resetCoefficient_InHomogeneousConstraint(self):
1418 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1419 mypde.setSymmetryOn()
1420 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1421 x=self.domain.getX()
1422 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.,r=1,q=whereZero(x[0]))
1423 u1=mypde.getSolution()
1424 mypde.setValue(Y=2.,D=2)
1425 u2=mypde.getSolution()
1426 self.assertTrue(self.check(u2,u1),'first solution is wrong.')
1427 u2=mypde.getSolution()
1428 self.assertTrue(self.check(u2,u1),'first solution is wrong.')
1429 mypde.setValue(r=2,Y=4.)
1430 u2=mypde.getSolution()
1431 self.assertTrue(self.check(u2,2*u1),'second solution is wrong.')
1432
1433 def test_Status(self):
1434 DIM=self.domain.getDim()
1435 x=self.domain.getX()
1436 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1437 mypde.getSolverOptions().setSymmetryOn()
1438 mypde.getSolverOptions().setTolerance(self.RES_TOL)
1439 mypde.setValue(A=kronecker(self.domain), q=whereZero(x[0])+whereZero(x[0]-1.), Y=2.)
1440 x1=self.domain.getX()
1441 u1_ref=x1[0]*(1.-x1[0])
1442 u1=mypde.getSolution()
1443 error1=Lsup(u1-u1_ref)/Lsup(u1_ref)
1444 self.assertTrue(mypde.getDomainStatus() == mypde.getSystemStatus(), "status of first pde does not match domain status.")
1445 try:
1446 self.domain.setX(x*5)
1447 except:
1448 # setX not supported
1449 return
1450 self.assertTrue(mypde.getDomainStatus() != mypde.getSystemStatus(), "status of first pde matches updated domain status.")
1451 x2=self.domain.getX()
1452 u2_ref=x2[0]*(5.-x2[0])
1453 u2=mypde.getSolution()
1454 error2=Lsup(u2-u2_ref)/Lsup(u2_ref)
1455 self.assertTrue(error2 <= max(error1,self.RES_TOL)*10., "solution of second PDE wrong.")
1456 self.assertTrue(mypde.getDomainStatus() == mypde.getSystemStatus(), "status of second pde does not match domain status.")
1457
1458 def test_symmetryCheckTrue_System(self):
1459 d=self.domain.getDim()
1460 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1461 A=numpy.ones((self.N,d,self.N,d))
1462 C=2*numpy.ones((self.N,self.N,d))
1463 B=2*numpy.ones((self.N,d,self.N))
1464 D=3*numpy.ones((self.N,self.N))
1465 d=4*numpy.ones((self.N,self.N))
1466 d_contact=5*numpy.ones((self.N,self.N))
1467 pars={"A":A, "B":B, "C":C, "D":D, "d":d, "A_reduced":-A, "B_reduced":-B, "C_reduced":-C, "D_reduced":-D, "d_reduced":-d}
1468 if self.domain.supportsContactElements():
1469 pars["d_contact"]=d_contact
1470 pars["d_contact_reduced"]=-d_contact
1471 mypde.setValue(**pars)
1472 self.assertTrue(mypde.checkSymmetry(verbose=False),"symmetry detected")
1473
1474 def test_symmetryCheckFalse_A_System(self):
1475 d=self.domain.getDim()
1476 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1477 A=numpy.ones((self.N,d,self.N,d))
1478 A[1,1,1,0]=0.
1479 mypde.setValue(A=A)
1480 self.assertTrue(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1481 def test_symmetryCheckFalse_BC_System(self):
1482 d=self.domain.getDim()
1483 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1484 C=2*numpy.ones((self.N,self.N,d))
1485 B=2*numpy.ones((self.N,d,self.N))
1486 B[0,0,1]=1.
1487 mypde.setValue(B=B,C=C)
1488 self.assertTrue(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1489
1490 def test_symmetryCheckFalse_D_System(self):
1491 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1492 D=3*numpy.ones((self.N,self.N))
1493 D[0,1]=0.
1494 mypde.setValue(D=D)
1495 self.assertTrue(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1496
1497 def test_symmetryCheckFalse_d_System(self):
1498 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1499 d=4*numpy.ones((self.N,self.N))
1500 d[0,1]=0.
1501 mypde.setValue(d=d)
1502 self.assertTrue(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1503
1504 def test_symmetryCheckFalse_d_contact_System(self):
1505 if self.domain.supportsContactElements():
1506 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1507 d_contact=5*numpy.ones((self.N,self.N))
1508 d_contact[0,1]=0.
1509 mypde.setValue(d_contact=d_contact)
1510 self.assertTrue(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1511
1512 def test_symmetryCheckFalse_A_reduced_System(self):
1513 d=self.domain.getDim()
1514 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1515 A=numpy.ones((self.N,d,self.N,d))
1516 A[1,1,1,0]=0.
1517 mypde.setValue(A_reduced=A)
1518 self.assertTrue(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1519 def test_symmetryCheckFalse_BC_reduced_System(self):
1520 d=self.domain.getDim()
1521 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1522 C=2*numpy.ones((self.N,self.N,d))
1523 B=2*numpy.ones((self.N,d,self.N))
1524 B[0,0,1]=1.
1525 mypde.setValue(B_reduced=B,C_reduced=C)
1526 self.assertTrue(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1527
1528 def test_symmetryCheckFalse_D_reduced_System(self):
1529 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1530 D=3*numpy.ones((self.N,self.N))
1531 D[0,1]=0.
1532 mypde.setValue(D_reduced=D)
1533 self.assertTrue(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1534
1535 def test_symmetryCheckFalse_d_reduced_System(self):
1536 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1537 d=4*numpy.ones((self.N,self.N))
1538 d[0,1]=0.
1539 mypde.setValue(d_reduced=d)
1540 self.assertTrue(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1541
1542 def test_symmetryCheckFalse_d_contact_reduced_System(self):
1543 if self.domain.supportsContactElements():
1544 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1545 d_contact=5*numpy.ones((self.N,self.N))
1546 d_contact[0,1]=0.
1547 mypde.setValue(d_contact_reduced=d_contact)
1548 self.assertTrue(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1549
1550 def test_symmetryCheckTrue_Scalar(self):
1551 d=self.domain.getDim()
1552 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1553 A=numpy.ones((d,d))
1554 C=2*numpy.ones((d,))
1555 B=2*numpy.ones((d,))
1556 D=3
1557 d=4
1558 d_contact=5
1559 pars={"A":A, "B":B, "C":C, "D":D, "d":d, "A_reduced":-A, "B_reduced":-B, "C_reduced":-C, "D_reduced":-D, "d_reduced":-d}
1560 if self.domain.supportsContactElements():
1561 pars["d_contact"]=d_contact
1562 pars["d_contact_reduced"]=-d_contact
1563 mypde.setValue(**pars)
1564 self.assertTrue(mypde.checkSymmetry(verbose=False),"symmetry detected")
1565
1566 def test_symmetryCheckFalse_A_Scalar(self):
1567 d=self.domain.getDim()
1568 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1569 A=numpy.ones((d,d))
1570 A[1,0]=0.
1571 mypde.setValue(A=A)
1572 self.assertTrue(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1573 def test_symmetryCheckFalse_BC_Scalar(self):
1574 d=self.domain.getDim()
1575 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1576 C=2*numpy.ones((d,))
1577 B=2*numpy.ones((d,))
1578 B[0]=1.
1579 mypde.setValue(B=B,C=C)
1580 self.assertTrue(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1581 def test_symmetryCheckFalse_A_reduced_Scalar(self):
1582 d=self.domain.getDim()
1583 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1584 A=numpy.ones((d,d))
1585 A[1,0]=0.
1586 mypde.setValue(A_reduced=A)
1587 self.assertTrue(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1588 def test_symmetryCheckFalse_BC_reduced_Scalar(self):
1589 d=self.domain.getDim()
1590 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1591 C=2*numpy.ones((d,))
1592 B=2*numpy.ones((d,))
1593 B[0]=1.
1594 mypde.setValue(B_reduced=B,C_reduced=C)
1595 self.assertTrue(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1596 #
1597 # solver checks (single PDE)
1598 #
1599 def test_symmetryOnIterative(self):
1600 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1601 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1602 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1603 u=mypde.getSolution()
1604 self.assertTrue(self.check(u,1.),'solution is wrong.')
1605 def test_symmetryOnDirect(self):
1606 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1607 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1608 mypde.getSolverOptions().setSolverMethod(SolverOptions.DIRECT)
1609 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1610 u=mypde.getSolution()
1611 self.assertTrue(self.check(u,1.),'solution is wrong.')
1612 def test_PCG_JACOBI(self):
1613 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1614 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1615 mypde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
1616 mypde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
1617 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1618 u=mypde.getSolution()
1619 self.assertTrue(self.check(u,1.),'solution is wrong.')
1620 def test_PCG_GAUSS_SEIDEL(self):
1621 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1622 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1623 mypde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
1624 mypde.getSolverOptions().setPreconditioner(SolverOptions.GAUSS_SEIDEL)
1625 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1626 u=mypde.getSolution()
1627 self.assertTrue(self.check(u,1.),'solution is wrong.')
1628 def test_PCG_AMG(self):
1629 if self.order!=2:
1630 if getEscriptParamInt('DISABLE_AMG', 0):
1631 print("AMG test disabled on MPI build")
1632 return
1633 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1634 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1635 mypde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
1636 mypde.getSolverOptions().setPreconditioner(SolverOptions.AMG)
1637 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1638 u=mypde.getSolution()
1639 self.assertTrue(self.check(u,1.),'solution is wrong.')
1640 def test_PCG_ILU0(self):
1641 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1642 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1643 mypde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
1644 mypde.getSolverOptions().setPreconditioner(SolverOptions.ILU0)
1645 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1646 u=mypde.getSolution()
1647 self.assertTrue(self.check(u,1.),'solution is wrong.')
1648 def test_PCG_RILU(self):
1649 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1650 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1651 mypde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
1652 mypde.getSolverOptions().setPreconditioner(SolverOptions.RILU)
1653 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1654 u=mypde.getSolution()
1655 self.assertTrue(self.check(u,1.),'solution is wrong.')
1656 def test_PCG_REC_ILU(self):
1657 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1658 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1659 mypde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
1660 mypde.getSolverOptions().setPreconditioner(SolverOptions.REC_ILU)
1661 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1662 u=mypde.getSolution()
1663 self.assertTrue(self.check(u,1.),'solution is wrong.')
1664 def test_DIRECT(self):
1665 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1666 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1667 mypde.getSolverOptions().setSolverMethod(SolverOptions.DIRECT)
1668 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1669 u=mypde.getSolution()
1670 self.assertTrue(self.check(u,1.),'solution is wrong.')
1671 def test_BICGSTAB_JACOBI(self):
1672 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1673 mypde.getSolverOptions().setSolverMethod(SolverOptions.BICGSTAB)
1674 mypde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
1675 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1676 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1677 u=mypde.getSolution()
1678 self.assertTrue(self.check(u,1.),'solution is wrong.')
1679 def test_BICGSTAB_GAUSS_SEIDEL(self):
1680 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1681 mypde.getSolverOptions().setSolverMethod(SolverOptions.BICGSTAB)
1682 mypde.getSolverOptions().setPreconditioner(SolverOptions.GAUSS_SEIDEL)
1683 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1684 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1685 u=mypde.getSolution()
1686 self.assertTrue(self.check(u,1.),'solution is wrong.')
1687 def test_BICGSTAB_AMG(self):
1688 if self.order!=2:
1689 if getEscriptParamInt('DISABLE_AMG', 0):
1690 print("AMG test disabled on MPI build")
1691 return
1692 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1693 mypde.getSolverOptions().setSolverMethod(SolverOptions.BICGSTAB)
1694 mypde.getSolverOptions().setPreconditioner(SolverOptions.AMG)
1695 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1696 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1697 u=mypde.getSolution()
1698 self.assertTrue(self.check(u,1.),'solution is wrong.')
1699 def test_BICGSTAB_ILU0(self):
1700 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1701 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1702 mypde.getSolverOptions().setSolverMethod(SolverOptions.BICGSTAB)
1703 mypde.getSolverOptions().setPreconditioner(SolverOptions.ILU0)
1704 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1705 u=mypde.getSolution()
1706 self.assertTrue(self.check(u,1.),'solution is wrong.')
1707 def test_BICGSTAB_RILU(self):
1708 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1709 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1710 mypde.getSolverOptions().setSolverMethod(SolverOptions.BICGSTAB)
1711 mypde.getSolverOptions().setPreconditioner(SolverOptions.RILU)
1712 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1713 u=mypde.getSolution()
1714 self.assertTrue(self.check(u,1.),'solution is wrong.')
1715 def test_BICGSTAB_REC_ILU(self):
1716 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1717 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1718 mypde.getSolverOptions().setSolverMethod(SolverOptions.BICGSTAB)
1719 mypde.getSolverOptions().setPreconditioner(SolverOptions.REC_ILU)
1720 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1721 u=mypde.getSolution()
1722 self.assertTrue(self.check(u,1.),'solution is wrong.')
1723 def test_MINRES_JACOBI(self):
1724 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1725 mypde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
1726 mypde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
1727 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1728 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1729 u=mypde.getSolution()
1730 self.assertTrue(self.check(u,1.),'solution is wrong.')
1731 def test_MINRES_GAUSS_SEIDEL(self):
1732 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1733 mypde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
1734 mypde.getSolverOptions().setPreconditioner(SolverOptions.GAUSS_SEIDEL)
1735 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1736 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1737 u=mypde.getSolution()
1738 self.assertTrue(self.check(u,1.),'solution is wrong.')
1739 def test_MINRES_AMG(self):
1740 if self.order!=2:
1741 if getEscriptParamInt('DISABLE_AMG',0):
1742 print("AMG test disabled on MPI build")
1743 return
1744 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1745 mypde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
1746 mypde.getSolverOptions().setPreconditioner(SolverOptions.AMG)
1747 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1748 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1749 u=mypde.getSolution()
1750 self.assertTrue(self.check(u,1.),'solution is wrong.')
1751 def test_MINRES_ILU0(self):
1752 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1753 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1754 mypde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
1755 mypde.getSolverOptions().setPreconditioner(SolverOptions.ILU0)
1756 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1757 u=mypde.getSolution()
1758 self.assertTrue(self.check(u,1.),'solution is wrong.')
1759 def test_MINRES_RILU(self):
1760 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1761 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1762 mypde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
1763 mypde.getSolverOptions().setPreconditioner(SolverOptions.RILU)
1764 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1765 u=mypde.getSolution()
1766 self.assertTrue(self.check(u,1.),'solution is wrong.')
1767 def test_MINRES_REC_ILU(self):
1768 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1769 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1770 mypde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
1771 mypde.getSolverOptions().setPreconditioner(SolverOptions.REC_ILU)
1772 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1773 u=mypde.getSolution()
1774 self.assertTrue(self.check(u,1.),'solution is wrong.')
1775 def test_TFQMR_JACOBI(self):
1776 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1777 mypde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
1778 mypde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
1779 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1780 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1781 u=mypde.getSolution()
1782 self.assertTrue(self.check(u,1.),'solution is wrong.')
1783 def test_TFQMR_GAUSS_SEIDEL(self):
1784 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1785 mypde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
1786 mypde.getSolverOptions().setPreconditioner(SolverOptions.GAUSS_SEIDEL)
1787 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1788 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1789 u=mypde.getSolution()
1790 self.assertTrue(self.check(u,1.),'solution is wrong.')
1791 def test_TFQMR_AMG(self):
1792 if self.order!=2:
1793 if getEscriptParamInt(