def test_newmark_basic_2nd_order_no_damping(): """ Test the explicit case of newmark of simple a 2nd order ODE, ybis = constant""" f = lambda t: 9.82/2.0 * t**2 + 5 """ Take off in a rocket at g-acc from 5m above grounds """ f2 = lambda t, x, y: 9.82 y0 = 5.0 v0 = 0.0 prob = Explicit_Problem(f2, y0) nmark = Newmark(prob, v0) end = 10.0 t, y = nmark.simulate(end) print y[-1], f(end), t[-1] nose.tools.assert_almost_equal(y[-1], f(end))
def test_newmark_basic_2nd_order_damping(): """ Test the implicit case of newmark of simple a 2nd order ODE, ybis(t) = constant* t. Tests for several values of beta and gamma. """ 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([0.0,0.33,0.66,1.0]) for beta in vals: for gamma in vals: nmark = Newmark(prob, v0, beta=beta, gamma=gamma) end = 10.0 t, y = nmark.simulate(end) nose.tools.assert_almost_equal(y[-1]/y[-1], f(end)/y[-1],places = 1)
def test_pend_newmark_against_normal(): """ Test out newmark 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 pend = p.Pendulum2nd() ode = pend.fcn end = 15 y0 = pend.initial_condition() prob = Explicit_Problem(ode, y0[0]) nmark = Newmark(prob, y0[1], beta = .7, gamma = .5) t, y_2 = nmark.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_2[-1]/y_3[-1][0],places = 1)