/[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 5148 - (show annotations)
Mon Sep 15 01:25:23 2014 UTC (5 years ago) by caltinay
File MIME type: text/x-python
File size: 202517 byte(s)
Merging ripley diagonal storage + CUDA support into trunk.
Options file version has been incremented due to new options
'cuda' and 'nvccflags'.

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