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