コード例 #1
0
ファイル: hdm.py プロジェクト: celesmec/eps
def eqn_s(max_deg, order=2, num_item=1, t_order_max=15, prefix=''):
    """
	"""
    from pyranha.math import partial, truncate_degree
    if order == 1:
        index = ''
    if order > 1:
        pbrackets = ['t1h1'] if order == 2 else [
            't1h2', 't2h1_h2', 't2h1_t1a1', 't2h1_t1h1', 't1t1h1', 't1t1a1'
        ]
        if num_item == 1: index = '_' + str(order)
        if num_item > 1:
            index = '_' + pbrackets[num_item -
                                    2] + '_tor' + str(t_order_max).rjust(
                                        2, '0')
    PATH = PREFIX + 'HDM/SUMS/HAM/HAM' + str(order) + prefix + '/'
    for file2 in os.listdir(PATH):
        if index in file2 and file2[0] == 'h':
            series = epst(0)
            lf(series, PATH + file2, df.boost_portable, cf.bzip2)
            for i in range(8, len(pq_list)):
                motion = -partial(series, pq_list[i]) if (
                    pq_list[i][0] in 'qyv') else partial(series, pq_list[i])
                if max_deg > 0:
                    motion = truncate_degree(motion, max_deg, pq_list[8:])
                PATH_SAVE = PREFIX + 'HDM/SUMS/EQN/EQN' + str(
                    order) + prefix + '/'
                sf(
                    motion.trim(), PATH_SAVE + 'e' + file2[1:-16] + '_' +
                    qp_list[i] + '.epst.boostp.bz2', df.boost_portable,
                    cf.bzip2)
コード例 #2
0
ファイル: hdm.py プロジェクト: celesmec/eps3
def eqn_1(out_post='', pair=''):
    """
	"""
    from pyranha.math import partial
    out_post = out_post if out_post == '' else '_' + out_post
    PATH = PREFIX + 'HDM/HAM1/H1' + out_post + '/'
    for file2 in os.listdir(PATH):
        if pair in file2 or pair == '':
            start = time.time()
            series = epst(0)
            lf(series, PATH + file2, df.boost_portable, cf.bzip2)
            for i in range(len(pq_list)):
                motion = -partial(series, pq_list[i]) if (
                    pq_list[i][0] in 'qyv') else partial(series, pq_list[i])
                motion = motion.trim()
                if motion != epst(0):
                    PATH_SAVE = PREFIX + 'HDM/EQN1/H1' + out_post + '/' + qp_list[
                        i] + '/'
                    if not os.path.exists(PATH_SAVE): os.makedirs(PATH_SAVE)
                    sf(
                        motion, PATH_SAVE + 'e' + file2[1:-16] + '_' +
                        pq_list[i] + '.epst.boostp.bz2', df.boost_portable,
                        cf.bzip2)
                print file2[:-16], qp_list[i], sum([
                    len(item.list)
                    for item in [jtem[0].list[0][0] for jtem in motion.list]
                ]), str('%.1f' % (time.time() - start)).rjust(4, ' '), 's'
