Beispiel #1
0
def evl_f(elmass, series_input, series_type):
    """
	Evaluation of the series.
	"""
    from mpmath import mpf
    from pyranha.math import evaluate
    # -------- coordinates & masses --------
    num_pl = len(elmass[0])
    gmj, mpj, km = jacobiAMass(elmass[1], elmass[2])
    mm = massesRatio(elmass[1], elmass[2])
    mp = [1. / elmass[2]] + [
        elmass[1][i] / elmass[1][0] / elmass[2] for i in range(len(elmass[1]))
    ][1:]
    sp = [1. + elmass[2] * sum(mp[1:i + 1]) for i in range(len(elmass[1]))]
    # -------- dictionaries --------
    evaldict = {'K0': mpf(elmass[1][0])}
    evaldict.update({'m' + str(i + 1): mpf(mp[i + 1]) for i in range(num_pl)})
    evaldict.update({'s' + str(i + 1): mpf(sp[i + 1]) for i in range(num_pl)})
    evaldict.update(
        {'L' + str(i + 1): mpf(elmass[0][i][0])
         for i in range(num_pl)})
    evaldict.update(
        {'x' + str(i + 1): mpf(elmass[0][i][1])
         for i in range(num_pl)})
    evaldict.update(
        {'y' + str(i + 1): mpf(elmass[0][i][2])
         for i in range(num_pl)})
    evaldict.update(
        {'u' + str(i + 1): mpf(elmass[0][i][3])
         for i in range(num_pl)})
    evaldict.update(
        {'v' + str(i + 1): mpf(elmass[0][i][4])
         for i in range(num_pl)})
    evaldict.update(
        {'q' + str(i + 1): mpf(elmass[0][i][5])
         for i in range(num_pl)})
    evaldict.update({
        r'\nu_{q' + str(i + 1) + '}':
        mpf(gmj[i]**2 * mpj[i]**3 * elmass[0][i][0]**-3)
        for i in range(num_pl)
    })
    if type(series_input) == str:
        series = series_type
        lf(series, series_input, df.boost_portable, cf.bzip2)
        series_eval = evaluate(series, evaldict)
    else:
        series_eval = evaluate(series_input, evaldict)
    return float(series_eval)
