/[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 6303 - (show annotations)
Sat Jun 18 10:53:18 2016 UTC (2 years, 3 months ago) by caltinay
File MIME type: text/x-python
File size: 210714 byte(s)
changed default value for ILUT drop tolerance and fixed a typo.

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