Beispiel #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
Beispiel #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
Beispiel #3
0
 def test_nbr_fcn_evals_due_to_jac(self):
     sim = Radau5DAE(self.mod)
     
     sim.usejac = False
     sim.simulate(1)
     
     assert sim.statistics["nfcnjacs"] > 0
Beispiel #4
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
Beispiel #5
0
 def test_simulate_explicit(self):
     """
     Test a simulation of an explicit problem using Radau5DAE.
     """
     f = lambda t,y:N.array(-y)
     y0 = [1.0]
     
     problem = Explicit_Problem(f,y0)
     simulator = Radau5DAE(problem)
     
     assert simulator.yd0[0] == -simulator.y0[0]
     
     t,y = simulator.simulate(1.0)
     
     nose.tools.assert_almost_equal(float(y[-1]), float(N.exp(-1.0)),4)
Beispiel #6
0
    def test_switches(self):
        """
        This tests that the switches are actually turned when override.
        """
        res = lambda t,x,xd,sw: N.array([1.0 - xd])
        state_events = lambda t,x,xd,sw: N.array([x[0]-1.])
        def handle_event(solver, event_info):
            solver.sw = [False] #Override the switches to point to another instance
        
        mod = Implicit_Problem(res,[0.0], [1.0])
        mod.sw0 = [True]

        mod.state_events = state_events
        mod.handle_event = handle_event
        
        sim = Radau5DAE(mod)
        assert sim.sw[0] == True
        sim.simulate(3)
        assert sim.sw[0] == False