コード例 #3
0
ファイル: hdm.py プロジェクト: celesmec/eps
def chn_N(N, num_item=1, t_order_max=15, isDouble=False):
    """
	"""
    from pyranha.math import partial
    if N == 1:
        PATH_INT = [
            PREFIX + 'HDM/INT' + str(i + 1) + '/H' + str(i + 1) + '/'
            for i in range(3)
        ]
    else:
        BRACKETS = ['T1H1', 'T1A1'] if N == 2 else [
            'T1H2', 'T1A2', 'T2H1_H2', 'T2H1_T1A1', 'T2H1_T1H1', 'T2A1_H2',
            'T2A1_T1A1', 'T2A1_T1H1', 'T1T1H1', 'T1T1A1'
        ]
        PATH_INT = PREFIX + 'HDM/INT' + str(N) + '/' + BRACKETS[
            num_item - 1] + '_TOR' + str(t_order_max).rjust(2, '0')
    (type2, epst2) = ('d', epsd) if isDouble else ('t', epst)
    for j in range(len(PATHS_INT)):
        list_dir = os.listdir(PATHS_INT[j]) if N > 1 else ['']
        for subdir in list_dir:
            for file2 in os.listdir(PATHS_INT[j] + subdir + '/'):
                start = time.time()
                order = int(file2[1])
                series = epst2(0)
                lf(series, PATHS_INT[j] + subdir + '/' + file2,
                   df.boost_portable, cf.bzip2)
                for i in range(len(pq_list)):
                    if i in range(4):
                        s_prev = epst2('s' + str(i)) if i != 0 else 1
                        part_diff_nu = -3 * epst2('K0')**2 * (
                            epst2('m' + str(i + 1))**3 * s_prev *
                            epst2('s' + str(i + 1))**
                            -1) * epst2('L' + str(i + 1))**-4
                        epst2.register_custom_derivative(
                            pq_list[i], lambda temp: temp.partial(pq_list[i]) +
                            temp.partial(r'\nu_{' + qp_list[i] + r'}'
                                         ) * part_diff_nu)
                        change = partial(series, pq_list[i])
                        epst2.unregister_all_custom_derivatives()
                    else:
                        change = -partial(series, pq_list[i]) if (
                            pq_list[i][0] in 'qyv') else partial(
                                series, pq_list[i])
                    if change != epst2(0):
                        PATH_SAVE = PREFIX + 'HDM/CHN' + str(
                            order) + '/' + INT_DIRS[j] + '/' + qp_list[
                                i] + '/' + subdir + '/'
                        if not os.path.exists(PATH_SAVE):
                            os.makedirs(PATH_SAVE)
                        sf(
                            change.trim(), PATH_SAVE + 'c' + file2[1:-16] +
                            '_' + pq_list[i] + '.eps' + type2 + '.boostp.bz2',
                            df.boost_portable, cf.bzip2)
                print PATHS_INT[j] + subdir + '/' + file2[:-16], str(
                    '%.1f' % (time.time() - start)).rjust(4, ' '), 's'
コード例 #4
0
ファイル: hdm.py プロジェクト: celesmec/eps3
def d_phi1(out_post='', pair=''):
    """
	"""
    from pyranha.math import partial
    out_post = out_post if out_post == '' else '_' + out_post
    PATH_PHI = PREFIX + 'HDM/PHI1/H1' + out_post + '/'
    for file2 in os.listdir(PATH_PHI):
        if pair in file2 or pair == '':
            start = time.time()
            series = epst(0)
            lf(series, PATH_PHI + file2, df.boost_portable, cf.bzip2)
            for i in range(len(pq_list)):
                diff = partial(series, pq_list[i])
                diff = diff.trim()
                if diff != epst(0):
                    PATH_SAVE = PREFIX + 'HDM/D_PHI1/H1' + out_post + '/' + pq_list[
                        i] + '/'
                    if not os.path.exists(PATH_SAVE): os.makedirs(PATH_SAVE)
                    sf(
                        diff, PATH_SAVE + file2[:-16] + '_' + pq_list[i] +
                        '.epst.boostp.bz2', df.boost_portable, cf.bzip2)
                print file2[:-16], pq_list[i], sum([
                    len(item.list)
                    for item in [jtem[0].list[0][0] for jtem in diff.list]
                ]), str('%.1f' % (time.time() - start)).rjust(4, ' '), 's'
コード例 #5
0
ファイル: hdm.py プロジェクト: celesmec/eps
def d_phi1():
    """
	"""
    from pyranha.math import partial
    PATHS_PHI = [
        PREFIX + 'HDM/PHI' + str(i + 1) + '/H' + str(i + 1) + '/'
        for i in range(3)
    ]
    for PATH_PHI in PATHS_PHI:
        if os.path.isdir(PATH_PHI):
            for file2 in os.listdir(PATH_PHI):
                start = time.time()
                order = int(file2[1])
                series = epst(0)
                lf(series, PATH_PHI + file2, df.boost_portable, cf.bzip2)
                for i in range(len(pq_list)):
                    diff = partial(series, pq_list[i])
                    if diff != epst(0):
                        PATH_SAVE = PREFIX + 'HDM/DIF1/PHI' + str(
                            order) + '/H' + str(order) + '/' + pq_list[i] + '/'
                        if not os.path.exists(PATH_SAVE):
                            os.makedirs(PATH_SAVE)
                        sf(
                            diff.trim(), PATH_SAVE + file2[:-16] + '_' +
                            pq_list[i] + '.epst.boostp.bz2', df.boost_portable,
                            cf.bzip2)
                print '/PHI' + str(order) + '/H' + str(
                    order) + '/' + file2[:-16], str(
                        '%.1f' % (time.time() - start)).rjust(4, ' '), 's'