Beispiel #2
0
def check_items(elmass, series2, isPrint):
    """
	Checking accuracy of items of the hamiltonian.
	"""
    from math import fabs
    from mpmath import mpf
    from pyranha.math import evaluate
    from eps.tools import kepler2cart, kepler2poincare, poincare2kepler, jacobiAMass
    elements, gmass, mu = elmass
    # -------- masses --------
    mp = [1. / mu] + [gmass[i] / gmass[0] / mu for i in range(len(gmass))][1:]
    sp = [1. + mu * sum(mp[1:i + 1]) for i in range(len(gmass))]
    gmj, mpj, km = jacobiAMass(gmass, mu)
    # -------- coordinates --------
    rlen1 = range(len(elements))
    kepler = [poincare2kepler(elements[i], km[i]) for i in rlen1]
    x, y, z = [0. for i in rlen1], [0. for i in rlen1], [0. for i in rlen1]
    for i in rlen1:
        x[i], y[i], z[i] = kepler2cart(kepler[i], km[i])[:3]
    r = [(x[i]**2 + y[i]**2 + z[i]**2)**0.5 for i in rlen1]
    PE = [kepler2poincare(kepler[i], km[i]) for i in rlen1]
    # pairs 21, 32, 43, 31, 42, 41:
    rr = {
        '21': r[0] / r[1],
        '32': r[1] / r[2],
        '43': r[2] / r[3],
        '31': r[0] / r[2],
        '42': r[1] / r[3],
        '41': r[0] / r[3]
    }
    sc = {
        '21': (x[0] * x[1] + y[0] * y[1] + z[0] * z[1]),
        '32': (x[1] * x[2] + y[1] * y[2] + z[1] * z[2]),
        '43': (x[2] * x[3] + y[2] * y[3] + z[2] * z[3]),
        '31': (x[0] * x[2] + y[0] * y[2] + z[0] * z[2]),
        '42': (x[1] * x[3] + y[1] * y[3] + z[1] * z[3]),
        '41': (x[0] * x[3] + y[0] * y[3] + z[0] * z[3])
    }
    cs = {
        '21': (x[0] * x[1] + y[0] * y[1] + z[0] * z[1]) / r[0] / r[1],
        '32': (x[1] * x[2] + y[1] * y[2] + z[1] * z[2]) / r[1] / r[2],
        '43': (x[2] * x[3] + y[2] * y[3] + z[2] * z[3]) / r[2] / r[3],
        '31': (x[0] * x[2] + y[0] * y[2] + z[0] * z[2]) / r[0] / r[2],
        '42': (x[1] * x[3] + y[1] * y[3] + z[1] * z[3]) / r[1] / r[3],
        '41': (x[0] * x[3] + y[0] * y[3] + z[0] * z[3]) / r[0] / r[3]
    }
    dd = {
        '21': ((x[1] - x[0])**2 + (y[1] - y[0])**2 + (z[1] - z[0])**2)**-0.5,
        '32': ((x[2] - x[1])**2 + (y[2] - y[1])**2 + (z[2] - z[1])**2)**-0.5,
        '43': ((x[3] - x[2])**2 + (y[3] - y[2])**2 + (z[3] - z[2])**2)**-0.5,
        '31': ((x[2] - x[0])**2 + (y[2] - y[0])**2 + (z[2] - z[0])**2)**-0.5,
        '42': ((x[3] - x[1])**2 + (y[3] - y[1])**2 + (z[3] - z[1])**2)**-0.5,
        '41': ((x[3] - x[0])**2 + (y[3] - y[0])**2 + (z[3] - z[0])**2)**-0.5
    }
    # -------- dictionaries --------
    evaldict = {'K0': mpf(gmass[0]), 'm1': mpf(mp[1]), 'm2': mpf(mp[2]), 'm3': mpf(mp[3]), 'm4': mpf(mp[4]), 's1': mpf(sp[1]), 's2': mpf(sp[2]), 's3': mpf(sp[3]), 's4': mpf(sp[4]),\
       'K1': mpf(gmj[0]**0.5), 'M1': mpf(mpj[0]), 'L1': mpf(PE[0][0]), 'x1': mpf(PE[0][1]), 'y1': mpf(PE[0][2]), 'u1': mpf(PE[0][3]), 'v1': mpf(PE[0][4]), 'q1': mpf(PE[0][5]),\
       'K2': mpf(gmj[1]**0.5), 'M2': mpf(mpj[1]), 'L2': mpf(PE[1][0]), 'x2': mpf(PE[1][1]), 'y2': mpf(PE[1][2]), 'u2': mpf(PE[1][3]), 'v2': mpf(PE[1][4]), 'q2': mpf(PE[1][5]),\
       'K3': mpf(gmj[2]**0.5), 'M3': mpf(mpj[2]), 'L3': mpf(PE[2][0]), 'x3': mpf(PE[2][1]), 'y3': mpf(PE[2][2]), 'u3': mpf(PE[2][3]), 'v3': mpf(PE[2][4]), 'q3': mpf(PE[2][5]),\
       'K4': mpf(gmj[3]**0.5), 'M4': mpf(mpj[3]), 'L4': mpf(PE[3][0]), 'x4': mpf(PE[3][1]), 'y4': mpf(PE[3][2]), 'u4': mpf(PE[3][3]), 'v4': mpf(PE[3][4]), 'q4': mpf(PE[3][5])}
    # -------- evaluation --------
    temp1_all, temp2_all, length1_all = 0, 0, 0
    tmp1, tmp2 = [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]
    for file2, series1, length1 in series2:
        if file2[0] != 'A':
            temp1, temp2 = 0, 0
            length1_all += length1
            if isPrint: print file2[:-16] + ':',
            if file2[:2] == 'H0':
                temp1 = evaluate(series1, evaldict)
                temp2 = -F(1, 2) * (mpj[0]**3 * gmj[0]**2 * PE[0][0]**-2 +
                                    mpj[1]**3 * gmj[1]**2 * PE[1][0]**-2 +
                                    mpj[2]**3 * gmj[2]**2 * PE[2][0]**-2 +
                                    mpj[3]**3 * gmj[3]**2 * PE[3][0]**-2)
                temp1_h0, temp2_h0 = temp1, temp2
            if '_21_' in file2:
                temp1 = evaluate(series1, evaldict)
                if 'H1' in file2:
                    temp2 = -mp[1] * mp[2] * dd['21']
                    temp1_all += temp1
                    temp2_all += temp2
                    tmp1[0] += temp1
                    tmp2[0] += temp2
                if 'H2' in file2:
                    temp2 = mp[1] * mp[2] * (mm[1] * sc['21'] -
                                             mm[1] * r[0]**2) * dd['21']**3
                    temp1_all += mu * temp1
                    temp2_all += mu * temp2
                    tmp1[0] += mu * temp1
                    tmp2[0] += mu * temp2
                if 'H3' in file2:
                    temp2 = -1.5 * mp[1] * mp[2] * (
                        mm[1] * sc['21'] - mm[1] *
                        r[0]**2)**2 * dd['21']**5 + 0.5 * mp[1] * mp[2] * (
                            mm[1] * r[0])**2 * dd['21']**3
                    temp1_all += mu**2 * temp1
                    temp2_all += mu**2 * temp2
                    tmp1[0] += mu**2 * temp1
                    tmp2[0] += mu**2 * temp2
            if '_32_' in file2:
                temp1 = evaluate(series1, evaldict)
                if 'H1' in file2:
                    temp2 = -mp[2] * mp[3] * dd['32']
                    temp1_all += temp1
                    temp2_all += temp2
                    tmp1[1] += temp1
                    tmp2[1] += temp2
                if 'H2' in file2:
                    temp2 = mp[2] * mp[3] * (mm[2] * sc['32'] -
                                             mm[2] * r[1]**2) * dd['32']**3
                    temp1_all += mu * temp1
                    temp2_all += mu * temp2
                    tmp1[1] += mu * temp1
                    tmp2[1] += mu * temp2
                if 'H3' in file2:
                    temp2 = -1.5 * mp[2] * mp[3] * (
                        mm[2] * sc['32'] - mm[2] *
                        r[1]**2)**2 * dd['32']**5 + 0.5 * mp[2] * mp[3] * (
                            mm[2] * r[1])**2 * dd['32']**3
                    temp1_all += mu**2 * temp1
                    temp2_all += mu**2 * temp2
                    tmp1[1] += mu**2 * temp1
                    tmp2[1] += mu**2 * temp2
            if '_43_' in file2:
                temp1 = evaluate(series1, evaldict)
                if 'H1' in file2:
                    temp2 = -mp[3] * mp[4] * dd['43']
                    temp1_all += temp1
                    temp2_all += temp2
                    tmp1[2] += temp1
                    tmp2[2] += temp2
                if 'H2' in file2:
                    temp2 = mp[3] * mp[4] * (mm[3] * sc['43'] -
                                             mm[3] * r[2]**2) * dd['43']**3
                    temp1_all += mu * temp1
                    temp2_all += mu * temp2
                    tmp1[2] += mu * temp1
                    tmp2[2] += mu * temp2
                if 'H3' in file2:
                    temp2 = -1.5 * mp[3] * mp[4] * (
                        mm[3] * sc['43'] - mm[3] *
                        r[2]**2)**2 * dd['43']**5 + 0.5 * mp[3] * mp[4] * (
                            mm[3] * r[2])**2 * dd['43']**3
                    temp1_all += mu**2 * temp1
                    temp2_all += mu**2 * temp2
                    tmp1[2] += mu**2 * temp1
                    tmp2[2] += mu**2 * temp2
            if '_31_' in file2:
                temp1 = evaluate(series1, evaldict)
                if 'H1' in file2:
                    temp2 = -mp[1] * mp[3] * dd['31']
                    temp1_all += temp1
                    temp2_all += temp2
                    tmp1[3] += temp1
                    tmp2[3] += temp2
                if 'H2' in file2:
                    temp2 = mp[1] * mp[3] * (
                        mm[1] * sc['31'] - mm[1] * r[0]**2 + mm[2] * sc['32'] -
                        mm[2] * sc['21']) * dd['31']**3
                    temp1_all += mu * temp1
                    temp2_all += mu * temp2
                    tmp1[3] += mu * temp1
                    tmp2[3] += mu * temp2
                if 'H3' in file2:
                    temp2 = -1.5*mp[1]*mp[3]*(mm[1]*sc['31'] - mm[1]*r[0]**2 + mm[2]*sc['32'] - mm[2]*sc['21'])**2 * dd['31']**5 +\
                       0.5*mp[1]*mp[3]*((mm[1]*r[0])**2 + (mm[2]*r[1])**2 + 2*mm[1]*mm[2]*sc['21']) * dd['31']**3
                    temp1_all += mu**2 * temp1
                    temp2_all += mu**2 * temp2
                    tmp1[3] += mu**2 * temp1
                    tmp2[3] += mu**2 * temp2
            if '_42_' in file2:
                temp1 = evaluate(series1, evaldict)
                if 'H1' in file2:
                    temp2 = -mp[2] * mp[4] * dd['42']
                    temp1_all += temp1
                    temp2_all += temp2
                    tmp1[4] += temp1
                    tmp2[4] += temp2
                if 'H2' in file2:
                    temp2 = mp[2] * mp[4] * (
                        mm[2] * sc['42'] - mm[2] * r[1]**2 + mm[3] * sc['43'] -
                        mm[3] * sc['32']) * dd['42']**3
                    temp1_all += mu * temp1
                    temp2_all += mu * temp2
                    tmp1[4] += mu * temp1
                    tmp2[4] += mu * temp2
                if 'H3' in file2:
                    temp2 = -1.5*mp[2]*mp[4]*(mm[2]*sc['42'] - mm[2]*r[1]**2 + mm[3]*sc['43'] - mm[3]*sc['32'])**2 * dd['42']**5 +\
                       0.5*mp[2]*mp[4]*((mm[2]*r[1])**2 + (mm[3]*r[2])**2 + 2*mm[2]*mm[3]*sc['32']) * dd['42']**3
                    temp1_all += mu**2 * temp1
                    temp2_all += mu**2 * temp2
                    tmp1[4] += mu**2 * temp1
                    tmp2[4] += mu**2 * temp2
            if '_41_' in file2:
                temp1 = evaluate(series1, evaldict)
                if 'H1' in file2:
                    temp2 = -mp[1] * mp[4] * dd['41']
                    temp1_all += temp1
                    temp2_all += temp2
                    tmp1[5] += temp1
                    tmp2[5] += temp2
                if 'H2' in file2:
                    temp2 = mp[1] * mp[4] * (
                        mm[1] * sc['41'] - mm[1] * r[0]**2 + mm[2] * sc['42'] -
                        mm[2] * sc['21'] + mm[3] * sc['43'] -
                        mm[3] * sc['31']) * dd['41']**3
                    temp1_all += mu * temp1
                    temp2_all += mu * temp2
                    tmp1[5] += mu * temp1
                    tmp2[5] += mu * temp2
                if 'H3' in file2:
                    temp2 = -1.5*mp[1]*mp[4]*(mm[1]*sc['41'] - mm[1]*r[0]**2 + mm[2]*sc['42'] - mm[2]*sc['21'] + mm[3]*sc['43'] - mm[3]*sc['31'])**2 * dd['41']**5 +\
                       0.5*mp[1]*mp[4]*((mm[1]*r[0])**2 + (mm[2]*r[1])**2 + (mm[3]*r[2])**2 + 2*mm[1]*mm[2]*sc['21'] + 2*mm[1]*mm[3]*sc['31'] + 2*mm[2]*mm[3]*sc['32']) * dd['41']**3
                    temp1_all += mu**2 * temp1
                    temp2_all += mu**2 * temp2
                    tmp1[5] += mu**2 * temp1
                    tmp2[5] += mu**2 * temp2
            if 'H1_44_' in file2:
                temp1 = evaluate(series1, evaldict)
                temp2 = mp[2] * (mm[1] * sc['21']) * r[1]**-3 + mp[3] * (
                    mm[1] * sc['31'] + mm[2] * sc['32']) * r[2]**-3 + mp[4] * (
                        mm[1] * sc['41'] + mm[2] * sc['42'] +
                        mm[3] * sc['43']) * r[3]**-3
                temp1_all += temp1
                temp2_all += temp2
                tmp1[6] += temp1
                tmp2[6] += temp2
            if 'H2_44_' in file2:
                temp1 = evaluate(series1, evaldict)
                temp2 = mp[2]*(-1.5*(mm[1]*sc['21'])**2*r[1]**-5 + 0.5*(mm[1]*r[0])**2 * r[1]**-3) + \
                  mp[3]*(-1.5*(mm[1]*sc['31'] + mm[2]*sc['32'])**2 * r[2]**-5 + 0.5*((mm[1]*r[0])**2 + (mm[2]*r[1])**2 + 2*mm[1]*mm[2]*sc['21']) * r[2]**-3) + \
                  mp[4]*(-1.5*(mm[1]*sc['41'] + mm[2]*sc['42'] + mm[3]*sc['43'])**2 * r[3]**-5 + \
                    0.5*((mm[1]*r[0])**2 + (mm[2]*r[1])**2 + (mm[3]*r[2])**2 + 2*mm[1]*mm[2]*sc['21'] + 2*mm[2]*mm[3]*sc['32'] + 2*mm[1]*mm[3]*sc['31']) * r[3]**-3)
                temp1_all += mu * temp1
                temp2_all += mu * temp2
                tmp1[6] += mu * temp1
                tmp2[6] += mu * temp2
            if 'H3_44_' in file2:
                temp1 = evaluate(series1, evaldict)
                temp2 = mp[2]*(2.5*(mm[1]*sc['21'])**3 * r[1]**-7 - 1.5*(mm[1]*sc['21'])*(mm[1]*r[0])**2 * r[1]**-5) + \
                  mp[3]*(2.5*(mm[1]*sc['31'] + mm[2]*sc['32'])**3 * r[2]**-7 - 1.5*(mm[1]*sc['31'] + mm[2]*sc['32'])*((mm[1]*r[0])**2 + (mm[2]*r[1])**2 + 2*mm[1]*mm[2]*sc['21']) * r[2]**-5) + \
                  mp[4]*(2.5*(mm[1]*sc['41'] + mm[2]*sc['42'] + mm[3]*sc['43'])**3 * r[3]**-7 - \
                      1.5*(mm[1]*sc['41'] + mm[2]*sc['42'] + mm[3]*sc['43'])* \
                      ((mm[1]*r[0])**2 + (mm[2]*r[1])**2 + (mm[3]*r[2])**2 + 2*mm[1]*mm[2]*sc['21'] + 2*mm[2]*mm[3]*sc['32'] + 2*mm[1]*mm[3]*sc['31']) * r[3]**-5)
                temp1_all += mu**2 * temp1
                temp2_all += mu**2 * temp2
                tmp1[6] += mu**2 * temp1
                tmp2[6] += mu**2 * temp2
            if isPrint:
                if file2[:2] != 'H0':
                    print '%.12e' % temp1, '%.12e' % temp2, '%.1e' % fabs(
                        (temp1 - temp2) / temp2), length1
                else:
                    print '%.12e' % temp1, '%.12e' % temp2, '%.1e' % 0, length1
    print '\n'
    for i in range(7):
        if isPrint:
            print i + 1, '%.12e' % tmp1[i], '%.12e' % tmp2[i], '%.1e' % fabs(
                (tmp1[i] - tmp2[i]) / tmp2[i])
    h0_1 = temp1_h0 + gmass[0] * mu * temp1_all
    h0_2 = temp2_h0 + gmass[0] * mu * temp2_all
    prec = fabs((h0_2 - h0_1) / h0_2)
    if isPrint:
        print '%.12e' % temp1_all, '%.12e' % temp2_all, '%.1e' % fabs(
            (temp1_all - temp2_all) / temp2_all), length1_all
    print '%.12e' % h0_1, '%.12e' % h0_2, '%.1e' % prec, length1_all + 4
    return h0_1, h0_2, prec
