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

Contents of /trunk/pygtk/test.py

Parent Directory Parent Directory | Revision Log Revision Log


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

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