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