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

Annotation of /trunk/test.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 942 - (hide annotations) (download) (as text)
Sat Nov 25 05:26:47 2006 UTC (12 years, 9 months ago) by johnpye
Original Path: trunk/pygtk/test.py
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 johnpye 669 import unittest
2 johnpye 938 import ascpy
3 johnpye 940 import math
4 johnpye 669
5     class AscendTest(unittest.TestCase):
6    
7 johnpye 933 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 johnpye 941 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 johnpye 932 def testlog10(self):
25 johnpye 933 self.L.load('johnpye/testlog10.a4c')
26     T = self.L.findType('testlog10')
27 johnpye 932 M = T.getSimulation('sim')
28 johnpye 942 M.solve(ascpy.Solver("QRSlv"),ascpy.SolverReporter())
29 johnpye 932 M.run(T.getMethod('self_test'))
30    
31 johnpye 941 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 johnpye 942 # this routine is reused by both testIDA and testLSODE
38 johnpye 941 def _testIntegrator(self,integratorname):
39 johnpye 940 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 johnpye 941 t_end = math.pi
45 johnpye 940
46     I = ascpy.Integrator(M)
47     I.setReporter(ascpy.IntegratorReporterNull(I))
48 johnpye 941 I.setEngine(integratorname);
49 johnpye 940 I.setLinearTimesteps(ascpy.Units("s"), 0.0, t_end, 100);
50 johnpye 941 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 johnpye 940 I.analyse();
55     I.solve();
56 johnpye 941 print "At end of simulation,"
57     print "x = %f" % M.sim.x
58     print "v = %f" % M.sim.v
59 johnpye 940 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 johnpye 941 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 johnpye 942 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 johnpye 932 class NotToBeTested:
110     def nothing(self):
111     pass
112 johnpye 689
113 johnpye 669 if __name__=='__main__':
114     unittest.main()

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