コード例 #6
0
ファイル: hdm.py プロジェクト: celesmec/eps3
def chn_1(out_post='', pair=''):
    """
	"""
    from pyranha.math import partial
    out_post = out_post if out_post == '' else '_' + out_post
    PATH = PREFIX + 'HDM/INT1/H1' + out_post + '/'
    for file2 in os.listdir(PATH):
        if pair in file2 or pair == '':
            start = time.time()
            series = epst(0)
            lf(series, PATH + file2, df.boost_portable, cf.bzip2)
            for i in range(len(pq_list)):
                if i in range(4):
                    s_prev = epst('s' + str(i)) if i != 0 else 1
                    part_diff_nu = -3 * epst('K0')**2 * (
                        epst('m' + str(i + 1))**3 * s_prev *
                        epst('s' + str(i + 1))**-1) * epst('L' +
                                                           str(i + 1))**-4
                    epst.register_custom_derivative(
                        pq_list[i],
                        lambda temp: temp.partial(pq_list[i]) + temp.partial(
                            r'\nu_{' + qp_list[i] + r'}') * part_diff_nu)
                    change = partial(series, pq_list[i])
                    epst.unregister_all_custom_derivatives()
                else:
                    change = -partial(series, pq_list[i]) if (
                        pq_list[i][0] in 'qyv') else partial(
                            series, pq_list[i])
                change = change.trim()
                if change != epst(0):
                    PATH_SAVE = PREFIX + 'HDM/CHN1/H1' + out_post + '/' + qp_list[
                        i] + '/'
                    if not os.path.exists(PATH_SAVE): os.makedirs(PATH_SAVE)
                    sf(
                        change, PATH_SAVE + 'c' + file2[1:-16] + '_' +
                        pq_list[i] + '.epst.boostp.bz2', df.boost_portable,
                        cf.bzip2)
                print file2[:-16], qp_list[i], sum([
                    len(item.list)
                    for item in [jtem[0].list[0][0] for jtem in change.list]
                ]), str('%.1f' % (time.time() - start)).rjust(4, ' '), 's'
コード例 #7
0
ファイル: hdm.py プロジェクト: celesmec/eps3
def eqn_s(max_deg, order=2, out_save=''):
    """
	"""
    from pyranha.math import partial, truncate_degree
    out_save = out_save if out_save == '' else '_' + out_save
    PATH = PREFIX + 'SUM/HAM/HAM' + str(order) + out_save + '/'
    for file2 in os.listdir(PATH):
        if index in file2 and file2[0] == 'h':
            series = epst(0)
            lf(series, PATH + file2, df.boost_portable, cf.bzip2)
            for i in range(8, len(pq_list)):
                motion = -partial(series, pq_list[i]) if (
                    pq_list[i][0] in 'qyv') else partial(series, pq_list[i])
                if max_deg > 0:
                    motion = truncate_degree(motion, max_deg, pq_list[8:])
                PATH_SAVE = PREFIX + 'SUM/EQN/EQN' + str(
                    order) + out_save + '/'
                if not os.path.exists(PATH_SAVE): os.makedirs(PATH_SAVE)
                sf(
                    motion.trim(), PATH_SAVE + 'e' + file2[1:-16] + '_' +
                    qp_list[i] + '.epst.boostp.bz2', df.boost_portable,
                    cf.bzip2)
