/[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 1016 by johnpye, Wed Jan 3 05:56:12 2007 UTC revision 1017 by johnpye, Wed Jan 3 06:40:21 2007 UTC
# Line 162  class TestLSODE(Ascend): Line 162  class TestLSODE(Ascend):
162          I.setMaxSubStep(0.001)          I.setMaxSubStep(0.001)
163          I.setMaxSubSteps(10000)          I.setMaxSubSteps(10000)
164          I.setReporter(ascpy.IntegratorReporterConsole(I))          I.setReporter(ascpy.IntegratorReporterConsole(I))
165          I.setLinearTimesteps(ascpy.Units(), 1.0, 1.5, 5);          I.setLinearTimesteps(ascpy.Units(), 1.0, 1.5, 5)
166          I.analyse()          I.analyse()
167          I.solve()          I.solve()
168          M.run(T.getMethod('self_test'))          M.run(T.getMethod('self_test'))
# Line 184  class TestLSODE(Ascend): Line 184  class TestLSODE(Ascend):
184          I.setMaxSubSteps(10000)          I.setMaxSubSteps(10000)
185                    
186          I.setReporter(ascpy.IntegratorReporterConsole(I))          I.setReporter(ascpy.IntegratorReporterConsole(I))
187          I.setLinearTimesteps(ascpy.Units("s"), 0, 2*float(M.v)/float(M.g), 2);          I.setLinearTimesteps(ascpy.Units("s"), 0, 2*float(M.v)/float(M.g), 2)
188          I.analyse()          I.analyse()
189          I.solve()          I.solve()
190          print "At end of simulation,"          print "At end of simulation,"
# Line 199  class TestLSODE(Ascend): Line 199  class TestLSODE(Ascend):
199          I = ascpy.Integrator(M)          I = ascpy.Integrator(M)
200          I.setEngine('LSODE')          I.setEngine('LSODE')
201          I.setReporter(ascpy.IntegratorReporterConsole(I))          I.setReporter(ascpy.IntegratorReporterConsole(I))
202          I.setLinearTimesteps(ascpy.Units("s"), 0, 200, 5);          I.setLinearTimesteps(ascpy.Units("s"), 0, 200, 5)
203          I.analyse()          I.analyse()
204          print "Number of vars = %d" % I.getNumVars()          print "Number of vars = %d" % I.getNumVars()
205          assert I.getNumVars()==2          assert I.getNumVars()==2
# Line 207  class TestLSODE(Ascend): Line 207  class TestLSODE(Ascend):
207          assert I.getNumObservedVars() == 3;          assert I.getNumObservedVars() == 3;
208          assert abs(M.R - 832) < 1.0          assert abs(M.R - 832) < 1.0
209          assert abs(M.F - 21.36) < 0.1          assert abs(M.F - 21.36) < 0.1
210            
211    #-------------------------------------------------------------------------------
212    # Testing of freesteam external steam properties functions
213    
214    try:
215        import freesteam
216        have_freesteam = True
217    except ImportException,e:
218        have_freesteam = False
219    
220    if have_freesteam:
221        class TestFreesteam(Ascend):
222            def testfreesteam(self):
223                self.L.load('johnpye/thermalequilibrium2.a4c')
224                #M = self.L.findType('thermalequilibrium2').getSimulation('sim')
225                #M.setSolver(ascpy.Solver("QRSlv"))
226                #I = ascpy.Integrator(M)
227                #I.setEngine('LSODE')
228                #I.setReporter(ascpy.IntegratorReporterConsole(I))
229                #I.setLinearTimesteps(ascpy.Units("s"), 0, 3000, 30)
230                #I.setMinSubStep(0.01)
231                #I.setInitialSubStep(0.1)
232                #I.analyse()
233                #print "Number of vars = %d" % I.getNumVars()
234                #assert I.getNumVars()==2
235                #I.solve()
236                #assert I.getNumObservedVars() == 3;
237                #assert abs(M.R - 832) < 1.0
238                #assert abs(M.F - 21.36) < 0.1
239    
240    
241    #-------------------------------------------------------------------------------
242    # Testing of IDA models using DENSE linear solver
243    
244  class TestIDADENSE(Ascend):  class TestIDADENSE(Ascend):
245        """IDA DAE integrator, DENSE linear solver"""
246    
247      def testnewton(self):      def testnewton(self):
248          sys.stderr.write("STARTING TESTNEWTON\n")          sys.stderr.write("STARTING TESTNEWTON\n")
# Line 225  class TestIDADENSE(Ascend): Line 259  class TestIDADENSE(Ascend):
259          I.setMaxSubSteps(10000)          I.setMaxSubSteps(10000)
260                    
261          I.setReporter(ascpy.IntegratorReporterConsole(I))          I.setReporter(ascpy.IntegratorReporterConsole(I))
262          I.setLinearTimesteps(ascpy.Units("s"), 0, 2*float(M.v)/float(M.g), 2);          I.setLinearTimesteps(ascpy.Units("s"), 0, 2*float(M.v)/float(M.g), 2)
263          I.analyse()          I.analyse()
264          I.solve()          I.solve()
265          print "At end of simulation,"          print "At end of simulation,"
# Line 247  class TestIDADENSE(Ascend): Line 281  class TestIDADENSE(Ascend):
281          assert I.getNumVars()==2          assert I.getNumVars()==2
282          assert abs(M.R - 1000) < 1e-300          assert abs(M.R - 1000) < 1e-300
283          I.solve()          I.solve()
284          assert I.getNumObservedVars() == 3;          assert I.getNumObservedVars() == 3
285          assert abs(M.R - 832) < 1.0          assert abs(M.R - 832) < 1.0
286          assert abs(M.F - 21.36) < 0.1          assert abs(M.F - 21.36) < 0.1
287                    
288      def testdenx(self):      def testdenx(self):
289          self.L.load('johnpye/idadenx.a4c')          self.L.load('johnpye/idadenx.a4c')
290          M = self.L.findType('idadenx').getSimulation('sim')          M = self.L.findType('idadenx').getSimulation('sim')
291          M.solve(ascpy.Solver("QRSlv"),ascpy.SolverReporter())            M.setSolver(ascpy.Solver("QRSlv"))
292          I = ascpy.Integrator(M)          I = ascpy.Integrator(M)
293          I.setEngine('IDA')          I.setEngine('IDA')
294          I.setParameter('calcic','NONE')          I.setParameter('calcic','NONE')
295          I.setParameter('linsolver','DENSE')          I.setParameter('linsolver','DENSE')
296          I.setReporter(ascpy.IntegratorReporterConsole(I))          I.setReporter(ascpy.IntegratorReporterConsole(I))
297          I.setLogTimesteps(ascpy.Units("s"), 0.4, 4e10, 11);          I.setLogTimesteps(ascpy.Units("s"), 0.4, 4e10, 11)
298          I.setMaxSubStep(0);          I.setMaxSubStep(0);
299          I.setInitialSubStep(0);          I.setInitialSubStep(0)
300          I.setMaxSubSteps(0);          I.setMaxSubSteps(0);
301          I.setParameter('autodiff',True)          I.setParameter('autodiff',True)
302          I.analyse()          I.analyse()
303          I.solve()          I.solve()
304          assert abs(float(M.y1) - 5.1091e-08) < 1e-10;          assert abs(float(M.y1) - 5.1091e-08) < 1e-10
305          assert abs(float(M.y2) - 2.0437e-13) < 1e-15;          assert abs(float(M.y2) - 2.0437e-13) < 1e-15
306          assert abs(float(M.y3) - 1.0) < 1e-5;          assert abs(float(M.y3) - 1.0) < 1e-5
307    
308      def testkryxDENSE(self):      def testkryxDENSE(self):
309          self.L.load('johnpye/idakryx.a4c')          self.L.load('johnpye/idakryx.a4c')
# Line 288  class TestIDADENSE(Ascend): Line 322  class TestIDADENSE(Ascend):
322          I.setParameter('atolvect',False)          I.setParameter('atolvect',False)
323          I.setParameter('calcic','YA_YDP')          I.setParameter('calcic','YA_YDP')
324          I.analyse()          I.analyse()
325          I.setLogTimesteps(ascpy.Units("s"), 0.01, 10.24, 11);          I.setLogTimesteps(ascpy.Units("s"), 0.01, 10.24, 11)
326          I.solve()          I.solve()
327          assert abs(M.u[2][2].getValue()) < 1e-5          assert abs(M.u[2][2].getValue()) < 1e-5
328                
329    #-------------------------------------------------------------------------------
330    # Testing of IDA models using SPGMR linear solver (Krylov)
331        
332  # these tests are disabled until SPGMR preconditioning has been implemented  # these tests are disabled until SPGMR preconditioning has been implemented
333  class TestIDASPGMR:#(Ascend):  class TestIDASPGMR:#(Ascend):
334      def testlotka(self):      def testlotka(self):
# Line 301  class TestIDASPGMR:#(Ascend): Line 338  class TestIDASPGMR:#(Ascend):
338          I = ascpy.Integrator(M)          I = ascpy.Integrator(M)
339          I.setEngine('IDA')          I.setEngine('IDA')
340          I.setReporter(ascpy.IntegratorReporterConsole(I))          I.setReporter(ascpy.IntegratorReporterConsole(I))
341          I.setLinearTimesteps(ascpy.Units("s"), 0, 200, 5);          I.setLinearTimesteps(ascpy.Units("s"), 0, 200, 5)
342          I.setParameter('rtol',1e-8);          I.setParameter('rtol',1e-8)
343          I.analyse()          I.analyse()
344          assert I.getNumVars()==2          assert I.getNumVars()==2
345          assert abs(M.R - 1000) < 1e-300          assert abs(M.R - 1000) < 1e-300
346          I.solve()          I.solve()
347          assert I.getNumObservedVars() == 3;          assert I.getNumObservedVars() == 3
348          assert abs(M.R - 832) < 1.0          assert abs(M.R - 832) < 1.0
349          assert abs(M.F - 21.36) < 0.1          assert abs(M.F - 21.36) < 0.1
350    
# Line 331  class TestIDASPGMR:#(Ascend): Line 368  class TestIDASPGMR:#(Ascend):
368          I.setParameter('calcic','Y')          I.setParameter('calcic','Y')
369          I.analyse()          I.analyse()
370          I.setLogTimesteps(ascpy.Units("s"), 0.01, 10.24, 10);          I.setLogTimesteps(ascpy.Units("s"), 0.01, 10.24, 10);
371          print M.udot[1][3];          print M.udot[1][3]
372          I.solve()          I.solve()
373          assert 0          assert 0
374    
# Line 347  class TestIDASPGMR:#(Ascend): Line 384  class TestIDASPGMR:#(Ascend):
384          I.setMaxSubStep(0.001)          I.setMaxSubStep(0.001)
385          I.setMaxSubSteps(10000)          I.setMaxSubSteps(10000)
386          I.setReporter(ascpy.IntegratorReporterConsole(I))          I.setReporter(ascpy.IntegratorReporterConsole(I))
387          I.setLinearTimesteps(ascpy.Units(), 1.0, 1.5, 5);          I.setLinearTimesteps(ascpy.Units(), 1.0, 1.5, 5)
388          I.analyse()          I.analyse()
389          I.solve()          I.solve()
390          M.run(T.getMethod('self_test'))          M.run(T.getMethod('self_test'))
# Line 359  class TestIDASPGMR:#(Ascend): Line 396  class TestIDASPGMR:#(Ascend):
396          I = ascpy.Integrator(M)          I = ascpy.Integrator(M)
397          I.setEngine('IDA')          I.setEngine('IDA')
398          I.setReporter(ascpy.IntegratorReporterConsole(I))          I.setReporter(ascpy.IntegratorReporterConsole(I))
399          I.setLogTimesteps(ascpy.Units("s"), 0.4, 4e10, 11);          I.setLogTimesteps(ascpy.Units("s"), 0.4, 4e10, 11)
400          I.setMaxSubStep(0);          I.setMaxSubStep(0);
401          I.setInitialSubStep(0);          I.setInitialSubStep(0);
402          I.setMaxSubSteps(0);          I.setMaxSubSteps(0);
# Line 369  class TestIDASPGMR:#(Ascend): Line 406  class TestIDASPGMR:#(Ascend):
406          I.setParameter('maxncf',10)          I.setParameter('maxncf',10)
407          I.analyse()          I.analyse()
408          I.solve()          I.solve()
409          assert abs(float(M.y1) - 5.1091e-08) < 1e-10;          assert abs(float(M.y1) - 5.1091e-08) < 1e-10
410          assert abs(float(M.y2) - 2.0437e-13) < 1e-15;          assert abs(float(M.y2) - 2.0437e-13) < 1e-15
411          assert abs(float(M.y3) - 1.0) < 1e-5;          assert abs(float(M.y3) - 1.0) < 1e-5
412    
413  # move code above down here if you want to temporarily avoid testing it  # move code above down here if you want to temporarily avoid testing it
414  class NotToBeTested:  class NotToBeTested:

Legend:
Removed from v.1016  
changed lines
  Added in v.1017

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