예제 #1
0
def test_plotTrajectory():

    from phdtools.models import lotkavolterra, decay

    # Construct a 2D flow
    y0 = [0.5, 0.6]
    ts = np.linspace(0, 10, 100)
    traj = Trajectory(lotkavolterra, y0, ts)
    roiX = np.linspace(0, 3, 10)
    roiY = np.linspace(0, 5, 20)

    # Plot a the trajectory in the phase plane
    traj.plotTrajectory()

    # Construct a 1D flow
    y0 = [0.5]
    ts = np.linspace(0, 10, 100)
    traj = Trajectory(decay, y0, ts)
    roiX = np.linspace(0, 3, 10)
    roiY = np.linspace(0, 5, 20)

    # Try to plot. Should fail
    with pytest.raises(ValueError) as excinfo:
        traj.plotTrajectory()
    assert 'Only available for 2 or 3 dimensions' in str(excinfo.value)
예제 #2
0
def test_solve():

    from phdtools.models import decay

    y0 = [1]
    ts = np.linspace(0, 20, 100)

    traj = Trajectory(decay, y0, ts)
    traj.solve()

    sol = traj.sol
    ylast = sol[-1, :]

    tol = 1e-2
    assert (np.abs(ylast[0]) < tol)  # Expected 0.0
예제 #3
0
def test_solve_torus():

    from phdtools.models import strogatz

    y0 = [1, 2]
    ts = np.linspace(0, 25, 300)

    traj = Trajectory(strogatz, y0, ts, topology='torus')
    traj.solve()

    # Check the periodic boundaries
    above_lower_bound = (traj.sol >= 0.0).all()
    below_upper_bound = (traj.sol <= 2 * np.pi).all()

    assert (above_lower_bound)
    assert (below_upper_bound)