コード例 #8
0
	def __init__(self,params = __default_params):
		from numpy import dot
		from mpmath import mpf
		from fractions import Fraction as Frac
		import sympy
		from IPython.parallel import Client
		# Set up constants.
		self.__eps_val = (1./mpf(299792458.))**2
		self.__GG_val = mpf(6.673E-11)
		# Various variables.
		Gt,I1,GG,m2,L,r,a,v2,Gtxy,ht,Ht,Gxy,h,H,J2,g,G,f,e,E,eps,hs,Hts,Gtxys = [pt(name) for name in ['\\tilde{G}','\\mathcal{I}_1',\
			'\\mathcal{G}','m_2','L','r','a','v2','\\tilde{G}_{xy}','\\tilde{h}','\\tilde{H}','G_{xy}','h','H','J_2','g','G','f','e','E',\
			'\\varepsilon','h_\\ast','\\tilde{H}_\\ast','\\tilde{G}_{xy\\ast}']]
		# The unperturbed Hamiltonian.
		H0 = Gt**2 * I1 / 2 - GG**2 * m2**2 * L**-2 / 2
		self.__HH0 = H0
		# Pieces of the perturbed Hamiltonian.
		Gt_vec = [Gtxy * math.sin(ht),-Gtxy * math.cos(ht),Ht]
		J2_vec = [0,0,J2]
		r_vec = dot(celmec.orbitalR([math.cos(g),math.sin(g),H*G**-1,Gxy*G**-1,math.cos(h),math.sin(h)]),[r*math.cos(f),r*math.sin(f),0])
		r_cross_v = [Gxy * math.sin(h),-Gxy * math.cos(h),H]
		H1 = -Frac(1,8) * v2 ** 2 - Frac(3,2) * v2 * GG * m2 * r ** -1 + Frac(1,2) * GG**2 * m2**2 * r**-2 +\
			Frac(3,2) * GG * m2 * r**-3 * dot(Gt_vec,r_cross_v) + 2 * GG * r**-3 * dot(J2_vec,r_cross_v) +\
			GG * r**-3 * (3 * dot(Gt_vec,r_vec) * dot(J2_vec,r_vec) * r**-2 - dot(Gt_vec,J2_vec))
		H1 = H1.subs('v2',GG * m2 * (2 * r**-1 - a ** -1)).subs('a',L ** 2 * (GG * m2)**-1)
		# Verify formula in the paper.
		assert(-Frac(1,8)*GG**4*m2**4*L**-4+r**-1*2*GG**3*m2**3*L**-2-r**-2*3*GG**2*m2**2+GG*r**-3*(\
			2*J2*H+3*J2*Gxy**2*Ht*(G**-2)/2+3*m2*Ht*H/2-J2*Ht+(3*m2/2*Gtxy*Gxy-3*J2/2*H*Gxy*Gtxy*G**-2)*math.cos(ht-h)+\
			3*J2*(-Frac(1,2)*Gxy**2*Ht*G**-2*math.cos(2*f+2*g)-Frac(1,4)*Gxy*Gtxy*G**-1*(1-H*G**-1)*math.cos(2*f+2*g+ht-h)+\
			Frac(1,4)*Gxy*Gtxy*G**-1*(1+H*G**-1)*math.cos(2*f+2*g-ht+h))) == H1)
		# Split the Hamiltonian in parts.
		A0 = H1.transform(lambda t: (t[0].filter(lambda t: t[1].degree(['r']) == 0),t[1])).filter(lambda t: t[1] == pt(1)).subs('r',pt(1))
		A1 = H1.transform(lambda t: (t[0].filter(lambda t: t[1].degree(['r']) == -1),t[1])).filter(lambda t: t[1] == pt(1)).subs('r',pt(1))
		A2 = H1.transform(lambda t: (t[0].filter(lambda t: t[1].degree(['r']) == -2),t[1])).filter(lambda t: t[1] == pt(1)).subs('r',pt(1))
		A3a = H1.transform(lambda t: (t[0].filter(lambda t: t[1].degree(['r']) == -3),t[1])).filter(lambda t: t[1] == pt(1)).subs('r',pt(1))
		A3b = H1.filter(lambda t: t[1] == math.cos(ht - h)).transform(lambda t: (t[0],pt(1))).subs('r',pt(1))
		B0 = H1.filter(lambda t: t[1] == math.cos(2*f + 2*g)).transform(lambda t: (t[0],pt(1))).subs('r',pt(1))
		B1 = H1.filter(lambda t: t[1] == math.cos(2*f + 2*g + ht - h)).transform(lambda t: (t[0],pt(1))).subs('r',pt(1))
		B2 = H1.filter(lambda t: t[1] == math.cos(2*f + 2*g - ht + h)).transform(lambda t: (t[0],pt(1))).subs('r',pt(1))
		# Make sure we got them right.
		assert(A0 + A1 * r**-1 + A2 * r**-2 + r**-3 * (A3a + A3b * math.cos(ht - h)) + r**-3 * (B0 * math.cos(2*f + 2*g) +\
			B1 * math.cos(2*f + 2*g + ht - h) + B2 * math.cos(2*f + 2*g - ht + h)) == H1)
		# This is the integrand in f (without the part that is integrated in E).
		f_int = A2 * r**-2 + r**-3 * (A3a + A3b * math.cos(ht - h)) + r**-3 * (B0 * math.cos(2*f + 2*g) + B1 * math.cos(2*f + 2*g + ht - h) + B2 * math.cos(2*f + 2*g - ht + h))
		# Change the integration variable to f (with the constant parts already taken out of the integral).
		f_int *= r**2
		# Substitute the definition of 1/r in terms of f.
		f_int = f_int.subs('r',pt('rm1')**-1).subs('rm1',GG*m2*G**-2*(1+e*math.cos(f)))
		# This is the integrand in E.
		E_int = A1 * r**-1
		# Change the integration variable to f.
		E_int *= r**2
		# Change the integration variable to E.
		E_int *= L*G*r**-1*GG**-1*m2**-1
		assert(E_int == A1*G*L*GG**-1*m2**-1)
		# K1.
		K1 = GG**2 * m2**2 * G**-1 * L**-3 * (f_int + E_int).filter(lambda t: t[1].t_degree(['f']) == 0)
		# K.
		K = K1 + A0
		# The generator.
		chi = G**-1 * (E_int.integrate('E') + f_int.integrate('f')) - L**3 * GG**-2 * m2**-2 * K1.integrate('l')
		# Verifiy that chi satisfies the homological equation, yielding K.
		assert((math.pbracket(H0,chi,['L','G','H','\\tilde{G}','\\tilde{H}'],['l','g','h','\\tilde{g}','\\tilde{h}']) + H1)\
			.subs('r',pt('rm1')**-1).subs('rm1',GG*m2*G**-2*(1+e*math.cos(f))) == K)
		# This is the complete Hamiltonian, with the two coordinates compressed into a single one.
		HHp = H0 + eps * K.subs('h',ht+hs).subs('\\tilde{H}',Hts-H).subs('\\tilde{G}_{xy}',Gtxys)
		# Record it as a member.
		self.__HHp = HHp
		# F0 and F1.
		F0 = HHp.filter(lambda t: t[1].t_degree(['h_\\ast']) == 0).transform(lambda t: (t[0].filter(lambda t: t[1].degree(['\\varepsilon']) == 1),t[1])).subs('\\varepsilon',pt(1))
		F1 = HHp.filter(lambda t: t[1].t_degree(['h_\\ast']) == 1).transform(lambda t: (t[0].filter(lambda t: t[1].degree(['\\varepsilon']) == 1),t[1])).subs('\\varepsilon',pt(1)).subs('h_\\ast',pt(0))
		assert(H0 + eps * F0 + eps * F1 * math.cos(pt('h_\\ast')) == H0 + eps * K.subs('h',ht+hs).subs('\\tilde{H}',Hts-H).subs('\\tilde{G}_{xy}',Gtxys))
		self.__F0 = F0
		self.__F1 = F1
		# Quartic polynomial.
		f4H = (eps**2 * F1 ** 2 - (pt('\\mathcal{H}^\\prime') - H0 - eps * F0)**2)\
			.ipow_subs('G_{xy}',2,G**2-H**2)\
			.ipow_subs('\\tilde{G}_{xy\\ast}',2,Gt**2-(Hts-H)**2)
		a4 = f4H.transform(lambda t: (t[0].filter(lambda t: t[1].degree(['H']) == 0),t[1]))
		a3 = f4H.transform(lambda t: (t[0].filter(lambda t: t[1].degree(['H']) == 1),t[1])).subs('H',pt(1)) / 4
		a2 = f4H.transform(lambda t: (t[0].filter(lambda t: t[1].degree(['H']) == 2),t[1])).subs('H',pt(1)) / 6
		a1 = f4H.transform(lambda t: (t[0].filter(lambda t: t[1].degree(['H']) == 3),t[1])).subs('H',pt(1)) / 4
		a0 = f4H.transform(lambda t: (t[0].filter(lambda t: t[1].degree(['H']) == 4),t[1])).subs('H',pt(1))
		# NOTE: these are not the polynomial coefficient strictly speaking, they are normalised by 4, 6 and 4
		# as shown above and in the assert below.
		self.__f4_cf = (a0,a1,a2,a3,a4)
		# Check we got them right.
		assert(a4+4*a3*H+6*a2*H**2+4*a1*H**3+a0*H**4 == f4H)
		# Store the coefficients - from high degree to low.
		self.__f4_coeffs = [t[0] * t[1].trim() for t in zip([1,4,6,4,1],self.__f4_cf)]
		# Derivatives of the quartic poly.
		f4Hp = math.partial(f4H,'H')
		f4Hpp = math.partial(f4Hp,'H')
		f4Hppp = math.partial(f4Hpp,'H')
		f4Hpppp = math.partial(f4Hppp,'H')
		# Check the derivatives for consistency.
		assert(f4Hp == 4*a3 + 12*a2*H + 12*a1*H**2 + 4*a0*H**3)
		assert(f4Hpp == 12*a2 + 24*a1*H + 12*a0*H**2)
		assert(f4Hppp == 24*a1 + 24*a0*H)
		assert(f4Hpppp == 24*a0)
		self.__f4 = [f4H, f4Hp, f4Hpp, f4Hppp, f4Hpppp]
		# Invariants for wp.
		g2 = a0*a4 - 4*a1*a3 + 3*a2**2
		g3 = a0*a2*a4 + 2*a1*a2*a3 - (a2**3) - (a0*a3**2) - (a1**2*a4)
		self.__g2 = g2
		self.__g3 = g3
		# Solve the angles.
		# Extract cosine of h_s.
		#chs = sympy.solve((spin_gr_theory.__to_sympy(self.HHp.trim())-sympy.Symbol('\\mathcal{H}^\\prime')).replace(sympy.cos(sympy.Symbol('h_\\ast')),sympy.Symbol('chs')),sympy.Symbol('chs'))[0]
		#ipy_view = Client().load_balanced_view()
		#g_sol = ipy_view.apply_async(spin_gr_theory.__solve_g,chs,spin_gr_theory.__to_sympy(math.partial(self.HHp.trim(),'G')))
		#hs_sol = ipy_view.apply_async(spin_gr_theory.__solve_hs,chs,spin_gr_theory.__to_sympy(math.partial(self.HHp.trim(),'H')))
		#ht_sol = ipy_view.apply_async(spin_gr_theory.__solve_ht,chs,spin_gr_theory.__to_sympy(math.partial(self.HHp.trim(),'\\tilde{H}_\\ast')))
		#self.__g_sol = g_sol.get()
		#self.__hs_sol = hs_sol.get()
		#self.__ht_sol = ht_sol.get()
		import pickle
		self.__g_sol = pickle.load(open('g_sol.pickle','rb'))
		self.__hs_sol = pickle.load(open('hs_sol.pickle','rb'))
		self.__ht_sol = pickle.load(open('ht_sol.pickle','rb'))
		# Set the parameters of the theory.
		self.__set_params(params)
		# Some sanity checks.
		HHp,G,L,H,GG,eps,m2,Hts,Gt,J2,hs,Gxy,Gtxys = [sympy.Symbol(s) for s in ['\\mathcal{H}^\\prime','G','L','H','\\mathcal{G}',\
			'\\varepsilon','m_2','\\tilde{H}_\\ast','\\tilde{G}','J_2','h_\\ast','G_{xy}','\\tilde{G}_{xy\\ast}']]
		# Phi_g^4 going to zero in the equilibrium point.
		assert(self.g_sol[0][3][1].subs(HHp,spin_gr_theory.__to_sympy(self.HHp.ipow_subs('G_{xy}',2,pt('G')**2\
			-pt('H')**2).subs('H',pt('G')**2*pt('m_2')*pt('J_2')**-1))).ratsimp() == 0)
		# Reduction to Einstein precession.
		simpl_HHp_ein = spin_gr_theory.__to_sympy(self.HHp.subs('J_2',0).subs('\\tilde{G}_{xy\\ast}',0).subs('\\tilde{H}_\\ast',pt('H'))\
			.subs('\\tilde{G}',0))
		ein_prec = sum([t[0]*t[1] for t in self.g_sol[0]]).subs('J_2',0).subs(Hts,H).subs(Gt,0)\
			.subs(HHp,simpl_HHp_ein).ratsimp()
		assert(ein_prec == 3 * eps * GG**4 * m2**4/(G**2*L**3))
		# Lense-Thirring precession for g.
		simpl_HHp_lt = spin_gr_theory.__to_sympy(self.HHp.subs('\\tilde{G}_{xy\\ast}',0).subs('\\tilde{H}_\\ast',pt('H'))\
			.subs('\\tilde{G}',0))
		lt_prec = sum([t[0]*t[1] for t in self.g_sol[0]]).subs(Hts,H).subs(Gt,0).subs(HHp,simpl_HHp_lt).ratsimp()
		assert(lt_prec == (eps * ((-6*H*J2*GG**4*m2**3)/(G**4*L**3)+3*GG**4*m2**4/(G**2*L**3))).ratsimp())
		# Geodetic effect on g.
		simpl_HHp_ge = spin_gr_theory.__to_sympy(self.HHp.subs('J_2',0)).subs(sympy.cos(hs),-1).subs(Gxy,sympy.sqrt(G**2-H**2))\
			.subs(Gtxys,sympy.sqrt(Gt**2-(Hts-H)**2)).subs(H,(Hts**2+G**2-Gt**2)/(2*Hts))
		ge_g = sum([t[0]*t[1] for t in self.g_sol[0]]).subs(J2,0).subs(Gxy,sympy.sqrt(G**2-H**2))\
			.subs(Gtxys,sympy.sqrt(Gt**2-(Hts-H)**2)).subs(H,(Hts**2+G**2-Gt**2)/(2*Hts)).subs(HHp,simpl_HHp_ge).ratsimp()
		assert(ge_g == (1 / (4*G**4*L**3) * (15*G**2*GG**4*eps*m2**4+9*GG**4*Gt**2*eps*m2**4-9*GG**4*Hts**2*eps*m2**4)).ratsimp())
		# No precession in h for Einstein case.
		assert((sum([t[0]*t[1] for t in self.hs_sol[0]]) + sum([t[0]*t[1] for t in self.ht_sol[0]])).subs(HHp,simpl_HHp_ein)\
			.subs('J_2',0).subs(Hts,H).ratsimp().subs(Gt,0) == 0)
		# h precession in LT.
		assert((sum([t[0]*t[1] for t in self.hs_sol[0]]) + sum([t[0]*t[1] for t in self.ht_sol[0]])).subs(HHp,simpl_HHp_lt)\
			.subs(Hts,H).ratsimp().subs(Gt,0).ratsimp() == 2*eps*J2*GG**4*m2**3/(G**3*L**3))
		# Geodetic effect for h and ht.
		assert((sum([t[0]*t[1] for t in self.hs_sol[0]]) + sum([t[0]*t[1] for t in self.ht_sol[0]])).subs(HHp,simpl_HHp_ge)\
			.subs(J2,0).subs(H,(Hts**2+G**2-Gt**2)/(2*Hts)).ratsimp() == 3*GG**4*Hts*eps*m2**4/(2*G**3*L**3))
		assert((sum([t[0]*t[1] for t in self.ht_sol[0]])).subs(HHp,simpl_HHp_ge)\
			.subs(J2,0).subs(H,(Hts**2+G**2-Gt**2)/(2*Hts)).ratsimp() == 3*GG**4*Hts*eps*m2**4/(2*G**3*L**3))
