コード例 #1
0
def run_example(with_plots=True):
    """
    Example of the use of CVode for a differential equation
    with a iscontinuity (state event) and the need for an event iteration.
    
    on return:
    
       - :dfn:`exp_mod`    problem instance
    
       - :dfn:`exp_sim`    solver instance
    """
    #Create an instance of the problem
    exp_mod = Extended_Problem()  #Create the problem

    exp_sim = CVode(exp_mod)  #Create the solver

    exp_sim.verbosity = 0
    exp_sim.report_continuously = True

    #Simulate
    t, y = exp_sim.simulate(
        10.0, 1000)  #Simulate 10 seconds with 1000 communications points
    exp_sim.print_event_data()

    #Plot
    if with_plots:
        import pylab as P
        P.plot(t, y)
        P.title(exp_mod.name)
        P.ylabel('States')
        P.xlabel('Time')
        P.show()

    #Basic test
    nose.tools.assert_almost_equal(y[-1][0], 8.0)
    nose.tools.assert_almost_equal(y[-1][1], 3.0)
    nose.tools.assert_almost_equal(y[-1][2], 2.0)

    return exp_mod, exp_sim