def test_hht_basic_2nd_order_spring(): """ Test the hht method for a spring system. Tests for several values of alpha. """ y0 = 3.0 v0 = 2.0 ode = mass_spring_damper(3, 2, 3) prob = Explicit_Problem(ode, y0) vals = array([-1.0/3.0,-0.2,-0.1,-0.05,0.0]) for alpha in vals: hht = HHT(prob, v0, alpha = alpha) end = 10.0 t, y = hht.simulate(end) nose.tools.assert_almost_equal(y[-1]/y[-1], ode.explicit(end, v0, y0)/y[-1],places = 1)
def test_hht_basic_2nd_order_damping(): """ Test hht of simple a 2nd order ODE, ybis(t) = constant* t. Tests for several values of alpha. """ f = lambda t: 5.0/3.0* t**3 + 2*t + 3 """ Take off in a rocket at g-acc from 5m above ground, v0 = 10m/s """ def ode_2(t,x,y): return 10.0 * t y0 = 3.0 v0 = 2.0 prob = Explicit_Problem(ode_2, y0) vals = array([-1.0/3.0,-0.2,-0.1,-0.05,0.0]) for alpha in vals: hht = HHT(prob, v0, alpha = alpha) end = 10.0 t, y = hht.simulate(end) nose.tools.assert_almost_equal(y[-1]/y[-1], f(end)/y[-1],places = 1)
def test_against_normal_solvers(): """ Test the HHT method on the damper system and compares the result against a simulation using LSODAR """ end = 10.0 ode = flattened_2nd_order(3, 2, 3) y0 = 3.0 v0 = 2.0 prob = Explicit_Problem(ode, [y0,v0]) exp_sim = LSODAR(prob) t, y = exp_sim.simulate(end) ode = mass_spring_damper(3, 2, 3) prob = Explicit_Problem(ode, y0) hht = HHT(prob, v0, alpha = -0.2) t, y_2 = hht.simulate(end) nose.tools.assert_almost_equal(y[-1][0]/y[-1][0], y_2[-1]/y[-1][0],places = 1)
def test_pend_hht_against_normal(): """ Test out hht solver againts the pendulum by comparing the result of a simulation against one done by assimulo""" import problems as p from matplotlib.pylab import plot, show, figure pend = p.Pendulum2nd() ode = pend.fcn end = 15 y0 = pend.initial_condition() prob = Explicit_Problem(ode, y0[0]) hht = HHT(prob, y0[1], alpha=-0.2) t, y_1 = hht.simulate(end) ode = pend.fcn_1 prob = Explicit_Problem(ode, y0) sim = LSODAR(prob) t, y_3 = sim.simulate(end) nose.tools.assert_almost_equal(y_3[-1][0]/y_3[-1][0], y_1[-1]/y_3[-1][0],places = 1)