Beispiel #3
0
def check_base(elmass, num=0, p=1, q=2, c_max=25, deg=1):
    """
	Checking accuracy of base series.
	"""
    from math import fabs
    from mpmath import mpf
    from pyranha.math import evaluate
    from eps.tools import kepler2cart, kepler2poincare, jacobiAMass
    elements, gmass, mu = elmass
    # -------- masses --------
    mp = [1. / mu] + [gmass[i] / gmass[0] / mu for i in range(len(gmass))][1:]
    sp = [1. + mu * sum(mp[1:i + 1]) for i in range(len(gmass))]
    gmj, mpj, km = jacobiAMass(gmass, mu)
    # -------- coordinates --------
    rlen1 = range(len(elements))
    x, y, z = [0. for i in rlen1], [0. for i in rlen1], [0. for i in rlen1]
    for i in rlen1:
        x[i], y[i], z[i] = kepler2cart(elements[i], km[i])[:3]
    r = [(x[i]**2 + y[i]**2 + z[i]**2)**0.5 for i in rlen1]
    PE = [kepler2poincare(elements[i], km[i]) for i in rlen1]
    # pairs 21, 32, 43, 31, 42, 41:
    rr = {
        '21': r[0] / r[1],
        '32': r[1] / r[2],
        '43': r[2] / r[3],
        '31': r[0] / r[2],
        '42': r[1] / r[3],
        '41': r[0] / r[3]
    }
    cs = {
        '21': (x[0] * x[1] + y[0] * y[1] + z[0] * z[1]) / r[0] / r[1],
        '32': (x[1] * x[2] + y[1] * y[2] + z[1] * z[2]) / r[1] / r[2],
        '43': (x[2] * x[3] + y[2] * y[3] + z[2] * z[3]) / r[2] / r[3],
        '31': (x[0] * x[2] + y[0] * y[2] + z[0] * z[2]) / r[0] / r[2],
        '42': (x[1] * x[3] + y[1] * y[3] + z[1] * z[3]) / r[1] / r[3],
        '41': (x[0] * x[3] + y[0] * y[3] + z[0] * z[3]) / r[0] / r[3]
    }
    dd = {
        '21': ((x[1] - x[0])**2 + (y[1] - y[0])**2 + (z[1] - z[0])**2)**-0.5,
        '32': ((x[2] - x[1])**2 + (y[2] - y[1])**2 + (z[2] - z[1])**2)**-0.5,
        '43': ((x[3] - x[2])**2 + (y[3] - y[2])**2 + (z[3] - z[2])**2)**-0.5,
        '31': ((x[2] - x[0])**2 + (y[2] - y[0])**2 + (z[2] - z[0])**2)**-0.5,
        '42': ((x[3] - x[1])**2 + (y[3] - y[1])**2 + (z[3] - z[1])**2)**-0.5,
        '41': ((x[3] - x[0])**2 + (y[3] - y[0])**2 + (z[3] - z[0])**2)**-0.5
    }
    # -------- dictionaries --------
    evaldict = {'K0': mpf(gmass[0]), 'm1': mpf(mp[1]), 'm2': mpf(mp[2]), 'm3': mpf(mp[3]), 'm4': mpf(mp[4]), 's1': mpf(sp[1]), 's2': mpf(sp[2]), 's3': mpf(sp[3]), 's4': mpf(sp[4]),\
       'K1': mpf(gmj[0]**0.5), 'M1': mpf(mpj[0]), 'L1': mpf(PE[0][0]), 'x1': mpf(PE[0][1]), 'y1': mpf(PE[0][2]), 'u1': mpf(PE[0][3]), 'v1': mpf(PE[0][4]), 'q1': mpf(PE[0][5]),\
       'K2': mpf(gmj[1]**0.5), 'M2': mpf(mpj[1]), 'L2': mpf(PE[1][0]), 'x2': mpf(PE[1][1]), 'y2': mpf(PE[1][2]), 'u2': mpf(PE[1][3]), 'v2': mpf(PE[1][4]), 'q2': mpf(PE[1][5]),\
       'K3': mpf(gmj[2]**0.5), 'M3': mpf(mpj[2]), 'L3': mpf(PE[2][0]), 'x3': mpf(PE[2][1]), 'y3': mpf(PE[2][2]), 'u3': mpf(PE[2][3]), 'v3': mpf(PE[2][4]), 'q3': mpf(PE[2][5]),\
       'K4': mpf(gmj[3]**0.5), 'M4': mpf(mpj[3]), 'L4': mpf(PE[3][0]), 'x4': mpf(PE[3][1]), 'y4': mpf(PE[3][2]), 'u4': mpf(PE[3][3]), 'v4': mpf(PE[3][4]), 'q4': mpf(PE[3][5])}
    # -------- evaluation x, y, z --------
    if num in [0, 1]:
        for n in range(1, 17):
            start = time.time()
            coord_s = xyz(p, n)
            coord_e = [x[p - 1], y[p - 1], z[p - 1]]
            accuracy = [0, 0, 0]
            sum_items = [0, 0, 0]
            finish = time.time() - start
            for i in range(len(coord_s)):
                for item in coord_s[i].list:
                    for jtem in item[0].list:
                        sum_items[i] += len(jtem[0].list)
                accuracy[i] = fabs(
                    (coord_e[i] - evaluate(coord_s[i], evaldict)) / coord_e[i])
            print 'n =', str(n).rjust(2, ' '),  '|x  ', ('%.2f'%finish).rjust(5, ' '), str(sum_items[0]).rjust(5, ' '), '%.1e'%accuracy[0], ' ',\
                     '|y  ', ('%.2f'%finish).rjust(5, ' '), str(sum_items[1]).rjust(5, ' '), '%.1e'%accuracy[1], ' ',\
                     '|z  ', ('%.2f'%finish).rjust(5, ' '), str(sum_items[2]).rjust(5, ' '), '%.1e'%accuracy[2]
    # -------- evaluation r, 1/r', r/r' --------
    if num in [0, 2]:
        for n in range(1, 17):
            temp, finish, accuracy = [], [], [0, 0, 0]
            start = time.time()
            temp.append(rrr(p, n, deg))
            finish.append(time.time() - start)
            start = time.time()
            temp.append(one_r(q, n, deg))
            finish.append(time.time() - start)
            pt.set_auto_truncate_degree(F(n), [
                'x' + str(p), 'y' + str(p), 'u' + str(p), 'v' + str(p),
                'x' + str(q), 'y' + str(q), 'u' + str(q), 'v' + str(q)
            ])
            start = time.time()
            temp.append(rrr(p, n, deg) * one_r(q, n, deg))
            finish.append(time.time() - start)
            pt.unset_auto_truncate_degree()
            sum_items = [0, 0, 0]
            for i in range(3):
                for item in temp[i].list:
                    for jtem in item[0].list:
                        sum_items[i] += len(jtem[0].list)
            accuracy[0] = fabs(
                (r[p - 1]**deg - evaluate(temp[0], evaldict)) / r[p - 1]**deg)
            accuracy[1] = fabs((r[q - 1]**-deg - evaluate(temp[1], evaldict)) /
                               r[q - 1]**-deg)
            accuracy[2] = fabs(
                ((rr[str(q) + str(p)])**deg - evaluate(temp[2], evaldict)) /
                rr[str(q) + str(p)]**deg)
            print 'n =', str(n).rjust(2, ' '),  '|r  ', ('%.2f'%finish[0]).rjust(5, ' '), str(sum_items[0]).rjust(5, ' '), '%.1e'%accuracy[0], ' ',\
                     '|1/r', ('%.2f'%finish[1]).rjust(5, ' '), str(sum_items[1]).rjust(5, ' '), '%.1e'%accuracy[1], ' ',\
                     '|r/r', ('%.2f'%finish[2]).rjust(5, ' '), str(sum_items[2]).rjust(5, ' '), '%.1e'%accuracy[2]
    # -------- evaluation cos --------
    if num in [0, 3]:
        for n in range(1, 17):
            start = time.time()
            temp = cosine(p, q, n, deg)
            finish = time.time() - start
            sum_items = 0
            for item in temp.list:
                for jtem in item[0].list:
                    sum_items += len(jtem[0].list)
            accuracy = fabs(
                (cs[str(q) + str(p)]**deg - evaluate(temp, evaldict)) /
                cs[str(q) + str(p)]**deg)
            print 'n =', str(n).rjust(
                2, ' '), '|cos', '%.2f' % finish, str(sum_items).rjust(
                    8, ' '), '%.1e' % accuracy
    # -------- evaluation 1/d --------
    if num in [0, 4]:
        for i in range(1, 17):
            start = time.time()
            temp = one_delta(p, q, i, c_max, deg, isPrint=False)
            finish = time.time() - start
            sum_items = 0
            for item in temp.list:
                for jtem in item[0].list:
                    sum_items += len(jtem[0].list)
            evaluated = evaluate(temp, evaldict)
            accuracy = fabs((dd[str(q) + str(p)]**deg - evaluated) /
                            dd[str(q) + str(p)]**deg)
            print 'n =', str(n).rjust(
                2, ' '), '|1/d', '%.2f' % finish, str(sum_items).rjust(
                    8, ' '), '%.16e' % dd[str(q) + str(
                        p)]**deg, '%.16e' % evulated, '%.1e' % accuracy
