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