コード例 #9
0
ファイル: hdm.py プロジェクト: celesmec/eps3
def pb_t1t1f1(f=0,
              m=4,
              num_br=0,
              num_subr=0,
              t_order_max=20,
              in1_post='',
              in2_post='',
              out_post='',
              isAver=True,
              isDouble=False,
              isPrint=True):
    """
	Poisson brackets {T_1, {T_1, H_1}} and {T_1, {T_1, A_1}}.
	"""
    from pyranha.math import cos, sin, degree, ldegree, t_degree, t_ldegree, t_order, t_lorder, partial, truncate_degree
    in1_post = in1_post if in1_post == '' else '_' + in1_post
    in2_post = in2_post if in2_post == '' else '_' + in2_post
    out_post = out_post if out_post == '' else '_' + out_post
    if f == 0: c = -1. / 6. if isDouble else F(-1, 6)
    if f == 1: c = 1. / 6. if isDouble else F(1, 6)
    TYPE2 = 'A' if f == 0 else 'H'
    PATH_CHN = PREFIX + 'HDM/CHN1/H1' + in1_post + '/'
    PATH_BRA = PREFIX + 'HDM/PHI2/T1' + TYPE2 + '1' + in2_post + '_TOR' + str(
        t_order_max).rjust(2, '0') + '/'
    (one, max_m, type2, pt2,
     epst2) = (1., m, 'd', pd, epsd) if isDouble else (1, F(m), 't', pt, epst)
    for i in range(len(pq_list))[num_bracket:num_bracket + 1]:
        TYPE = 'HAM' if isAver else 'PHI'
        PATH_SAVE = PREFIX + 'HDM/' + TYPE + '3/T1T1' + TYPE2 + '1' + out_post + '_TOR' + str(
            t_order_max).rjust(2,
                               '0') + '/' + pq_list[i] + '_' + qp_list[i] + '/'
        for file1 in os.listdir(PATH_CHN + qp_list[i]):  # diff L,q (chn q,L)
            diff1 = epst(0)
            lf(diff1, PATH_CHN + qp_list[i] + '/' + file1, df.boost_portable,
               cf.bzip2)
            diff1 = truncate_degree(diff1, F(m), pq_list[8:])
            new_diff1 = epst2(0)
            for item1 in diff1.list:
                if t_order(item1[1]) <= t_order_max:
                    new_diff1 += one * (item1[0] * item1[1])
            #new_diff1 = epst(0)
            #lf(new_diff1, PATH_CHN + qp_list[i]+'/'+file1, df.boost_portable, cf.bzip2)
            #new_diff1 = truncate_degree(new_diff1, F(m), pq_list[8:])
            if isPrint:
                print file1[:
                            -16]  #+':', sum([len(item.list) for item in [jtem[0].list[0][0] for jtem in new_diff1.list]]), len(new_diff1.list)
            for subdir in os.listdir(PATH_BRA)[num_subr:num_subr + 1]:
                for file2 in os.listdir(PATH_BRA + subdir + '/'):
                    CHECK_FILE = PATH_SAVE + '/' + TYPE[0].lower(
                    ) + '3_' + file1[3:5] + '_(' + subdir + '_' + file2[
                        3:8] + ').eps' + type2 + '.boostp.bz2'
                    if not os.path.isfile(CHECK_FILE):
                        if '44' in file2[3:8]:
                            num_list = range(1, 5)
                        else:
                            num_list = range(int(file2[4:5]),
                                             int(file2[3:4]) + 1)
                            num_list += range(int(file2[7:8]),
                                              int(file2[6:7]) + 1)
                        if int(pq_list[i][1]) in num_list:
                            start = time.time()
                            diff2 = epst(0)
                            lf(diff2, PATH_BRA + subdir + '/' + file2,
                               df.boost_portable, cf.bzip2)
                            diff2 = truncate_degree(diff2, F(m), pq_list[8:])
                            new_diff2 = epst2(0)
                            for item1 in diff2.list:
                                if t_order(item1[1]) <= t_order_max:
                                    new_diff2 += one * (item1[0] * item1[1])
                            #new_diff2 = epst(0)
                            #lf(new_diff2, PATH_BRA + subdir+'/'+file2, df.boost_portable, cf.bzip2)
                            #new_diff2 = truncate_degree(new_diff2, F(m), pq_list[8:])
                            if i in range(4, 8):
                                s_prev = epst2('s' +
                                               str(i - 4)) if i != 4 else 1
                                part_diff_nu = -3 * epst2('K0')**2 * (
                                    epst2('m' + str(i - 4 + 1))**3 * s_prev *
                                    epst2('s' + str(i - 4 + 1))**
                                    -1) * epst2('L' + str(i - 4 + 1))**-4
                                epst2.register_custom_derivative(
                                    qp_list[i],
                                    lambda temp: temp.partial(qp_list[
                                        i]) + temp.partial(r'\nu_{' + pq_list[
                                            i] + r'}') * part_diff_nu)
                                new_diff2 = partial(new_diff2, qp_list[i])
                                epst2.unregister_all_custom_derivatives()
                            else:
                                new_diff2 = partial(new_diff2, qp_list[i])
                            if isPrint:
                                print subdir, file2[:
                                                    -16]  #+':', sum([len(item.list) for item in [jtem[0].list[0][0] for jtem in new_diff2.list]]), len(new_diff2.list)
                            pt2.set_auto_truncate_degree(max_m, pq_list[8:])
                            if isAver:
                                count = 0
                                new_result = epst2(0)
                                for item in new_diff1.list:
                                    for jtem in new_diff2.list:
                                        trig = item[1] * jtem[1]
                                        for ktem in trig.list:
                                            if ktem[1] == 1:
                                                temp_result = c * (item[0] *
                                                                   jtem[0] *
                                                                   ktem[0])
                                                new_result = new_result + temp_result
                                    print c, item[1]
                                    count += 1
                            else:
                                result = c * new_diff1 * new_diff2
                            pt2.unset_auto_truncate_degree()
                            if not isAver:
                                new_result = epst2(0)
                                for item1 in result.list:
                                    if t_order(item1[1]) <= t_order_max:
                                        new_result += item1[0] * item1[1]
                            if new_result != epst2(0):
                                if not os.path.exists(PATH_SAVE):
                                    os.makedirs(PATH_SAVE)
                                sf(
                                    new_result.trim(), PATH_SAVE + '/' +
                                    TYPE[0].lower() + '3_' + file1[3:5] +
                                    '_(' + subdir + '_' + file2[3:8] +
                                    ').eps' + type2 + '.boostp.bz2',
                                    df.boost_portable, cf.bzip2)
                            print 'bracket:', pq_list[i] + '_' + qp_list[
                                i], file1[:-16], file2[:-16], str(
                                    '%.1f' % (time.time() - start)).rjust(
                                        4, ' '), 's'
コード例 #10
0
ファイル: int.py プロジェクト: celesmec/eps3
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]
コード例 #11
0
ファイル: int.py プロジェクト: celesmec/eps3
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()