Beispiel #4
0
def evl_s(elmass=[[], [], 0],
          num_pl=4,
          order=2,
          max_n=0,
          func='eqn',
          prefix='',
          is_q=False):
    """
	Evaluation of the constructed series.
	"""
    from mpmath import mpf
    from pyranha.math import evaluate, truncate_degree
    from eps.tools import jacobiAMass
    # -------- coordinates & masses --------
    gmj, mpj, km = jacobiAMass(elmass[1], elmass[2])
    mp = [1. / elmass[2]] + [
        elmass[1][i] / elmass[1][0] / elmass[2] for i in range(len(elmass[1]))
    ][1:]
    sp = [1. + elmass[2] * sum(mp[1:i + 1]) for i in range(len(elmass[1]))]
    # -------- dictionaries --------
    evaldict = {'K0': mpf(elmass[1][0]),\
       'L1': mpf(elmass[0][0][0]), 'm1': mpf(mp[1]), 's1': mpf(sp[1]), r'\nu_{q1}': mpf(gmj[0]**2*mpj[0]**3*elmass[0][0][0]**-3),\
       'L2': mpf(elmass[0][1][0]), 'm2': mpf(mp[2]), 's2': mpf(sp[2]), r'\nu_{q2}': mpf(gmj[1]**2*mpj[1]**3*elmass[0][1][0]**-3),\
       'L3': mpf(elmass[0][2][0]), 'm3': mpf(mp[3]), 's3': mpf(sp[3]), r'\nu_{q3}': mpf(gmj[2]**2*mpj[2]**3*elmass[0][2][0]**-3),\
       'L4': mpf(elmass[0][3][0]), 'm4': mpf(mp[4]), 's4': mpf(sp[4]), r'\nu_{q4}': mpf(gmj[3]**2*mpj[3]**3*elmass[0][3][0]**-3),\
       'x1': mpf(elmass[0][0][1]), 'y1': mpf(elmass[0][0][2]), 'u1': mpf(elmass[0][0][3]), 'v1': mpf(elmass[0][0][4]), 'q1': mpf(elmass[0][0][5]),\
       'x2': mpf(elmass[0][1][1]), 'y2': mpf(elmass[0][1][2]), 'u2': mpf(elmass[0][1][3]), 'v2': mpf(elmass[0][1][4]), 'q2': mpf(elmass[0][1][5]),\
       'x3': mpf(elmass[0][2][1]), 'y3': mpf(elmass[0][2][2]), 'u3': mpf(elmass[0][2][3]), 'v3': mpf(elmass[0][2][4]), 'q3': mpf(elmass[0][2][5]),\
       'x4': mpf(elmass[0][3][1]), 'y4': mpf(elmass[0][3][2]), 'u4': mpf(elmass[0][3][3]), 'v4': mpf(elmass[0][3][4]), 'q4': mpf(elmass[0][3][5])}
    for i in range(num_pl, 4):
        evaldict.update({'m' + str(i + 1): 0.})
    # -------- loop --------
    return_temp = {}
    for file2 in os.listdir(PREFIX + 'SUM/' + func.upper() + '/' +
                            func.upper() + str(order) + prefix + '/'):
        if func[0] in file2[0]:
            if order == 1:
                c = (elmass[2] * elmass[1][0])
            if order == 2:
                c = elmass[1][0] * elmass[2]**order if file2[3] == str(
                    order) else (elmass[1][0] * elmass[2])**order
            if order == 3:
                c = elmass[1][0]**2 * elmass[2]**order if (
                    ('_t1h2' in file2[:-16]) or
                    ('_t2h1_h2' in file2[:-16])) else (elmass[1][0] *
                                                       elmass[2])**order
            series = epst(0)
            if is_q or (not is_q
                        and file2.split('.')[0].split('_')[-1][0] != 'q'):
                lf(
                    series, PREFIX + 'SUM/' + func.upper() + '/' +
                    func.upper() + str(order) + prefix + '/' + file2,
                    df.boost_portable, cf.bzip2)
                #if max_n > 0:
                #	series = truncate_degree(series, max_n, pq_list[8:])
            if num_pl in [2, 3]:
                for key3 in ['m1', 'm2', 'm3', 'm4']:
                    series = series.subs(key3, F(evaldict[key3]))
                series = series.trim()
            eval_series = c * evaluate(series, evaldict)
            sum_items = 0
            for item in series.list:
                for jtem in item[0].list:
                    sum_items += len(jtem[0].list)
            print file2[:-16] + ':', '%.16e' % eval_series, sum_items
            return_temp.update({file2.split('.')[0]: eval_series})
    return return_temp
