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

Contents of /trunk/pygtk/test.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1073 - (show annotations) (download) (as text)
Tue Jan 9 01:44:59 2007 UTC (15 years, 5 months ago) by johnpye
File MIME type: text/x-python
File size: 20843 byte(s)
Added Instance.as(units) method to Python bindings (bug #302)
1 #!/usr/bin/env python
2 import unittest
3
4 import platform, sys
5 if platform.system() != "Windows":
6 import dl
7 sys.setdlopenflags(dl.RTLD_GLOBAL|dl.RTLD_NOW)
8
9 import ascpy
10 import math
11 import os, subprocess
12 import atexit
13
14 try:
15 import cunit
16 except:
17 pass
18
19 class Ascend(unittest.TestCase):
20
21 def setUp(self):
22 import ascpy
23 self.L = ascpy.Library()
24
25 def tearDown(self):
26 self.L.clear()
27 del self.L
28
29 class AscendSelfTester(Ascend):
30
31 def _run(self,modelname,solvername="QRSlv",filename=None):
32 if filename==None:
33 filename = 'johnpye/%s.a4c' % modelname
34 self.L.load(filename)
35 T = self.L.findType(modelname)
36 M = T.getSimulation('sim')
37 M.build()
38 M.solve(ascpy.Solver(solvername),ascpy.SolverReporter())
39 M.run(T.getMethod('self_test'))
40 return M
41
42 class TestCompiler(Ascend):
43
44 def testloading(self):
45 pass
46
47 def testsystema4l(self):
48 self.L.load('system.a4l')
49
50 def testatomsa4l(self):
51 self.L.load('atoms.a4l')
52
53 class TestSolver(AscendSelfTester):
54
55 def testlog10(self):
56 self._run('testlog10')
57
58 def testconopt(self):
59 self._run('testconopt',"CONOPT")
60
61 def testcmslv2(self):
62 self._run('testcmslv2',"CMSlv")
63
64 def testsunpos1(self):
65 self._run('example_1_6_1',"QRSlv","johnpye/sunpos.a4c")
66
67 def testsunpos2(self):
68 self._run('example_1_6_2',"QRSlv","johnpye/sunpos.a4c")
69
70 def testsunpos3(self):
71 self._run('example_1_7_1',"QRSlv","johnpye/sunpos.a4c")
72
73 def testsunpos4(self):
74 self._run('example_1_7_2',"QRSlv","johnpye/sunpos.a4c")
75
76 def testsunpos5(self):
77 self._run('example_1_7_3',"QRSlv","johnpye/sunpos.a4c")
78
79 def testsunpos6(self):
80 self._run('example_1_8_1',"QRSlv","johnpye/sunpos.a4c")
81
82 def testinstanceas(self):
83 M = self._run('example_1_6_1',"QRSlv","johnpye/sunpos.a4c")
84 self.assertAlmostEqual( float(M.t_solar), M.t_solar.as("s"))
85 self.assertAlmostEqual( float(M.t_solar)/3600, M.t_solar.as("h"))
86
87 class TestIntegrator(Ascend):
88
89 def testListIntegrators(self):
90 I = ascpy.Integrator.getEngines()
91 s1 = sorted([str(i) for i in I.values()])
92 s2 = sorted(['IDA','LSODE','AWW'])
93 assert s1==s2
94
95 # this routine is reused by both testIDA and testLSODE
96 def _testIntegrator(self,integratorname):
97 self.L.load('johnpye/shm.a4c')
98 M = self.L.findType('shm').getSimulation('sim')
99 M.setSolver(ascpy.Solver('QRSlv'))
100 print M.getChildren()
101 assert float(M.x) == 10.0
102 assert float(M.v) == 0.0
103 t_end = math.pi
104
105 I = ascpy.Integrator(M)
106 I.setReporter(ascpy.IntegratorReporterNull(I))
107 I.setEngine(integratorname);
108 I.setLinearTimesteps(ascpy.Units("s"), 0.0, t_end, 100);
109 I.setMinSubStep(0.0005); # these limits are required by IDA at present (numeric diff)
110 I.setMaxSubStep(0.02);
111 I.setInitialSubStep(0.001);
112 I.setMaxSubSteps(200);
113 if(integratorname=='IDA'):
114 I.setParameter('autodiff',False)
115 I.analyse();
116 I.solve();
117 print "At end of simulation,"
118 print "x = %f" % M.x
119 print "v = %f" % M.v
120 assert abs(float(M.x) + 10) < 1e-2
121 assert abs(float(M.v)) < 1e-2
122 assert I.getNumObservedVars() == 3
123
124 def testInvalidIntegrator(self):
125 self.L.load('johnpye/shm.a4c')
126 M = self.L.findType('shm').getSimulation('sim')
127 M.setSolver(ascpy.Solver('QRSlv'))
128 I = ascpy.Integrator(M)
129 try:
130 I.setEngine('___NONEXISTENT____')
131 except RuntimeError:
132 return
133 self.fail("setEngine did not raise error!")
134
135 def testLSODE(self):
136 self._testIntegrator('LSODE')
137
138 def testIDA(self):
139 self._testIntegrator('IDA')
140
141 def testparameters(self):
142 self.L.load('johnpye/shm.a4c')
143 M = self.L.findType('shm').getSimulation('sim')
144 M.build()
145 I = ascpy.Integrator(M)
146 I.setEngine('IDA')
147 P = I.getParameters()
148 for p in P:
149 print p.getName(),"=",p.getValue()
150 assert len(P)==11
151 assert P[0].isStr()
152 assert P[0].getName()=="linsolver"
153 assert P[0].getValue()=='SPGMR'
154 assert P[2].getName()=="autodiff"
155 assert P[2].getValue()==True
156 assert P[7].getName()=="atolvect"
157 assert P[7].getBoolValue() == True
158 P[2].setBoolValue(False)
159 assert P[2].getBoolValue()==False
160 I.setParameters(P)
161 assert I.getParameterValue('autodiff')==False
162 I.setParameter('autodiff',True)
163 try:
164 v = I.getParameterValue('nonexist')
165 except KeyError:
166 pass
167 else:
168 self.fail('Failed to trip invalid Integrator parameter')
169
170 class TestLSODE(Ascend):
171
172 def testzill(self):
173 self.L.load('johnpye/zill.a4c')
174 T = self.L.findType('zill')
175 M = T.getSimulation('sim')
176 M.setSolver(ascpy.Solver('QRSlv'))
177 I = ascpy.Integrator(M)
178 I.setEngine('LSODE')
179 I.setMinSubStep(1e-7)
180 I.setMaxSubStep(0.001)
181 I.setMaxSubSteps(10000)
182 I.setReporter(ascpy.IntegratorReporterConsole(I))
183 I.setLinearTimesteps(ascpy.Units(), 1.0, 1.5, 5)
184 I.analyse()
185 I.solve()
186 M.run(T.getMethod('self_test'))
187
188 def testnewton(self):
189 sys.stderr.write("STARTING TESTNEWTON\n")
190 self.L.load('johnpye/newton.a4c')
191 T = self.L.findType('newton')
192 M = T.getSimulation('sim')
193 M.solve(ascpy.Solver("QRSlv"),ascpy.SolverReporter())
194 I = ascpy.Integrator(M)
195 I.setEngine('LSODE')
196 I.setParameter('rtolvect',False)
197 I.setParameter('rtol',1e-7)
198 I.setParameter('atolvect',False)
199 I.setParameter('atol',1e-7)
200 I.setMinSubStep(1e-7)
201 I.setMaxSubStep(0.001)
202 I.setMaxSubSteps(10000)
203
204 I.setReporter(ascpy.IntegratorReporterConsole(I))
205 I.setLinearTimesteps(ascpy.Units("s"), 0, 2*float(M.v)/float(M.g), 2)
206 I.analyse()
207 I.solve()
208 print "At end of simulation,"
209 print "x = %f" % M.x
210 print "v = %f" % M.v
211 M.run(T.getMethod('self_test'))
212
213 def testlotka(self):
214 self.L.load('johnpye/lotka.a4c')
215 M = self.L.findType('lotka').getSimulation('sim')
216 M.setSolver(ascpy.Solver("QRSlv"))
217 I = ascpy.Integrator(M)
218 I.setEngine('LSODE')
219 I.setReporter(ascpy.IntegratorReporterConsole(I))
220 I.setLinearTimesteps(ascpy.Units("s"), 0, 200, 5)
221 I.analyse()
222 print "Number of vars = %d" % I.getNumVars()
223 assert I.getNumVars()==2
224 I.solve()
225 assert I.getNumObservedVars() == 3;
226 assert abs(M.R - 832) < 1.0
227 assert abs(M.F - 21.36) < 0.1
228
229 #-------------------------------------------------------------------------------
230 # Testing of a external blackbox functions
231
232 class TestBlackBox(AscendSelfTester):
233 def testparsefail0(self):
234 try:
235 self.L.load('test/blackbox/parsefail0.a4c')
236 self.fail("parsefail0 should not have loaded without errors")
237 except:
238 pass
239
240 def testparsefail1(self):
241 try:
242 self.L.load('test/blackbox/parsefail1.a4c')
243 self.fail("parsefail1 should not have loaded without errors")
244 except:
245 pass
246
247 def testparsefail2(self):
248 try:
249 self.L.load('test/blackbox/parsefail2.a4c')
250 self.fail("parsefail2 should not have loaded without errors")
251 except:
252 pass
253
254 def testparsefail3(self):
255 try:
256 self.L.load('test/blackbox/parsefail3.a4c')
257 self.fail("parsefail3 should not have loaded without errors")
258 except:
259 pass
260
261 def testparsefail4(self):
262 try:
263 self.L.load('test/blackbox/parsefail4.a4c')
264 self.fail("parsefail4 should not have loaded")
265 except:
266 pass
267
268 def testfail1(self):
269 """Mismatched arg counts check-- tests bbox, not ascend."""
270 self.L.load('test/blackbox/fail1.a4c')
271 try:
272 M = self.L.findType('fail1').getSimulation('sim')
273 self.fail("expected exception was not raised")
274 except RuntimeError,e:
275 print "Caught exception '%s', assumed ok" % e
276
277 def testfail2(self):
278 """Incorrect data arg check -- tests bbox, not ascend"""
279 self.L.load('test/blackbox/fail2.a4c')
280 try:
281 M = self.L.findType('fail2').getSimulation('sim')
282 self.fail("expected exception was not raised")
283 except RuntimeError,e:
284 print "Caught exception '%s', assumed ok (should mention errors during instantiation)" % e
285
286 def testpass1(self):
287 """simple single bbox forward solve"""
288 M = self._run('pass1',filename='test/blackbox/pass.a4c')
289
290 def testpass2(self):
291 """simple single bbox reverse solve"""
292 M = self._run('pass2',filename='test/blackbox/pass.a4c')
293
294 def testpass3(self):
295 """simple double bbox solve"""
296 M = self._run('pass3',filename='test/blackbox/pass3.a4c')
297
298 def testpass4(self):
299 """simple double bbox reverse solve"""
300 M = self._run('pass4',filename='test/blackbox/pass3.a4c')
301
302 def testpass5(self):
303 M = self._run('pass5',filename='test/blackbox/pass5.a4c')
304
305 def testpass6(self):
306 M = self._run('pass6',filename='test/blackbox/pass5.a4c')
307
308 def testpass7(self):
309 M = self._run('pass7',filename='test/blackbox/passmerge.a4c')
310
311 def testpass8(self):
312 M = self._run('pass8',filename='test/blackbox/passmerge.a4c')
313
314 def testpass9(self):
315 M = self._run('pass9',filename='test/blackbox/passmerge.a4c')
316
317 def testpass10(self):
318 M = self._run('pass10',filename='test/blackbox/passmerge.a4c')
319
320 def testpass11(self):
321 M = self._run('pass11',filename='test/blackbox/passmerge.a4c')
322
323 def testpass12(self):
324 M = self._run('pass12',filename='test/blackbox/passmerge.a4c')
325
326 # this test doesn't work: 'system is inconsistent' -- and structurally singular
327 # def testpass13(self):
328 # """cross-merged input/output solve"""
329 # M = self._run('pass13',filename='test/blackbox/passmerge.a4c')
330
331 def testpass14(self):
332 """cross-merged input/output reverse solve"""
333 M = self._run('pass14',filename='test/blackbox/passmerge.a4c')
334
335 def testpass20(self):
336 M = self._run('pass20',filename='test/blackbox/passarray.a4c')
337
338 def testparsefail21(self):
339 """dense array of black boxes wrong syntax"""
340 try:
341 self.L.load('test/blackbox/parsefail21.a4c')
342 self.fail("parsefail21 should not have loaded without errors")
343 except:
344 pass
345
346 def testpass22(self):
347 M = self._run('pass22',filename='test/blackbox/passarray.a4c')
348
349 def testpass23(self):
350 M = self._run('pass23',filename='test/blackbox/passarray.a4c')
351
352 def testpass61(self):
353 M = self._run('pass61',filename='test/blackbox/reinstantiate.a4c')
354
355 def testpass62(self):
356 M = self._run('pass62',filename='test/blackbox/reinstantiate.a4c')
357
358 def testpass64(self):
359 M = self._run('pass64',filename='test/blackbox/reinstantiate.a4c')
360
361 def testpass65(self):
362 M = self._run('pass65',filename='test/blackbox/reinstantiate.a4c')
363
364 def testpass66(self):
365 M = self._run('pass66',filename='test/blackbox/reinstantiate.a4c')
366
367 def testpass67(self):
368 M = self._run('pass67',filename='test/blackbox/reinstantiate.a4c')
369
370 class TestExtFn(AscendSelfTester):
371 def testextfntest(self):
372 M = self._run('extfntest',filename='johnpye/extfn/extfntest.a4c')
373 self.assertAlmostEqual(M.y, 2);
374 self.assertAlmostEqual(M.x, 1);
375 self.assertAlmostEqual(M.y, M.x + 1);
376
377 def testextrelfor(self):
378 M = self._run('extrelfor',filename='johnpye/extfn/extrelfor.a4c')
379
380 ## @TODO fix bug with badly-named bbox rel in a loop (Ben, maybe)
381 # def testextrelforbadnaming(self):
382 # self.L.load('johnpye/extfn/extrelforbadnaming.a4c')
383 # T = self.L.findType('extrelfor')
384 # M = T.getSimulation('sim')
385 # M.solve(ascpy.Solver('QRSlv'),ascpy.SolverReporter())
386 # print "x[1] = %f" % M.x[1]
387 # print "x[2] = %f" % M.x[2]
388 # print "x[3] = %f" % M.x[3]
389 # print "x[4] = %f" % M.x[4]
390 # print "x[5] = %f" % M.x[5]
391 # M.run(T.getMethod('self_test'))
392
393 def testextrelrepeat(self):
394 M = self._run('extrelrepeat',filename='johnpye/extfn/extrelrepeat.a4c')
395
396 #-------------------------------------------------------------------------------
397 # Testing of a ExtPy - external python methods
398
399 class TestExtPy(AscendSelfTester):
400 def test1(self):
401 self.L.load('johnpye/extpy/extpytest.a4c')
402 T = self.L.findType('extpytest')
403 M = T.getSimulation('sim')
404 M.run(T.getMethod('self_test'))
405
406 def test2(self):
407 self.L.load('johnpye/extpy/extpytest.a4c')
408 T = self.L.findType('extpytest')
409 M = T.getSimulation('sim')
410 M.run(T.getMethod('pythonthing'))
411 M.run(T.getMethod('pythonthing'))
412 M.run(T.getMethod('pythonthing'))
413 M.run(T.getMethod('pythonthing'))
414 # causes crash!
415
416 #-------------------------------------------------------------------------------
417 # Testing of saturated steam properties library (iapwssatprops.a4c)
418
419 class TestSteam(AscendSelfTester):
420 def testiapwssatprops1(self):
421 M = self._run('testiapwssatprops1',filename='steam/iapwssatprops.a4c')
422 def testiapwssatprops2(self):
423 M = self._run('testiapwssatprops2',filename='steam/iapwssatprops.a4c')
424 def testiapwssatprops3(self):
425 M = self._run('testiapwssatprops3',filename='steam/iapwssatprops.a4c')
426 def testsatsteamstream(self):
427 M = self._run('satsteamstream',filename='steam/satsteamstream.a4c')
428
429 def testsatsteamstream(self):
430 M = self._run('satsteamstream',filename='steam/satsteamstream.a4c')
431
432 ## @TODO fix error capture from bounds checking during initialisation
433 # def testiapwssat1(self):
434 # M = self._run('testiapwssat1',filename='steam/iapwssat.a4c')
435
436 ## @TODO fix bug with unpivoted node[i].hg_expr eqns.
437 # def testdsgsat(self):
438 # self.L.load('steam/dsgsat2.a4c')
439 # T = self.L.findType('dsgsat2')
440 # M = T.getSimulation('sim')
441 # M.solve(ascpy.Solver('QRSlv'),ascpy.SolverReporter())
442 # M.run(T.getMethod('fixed_states'))
443 # I = ascpy.Integrator(M)
444 # I.setEngine('LSODE')
445 # I.setReporter(ascpy.IntegratorReporterConsole(I))
446 # I.setReporter(ascpy.IntegratorReporterConsole(I))
447 # I.setLinearTimesteps(ascpy.Units("s"), 0, 5, 100)
448 # I.setMinSubStep(0.01)
449 # I.setMaxSubStep(0.02)
450 # I.setInitialSubStep(0.1)
451 # I.analyse()
452 # I.solve()
453 # #M.checkStructuralSingularity() causes crash!
454
455 #-------------------------------------------------------------------------------
456 # Testing of freesteam external steam properties functions
457
458 with_freesteam = True
459 try:
460 # we assume that if the freesteam python module is installed, the ASCEND
461 # external library will also be.
462 import freesteam
463 have_freesteam = True
464 except ImportError,e:
465 have_freesteam = False
466
467 if with_freesteam and have_freesteam:
468 class TestFreesteam(AscendSelfTester):
469 def testfreesteamtest(self):
470 """run the self-test cases bundled with freesteam"""
471 self._run('testfreesteam',filename='testfreesteam.a4c')
472
473 def testload(self):
474 """check that we can load 'thermalequilibrium2' (IMPORT "freesteam", etc)"""
475 self.L.load('johnpye/thermalequilibrium2.a4c')
476
477 def testinstantiate(self):
478 """load an instantiate 'thermalequilibrium2'"""
479 self.testload()
480 M = self.L.findType('thermalequilibrium2').getSimulation('sim')
481 return M
482
483 def testintegrate(self):
484 """integrate transfer of heat from one mass of water/steam to another
485 according to Newton's law of cooling"""
486 M = self.testinstantiate()
487 M.setSolver(ascpy.Solver("QRSlv"))
488 I = ascpy.Integrator(M)
489 I.setEngine('LSODE')
490 I.setReporter(ascpy.IntegratorReporterConsole(I))
491 I.setLinearTimesteps(ascpy.Units("s"), 0, 3000, 30)
492 I.setMinSubStep(0.01)
493 I.setInitialSubStep(1)
494 I.analyse()
495 print "Number of vars = %d" % I.getNumVars()
496 assert I.getNumVars()==2
497 I.solve()
498 assert I.getNumObservedVars() == 3;
499 print "S[1].T = %f K" % M.S[1].T
500 print "S[2].T = %f K" % M.S[2].T
501 print "Q = %f W" % M.Q
502 self.assertAlmostEqual(float(M.S[1].T),506.77225109,5);
503 self.assertAlmostEqual(float(M.S[2].T),511.605173967,5);
504 self.assertAlmostEqual(float(M.Q),-48.32922877329,3);
505 self.assertAlmostEqual(float(M.t),3000);
506 print "Note that the above values have not been verified analytically"
507
508 #-------------------------------------------------------------------------------
509 # Testing of IDA models using DENSE linear solver
510
511 class TestIDADENSE(Ascend):
512 """IDA DAE integrator, DENSE linear solver"""
513
514 def testnewton(self):
515 sys.stderr.write("STARTING TESTNEWTON\n")
516 self.L.load('johnpye/newton.a4c')
517 T = self.L.findType('newton')
518 M = T.getSimulation('sim')
519 M.solve(ascpy.Solver("QRSlv"),ascpy.SolverReporter())
520 I = ascpy.Integrator(M)
521 I.setEngine('IDA')
522 I.setParameter('linsolver','DENSE')
523 I.setParameter('safeeval',True)
524 I.setParameter('rtol',1e-8)
525 I.setMaxSubStep(0.001)
526 I.setMaxSubSteps(10000)
527
528 I.setReporter(ascpy.IntegratorReporterConsole(I))
529 I.setLinearTimesteps(ascpy.Units("s"), 0, 2*float(M.v)/float(M.g), 2)
530 I.analyse()
531 I.solve()
532 print "At end of simulation,"
533 print "x = %f" % M.x
534 print "v = %f" % M.v
535 M.run(T.getMethod('self_test'))
536
537 def testlotka(self):
538 self.L.load('johnpye/lotka.a4c')
539 M = self.L.findType('lotka').getSimulation('sim')
540 M.setSolver(ascpy.Solver("QRSlv"))
541 I = ascpy.Integrator(M)
542 I.setEngine('IDA')
543 I.setReporter(ascpy.IntegratorReporterConsole(I))
544 I.setLinearTimesteps(ascpy.Units("s"), 0, 200, 5);
545 I.setParameter('linsolver','DENSE')
546 I.setParameter('rtol',1e-8);
547 I.analyse()
548 assert I.getNumVars()==2
549 assert abs(M.R - 1000) < 1e-300
550 I.solve()
551 assert I.getNumObservedVars() == 3
552 assert abs(M.R - 832) < 1.0
553 assert abs(M.F - 21.36) < 0.1
554
555 def testdenx(self):
556 print "-----------------------------====="
557 self.L.load('johnpye/idadenx.a4c')
558 M = self.L.findType('idadenx').getSimulation('sim')
559 M.setSolver(ascpy.Solver("QRSlv"))
560 I = ascpy.Integrator(M)
561 I.setEngine('IDA')
562 I.setParameter('calcic','YA_YPD')
563 I.setParameter('linsolver','DENSE')
564 I.setReporter(ascpy.IntegratorReporterConsole(I))
565 I.setLogTimesteps(ascpy.Units("s"), 0.4, 4e10, 11)
566 I.setMaxSubStep(0);
567 I.setInitialSubStep(0)
568 I.setMaxSubSteps(0);
569 I.setParameter('autodiff',True)
570 I.analyse()
571 I.solve()
572 assert abs(float(M.y1) - 5.1091e-08) < 2e-9
573 assert abs(float(M.y2) - 2.0437e-13) < 2e-14
574 assert abs(float(M.y3) - 1.0) < 1e-5
575
576 ## @TODO fails during IDACalcIC (model too big?)
577 # def testkryx(self):
578 # self.L.load('johnpye/idakryx.a4c')
579 # ascpy.getCompiler().setUseRelationSharing(False)
580 # M = self.L.findType('idakryx').getSimulation('sim')
581 # M.setSolver(ascpy.Solver('QRSlv'))
582 # M.build()
583 # I = ascpy.Integrator(M)
584 # I.setEngine('IDA')
585 # I.setReporter(ascpy.IntegratorReporterConsole(I))
586 # I.setParameter('linsolver','DENSE')
587 # I.setParameter('maxl',8)
588 # I.setParameter('gsmodified',False)
589 # I.setParameter('autodiff',True)
590 # I.setParameter('rtol',0)
591 # I.setParameter('atol',1e-3);
592 # I.setParameter('atolvect',False)
593 # I.setParameter('calcic','YA_YDP')
594 # I.analyse()
595 # I.setLogTimesteps(ascpy.Units("s"), 0.01, 10.24, 11)
596 # I.solve()
597 # assert abs(M.u[2][2].getValue()) < 1e-5
598
599 #-------------------------------------------------------------------------------
600 # Testing of IDA models using SPGMR linear solver (Krylov)
601
602 # these tests are disabled until SPGMR preconditioning has been implemented
603 class TestIDASPGMR:#(Ascend):
604 def testlotka(self):
605 self.L.load('johnpye/lotka.a4c')
606 M = self.L.findType('lotka').getSimulation('sim')
607 M.setSolver(ascpy.Solver("QRSlv"))
608 I = ascpy.Integrator(M)
609 I.setEngine('IDA')
610 I.setReporter(ascpy.IntegratorReporterConsole(I))
611 I.setLinearTimesteps(ascpy.Units("s"), 0, 200, 5)
612 I.setParameter('rtol',1e-8)
613 I.analyse()
614 assert I.getNumVars()==2
615 assert abs(M.R - 1000) < 1e-300
616 I.solve()
617 assert I.getNumObservedVars() == 3
618 assert abs(M.R - 832) < 1.0
619 assert abs(M.F - 21.36) < 0.1
620
621
622 def testkryx(self):
623 self.L.load('johnpye/idakryx.a4c')
624 M = self.L.findType('idakryx').getSimulation('sim')
625 M.build()
626 I = ascpy.Integrator(M)
627 I.setEngine('IDA')
628 I.setReporter(ascpy.IntegratorReporterConsole(I))
629 I.setParameter('linsolver','SPGMR')
630 I.setParameter('prec','JACOBI')
631 I.setParameter('maxl',8)
632 I.setParameter('gsmodified',False)
633 I.setParameter('autodiff',True)
634 I.setParameter('gsmodified',True)
635 I.setParameter('rtol',0)
636 I.setParameter('atol',1e-3);
637 I.setParameter('atolvect',False)
638 I.setParameter('calcic','Y')
639 I.analyse()
640 I.setLogTimesteps(ascpy.Units("s"), 0.01, 10.24, 10);
641 print M.udot[1][3]
642 I.solve()
643 assert 0
644
645 def testzill(self):
646 self.L.load('johnpye/zill.a4c')
647 T = self.L.findType('zill')
648 M = T.getSimulation('sim')
649 M.setSolver(ascpy.Solver('QRSlv'))
650 I = ascpy.Integrator(M)
651 I.setEngine('IDA')
652 I.setParameter('safeeval',False)
653 I.setMinSubStep(1e-7)
654 I.setMaxSubStep(0.001)
655 I.setMaxSubSteps(10000)
656 I.setReporter(ascpy.IntegratorReporterConsole(I))
657 I.setLinearTimesteps(ascpy.Units(), 1.0, 1.5, 5)
658 I.analyse()
659 I.solve()
660 M.run(T.getMethod('self_test'))
661
662 def testdenxSPGMR(self):
663 self.L.load('johnpye/idadenx.a4c')
664 M = self.L.findType('idadenx').getSimulation('sim')
665 M.setSolver(ascpy.Solver('QRSlv'))
666 I = ascpy.Integrator(M)
667 I.setEngine('IDA')
668 I.setReporter(ascpy.IntegratorReporterConsole(I))
669 I.setLogTimesteps(ascpy.Units("s"), 0.4, 4e10, 11)
670 I.setMaxSubStep(0);
671 I.setInitialSubStep(0);
672 I.setMaxSubSteps(0);
673 I.setParameter('autodiff',True)
674 I.setParameter('linsolver','SPGMR')
675 I.setParameter('gsmodified',False)
676 I.setParameter('maxncf',10)
677 I.analyse()
678 I.solve()
679 assert abs(float(M.y1) - 5.1091e-08) < 1e-10
680 assert abs(float(M.y2) - 2.0437e-13) < 1e-15
681 assert abs(float(M.y3) - 1.0) < 1e-5
682
683 # move code above down here if you want to temporarily avoid testing it
684 class NotToBeTested:
685 def nothing(self):
686 pass
687
688 if __name__=='__main__':
689 atexit.register(ascpy.shutdown)
690 #suite = unittest.TestSuite()
691 #suite = unittest.defaultTestLoader.loadTestsFromName('__main__')
692 #unittest.TextTestRunner(verbosity=2).run(suite)
693 unittest.main()

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