コード例 #1
0
 def test_time_event(self):
     f = lambda t,y: [1.0]
     global tnext
     global nevent
     tnext = 0.0
     nevent = 0
     def time_events(t,y,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 = Explicit_Problem(f,0.0)
     exp_mod.time_events = time_events
     exp_mod.handle_event = handle_event
     
     #CVode
     exp_sim = _Radau5ODE(exp_mod)
     exp_sim(5.,100)
     
     assert nevent == 5
コード例 #2
0
 def setUp(self):
     """
     This sets up the test case.
     """
     def f(t,y):
         eps = 1.e-6
         my = 1./eps
         yd_0 = y[1]
         yd_1 = my*((1.-y[0]**2)*y[1]-y[0])
         
         return N.array([yd_0,yd_1])
     
     def jac(t,y):
         eps = 1.e-6
         my = 1./eps
         J = N.zeros([2,2])
         
         J[0,0]=0.
         J[0,1]=1.
         J[1,0]=my*(-2.*y[0]*y[1]-1.)
         J[1,1]=my*(1.-y[0]**2)
         
         return J
     
     #Define an Assimulo problem
     y0 = [2.0,-0.6] #Initial conditions
     
     exp_mod = Explicit_Problem(f,y0)
     exp_mod_t0 = Explicit_Problem(f,y0,1.0)
     
     exp_mod.jac = jac
     self.mod = exp_mod
         
     #Define an explicit solver
     self.sim = _Radau5ODE(exp_mod) #Create a Radau5 solve
     self.sim_t0 = _Radau5ODE(exp_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
     self.sim.usejac = False
コード例 #3
0
 def test_init(self):
     
     #Test both y0 in problem and not.
     sim = _Radau5ODE(self.mod)
     
     assert sim._leny == 2