Beispiel #5
0
def txt_q(elmass=[[], [], 0],
          PROBLEM='',
          paths=['', '', ''],
          isDouble=False,
          isEval=False):
    '''
	Writing text-files for the integration process (the fast variables).
	'''
    from mpmath import mpf
    from pyranha.math import degree, evaluate, partial, subs
    from eps.tools import jacobiAMass
    # -------- elements & masses --------
    gmj, mpj, km = jacobiAMass(elmass[1], elmass[2])
    mp = [1. / elmass[2]] + [
        elmass[1][i] / elmass[1][0] / elmass[2] for i in range(len(elmass[1]))
    ][1:]
    sp = [1. + elmass[2] * sum(mp[1:i + 1]) for i in range(len(elmass[1]))]
    list_elem = [jtem + item for item in '1234' for jtem in 'xyuv']
    num_pl = len(elmass[0])
    order = 2 if (paths[1] != '' and paths[2] != '') else 1
    max_range = num_pl * 4 if num_pl in [2, 3] else 16
    epst2 = epsd if isDouble else epst
    typef = mpf if isEval else float
    series = [epst(0) for key in range(len(paths))]
    series2 = [0 for key in range(num_pl)]
    # -------- dictionaries & lists --------
    evaldict = {'K0': typef(elmass[1][0])}
    evaldict.update(
        {'m' + str(i + 1): typef(mp[i + 1])
         for i in range(num_pl)})
    evaldict.update(
        {'s' + str(i + 1): typef(sp[i + 1])
         for i in range(num_pl)})
    evaldict.update(
        {'L' + str(i + 1): typef(elmass[0][i][0])
         for i in range(num_pl)})
    const = [
        elmass[1][0] * elmass[2], (elmass[1][0] * elmass[2])**2,
        elmass[1][0] * elmass[2]**2
    ]
    # -------- hamiltonian --------
    for i in range(len(paths[:2 * order - 1])):
        lf(series[i], PREFIX + 'SUM/HAM/' + paths[i] + '.epst.boostp.bz2',
           df.boost_portable, cf.bzip2)
    if num_pl < 4:
        for key in paths[:2 * order - 1]:
            for key2 in ['m' + str(i + 1) for i in range(num_pl, 4)]:
                series[key] = subs(series[key], key2, 0)
            series[key] = series[key].trim()
    # -------- evaluation of motion equations --------
    start = time.time()
    for i in range(num_pl):
        for key in range(len(paths[:2 * order - 1])):
            temp_q = partial(series[key], 'L' + str(i + 1))
            if isEval:
                c, temp = 0, 0
                for item in temp_q.list:
                    for jtem in item[0].list:
                        for ktem in jtem[0].list:
                            c += 1
                            poly = 1
                            for j in range(max_range):
                                poly *= pt(pq_list[num_pl * 2 + j])**degree(
                                    ktem[1],
                                    pq_list[num_pl * 2 + j:num_pl * 2 + 1 + j])
                            temp += float(
                                evaluate((ktem[0] * ktem[1] * poly**-1).trim(),
                                         evaldict)) * poly
                            if c % 100000 == 0: print c
                temp_q = const[key] * temp
                print 'q' + str(i + 1), '->', c, 'terms for', int(time.time() -
                                                                  start), 's'
            else:
                for key2 in evaldict.keys():
                    temp_q = subs(temp_q, key2, evaldict[key2])
                temp_q = const[key] * (temp_q.trim())
                print 'q' + str(i + 1), 'for', int(time.time() - start), 's'
            series2[i] += temp_q
    # -------- write to files equations --------
    PATH_SAVE = PREFIX + 'EVL/TXTS/TXT_' + PROBLEM + '/'
    if not os.path.exists(PATH_SAVE): os.makedirs(PATH_SAVE)
    lines = ['' for key in range(num_pl)]
    length = [0 for key in range(num_pl)]
    for i in range(num_pl):
        for item in series2[i].list:
            if type(item[0]) != float:
                for jtem in item[0].list:
                    for ktem in jtem[0].list:
                        lines[i] += str('%.16e' % ktem[0]).rjust(24, ' ')
                        length[i] += 1
                        for elem in list_elem[:max_range]:
                            deg_elem = degree(ktem[1], [elem])
                            lines[i] += str(deg_elem).rjust(3, ' ')
                        lines[i] += '\n'
            else:
                lines[i] += str('%.16e' % item[0]).rjust(24, ' ')
                length[i] += 1
                for elem in list_elem[:max_range]:
                    deg_elem = degree(item[1], [elem])
                    lines[i] += str(deg_elem).rjust(3, ' ')
                lines[i] += '\n'
        f2 = open(PATH_SAVE + 'q' + str(i + 1) + '.txt', 'w')
        f2.write(str(length[i]) + '\n' + lines[i])
        print 'q' + str(i + 1) + ':', length[i]
