/[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 4242 - (show annotations)
Mon Feb 25 03:16:14 2013 UTC (6 years, 7 months ago) by jfenwick
Original Path: trunk/escript/test/python/test_linearPDEs.py
File MIME type: text/x-python
File size: 229406 byte(s)
Allow pure virtual classes to be exported to python.
Temporary fix for a ripley interpolation issue

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