def order_conditions(self,p):
        """
        Generate a list of order conditions up to order p
        """

        forest=rt.list_trees(0)
        for i in range(1,p+1): forest+=rt.list_trees(i)
        oc={rt.RootedTree(''):''}
        for tree in forest[1:]:
            oc[tree]=self.elementary_weight(tree)-rt.Emap(tree)
        return oc
def TSRKOrderConditions(p, ind='all'):
    from nodepy.rooted_trees import Emap_str
    forest = rt.list_trees(p)
    code = []
    for tree in forest:
        code.append(tsrk_elementary_weight_str(tree) + '-' + Emap_str(tree))
        code[-1] = code[-1].replace('--', '')
        code[-1] = code[-1].replace('1 ', 'e ')
        code[-1] = code[-1].replace('1)', 'e)')
    return code
def TSRKOrderConditions(p,ind='all'):
    from nodepy.rooted_trees import Emap_str
    forest=rt.list_trees(p)
    code=[]
    for tree in forest:
        code.append(tsrk_elementary_weight_str(tree)+'-'+Emap_str(tree))
        code[-1]=code[-1].replace('--','')
        code[-1]=code[-1].replace('1 ','e ')
        code[-1]=code[-1].replace('1)','e)')
    return code
示例#4
0
#Make matlab script to evaluate error coefficient
#for RK methods

from nodepy import rooted_trees as rt
from nodepy import runge_kutta_method as rk

p=10

f=open('oc_butcher.m','w')

ioc=1
for ip in range(2,p):
    f.write("if p>="+str(ip))
    f.write("\n  % order "+str(ip)+" conditions:\n")
    forest = rt.list_trees(ip)
    for tree in forest:
        oc=rk.elementary_weight_str(tree,style='matlab')
        rhs =str(rt.Emap(tree))
        f.write("  coneq("+str(ioc)+")="+oc+"-"+rhs+";\n")
        ioc+=1
    f.write("end\n\n")

f.close()
示例#5
0
#for RK methods

from nodepy import rooted_trees as rt
from nodepy import runge_kutta_method as rk

p_max=15

f=open('oc_butcher.py','w')

f.write("def order(rk,tol=1.e-13):\n")
f.write("    from numpy import dot,zeros,all,sum,abs\n")
f.write("    coneq = zeros((1000))\n")
f.write("    A=rk.A\n    b=rk.b\n    c=rk.c\n")
f.write("    coneq[0]=sum(b)-1.\n")
f.write("    if any(abs(coneq)>tol):\n")
f.write("        return 0")
for ip in range(2,p_max):
    print 'Generating order '+str(ip)+' conditions...'
    ioc=0
    f.write("\n    # order "+str(ip)+" conditions:\n")
    forest = rt.list_trees(ip)
    for tree in forest:
        oc=rk.elementary_weight_str(tree,style='python')
        rhs =str(rt.Emap(tree))
        f.write("    coneq["+str(ioc)+"]="+oc+"-"+rhs+".\n")
        ioc+=1
    f.write("    if any(abs(coneq)>tol):\n")
    f.write("        return "+str(ip-1))

f.close()