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

Contents of /trunk/pygtk/test.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 942 - (show annotations) (download) (as text)
Sat Nov 25 05:26:47 2006 UTC (13 years, 7 months ago) by johnpye
File MIME type: text/x-python
File size: 2900 byte(s)
Incorporated 'SolverParameters' functionality into 'Integrator', both at C level and C++/Python.
This shouldn't break Tcl/Tk as default parameters will be set and used invisibly.
1 import unittest
2 import ascpy
3 import math
4
5 class AscendTest(unittest.TestCase):
6
7 def setUp(self):
8 import ascpy
9 self.L = ascpy.Library()
10
11 def tearDown(self):
12 self.L.clear()
13 del self.L
14
15 def testloading(self):
16 pass
17
18 def testsystema4l(self):
19 self.L.load('system.a4l')
20
21 def testatomsa4l(self):
22 self.L.load('atoms.a4l')
23
24 def testlog10(self):
25 self.L.load('johnpye/testlog10.a4c')
26 T = self.L.findType('testlog10')
27 M = T.getSimulation('sim')
28 M.solve(ascpy.Solver("QRSlv"),ascpy.SolverReporter())
29 M.run(T.getMethod('self_test'))
30
31 def testListIntegrators(self):
32 I = ascpy.Integrator.getEngines()
33 s1 = sorted([str(i) for i in I.values()])
34 s2 = sorted(['IDA','LSODE'])
35 assert s1==s2
36
37 # this routine is reused by both testIDA and testLSODE
38 def _testIntegrator(self,integratorname):
39 self.L.load('johnpye/shm.a4c')
40 M = self.L.findType('shm').getSimulation('sim')
41 print M.sim.getChildren()
42 assert float(M.sim.x) == 10.0
43 assert float(M.sim.v) == 0.0
44 t_end = math.pi
45
46 I = ascpy.Integrator(M)
47 I.setReporter(ascpy.IntegratorReporterNull(I))
48 I.setEngine(integratorname);
49 I.setLinearTimesteps(ascpy.Units("s"), 0.0, t_end, 100);
50 I.setMinSubStep(0.0005); # these limits are required by IDA at present (numeric diff)
51 I.setMaxSubStep(0.02);
52 I.setInitialSubStep(0.001);
53 I.setMaxSubSteps(200);
54 I.analyse();
55 I.solve();
56 print "At end of simulation,"
57 print "x = %f" % M.sim.x
58 print "v = %f" % M.sim.v
59 assert abs(float(M.sim.x) + 10) < 1e-2
60 assert abs(float(M.sim.v)) < 1e-2
61 assert I.getNumObservedVars() == 3
62
63 def testInvalidIntegrator(self):
64 self.L.load('johnpye/shm.a4c')
65 M = self.L.findType('shm').getSimulation('sim')
66 I = ascpy.Integrator(M)
67 try:
68 I.setEngine('___NONEXISTENT____')
69 except IndexError:
70 return
71 self.fail("setEngine did not raise error!")
72
73 def testLSODE(self):
74 self._testIntegrator('LSODE')
75
76 def testIDA(self):
77 self._testIntegrator('IDA')
78
79 def testIDAwithDAE(self):
80 self.L.load('johnpye/idadenx.a4c')
81 M = self.L.findType('idadenx').getSimulation('sim')
82 I = ascpy.Integrator(M)
83 I.setEngine('IDA')
84 I.setReporter(ascpy.IntegratorReporterNull(I))
85 I.setLogTimesteps(ascpy.Units("s"), 0.4, 4e10, 11);
86 I.setMinSubStep(0.0005); # these limits are required by IDA at present (numeric diff)
87 I.setMaxSubStep(0.02);
88 I.setInitialSubStep(0.001);
89 I.setMaxSubSteps(500);
90 I.analyse();
91 I.solve();
92
93 def testIDAparameters(self):
94 self.L.load('johnpye/shm.a4c')
95 M = self.L.findType('shm').getSimulation('sim')
96 I = ascpy.Integrator(M)
97 I.setEngine('IDA')
98 P = I.getParameters()
99 print "THERE ARE %d PARAMETERS" % len(P)
100 print P[0]
101 assert P[0].getBoolValue() == True
102 P[0].setBoolValue(False)
103 I.setParameters(P)
104 P = I.getParameters()
105 assert P[0].getBoolValue() == False
106 print P[0]
107
108
109 class NotToBeTested:
110 def nothing(self):
111 pass
112
113 if __name__=='__main__':
114 unittest.main()

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