/[ascend]/trunk/test.py
ViewVC logotype

Annotation of /trunk/test.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1034 - (hide annotations) (download) (as text)
Thu Jan 4 05:37:55 2007 UTC (12 years, 11 months ago) by johnpye
Original Path: trunk/pygtk/test.py
File MIME type: text/x-python
File size: 17453 byte(s)
Switch 'void slv_*' function to output a 0-on-success error flag.
Added some debug output to ensure that such output gets through.
Fixed TestBlackBox.testfail1 to work, using above changes.
Simulation::solve now throws an exception on failure (will need to modify PyGTK GUI accordingly)
1 johnpye 1008 #!/usr/bin/env python
2 johnpye 669 import unittest
3 johnpye 1028
4     import platform, sys
5     if platform.system() != "Windows":
6     import dl
7     sys.setdlopenflags(dl.RTLD_GLOBAL|dl.RTLD_NOW)
8    
9 johnpye 938 import ascpy
10 johnpye 940 import math
11 johnpye 1028 import os, subprocess
12 johnpye 966 import atexit
13 johnpye 998 import cunit
14 johnpye 669
15 johnpye 956 class Ascend(unittest.TestCase):
16 johnpye 669
17 johnpye 933 def setUp(self):
18     import ascpy
19     self.L = ascpy.Library()
20    
21     def tearDown(self):
22     self.L.clear()
23     del self.L
24    
25 johnpye 1024 class AscendSelfTester(Ascend):
26    
27     def _run(self,modelname,solvername="QRSlv",filename=None):
28     if filename==None:
29     filename = 'johnpye/%s.a4c' % modelname
30     self.L.load(filename)
31     T = self.L.findType(modelname)
32     M = T.getSimulation('sim')
33     M.build()
34     M.solve(ascpy.Solver(solvername),ascpy.SolverReporter())
35     M.run(T.getMethod('self_test'))
36     return M
37    
38 johnpye 966 class TestCompiler(Ascend):
39    
40 johnpye 941 def testloading(self):
41     pass
42    
43     def testsystema4l(self):
44     self.L.load('system.a4l')
45    
46     def testatomsa4l(self):
47     self.L.load('atoms.a4l')
48    
49 johnpye 1024 class TestSolver(AscendSelfTester):
50 johnpye 966
51     def testlog10(self):
52     self._run('testlog10')
53    
54     def testconopt(self):
55     self._run('testconopt',"CONOPT")
56    
57     def testcmslv2(self):
58 johnpye 974 self._run('testcmslv2',"CMSlv")
59 johnpye 966
60     def testsunpos1(self):
61     self._run('example_1_6_1',"QRSlv","johnpye/sunpos.a4c")
62    
63     def testsunpos2(self):
64     self._run('example_1_6_2',"QRSlv","johnpye/sunpos.a4c")
65    
66     def testsunpos3(self):
67     self._run('example_1_7_1',"QRSlv","johnpye/sunpos.a4c")
68    
69     def testsunpos4(self):
70     self._run('example_1_7_2',"QRSlv","johnpye/sunpos.a4c")
71    
72     def testsunpos5(self):
73     self._run('example_1_7_3',"QRSlv","johnpye/sunpos.a4c")
74    
75     def testsunpos6(self):
76     self._run('example_1_8_1',"QRSlv","johnpye/sunpos.a4c")
77    
78     class TestIntegrator(Ascend):
79    
80 johnpye 941 def testListIntegrators(self):
81     I = ascpy.Integrator.getEngines()
82     s1 = sorted([str(i) for i in I.values()])
83 johnpye 972 s2 = sorted(['IDA','LSODE','AWW'])
84 johnpye 941 assert s1==s2
85    
86 johnpye 942 # this routine is reused by both testIDA and testLSODE
87 johnpye 941 def _testIntegrator(self,integratorname):
88 johnpye 940 self.L.load('johnpye/shm.a4c')
89     M = self.L.findType('shm').getSimulation('sim')
90 johnpye 972 M.setSolver(ascpy.Solver('QRSlv'))
91 johnpye 979 print M.getChildren()
92     assert float(M.x) == 10.0
93     assert float(M.v) == 0.0
94 johnpye 941 t_end = math.pi
95 johnpye 940
96     I = ascpy.Integrator(M)
97     I.setReporter(ascpy.IntegratorReporterNull(I))
98 johnpye 941 I.setEngine(integratorname);
99 johnpye 940 I.setLinearTimesteps(ascpy.Units("s"), 0.0, t_end, 100);
100 johnpye 941 I.setMinSubStep(0.0005); # these limits are required by IDA at present (numeric diff)
101     I.setMaxSubStep(0.02);
102     I.setInitialSubStep(0.001);
103     I.setMaxSubSteps(200);
104 johnpye 944 if(integratorname=='IDA'):
105     I.setParameter('autodiff',False)
106 johnpye 940 I.analyse();
107     I.solve();
108 johnpye 941 print "At end of simulation,"
109 johnpye 979 print "x = %f" % M.x
110     print "v = %f" % M.v
111     assert abs(float(M.x) + 10) < 1e-2
112     assert abs(float(M.v)) < 1e-2
113 johnpye 940 assert I.getNumObservedVars() == 3
114    
115 johnpye 941 def testInvalidIntegrator(self):
116 johnpye 966 self.L.load('johnpye/shm.a4c')
117 johnpye 941 M = self.L.findType('shm').getSimulation('sim')
118 johnpye 972 M.setSolver(ascpy.Solver('QRSlv'))
119 johnpye 941 I = ascpy.Integrator(M)
120     try:
121     I.setEngine('___NONEXISTENT____')
122 johnpye 972 except RuntimeError:
123 johnpye 941 return
124     self.fail("setEngine did not raise error!")
125    
126     def testLSODE(self):
127     self._testIntegrator('LSODE')
128    
129 johnpye 972 def testIDA(self):
130     self._testIntegrator('IDA')
131    
132 johnpye 1016 def testparameters(self):
133     self.L.load('johnpye/shm.a4c')
134     M = self.L.findType('shm').getSimulation('sim')
135     M.build()
136     I = ascpy.Integrator(M)
137     I.setEngine('IDA')
138     P = I.getParameters()
139     for p in P:
140     print p.getName(),"=",p.getValue()
141     assert len(P)==11
142     assert P[0].isStr()
143     assert P[0].getName()=="linsolver"
144     assert P[0].getValue()=='SPGMR'
145     assert P[2].getName()=="autodiff"
146     assert P[2].getValue()==True
147     assert P[7].getName()=="atolvect"
148     assert P[7].getBoolValue() == True
149     P[2].setBoolValue(False)
150     assert P[2].getBoolValue()==False
151     I.setParameters(P)
152     assert I.getParameterValue('autodiff')==False
153     I.setParameter('autodiff',True)
154     try:
155     v = I.getParameterValue('nonexist')
156     except KeyError:
157     pass
158     else:
159     self.fail('Failed to trip invalid Integrator parameter')
160    
161 johnpye 972 class TestLSODE(Ascend):
162    
163 johnpye 964 def testzill(self):
164     self.L.load('johnpye/zill.a4c')
165     T = self.L.findType('zill')
166     M = T.getSimulation('sim')
167 johnpye 972 M.setSolver(ascpy.Solver('QRSlv'))
168 johnpye 964 I = ascpy.Integrator(M)
169 johnpye 966 I.setEngine('LSODE')
170     I.setMinSubStep(1e-7)
171     I.setMaxSubStep(0.001)
172     I.setMaxSubSteps(10000)
173 johnpye 964 I.setReporter(ascpy.IntegratorReporterConsole(I))
174 johnpye 1017 I.setLinearTimesteps(ascpy.Units(), 1.0, 1.5, 5)
175 johnpye 964 I.analyse()
176     I.solve()
177     M.run(T.getMethod('self_test'))
178    
179 johnpye 962 def testnewton(self):
180 johnpye 973 sys.stderr.write("STARTING TESTNEWTON\n")
181 johnpye 962 self.L.load('johnpye/newton.a4c')
182     T = self.L.findType('newton')
183     M = T.getSimulation('sim')
184     M.solve(ascpy.Solver("QRSlv"),ascpy.SolverReporter())
185     I = ascpy.Integrator(M)
186     I.setEngine('LSODE')
187 johnpye 963 I.setParameter('rtolvect',False)
188     I.setParameter('rtol',1e-7)
189     I.setParameter('atolvect',False)
190     I.setParameter('atol',1e-7)
191     I.setMinSubStep(1e-7)
192     I.setMaxSubStep(0.001)
193     I.setMaxSubSteps(10000)
194    
195 johnpye 962 I.setReporter(ascpy.IntegratorReporterConsole(I))
196 johnpye 1017 I.setLinearTimesteps(ascpy.Units("s"), 0, 2*float(M.v)/float(M.g), 2)
197 johnpye 962 I.analyse()
198     I.solve()
199     print "At end of simulation,"
200 johnpye 979 print "x = %f" % M.x
201     print "v = %f" % M.v
202 johnpye 962 M.run(T.getMethod('self_test'))
203    
204 johnpye 961 def testlotka(self):
205     self.L.load('johnpye/lotka.a4c')
206     M = self.L.findType('lotka').getSimulation('sim')
207 johnpye 980 M.setSolver(ascpy.Solver("QRSlv"))
208 johnpye 961 I = ascpy.Integrator(M)
209     I.setEngine('LSODE')
210     I.setReporter(ascpy.IntegratorReporterConsole(I))
211 johnpye 1017 I.setLinearTimesteps(ascpy.Units("s"), 0, 200, 5)
212 johnpye 961 I.analyse()
213 johnpye 979 print "Number of vars = %d" % I.getNumVars()
214     assert I.getNumVars()==2
215 johnpye 961 I.solve()
216     assert I.getNumObservedVars() == 3;
217 johnpye 979 assert abs(M.R - 832) < 1.0
218     assert abs(M.F - 21.36) < 0.1
219 johnpye 1017
220     #-------------------------------------------------------------------------------
221 johnpye 1032 # Testing of a external blackbox functions
222 johnpye 1021
223 johnpye 1032 class TestBlackBox(AscendSelfTester):
224     def testparsefail0(self):
225     try:
226     self.L.load('test/blackbox/parsefail0.a4c')
227     self.fail("parsefail0 should not have loaded without errors")
228     except:
229     pass
230    
231     def testparsefail1(self):
232     try:
233     self.L.load('test/blackbox/parsefail1.a4c')
234     self.fail("parsefail1 should not have loaded without errors")
235     except:
236     pass
237    
238     def testparsefail2(self):
239     try:
240     self.L.load('test/blackbox/parsefail2.a4c')
241     self.fail("parsefail2 should not have loaded without errors")
242     except:
243     pass
244    
245     def testparsefail3(self):
246     try:
247     self.L.load('test/blackbox/parsefail3.a4c')
248     self.fail("parsefail3 should not have loaded without errors")
249     except:
250     pass
251    
252     def testparsefail4(self):
253     try:
254     self.L.load('test/blackbox/parsefail4.a4c')
255     self.fail("parsefail4 should not have loaded")
256     except:
257     pass
258    
259     def testfail1(self):
260     """Mismatched arg counts check-- tests bbox, not ascend."""
261     self.L.load('test/blackbox/fail1.a4c')
262     M = self.L.findType('fail1').getSimulation('sim')
263 johnpye 1034 try:
264     M.solve(ascpy.Solver("QRSlv"),ascpy.SolverReporter())
265     self.fail("expected exception was not raised")
266     except RuntimeError,e:
267     print "Caught exception '%s', assumed ok" % e
268 johnpye 1032
269     def testfail2(self):
270     """Incorrect data arg check -- tests bbox, not ascend"""
271     self.L.load('test/blackbox/fail2.a4c')
272     M = self.L.findType('fail2').getSimulation('sim')
273     M.solve(ascpy.Solver("QRSlv"),ascpy.SolverReporter())
274    
275     def testpass1(self):
276     """simple single bbox forward solve"""
277     M = self._run('pass1',filename='test/blackbox/pass.a4c')
278    
279     def testpass2(self):
280     """simple single bbox reverse solve"""
281     M = self._run('pass2',filename='test/blackbox/pass.a4c')
282    
283     def testpass3(self):
284     """simple double bbox solve"""
285     M = self._run('pass3',filename='test/blackbox/pass3.a4c')
286    
287     def testpass4(self):
288     """simple double bbox reverse solve"""
289     M = self._run('pass4',filename='test/blackbox/pass3.a4c')
290    
291     def testpass5(self):
292     M = self._run('pass5',filename='test/blackbox/pass5.a4c')
293    
294     def testpass6(self):
295     M = self._run('pass6',filename='test/blackbox/pass5.a4c')
296    
297     def testpass7(self):
298     M = self._run('pass7',filename='test/blackbox/passmerge.a4c')
299    
300     def testpass8(self):
301     M = self._run('pass8',filename='test/blackbox/passmerge.a4c')
302    
303     def testpass9(self):
304     M = self._run('pass9',filename='test/blackbox/passmerge.a4c')
305    
306     def testpass10(self):
307     M = self._run('pass10',filename='test/blackbox/passmerge.a4c')
308    
309     def testpass11(self):
310     M = self._run('pass11',filename='test/blackbox/passmerge.a4c')
311    
312     def testpass12(self):
313     M = self._run('pass12',filename='test/blackbox/passmerge.a4c')
314    
315     def testpass13(self):
316     """cross-merged input/output solve"""
317     M = self._run('pass13',filename='test/blackbox/passmerge.a4c')
318    
319     def testpass14(self):
320     """cross-merged input/output reverse solve"""
321     M = self._run('pass14',filename='test/blackbox/passmerge.a4c')
322    
323     def testpass20(self):
324     M = self._run('pass20',filename='test/blackbox/passarray.a4c')
325    
326     def testparsefail21(self):
327     """dense array of black boxes wrong syntax"""
328     try:
329     self.L.load('test/blackbox/parsefail21.a4c')
330     self.fail("parsefail21 should not have loaded without errors")
331     except:
332     pass
333    
334     def testpass22(self):
335     M = self._run('pass22',filename='test/blackbox/passarray.a4c')
336    
337     def testpass23(self):
338     M = self._run('pass23',filename='test/blackbox/passarray.a4c')
339    
340     def testpass61(self):
341     M = self._run('pass61',filename='test/blackbox/reinstantiate.a4c')
342    
343     def testpass62(self):
344     M = self._run('pass62',filename='test/blackbox/reinstantiate.a4c')
345    
346     def testpass64(self):
347     M = self._run('pass64',filename='test/blackbox/reinstantiate.a4c')
348    
349     def testpass65(self):
350     M = self._run('pass65',filename='test/blackbox/reinstantiate.a4c')
351    
352     def testpass66(self):
353     M = self._run('pass66',filename='test/blackbox/reinstantiate.a4c')
354    
355     def testpass67(self):
356     M = self._run('pass67',filename='test/blackbox/reinstantiate.a4c')
357    
358 johnpye 1024 class TestExtFn(AscendSelfTester):
359 johnpye 1021 def testextfntest(self):
360 johnpye 1024 M = self._run('extfntest',filename='johnpye/extfn/extfntest.a4c')
361     self.assertAlmostEqual(M.y, 2);
362     self.assertAlmostEqual(M.x, 1);
363 johnpye 1021 self.assertAlmostEqual(M.y, M.x + 1);
364    
365 johnpye 1024 # THIS TEST FAILS
366     # def testextrelfor(self):
367     # self.L.load('johnpye/extfn/extrelfor.a4c')
368     # T = self.L.findType('extrelfor')
369     # M = T.getSimulation('sim')
370     # M.solve(ascpy.Solver('QRSlv'),ascpy.SolverReporter())
371     # print "x[1] = %f" % M.x[1]
372     # print "x[2] = %f" % M.x[2]
373     # print "x[3] = %f" % M.x[3]
374     # M.run(T.getMethod('self_test'))
375    
376     def testextrelrepeat(self):
377     M = self._run('extrelrepeat',filename='johnpye/extfn/extrelrepeat.a4c')
378    
379 johnpye 1021 #-------------------------------------------------------------------------------
380 johnpye 1024 # Testing of a ExtPy - external python methods
381    
382     class TestExtPy(AscendSelfTester):
383     def testextpytest(self):
384 johnpye 1026 print "-------------------=--=-=-=-"
385 johnpye 1024 M = self._run('extpytest',filename='johnpye/extpy/extpytest.a4c')
386    
387     #-------------------------------------------------------------------------------
388 johnpye 1017 # Testing of freesteam external steam properties functions
389    
390 johnpye 1032 with_freesteam = True
391 johnpye 1017 try:
392     import freesteam
393     have_freesteam = True
394 johnpye 1018 except ImportError,e:
395 johnpye 1017 have_freesteam = False
396    
397 johnpye 1024 if with_freesteam and have_freesteam:
398 johnpye 1017 class TestFreesteam(Ascend):
399 johnpye 1021 def testload(self):
400 johnpye 1017 self.L.load('johnpye/thermalequilibrium2.a4c')
401 johnpye 1018
402 johnpye 1021 def testinstantiate(self):
403     self.testload()
404 johnpye 1018 M = self.L.findType('thermalequilibrium2').getSimulation('sim')
405 johnpye 1021
406     def testsolve(self):
407     self.testinstantiate()
408 johnpye 1018 M.setSolver(ascpy.Solver("QRSlv"))
409 johnpye 1017 #I = ascpy.Integrator(M)
410     #I.setEngine('LSODE')
411     #I.setReporter(ascpy.IntegratorReporterConsole(I))
412     #I.setLinearTimesteps(ascpy.Units("s"), 0, 3000, 30)
413     #I.setMinSubStep(0.01)
414     #I.setInitialSubStep(0.1)
415     #I.analyse()
416     #print "Number of vars = %d" % I.getNumVars()
417     #assert I.getNumVars()==2
418     #I.solve()
419     #assert I.getNumObservedVars() == 3;
420     #assert abs(M.R - 832) < 1.0
421     #assert abs(M.F - 21.36) < 0.1
422    
423    
424     #-------------------------------------------------------------------------------
425     # Testing of IDA models using DENSE linear solver
426    
427 johnpye 1016 class TestIDADENSE(Ascend):
428 johnpye 1017 """IDA DAE integrator, DENSE linear solver"""
429 johnpye 961
430 johnpye 979 def testnewton(self):
431     sys.stderr.write("STARTING TESTNEWTON\n")
432     self.L.load('johnpye/newton.a4c')
433     T = self.L.findType('newton')
434     M = T.getSimulation('sim')
435     M.solve(ascpy.Solver("QRSlv"),ascpy.SolverReporter())
436     I = ascpy.Integrator(M)
437     I.setEngine('IDA')
438 johnpye 1016 I.setParameter('linsolver','DENSE')
439 johnpye 979 I.setParameter('safeeval',True)
440     I.setParameter('rtol',1e-8)
441     I.setMaxSubStep(0.001)
442     I.setMaxSubSteps(10000)
443    
444     I.setReporter(ascpy.IntegratorReporterConsole(I))
445 johnpye 1017 I.setLinearTimesteps(ascpy.Units("s"), 0, 2*float(M.v)/float(M.g), 2)
446 johnpye 979 I.analyse()
447     I.solve()
448     print "At end of simulation,"
449     print "x = %f" % M.x
450     print "v = %f" % M.v
451     M.run(T.getMethod('self_test'))
452    
453 johnpye 991 def testlotkaDENSE(self):
454     self.L.load('johnpye/lotka.a4c')
455     M = self.L.findType('lotka').getSimulation('sim')
456     M.setSolver(ascpy.Solver("QRSlv"))
457     I = ascpy.Integrator(M)
458     I.setEngine('IDA')
459     I.setReporter(ascpy.IntegratorReporterConsole(I))
460     I.setLinearTimesteps(ascpy.Units("s"), 0, 200, 5);
461     I.setParameter('linsolver','DENSE')
462     I.setParameter('rtol',1e-8);
463     I.analyse()
464     assert I.getNumVars()==2
465     assert abs(M.R - 1000) < 1e-300
466     I.solve()
467 johnpye 1017 assert I.getNumObservedVars() == 3
468 johnpye 991 assert abs(M.R - 832) < 1.0
469     assert abs(M.F - 21.36) < 0.1
470 johnpye 972
471 johnpye 975 def testdenx(self):
472 johnpye 1026 print "-----------------------------====="
473 johnpye 942 self.L.load('johnpye/idadenx.a4c')
474     M = self.L.findType('idadenx').getSimulation('sim')
475 johnpye 1017 M.setSolver(ascpy.Solver("QRSlv"))
476 johnpye 942 I = ascpy.Integrator(M)
477     I.setEngine('IDA')
478 johnpye 1024 I.setParameter('calcic','YA_YPD')
479 johnpye 972 I.setParameter('linsolver','DENSE')
480 johnpye 944 I.setReporter(ascpy.IntegratorReporterConsole(I))
481 johnpye 1017 I.setLogTimesteps(ascpy.Units("s"), 0.4, 4e10, 11)
482 johnpye 950 I.setMaxSubStep(0);
483 johnpye 1017 I.setInitialSubStep(0)
484 johnpye 950 I.setMaxSubSteps(0);
485 johnpye 944 I.setParameter('autodiff',True)
486     I.analyse()
487     I.solve()
488 johnpye 1022 assert abs(float(M.y1) - 5.1091e-08) < 2e-9
489     assert abs(float(M.y2) - 2.0437e-13) < 2e-14
490 johnpye 1017 assert abs(float(M.y3) - 1.0) < 1e-5
491 johnpye 942
492 johnpye 990 def testkryxDENSE(self):
493     self.L.load('johnpye/idakryx.a4c')
494     M = self.L.findType('idakryx').getSimulation('sim')
495     M.setSolver(ascpy.Solver('QRSlv'))
496     M.build()
497     I = ascpy.Integrator(M)
498     I.setEngine('IDA')
499     I.setReporter(ascpy.IntegratorReporterConsole(I))
500     I.setParameter('linsolver','DENSE')
501     I.setParameter('maxl',8)
502     I.setParameter('gsmodified',False)
503     I.setParameter('autodiff',True)
504     I.setParameter('rtol',0)
505     I.setParameter('atol',1e-3);
506     I.setParameter('atolvect',False)
507 johnpye 1016 I.setParameter('calcic','YA_YDP')
508 johnpye 990 I.analyse()
509 johnpye 1017 I.setLogTimesteps(ascpy.Units("s"), 0.01, 10.24, 11)
510 johnpye 990 I.solve()
511     assert abs(M.u[2][2].getValue()) < 1e-5
512 johnpye 1017
513     #-------------------------------------------------------------------------------
514     # Testing of IDA models using SPGMR linear solver (Krylov)
515    
516 johnpye 1016 # these tests are disabled until SPGMR preconditioning has been implemented
517     class TestIDASPGMR:#(Ascend):
518     def testlotka(self):
519     self.L.load('johnpye/lotka.a4c')
520     M = self.L.findType('lotka').getSimulation('sim')
521     M.setSolver(ascpy.Solver("QRSlv"))
522 johnpye 951 I = ascpy.Integrator(M)
523     I.setEngine('IDA')
524     I.setReporter(ascpy.IntegratorReporterConsole(I))
525 johnpye 1017 I.setLinearTimesteps(ascpy.Units("s"), 0, 200, 5)
526     I.setParameter('rtol',1e-8)
527 johnpye 951 I.analyse()
528 johnpye 1016 assert I.getNumVars()==2
529     assert abs(M.R - 1000) < 1e-300
530 johnpye 951 I.solve()
531 johnpye 1017 assert I.getNumObservedVars() == 3
532 johnpye 1016 assert abs(M.R - 832) < 1.0
533     assert abs(M.F - 21.36) < 0.1
534 johnpye 951
535 johnpye 1016
536 johnpye 991 def testkryx(self):
537 johnpye 951 self.L.load('johnpye/idakryx.a4c')
538     M = self.L.findType('idakryx').getSimulation('sim')
539 johnpye 952 M.build()
540 johnpye 951 I = ascpy.Integrator(M)
541     I.setEngine('IDA')
542     I.setReporter(ascpy.IntegratorReporterConsole(I))
543 johnpye 992 I.setParameter('linsolver','SPGMR')
544 johnpye 993 I.setParameter('prec','JACOBI')
545 johnpye 970 I.setParameter('maxl',8)
546 johnpye 952 I.setParameter('gsmodified',False)
547     I.setParameter('autodiff',True)
548 johnpye 993 I.setParameter('gsmodified',True)
549 johnpye 952 I.setParameter('rtol',0)
550     I.setParameter('atol',1e-3);
551     I.setParameter('atolvect',False)
552 johnpye 993 I.setParameter('calcic','Y')
553 johnpye 952 I.analyse()
554     I.setLogTimesteps(ascpy.Units("s"), 0.01, 10.24, 10);
555 johnpye 1017 print M.udot[1][3]
556 johnpye 952 I.solve()
557     assert 0
558 johnpye 967
559 johnpye 1016 def testzill(self):
560     self.L.load('johnpye/zill.a4c')
561     T = self.L.findType('zill')
562     M = T.getSimulation('sim')
563     M.setSolver(ascpy.Solver('QRSlv'))
564     I = ascpy.Integrator(M)
565     I.setEngine('IDA')
566     I.setParameter('safeeval',False)
567     I.setMinSubStep(1e-7)
568     I.setMaxSubStep(0.001)
569     I.setMaxSubSteps(10000)
570     I.setReporter(ascpy.IntegratorReporterConsole(I))
571 johnpye 1017 I.setLinearTimesteps(ascpy.Units(), 1.0, 1.5, 5)
572 johnpye 1016 I.analyse()
573     I.solve()
574     M.run(T.getMethod('self_test'))
575    
576     def testdenxSPGMR(self):
577     self.L.load('johnpye/idadenx.a4c')
578     M = self.L.findType('idadenx').getSimulation('sim')
579     M.setSolver(ascpy.Solver('QRSlv'))
580     I = ascpy.Integrator(M)
581     I.setEngine('IDA')
582     I.setReporter(ascpy.IntegratorReporterConsole(I))
583 johnpye 1017 I.setLogTimesteps(ascpy.Units("s"), 0.4, 4e10, 11)
584 johnpye 1016 I.setMaxSubStep(0);
585     I.setInitialSubStep(0);
586     I.setMaxSubSteps(0);
587     I.setParameter('autodiff',True)
588     I.setParameter('linsolver','SPGMR')
589     I.setParameter('gsmodified',False)
590     I.setParameter('maxncf',10)
591     I.analyse()
592     I.solve()
593 johnpye 1017 assert abs(float(M.y1) - 5.1091e-08) < 1e-10
594     assert abs(float(M.y2) - 2.0437e-13) < 1e-15
595     assert abs(float(M.y3) - 1.0) < 1e-5
596 johnpye 1016
597 johnpye 943 # move code above down here if you want to temporarily avoid testing it
598 johnpye 932 class NotToBeTested:
599     def nothing(self):
600     pass
601 johnpye 1016
602 johnpye 669 if __name__=='__main__':
603 johnpye 966 atexit.register(ascpy.shutdown)
604 johnpye 1008 #suite = unittest.TestSuite()
605 johnpye 1003 #suite = unittest.defaultTestLoader.loadTestsFromName('__main__')
606 johnpye 1008 #unittest.TextTestRunner(verbosity=2).run(suite)
607     unittest.main()

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22