Ejemplo n.º 1
0
    def test_completed_step(self):
        """
        This tests the functionality of the method completed_step.
        """
        global nsteps
        nsteps = 0

        def f(t, y, yd):
            res_1 = y[0] + y[1] + 1.0
            res_2 = y[1]
            return N.array([res_1, res_2])

        def completed_step(solver):
            global nsteps
            nsteps += 1

        y0 = [-1.0, 0.0]
        yd0 = [1.0, 0.0]

        mod = Implicit_Problem(f, y0, yd0)
        mod.step_events = completed_step

        sim = IDA(mod)

        sim.simulate(2., 100)
        assert len(sim.t_sol) == 101
        assert nsteps == sim.statistics["nsteps"]

        sim = IDA(mod)
        nsteps = 0
        sim.simulate(2.)
        assert len(sim.t_sol) == sim.statistics["nsteps"] + 1
        assert nsteps == sim.statistics["nsteps"]
Ejemplo n.º 2
0
 def test_completed_step(self):
     """
     This tests the functionality of the method completed_step.
     """
     global nsteps
     nsteps = 0
     def f(t,y,yd):
         res_1 = y[0] + y[1]+1.0
         res_2 = y[1]
         return N.array([res_1, res_2])
     def completed_step(solver):
         global nsteps
         nsteps += 1
     
     y0 = [-1.0, 0.0]
     yd0 = [1.0 , 0.0]    
     
     mod = Implicit_Problem(f, y0, yd0)
     mod.step_events = completed_step
     
     sim = IDA(mod)
     
     sim.simulate(2., 100)
     assert len(sim.t_sol) == 101
     assert nsteps == sim.statistics["nsteps"]
     
     sim = IDA(mod)
     nsteps = 0
     sim.simulate(2.)
     assert len(sim.t_sol) == sim.statistics["nsteps"] + 1
     assert nsteps == sim.statistics["nsteps"]