コード例 #1
0
 def setUp(self):
     """
     This sets up the test case.
     """
     #Define the residual
     def f(t,y,yd):
         eps = 1.e-6
         my = 1./eps
         yd_0 = y[1]
         yd_1 = my*((1.-y[0]**2)*y[1]-y[0])
         
         res_0 = yd[0]-yd_0
         res_1 = yd[1]-yd_1
         
         return N.array([res_0,res_1])
     
     y0 = [2.0,-0.6] #Initial conditions
     yd0 = [-.6,-200000.]
     
     #Define an Assimulo problem
     self.mod = Implicit_Problem(f,y0,yd0)
     self.mod_t0 = Implicit_Problem(f,y0,yd0,1.0)
         
     #Define an explicit solver
     self.sim = _Radau5DAE(self.mod) #Create a Radau5 solve
     self.sim_t0 = _Radau5DAE(self.mod_t0)
     
     #Sets the parameters
     self.sim.atol = 1e-4 #Default 1e-6
     self.sim.rtol = 1e-4 #Default 1e-6
     self.sim.inith = 1.e-4 #Initial step-size
コード例 #2
0
 def test_time_event(self):
     f = lambda t,y,yd: y-yd
     global tnext
     global nevent
     tnext = 0.0
     nevent = 0
     def time_events(t,y,yd,sw):
         global tnext,nevent
         events = [1.0, 2.0, 2.5, 3.0]
         for ev in events:
             if t < ev:
                 tnext = ev
                 break
             else:
                 tnext = None
         nevent += 1
         return tnext
         
     def handle_event(solver, event_info):
         #solver.y+= 1.0
         global tnext
         nose.tools.assert_almost_equal(solver.t, tnext)
         assert event_info[0] == []
         assert event_info[1] == True
 
     exp_mod = Implicit_Problem(f,0.0,0.0)
     exp_mod.time_events = time_events
     exp_mod.handle_event = handle_event
     
     #CVode
     exp_sim = _Radau5DAE(exp_mod)
     exp_sim.verbosity = 0
     exp_sim(5.,100)
     
     assert nevent == 5
コード例 #3
0
    def test_init(self):
        """
        This tests the functionality of Radau5 Implicit Init.
        """
        #Test both y0 in problem and not.

        sim = _Radau5DAE(self.mod)
        
        assert sim._leny == 2