示例#1
0
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')
示例#2
0
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')
示例#3
0
#This code shows crazy behavior of DC

from nodepy import runge_kutta_method as rk
from nodepy import ivp
from nodepy import conv
import pylab as pl
import numpy as np

print 'initializing...'
methods = []
for p in (6, 8, 10, 12):
    methods.append(rk.extrap_pair(p))
print 'done'

myivp = ivp.detest('SB1')
tols = 10.**(-np.arange(2, 14))
[work, EX] = conv.ptest(methods, myivp, tols, verbosity=1)

pl.clf()
pl.hold(True)
pl.loglog(EX[0, :], work[0, :], 'b-o', linewidth=2.5)
pl.loglog(EX[1, :], work[1, :], 'y-d', linewidth=2.5)
pl.loglog(EX[2, :], work[2, :], 'c-p', linewidth=2.5)
pl.loglog(EX[3, :], work[3, :], 'm-s', linewidth=2.5)
pl.xticks([1.e0, 1.e-2, 1.e-4, 1.e-6, 1.e-8, 1.e-10, 1.e-12], fontsize=15)
pl.yticks(fontsize=15)
pl.grid()
pl.xlabel('Error at $\mathbf{t}_\mathrm{\mathbf{final}}$',
          fontsize=15,
          fontweight='bold')
pl.ylabel('Cost', fontsize=18, fontweight='bold')
#This code shows crazy behavior of DC

from nodepy import runge_kutta_method as rk
from nodepy import ivp
from nodepy import conv
import pylab as pl
import numpy as np

print 'initializing...'
methods = []
for p in (6,8,10,12):
    methods.append(rk.extrap_pair(p))
print 'done'

myivp = ivp.detest('SB1');
tols = 10.**(-np.arange(2,14))
[work,EX]=conv.ptest(methods,myivp,tols,verbosity=1);

pl.clf()
pl.hold(True)
pl.loglog(EX[0,:],work[0,:],'b-o',linewidth=2.5)
pl.loglog(EX[1,:],work[1,:],'y-d',linewidth=2.5)
pl.loglog(EX[2,:],work[2,:],'c-p',linewidth=2.5)
pl.loglog(EX[3,:],work[3,:],'m-s',linewidth=2.5)
pl.xticks([1.e0,1.e-2,1.e-4,1.e-6,1.e-8,1.e-10,1.e-12], fontsize=15)
pl.yticks(fontsize=15)
pl.grid()
pl.xlabel('Error at $\mathbf{t}_\mathrm{\mathbf{final}}$', fontsize=15,fontweight='bold')
pl.ylabel('Cost', fontsize=18,fontweight='bold')
#pl.ylim([1.e2,1.e5])
pl.hold(False)