/[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 6845 - (show annotations)
Wed Jul 3 06:03:14 2019 UTC (2 months, 2 weeks ago) by aellery
File MIME type: text/x-python
File size: 196912 byte(s)
-Turned run_comm1.py back on
-Dudley can now read files using gmsh MSH4 format
-Activated a test in test_linearPDEs that was turned off.


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