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