Beispiel #6
0
def sub_h(elmass=[[], [], 0],
          PROBLEM='',
          prefix='',
          postfix='',
          part=0,
          isDouble=False,
          isEval=False):
    '''
	The substitution mass parameters, denominators and L-elements (semi-major axes) into the Hamiltonian expansion.
	'''
    from mpmath import mpf
    from pyranha.math import degree, evaluate, subs
    from eps.tools import jacobiAMass
    # -------- elements & masses --------
    gmj, mpj, km = jacobiAMass(elmass[1], elmass[2])
    mp = [1. / elmass[2]] + [
        elmass[1][i] / elmass[1][0] / elmass[2] for i in range(len(elmass[1]))
    ][1:]
    sp = [1. + elmass[2] * sum(mp[1:i + 1]) for i in range(len(elmass[1]))]
    list_elem = [jtem + item for item in '1234' for jtem in 'xyuv']
    num_pl = len(elmass[0])
    max_range = num_pl * 4 if num_pl in [2, 3] else 16
    (epst2, type2) = (epsd, 'd') if isDouble else (epst, 't')
    typef = mpf if isEval else float
    # -------- dictionaries --------
    evaldict = {'K0': typef(elmass[1][0])}
    evaldict.update(
        {'m' + str(i + 1): typef(mp[i + 1])
         for i in range(num_pl)})
    evaldict.update(
        {'s' + str(i + 1): typef(sp[i + 1])
         for i in range(num_pl)})
    evaldict.update(
        {'L' + str(i + 1): typef(elmass[0][i][0])
         for i in range(num_pl)})
    eval_dnu = {
        r'\nu_{q' + str(i + 1) + '}':
        typef(gmj[i]**2 * mpj[i]**3 * elmass[0][i][0]**-3)
        for i in range(num_pl)
    }
    # -------- evaluation --------
    order = [0, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3]
    #index = {0: '', 1: '', 2: '_t1h1_tor', 3: '_2', 4: '_t1h2', 5: '_t2h1_h2', 6: '_t2h1_t1a1', 7: '_t2h1_t1h1', 8: '_t1t1a1', 9: '_t1t1h1', 10: '_3'}
    const = [
        1., elmass[1][0] * elmass[2], (elmass[2] * elmass[1][0])**2,
        elmass[1][0] * elmass[2]**2
    ]
    const += [elmass[1][0]**2 * elmass[2]**3 for i in range(2)] + [
        (elmass[1][0] * elmass[2])**3 for i in range(4)
    ] + [elmass[1][0] * elmass[2]**3]
    # -------- hamiltonian --------
    start = time.time()
    series_sum = 0
    PATH_DIR = PREFIX + 'SUM/HAM/HAM' + str(order[part]) + prefix + '/'
    for file2 in os.listdir(PATH_DIR):
        if postfix == '' or postfix in file2[:-16]:
            series = epst2(0)
            lf(series, PATH_DIR + file2, df.boost_portable, cf.bzip2)
            if num_pl < 4:
                for key in ['m' + str(i + 1) for i in range(num_pl, 4)]:
                    series = subs(series, key, 0)
                series = series.trim()
            if isEval:
                c, stemp = 0, 0
                for item in series.list:
                    for jtem in item[0].list:
                        c += 1
                        stemp += jtem[0] * float(evaluate(jtem[1], eval_dnu))
                if type(stemp) == int:
                    temp = stemp
                else:
                    stemp = stemp.trim()
                    print c, 'denominators'
                    c, temp = 0, 0
                    length = len(stemp)
                    for item in stemp.list:
                        c += 1
                        poly = 1
                        for j in range(max_range):
                            poly *= pd(pq_list[2 * num_pl + j])**degree(
                                item[1],
                                pq_list[2 * num_pl + j:2 * num_pl + 1 + j])
                        temp += float(
                            evaluate((item[0] * item[1] * poly**-1).trim(),
                                     evaldict)) * poly
                        if c % 10000 == 0:
                            print str(c) + '/' + str(length)
                    temp = temp.trim()
            else:
                c, temp = 0, 0
                for item in series.list:
                    for jtem in item[0].list:
                        c += 1
                        temp += jtem[0] * evaluate(jtem[1], eval_dnu)
                if type(temp) != int:
                    for key in evaldict.keys():
                        temp = subs(temp, key, evaldict[key])
                        print key
                    temp = temp.trim()
            series_sum += const[part] * temp
            print str(file2[:-16]) + ':', c, 'terms for', int(time.time() -
                                                              start), 's'
    # -------- write to file --------
    PATH_SAVE = PREFIX + 'EVL/SUMS/SUMS_' + PROBLEM + '/'
    if not os.path.exists(PATH_SAVE): os.makedirs(PATH_SAVE)
    sf(
        series_sum.trim(), PATH_SAVE + '/h' + str(order[part]) +
        prefix.lower() + postfix + '.epsd.boostp.bz2', df.boost_portable,
        cf.bzip2)
