def runtests(p, problem, parallel=False, tol=None): from nodepy import rk, ivp, conv import numpy as np from nodepy import loadmethod if tol is None: tol = [10.**(-m) for m in range(2, 11)] # Load methods print 'constructing Ex-Euler' ex = rk.extrap_pair(p) print 'constructing Ex-midpoint' exm = rk.extrap_pair(p / 2, 'midpoint') print 'constructing DC-Euler' dc = rk.DC_pair(p - 1) if p == 6: ork = rk.loadRKM('CMR6') elif p == 8: ork = rk.loadRKM('DP8') elif p == 10: ork = loadmethod.load_rkpair_from_file('rk108curtis.txt') elif p == 12: ork = loadmethod.load_rkpair_from_file('rk129hiroshi.txt') if problem == 'suite': myivp = ivp.detest_suite_minus() else: myivp = ivp.detest(problem) methods = [ork, ex, exm, dc] [work, err] = conv.ptest(methods, myivp, tol, verbosity=1, parallel=parallel) plot_efficiency(methods, err, work) fname = 'eff_' + problem + '_' + str(p) if parallel: fname = fname + '_par' plt.ylabel('Sequential derivative evaluations') plt.savefig(fname + '.pdf')
def run_tolerances(tols, p=8): from nodepy import rk from nodepy import loadmethod err = np.zeros((4, len(tols))) work = np.zeros((4, len(tols))) rkm = rk.loadRKM("BS5").__num__() q_ref, dx, iwork = stegoton(rkm, tol=1.0e-13) rkm = rk.extrap_pair(p / 2, "midpoint").__num__() rke = rk.extrap_pair(p).__num__() rkd = rk.DC_pair(p - 1, grid="cheb").__num__() if p == 6: ork = rk.loadRKM("CMR6") elif p == 8: ork = rk.loadRKM("DP8") elif p == 10: ork = loadmethod.load_rkpair_from_file("rk108curtis.txt") elif p == 12: ork = loadmethod.load_rkpair_from_file("rk129hiroshi.txt") for i, tol in enumerate(tols): q, dx, iwork = stegoton(ork, tol) err[0, i] = np.linalg.norm(q - q_ref, 1) * dx work[0, i] = iwork * len(rkm) q, dx, iwork = stegoton(rke, tol) err[2, i] = np.linalg.norm(q - q_ref, 1) * dx work[2, i] = iwork * len(rke) q, dx, iwork = stegoton(rkm, tol) err[1, i] = np.linalg.norm(q - q_ref, 1) * dx work[1, i] = iwork * len(rkm) q, dx, iwork = stegoton(rkd, tol) err[3, i] = np.linalg.norm(q - q_ref, 1) * dx work[3, i] = iwork * len(rkd) return err, work, ork
def run_tolerances(tols, p=8): from nodepy import rk from nodepy import loadmethod err = np.zeros((4, len(tols))) work = np.zeros((4, len(tols))) rkm = rk.loadRKM('BS5').__num__() q_ref, dx, iwork = stegoton(rkm, tol=1.e-13) rkm = rk.extrap_pair(p / 2, 'midpoint').__num__() rke = rk.extrap_pair(p).__num__() rkd = rk.DC_pair(p - 1, grid='cheb').__num__() if p == 6: ork = rk.loadRKM('CMR6') elif p == 8: ork = rk.loadRKM('DP8') elif p == 10: ork = loadmethod.load_rkpair_from_file('rk108curtis.txt') elif p == 12: ork = loadmethod.load_rkpair_from_file('rk129hiroshi.txt') for i, tol in enumerate(tols): q, dx, iwork = stegoton(ork, tol) err[0, i] = np.linalg.norm(q - q_ref, 1) * dx work[0, i] = iwork * len(rkm) q, dx, iwork = stegoton(rke, tol) err[2, i] = np.linalg.norm(q - q_ref, 1) * dx work[2, i] = iwork * len(rke) q, dx, iwork = stegoton(rkm, tol) err[1, i] = np.linalg.norm(q - q_ref, 1) * dx work[1, i] = iwork * len(rkm) q, dx, iwork = stegoton(rkd, tol) err[3, i] = np.linalg.norm(q - q_ref, 1) * dx work[3, i] = iwork * len(rkd) return err, work, ork
def runtests(p,problem,parallel=False,tol=None): from nodepy import rk, ivp, conv import numpy as np from nodepy import loadmethod if tol is None: tol = [10.**(-m) for m in range(2,11)] # Load methods print 'constructing Ex-Euler' ex = rk.extrap_pair(p); print 'constructing Ex-midpoint' exm = rk.extrap_pair(p/2,'midpoint'); print 'constructing DC-Euler' dc = rk.DC_pair(p-1); if p == 6: ork = rk.loadRKM('CMR6') elif p == 8: ork = rk.loadRKM('DP8') elif p == 10: ork = loadmethod.load_rkpair_from_file('rk108curtis.txt') elif p == 12: ork = loadmethod.load_rkpair_from_file('rk129hiroshi.txt') if problem == 'suite': myivp = ivp.detest_suite_minus() else: myivp = ivp.detest(problem); methods = [ork,ex,exm,dc] [work,err] = conv.ptest(methods,myivp,tol,verbosity=1,parallel=parallel); plot_efficiency(methods, err, work) fname = 'eff_'+problem+'_'+str(p) if parallel: fname = fname + '_par' plt.ylabel('Sequential derivative evaluations') plt.savefig(fname+'.pdf')
if p == 6: ork = rk.loadRKM('CMR6') elif p == 8: ork = rk.loadRKM('DP8') elif p == 10: ork = loadmethod.load_rkpair_from_file('rk108curtis.txt') elif p == 12: ork = loadmethod.load_rkpair_from_file('rk129hiroshi.txt') pp,q = ork.stability_function() I_R[0,i] = stability_function.real_stability_interval(pp,q) I_I[0,i] = stability_function.imaginary_stability_interval(pp,q) I_R_scaled[0,i] = I_R[0,i]/len(ork) I_I_scaled[0,i] = I_I[0,i]/len(ork) exe = rk.extrap_pair(p) pp,q = exe.stability_function() I_R[1,i] = stability_function.real_stability_interval(pp,q) I_I[1,i] = stability_function.imaginary_stability_interval(pp,q) I_R_scaled[1,i] = I_R[1,i]/len(exe) I_I_scaled[1,i] = I_I[1,i]/len(exe) if p%2==0: exm = rk.extrap_pair(p/2,'midpoint') pp,q = exm.stability_function() I_R[2,i] = stability_function.real_stability_interval(pp,q) I_I[2,i] = stability_function.imaginary_stability_interval(pp,q) I_R_scaled[2,i] = I_R[2,i]/len(exm) I_I_scaled[2,i] = I_I[2,i]/len(exm) dc = rk.DC_pair(p-1)