/[escript]/trunk/escript/py_src/test_pdetools.py
ViewVC logotype

Contents of /trunk/escript/py_src/test_pdetools.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 525 - (show annotations)
Tue Feb 14 06:56:13 2006 UTC (13 years, 8 months ago) by gross
File MIME type: text/x-python
File size: 11684 byte(s)
rob's strange NoPDE class added
1 # $Id$
2
3 """
4 Test suite for the pdetools module
5
6 The tests must be linked with a Domain class object in the setUp method:
7
8 from esys.finley import Rectangle
9 class Test_LinearPDEOnFinley(Test_LinearPDE):
10 def setUp(self):
11 self.domain = Rectangle(10,10,2)
12 suite = unittest.TestSuite()
13 suite.addTest(unittest.makeSuite(Test_LinearPDEOnFinley))
14 unittest.TextTestRunner(verbosity=2).run(suite)
15
16 """
17
18 __author__="Lutz Gross, l.gross@uq.edu.au"
19 __licence__="contact: esys@access.uq.edu.au"
20 __url__="http://www.iservo.edu.au/esys/escript"
21 __version__="$Revision$"
22 __date__="$Date$"
23
24 import unittest
25 from esys.escript import *
26 from esys.escript.pdetools import Locator,Projector,TimeIntegrationManager,NoPDE
27
28 class Test_pdetools(unittest.TestCase):
29 TOL=1.e-6
30 DEBUG=False
31 VERBOSE=False
32 def test_TimeIntegrationManager_scalar(self):
33 t=0.
34 dt=0.1
35 tm=TimeIntegrationManager(0.,p=1)
36 while t<1.:
37 t+=dt
38 tm.checkin(dt,t)
39 v_guess=tm.extrapolate(dt)
40 self.failUnless(abs(v_guess-(tm.getTime()+dt))<self.TOL,"extrapolation is wrong")
41
42 def test_TimeIntegrationManager_vector(self):
43 t=0.
44 dt=0.3
45 tm=TimeIntegrationManager(0.,0.,p=1)
46 while t<1.:
47 t+=dt
48 tm.checkin(dt,t,3*t)
49 v_guess=tm.extrapolate(dt)
50 e=max(abs(v_guess[0]-(tm.getTime()+dt)),abs(v_guess[1]-(tm.getTime()+dt)*3.))
51 self.failUnless(e<self.TOL,"extrapolation is wrong")
52
53 def test_Locator(self):
54 x=self.domain.getX()
55 l=Locator(self.domain,numarray.ones((self.domain.getDim(),)))
56 self.failUnless(ContinuousFunction(self.domain)==l.getFunctionSpace(),"wrong function space from domain")
57
58 l=Locator(ContinuousFunction(self.domain),numarray.ones((self.domain.getDim(),)))
59 self.failUnless(ContinuousFunction(self.domain)==l.getFunctionSpace(),"wrong function space")
60
61 xx=l.getX()
62 self.failUnless(isinstance(xx,numarray.NumArray),"wrong vector type")
63 self.failUnless(Lsup(xx-numarray.ones((self.domain.getDim(),)))<self.TOL,"location wrong")
64 xx=l(x)
65 self.failUnless(isinstance(xx,numarray.NumArray),"wrong vector type")
66 self.failUnless(Lsup(xx-numarray.ones((self.domain.getDim(),)))<self.TOL,"value wrong vector")
67 xx=l(x[0]+x[1])
68 self.failUnless(isinstance(xx,float),"wrong scalar type")
69 self.failUnless(abs(xx-2.)<self.TOL,"value wrong scalar")
70
71 def testProjector_rank0(self):
72 x=ContinuousFunction(self.domain).getX()
73 p=Projector(self.domain,reduce=False,fast=False)
74 td_ref=x[0]
75 td=p(td_ref.interpolate(Function(self.domain)))
76 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
77
78 def testProjector_rank1(self):
79 x=ContinuousFunction(self.domain).getX()
80 p=Projector(self.domain,reduce=False,fast=False)
81 td_ref=x
82 td=p(td_ref.interpolate(Function(self.domain)))
83 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
84
85 def testProjector_rank2(self):
86 x=ContinuousFunction(self.domain).getX()
87 p=Projector(self.domain,reduce=False,fast=False)
88 td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
89 td=p(td_ref.interpolate(Function(self.domain)))
90 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
91
92 def testProjector_rank3(self):
93 x=ContinuousFunction(self.domain).getX()
94 p=Projector(self.domain,reduce=False,fast=False)
95 td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
96 td=p(td_ref.interpolate(Function(self.domain)))
97 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
98
99 def testProjector_rank4(self):
100 x=ContinuousFunction(self.domain).getX()
101 p=Projector(self.domain,reduce=False,fast=False)
102 td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
103 td=p(td_ref.interpolate(Function(self.domain)))
104 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
105
106 def testProjector_rank0_fast(self):
107 x=ContinuousFunction(self.domain).getX()
108 h=Lsup(self.domain.getSize())
109 p=Projector(self.domain,reduce=False,fast=True)
110 td_ref=x[0]
111 td=p(td_ref.interpolate(Function(self.domain)))
112 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
113
114 def testProjector_rank1_fast(self):
115 x=ContinuousFunction(self.domain).getX()
116 h=Lsup(self.domain.getSize())
117 p=Projector(self.domain,reduce=False,fast=True)
118 td_ref=x
119 td=p(td_ref.interpolate(Function(self.domain)))
120 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
121
122 def testProjector_rank2_fast(self):
123 x=ContinuousFunction(self.domain).getX()
124 h=Lsup(self.domain.getSize())
125 p=Projector(self.domain,reduce=False,fast=True)
126 td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
127 td=p(td_ref.interpolate(Function(self.domain)))
128 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
129
130 def testProjector_rank3_fast(self):
131 x=ContinuousFunction(self.domain).getX()
132 h=Lsup(self.domain.getSize())
133 p=Projector(self.domain,reduce=False,fast=True)
134 td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
135 td=p(td_ref.interpolate(Function(self.domain)))
136 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
137
138 def testProjector_rank4_fast(self):
139 x=ContinuousFunction(self.domain).getX()
140 h=Lsup(self.domain.getSize())
141 p=Projector(self.domain,reduce=False,fast=True)
142 td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
143 td=p(td_ref.interpolate(Function(self.domain)))
144 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
145
146 def testProjector_rank0_reduced(self):
147 x=ContinuousFunction(self.domain).getX()
148 p=Projector(self.domain,reduce=True,fast=False)
149 td_ref=x[0]
150 td=p(td_ref.interpolate(Function(self.domain)))
151 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
152
153 def testProjector_rank1_reduced(self):
154 x=ContinuousFunction(self.domain).getX()
155 p=Projector(self.domain,reduce=True,fast=False)
156 td_ref=x
157 td=p(td_ref.interpolate(Function(self.domain)))
158 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
159
160 def testProjector_rank2_reduced(self):
161 x=ContinuousFunction(self.domain).getX()
162 p=Projector(self.domain,reduce=True,fast=False)
163 td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
164 td=p(td_ref.interpolate(Function(self.domain)))
165 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
166
167 def testProjector_rank3_reduced(self):
168 x=ContinuousFunction(self.domain).getX()
169 p=Projector(self.domain,reduce=True,fast=False)
170 td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
171 td=p(td_ref.interpolate(Function(self.domain)))
172 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
173
174 def testProjector_rank4_reduced(self):
175 x=ContinuousFunction(self.domain).getX()
176 p=Projector(self.domain,reduce=True,fast=False)
177 td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
178 td=p(td_ref.interpolate(Function(self.domain)))
179 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
180
181 def testProjector_rank0_fast_reduced(self):
182 x=ContinuousFunction(self.domain).getX()
183 h=Lsup(self.domain.getSize())
184 p=Projector(self.domain,reduce=True,fast=True)
185 td_ref=x[0]
186 td=p(td_ref.interpolate(Function(self.domain)))
187 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
188
189 def testProjector_rank1_fast_reduced(self):
190 x=ContinuousFunction(self.domain).getX()
191 h=Lsup(self.domain.getSize())
192 p=Projector(self.domain,reduce=True,fast=True)
193 td_ref=x
194 td=p(td_ref.interpolate(Function(self.domain)))
195 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
196
197 def testProjector_rank2_fast_reduced(self):
198 x=ContinuousFunction(self.domain).getX()
199 h=Lsup(self.domain.getSize())
200 p=Projector(self.domain,reduce=True,fast=True)
201 td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
202 td=p(td_ref.interpolate(Function(self.domain)))
203 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
204
205 def testProjector_rank3_fast_reduced(self):
206 x=ContinuousFunction(self.domain).getX()
207 h=Lsup(self.domain.getSize())
208 p=Projector(self.domain,reduce=True,fast=True)
209 td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
210 td=p(td_ref.interpolate(Function(self.domain)))
211 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
212
213 def testProjector_rank4_fast_reduced(self):
214 x=ContinuousFunction(self.domain).getX()
215 h=Lsup(self.domain.getSize())
216 p=Projector(self.domain,reduce=True,fast=True)
217 td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
218 td=p(td_ref.interpolate(Function(self.domain)))
219 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
220
221 def test_NoPDE_scalar_missing_r(self):
222 p=NoPDE(self.domain)
223 x=self.domain.getX()
224 msk=whereZero(x[0])
225 p.setValue(D=1.,Y=1.,q=msk)
226 u=p.getSolution()
227 u_ex=(1.-msk)
228 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")
229
230 def test_NoPDE_scalar_missing_Y(self):
231 p=NoPDE(self.domain)
232 x=self.domain.getX()
233 msk=whereZero(x[0])
234 p.setValue(D=1.,q=msk,r=2.)
235 u=p.getSolution()
236 u_ex=msk*2.
237 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")
238
239 def test_NoPDE_scalar_constant(self):
240 p=NoPDE(self.domain)
241 x=self.domain.getX()
242 msk=whereZero(x[0])
243 p.setValue(D=1.,Y=1.,q=msk,r=2.)
244 u=p.getSolution()
245 u_ex=(1.-msk)+msk*2.
246 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")
247
248 def test_NoPDE_scalar_variable(self):
249 p=NoPDE(self.domain)
250 x=self.domain.getX()
251 msk=whereZero(x[0])
252 p.setValue(D=x[0],Y=2*x[0],q=msk,r=2.)
253 u=p.getSolution()
254 u_ex=2.
255 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")
256
257 def test_NoPDE_vector_missing_Y(self):
258 p=NoPDE(self.domain)
259 x=self.domain.getX()
260 msk=whereZero(x[0])*[1.,0.]
261 p.setValue(D=1.,q=msk,r=2.)
262 u=p.getSolution()
263 u_ex=msk*2.
264 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")
265
266 def test_NoPDE_vector_missing_r(self):
267 p=NoPDE(self.domain)
268 x=self.domain.getX()
269 msk=whereZero(x[0])*[1.,0.]
270 p.setValue(D=1.,Y=1.,q=msk)
271 u=p.getSolution()
272 u_ex=(1.-msk)
273 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")
274
275 def test_NoPDE_vector_constant(self):
276 p=NoPDE(self.domain)
277 x=self.domain.getX()
278 msk=whereZero(x[0])*[1.,0.]
279 p.setValue(D=1.,Y=1.,q=msk,r=2.)
280 u=p.getSolution()
281 u_ex=(1.-msk)+msk*2.
282 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")
283
284 def test_NoPDE_vector_variable(self):
285 p=NoPDE(self.domain)
286 x=self.domain.getX()
287 msk=whereZero(x[0])*[1.,0.]
288 p.setValue(D=x[:2],Y=2*x[:2],q=msk,r=2.)
289 u=p.getSolution()
290 u_ex=2.
291 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")

  ViewVC Help
Powered by ViewVC 1.1.26