Beispiel #7
0
def txt_N(elmass=[[], [], 0], PROBLEM='', order=1, eps=1):
    '''
	Writing text-files for the integration process (the slow variables).
	'''
    from math import fabs
    from pyranha.math import degree, evaluate, partial
    list_elem = [jtem + item for item in '1234' for jtem in 'xyuv']
    num_pl = len(elmass[0])
    max_range = num_pl * 4 if num_pl in [2, 3] else 16
    series = {key: pd(0) for key in ['hm'] + pq_list[2 * num_pl:]}
    postfix = ''
    # -------- loop --------
    for file2 in os.listdir(PREFIX + 'EVL/SUMS/SUMS_' + PROBLEM + '/'):
        if int(file2[1]) <= order:
            temp = pd(0)
            lf(temp, PREFIX + 'EVL/SUMS/SUMS_' + PROBLEM + '/' + file2,
               df.boost_portable, cf.bzip2)
            series['hm'] += temp
    if eps != 1:
        postfix = '_' + str(eps)
        evaldict = {'x1': elmass[0][0][1], 'y1': elmass[0][0][2], 'u1': elmass[0][0][3], 'v1': elmass[0][0][4],\
           'x2': elmass[0][1][1], 'y2': elmass[0][1][2], 'u2': elmass[0][1][3], 'v2': elmass[0][1][4],\
           'x3': elmass[0][2][1], 'y3': elmass[0][2][2], 'u3': elmass[0][2][3], 'v3': elmass[0][2][4],\
           'x4': elmass[0][3][1], 'y4': elmass[0][3][2], 'u4': elmass[0][3][3], 'v4': elmass[0][3][4]}
        temp_sum = 0
        for jtem in series['hm'].list:
            temp = jtem[0] * jtem[1]
            if degree(temp, pq_list[2 * num_pl:]) <= 4:
                temp_sum += temp
                continue
            if fabs(evaluate(temp, evaldict)) > eps:
                temp_sum += temp
        series['hm'] = temp_sum
    # -------- motion equations --------
    for item in list_elem[:max_range]:
        dict_key = {'x': 'y', 'y': 'x', 'u': 'v', 'v': 'u'}
        for key in dict_key.keys():
            if item[0] == key:
                jtem = item.replace(item[0], dict_key[key])
        series[item] = -partial(series['hm'], jtem) if (
            jtem[0] in 'qyv') else partial(series['hm'], jtem)
    # -------- write to files hamiltonian and equations --------
    PATH_SAVE = PREFIX + 'EVL/TXTS/TXT_' + PROBLEM + postfix + '/'
    if not os.path.exists(PATH_SAVE): os.makedirs(PATH_SAVE)
    lines = {key: '' for key in ['hm'] + pq_list[2 * num_pl:]}
    length = {key: 0 for key in ['hm'] + pq_list[2 * num_pl:]}
    for what in ['hm'] + pq_list[2 * num_pl:]:
        for item in series[what].list:
            if type(item[0]) != float:
                for jtem in item[0].list:
                    for ktem in jtem[0].list:
                        lines[what] += str('%.16e' % ktem[0]).rjust(24, ' ')
                        length[what] += 1
                        for elem in list_elem[:max_range]:
                            deg_elem = degree(ktem[1], [elem])
                            lines[what] += str(deg_elem).rjust(3, ' ')
                        lines[what] += '\n'
            else:
                lines[what] += str('%.16e' % item[0]).rjust(24, ' ')
                length[what] += 1
                for elem in list_elem[:max_range]:
                    deg_elem = degree(item[1], [elem])
                    lines[what] += str(deg_elem).rjust(3, ' ')
                lines[what] += '\n'
        f2 = open(PATH_SAVE + what + '.txt', 'w')
        f2.write(str(length[what]) + '\n' + lines[what])
        print what + ':', length[what]
    # -------- write to files masses and elements --------
    f3 = open(PATH_SAVE + 'el.txt', 'w')
    for planet in elmass[0][:num_pl]:
        for elem in planet:
            f3.write(str('%.16e' % elem).rjust(24, ' '))
        f3.write('\n')
    f3.close()
    f4 = open(PATH_SAVE + 'gm.txt', 'w')
    for item in [elmass[2]] + elmass[1][:num_pl + 1]:
        f4.write(str('%.16e' % item).rjust(24, ' ') + '\n')
    f4.close()