/[ascend]/branches/fprops2/test.py
ViewVC logotype

Diff of /branches/fprops2/test.py

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

revision 1038 by johnpye, Thu Jan 4 08:11:55 2007 UTC revision 1039 by johnpye, Thu Jan 4 23:21:20 2007 UTC
# Line 365  class TestExtFn(AscendSelfTester): Line 365  class TestExtFn(AscendSelfTester):
365          self.assertAlmostEqual(M.x, 1);          self.assertAlmostEqual(M.x, 1);
366          self.assertAlmostEqual(M.y, M.x + 1);          self.assertAlmostEqual(M.y, M.x + 1);
367    
368  #   THIS TEST FAILS      def testextrelfor(self):
369  #   def testextrelfor(self):          M = self._run('extrelfor',filename='johnpye/extfn/extrelfor.a4c')
370  #       self.L.load('johnpye/extfn/extrelfor.a4c')  
371  #       T = self.L.findType('extrelfor')      def testextrelforbadnaming(self):
372  #       M = T.getSimulation('sim')          self.L.load('johnpye/extfn/extrelforbadnaming.a4c')
373  #       M.solve(ascpy.Solver('QRSlv'),ascpy.SolverReporter())          T = self.L.findType('extrelfor')
374  #       print "x[1] = %f" % M.x[1]          M = T.getSimulation('sim')
375  #       print "x[2] = %f" % M.x[2]          M.solve(ascpy.Solver('QRSlv'),ascpy.SolverReporter())
376  #       print "x[3] = %f" % M.x[3]          print "x[1] = %f" % M.x[1]
377  #       M.run(T.getMethod('self_test'))          print "x[2] = %f" % M.x[2]
378            print "x[3] = %f" % M.x[3]
379            print "x[4] = %f" % M.x[4]
380            print "x[5] = %f" % M.x[5]
381            M.run(T.getMethod('self_test'))
382    
383      def testextrelrepeat(self):      def testextrelrepeat(self):
384          M = self._run('extrelrepeat',filename='johnpye/extfn/extrelrepeat.a4c')          M = self._run('extrelrepeat',filename='johnpye/extfn/extrelrepeat.a4c')
# Line 392  class TestExtPy(AscendSelfTester): Line 396  class TestExtPy(AscendSelfTester):
396    
397  with_freesteam = True  with_freesteam = True
398  try:  try:
399        # we assume that if the freesteam python module is installed, the ASCEND
400        # external library will also be.
401      import freesteam      import freesteam
402      have_freesteam = True      have_freesteam = True
403  except ImportError,e:  except ImportError,e:
404      have_freesteam = False      have_freesteam = False
405    
406  if with_freesteam and have_freesteam:  if with_freesteam and have_freesteam:
407      class TestFreesteam(Ascend):      class TestFreesteam(AscendSelfTester):
408            def testfreesteamtest(self):
409                """run the self-test cases bundled with freesteam"""
410                self._run('testfreesteam',filename='testfreesteam.a4c')
411    
412          def testload(self):          def testload(self):
413                """check that we can load 'thermalequilibrium2' (IMPORT "freesteam", etc)"""
414              self.L.load('johnpye/thermalequilibrium2.a4c')              self.L.load('johnpye/thermalequilibrium2.a4c')
415    
416          def testinstantiate(self):          def testinstantiate(self):
417                """load an instantiate 'thermalequilibrium2'"""
418              self.testload()              self.testload()
419              M = self.L.findType('thermalequilibrium2').getSimulation('sim')              M = self.L.findType('thermalequilibrium2').getSimulation('sim')
420                return M
421    
422          def testsolve(self):          def testintegrate(self):
423              self.testinstantiate()              """integrate transfer of heat from one mass of water/steam to another
424                according to Newton's law of cooling"""
425                M = self.testinstantiate()
426              M.setSolver(ascpy.Solver("QRSlv"))              M.setSolver(ascpy.Solver("QRSlv"))
427              #I = ascpy.Integrator(M)              I = ascpy.Integrator(M)
428              #I.setEngine('LSODE')              I.setEngine('LSODE')
429              #I.setReporter(ascpy.IntegratorReporterConsole(I))              I.setReporter(ascpy.IntegratorReporterConsole(I))
430              #I.setLinearTimesteps(ascpy.Units("s"), 0, 3000, 30)              I.setLinearTimesteps(ascpy.Units("s"), 0, 3000, 30)
431              #I.setMinSubStep(0.01)              I.setMinSubStep(0.001)
432              #I.setInitialSubStep(0.1)              I.setInitialSubStep(0.01)
433              #I.analyse()              I.analyse()
434              #print "Number of vars = %d" % I.getNumVars()              print "Number of vars = %d" % I.getNumVars()
435              #assert I.getNumVars()==2              assert I.getNumVars()==2
436              #I.solve()              I.solve()
437              #assert I.getNumObservedVars() == 3;              assert I.getNumObservedVars() == 3;
438              #assert abs(M.R - 832) < 1.0              print "S[1].T = %f K" % M.S[1].T
439              #assert abs(M.F - 21.36) < 0.1              print "S[2].T = %f K" % M.S[2].T
440                print "Q = %f W" % M.Q      
441                self.assertAlmostEqual(float(M.S[1].T),506.77225109);
442                self.assertAlmostEqual(float(M.S[2].T),511.605173967);
443                self.assertAlmostEqual(float(M.Q),-48.32922877329);
444                self.assertAlmostEqual(float(M.t),3000);
445                print "Note that the above values have not been verified analytically"
446    
447  #-------------------------------------------------------------------------------  #-------------------------------------------------------------------------------
448  # Testing of IDA models using DENSE linear solver  # Testing of IDA models using DENSE linear solver

Legend:
Removed from v.1038  
changed lines
  Added in v.1039

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