コード例 #1
0
        plt.savefig('vib_%d_%d_u.eps' % (timesteps_per_period, num_periods))


#f = RHS(b=0.4, A_F=1, w_F=2)
f = RHS(b=0.4, A_F=0, w_F=2)
f = RHS(b=0.4, A_F=1, w_F=np.pi)
f = RHS(b=0.4, A_F=20,
        w_F=2 * np.pi)  # qualitatively wrong FE, almost ok BE, smaller T
#f = RHS(b=0.4, A_F=20, w_F=0.5*np.pi)  # cool, FE almost there, BE good

# Define different sets of experiments
solvers_theta = [
    odespy.ForwardEuler(f),
    # Implicit methods must use Newton solver to converge
    odespy.BackwardEuler(f, nonlinear_solver='Newton'),
    odespy.CrankNicolson(f, nonlinear_solver='Newton'),
]

solvers_RK = [odespy.RK2(f), odespy.RK4(f)]
solvers_accurate = [
    odespy.RK4(f),
    odespy.CrankNicolson(f, nonlinear_solver='Newton'),
    odespy.DormandPrince(f, atol=0.001, rtol=0.02)
]
solvers_CN = [odespy.CrankNicolson(f, nonlinear_solver='Newton')]

if __name__ == '__main__':
    timesteps_per_period = 20
    solver_collection = 'theta'
    num_periods = 1
    try:
コード例 #2
0
    (RHS(b=0.4, F=lambda t: 10 * sin(0.5 * pi * t)),
     'Medium damping, large forcing w/smaller frequency'),
    (RHS(b=1.2, F=lambda t: 10 * sin(0.5 * pi * t)),
     'Strong damping, large forcing w/smaller frequency'),
    (RHS(b=0.4, F=lambda t: 1 * sin(2 * pi * t)),
     'Medium damping, medium forcing w/larger frequency'),
    (RHS(b=0.4, F=lambda t: 10 * sin(2 * pi * t)),
     'Medium damping, large forcing w/larger frequency'),
    (RHS(b=1.2, F=lambda t: 10 * sin(2 * pi * t)),
     'Strong damping, large forcing w/larger frequency'),
]

for rhs, title in ODEs:
    solvers = [
        odespy.ForwardEuler(rhs),
        # Implicit methods must use Newton solver to converge
        odespy.BackwardEuler(rhs, nonlinear_solver='Newton'),
        odespy.CrankNicolson(rhs, nonlinear_solver='Newton'),
        VibSolverWrapper4Odespy(rhs),
    ]

    T = 20  # Period is 1
    dt = 0.05  # 20 steps per period
    filename = 'FEBNCN_' + title.replace(', ', '_').replace('w/', '')
    title = title + ' (dt=%g)' % dt
    plt.figure()
    run_solvers_and_plot(solvers, rhs, T, dt, title=title, filename=filename)

plt.show()
raw_input()