def guess_mapper(sol): n_c = len(constants_of_motion) if n_c == 0: return sol sol_out = Solution() sol_out.t = copy.copy(sol.t) sol_out.y = np.array([[fn(*sol.y[0]) for fn in states_2_states_fn]]) sol_out.q = sol.q if len(quads) > 0: sol_out.q = -0.0 * np.array([np.ones((len(quads)))]) sol_out.dynamical_parameters = sol.dynamical_parameters sol_out.dynamical_parameters[-n_c:] = np.array( [fn(*sol.y[0]) for fn in states_2_constants_fn]) sol_out.nondynamical_parameters = sol.nondynamical_parameters sol_out.aux = sol.aux return sol_out
def test_Shooting_4(): # This problem contains a quad and tests if the bvp solver correctly # integrates the quadfun. def odefun(t, x, p, const): return -x[1], x[0] def quadfun(t, x, p, const): return x[0] def bcfun(t0, X0, q0, tf, Xf, qf, params, ndp, aux): return X0[0], X0[1] - 1, qf[0] - 1.0 algo = Shooting(odefun, quadfun, bcfun) solinit = Solution() solinit.t = np.linspace(0, np.pi / 2, 2) solinit.y = np.array([[1, 0], [1, 0]]) solinit.q = np.array([[0], [0]]) out = algo.solve(solinit) assert (out.y[0,0] - 0) < tol assert (out.y[0,1] - 1) < tol assert (out.q[0,0] - 2) < tol assert (out.q[-1,0] - 1) < tol