Example #1
0
def test_run_adjoint2(trajectory_implicit):
    u, f, fu, fs, J, Ju, Js = trajectory_implicit
    w_tmn, vst_tmn = adjoint_terminal_condition(M, f[-1])
    w, vst = segment.get_wvst(w_tmn, vst_tmn, fu, Ju,
                              lorenz.adjoint_step_implicit)
    assert w.shape[0] == vst.shape[0]
    assert w.shape[2] == vst.shape[1]
    # test if w remains orthorgonal to f
    _ = (w[:, :-1] * f[:, np.newaxis, :]).sum(axis=-1)
    assert np.allclose(_, np.zeros(_.shape))
Example #2
0
def test_run_adjoint(trajectory):
    u, f, fu, fs, J, Ju, Js = trajectory
    w_tmn, vst_tmn = adjoint_terminal_condition(M, f[-1])
    w, vst = lorenz.run_adjoint(w_tmn, vst_tmn, fu, Ju, dt,
                                lorenz.adjoint_step_explicit)
    assert w.shape[0] == vst.shape[0] == nstep + 1
    assert w.shape[1] == M
    assert w.shape[2] == vst.shape[1] == m
    # test if w remains orthorgonal to f
    _ = (w * f[:, np.newaxis, :]).sum(axis=-1)
    assert np.allclose(_, np.zeros(_.shape))
Example #3
0
def test_terminal_condition_function():
    M_modes = 3
    m = 5
    f_tmn = np.random.rand(m)
    w_tmn, vst_tmn = adjoint_terminal_condition(M_modes, f_tmn)

    # check shape
    assert w_tmn.shape == (M_modes, m)
    assert vst_tmn.shape == f_tmn.shape == (m, )
    # check if w_tmn is orthogonal to f_tmn
    assert np.allclose(np.dot(w_tmn[:-1], f_tmn), np.zeros(M_modes - 1))
    # check the last column of w is f_tmn
    assert np.allclose(w_tmn[-1], f_tmn / np.linalg.norm(f_tmn))
    # check vst_tmn is zero
    assert np.allclose(vst_tmn, np.zeros(m))