Ejemplo n.º 1
0
def _test_NativeSys_two(NativeSys, nsteps=500):
    native1 = NativeSys.from_callback(vdp_f, 2, 1)

    tend2, k2, y02 = 2, [4, 3], (5, 4, 2)
    atol2, rtol2 = 1e-11, 1e-11

    native2 = NativeSys.from_callback(decay_dydt_factory(k2), len(k2) + 1)

    xout1, yout1, info1 = native1.integrate([0, 1, 2], [1, 0],
                                            params=[2.0],
                                            nsteps=nsteps)
    xout2, yout2, info2 = native2.integrate(tend2,
                                            y02,
                                            atol=atol2,
                                            rtol=rtol2,
                                            nsteps=nsteps)

    # blessed values:
    ref1 = [[1, 0], [0.44449086, -1.32847148], [-1.89021896, -0.71633577]]
    assert np.allclose(yout1, ref1)
    if 'nfev' in info1:
        assert info1['nfev'] > 0

    ref2 = np.array(bateman_full(y02, k2 + [0], xout2 - xout2[0],
                                 exp=np.exp)).T
    assert np.allclose(yout2, ref2, rtol=150 * rtol2, atol=150 * atol2)
Ejemplo n.º 2
0
def _test_NativeSys__band(NativeSys):
    tend, k, y0 = 2, [4, 3], (5, 4, 2)
    y = sp.symarray('y', len(k) + 1)
    dydt = decay_dydt_factory(k)
    f = dydt(0, y)
    odesys = NativeSys(zip(y, f), band=(1, 0))
    xout, yout, info = odesys.integrate(tend, y0, integrator='native')
    ref = np.array(bateman_full(y0, k + [0], xout - xout[0], exp=np.exp)).T
    assert np.allclose(yout, ref)
Ejemplo n.º 3
0
def _test_NativeSys__dep_by_name__single_varied(NativeSys):
    tend, kf, y0 = 2, [4, 3], {'a': (5, 3, 7, 9, 1, 6, 11), 'b': 4, 'c': 2}
    y = sp.symarray('y', len(kf) + 1)
    dydt = decay_dydt_factory(kf)
    f = dydt(0, y)
    odesys = NativeSys(zip(y, f), names='a b c'.split(), dep_by_name=True)
    results = odesys.integrate(tend, y0, integrator='native')
    for idx in range(len(y0['a'])):
        xout, yout, info = results[idx]
        assert info['success']
        assert xout.size == yout.shape[0] and yout.shape[1] == 3
        ref = np.array(
            bateman_full(
                [y0[k][idx] if k == 'a' else y0[k] for k in odesys.names],
                kf + [0],
                xout - xout[0],
                exp=np.exp)).T
        assert np.allclose(yout, ref)
Ejemplo n.º 4
0
def _test_NativeSys_two(NativeSys, nsteps=500):
    native1 = NativeSys.from_callback(vdp_f, 2, 1)

    tend2, k2, y02 = 2, [4, 3], (5, 4, 2)
    atol2, rtol2 = 1e-11, 1e-11

    native2 = NativeSys.from_callback(decay_dydt_factory(k2), len(k2)+1)

    xout1, yout1, info1 = native1.integrate([0, 1, 2], [1, 0], params=[2.0], nsteps=nsteps)
    xout2, yout2, info2 = native2.integrate(tend2, y02, atol=atol2, rtol=rtol2, nsteps=nsteps)

    # blessed values:
    ref1 = [[1, 0], [0.44449086, -1.32847148], [-1.89021896, -0.71633577]]
    assert np.allclose(yout1, ref1)
    if 'nfev' in info1:
        assert info1['nfev'] > 0

    ref2 = np.array(bateman_full(y02, k2+[0], xout2 - xout2[0], exp=np.exp)).T
    assert np.allclose(yout2, ref2, rtol=150*rtol2, atol=150*atol2)