/[escript]/trunk/escriptcore/test/python/test_linearPDEs.py
ViewVC logotype

Annotation of /trunk/escriptcore/test/python/test_linearPDEs.py

Parent Directory Parent Directory | Revision Log Revision Log


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

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