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

Diff of /trunk/pygtk/test.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 940 by johnpye, Fri Nov 24 08:07:33 2006 UTC revision 941 by johnpye, Fri Nov 24 10:46:32 2006 UTC
# Line 12  class AscendTest(unittest.TestCase): Line 12  class AscendTest(unittest.TestCase):
12          self.L.clear()          self.L.clear()
13          del self.L          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):      def testlog10(self):
25          self.L.load('johnpye/testlog10.a4c')          self.L.load('johnpye/testlog10.a4c')
26          T = self.L.findType('testlog10')          T = self.L.findType('testlog10')
# Line 19  class AscendTest(unittest.TestCase): Line 28  class AscendTest(unittest.TestCase):
28          M.solve(ascpy.Solver("QRSlv"),ascpy.SolverReporter())                M.solve(ascpy.Solver("QRSlv"),ascpy.SolverReporter())      
29          M.run(T.getMethod('self_test'))              M.run(T.getMethod('self_test'))    
30    
31      def testLSODE(self):      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        def _testIntegrator(self,integratorname):
38          self.L.load('johnpye/shm.a4c')          self.L.load('johnpye/shm.a4c')
39          M = self.L.findType('shm').getSimulation('sim')          M = self.L.findType('shm').getSimulation('sim')
40          print M.sim.getChildren()          print M.sim.getChildren()
41          assert float(M.sim.x) == 10.0          assert float(M.sim.x) == 10.0
42          assert float(M.sim.v) == 0.0          assert float(M.sim.v) == 0.0
43          t_end = 3 * math.pi          t_end = math.pi
44    
45          I = ascpy.Integrator(M)          I = ascpy.Integrator(M)
46          I.setReporter(ascpy.IntegratorReporterNull(I))          I.setReporter(ascpy.IntegratorReporterNull(I))
47          I.setEngine('LSODE');          I.setEngine(integratorname);
48          I.setLinearTimesteps(ascpy.Units("s"), 0.0, t_end, 100);          I.setLinearTimesteps(ascpy.Units("s"), 0.0, t_end, 100);
49          I.setMinSubStep(0.005);          I.setMinSubStep(0.0005); # these limits are required by IDA at present (numeric diff)
50          I.setMaxSubStep(0.5);          I.setMaxSubStep(0.02);
51          I.setInitialSubStep(0.01);          I.setInitialSubStep(0.001);
52          I.setMaxSubSteps(100);          I.setMaxSubSteps(200);
53          I.analyse();          I.analyse();
54          I.solve();          I.solve();
55            print "At end of simulation,"
56            print "x = %f" % M.sim.x
57            print "v = %f" % M.sim.v
58          assert abs(float(M.sim.x) + 10) < 1e-2          assert abs(float(M.sim.x) + 10) < 1e-2
59          assert abs(float(M.sim.v)) < 1e-2          assert abs(float(M.sim.v)) < 1e-2
60          assert I.getNumObservedVars() == 3          assert I.getNumObservedVars() == 3
61    
62  class NotToBeTested:      def testInvalidIntegrator(self):
63      def nothing(self):          self.L.load('johnpye/shm.a4c')
64          pass          M = self.L.findType('shm').getSimulation('sim')
65            I = ascpy.Integrator(M)
66            try:
67                I.setEngine('___NONEXISTENT____')
68            except IndexError:
69                return
70            self.fail("setEngine did not raise error!")
71    
72      def testloading(self):      def testLSODE(self):
73          pass          self._testIntegrator('LSODE')
74    
75      def testsystema4l(self):      def testIDA(self):
76          self.L.load('simpleflowsheet01.a4c')          self._testIntegrator('IDA')
77    
78      def testatomsa4l(self):  class NotToBeTested:
79          self.L.load('atoms.a4l')      def nothing(self):
80            pass
81                    
82  if __name__=='__main__':  if __name__=='__main__':
83      unittest.main()      unittest.main()

Legend:
Removed from v.940  
changed lines
  Added in v.941

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