Ejemplo n.º 1
0
l1, l2, l3, l4, eta = symbols('lambda[0] lambda[1] lambda[2] lambda[3] eta')
lf0, lf1 = symbols('lambda_f[0] lambda_f[1]')

# Additional parameters for damping term
R0 = symbols('BSSN_ETA_R0')
ep1, ep2 = symbols('BSSN_ETA_POWER[0] BSSN_ETA_POWER[1]')

xi1, xi2, xi3 = symbols('BSSN_XI[0] BSSN_XI[1] BSSN_XI[2] ')

# declare variables
a = dendro.scalar("alpha", "[pp]")
chi = dendro.scalar("chi", "[pp]")
K = dendro.scalar("K", "[pp]")

Gt = dendro.vec3("Gt", "[pp]")
b = dendro.vec3("beta", "[pp]")
B = dendro.vec3("B", "[pp]")

gt = dendro.sym_3x3("gt", "[pp]")
At = dendro.sym_3x3("At", "[pp]")

Gt_rhs = dendro.vec3("Gt_rhs", "[pp]")

# Lie derivative weight
weight = -Rational(2, 3)
weight_Gt = Rational(2, 3)

# specify the functions for computing first and second derivatives

d = dendro.set_first_derivative('grad')  # first argument is direction
Ejemplo n.º 2
0
def bssn_puncture_gauge(eta_damp, isStaged=False, prefix=""):

    if (not isStaged):

        C1 = dendro.get_first_christoffel()
        C2 = dendro.get_second_christoffel()
        C2_spatial = dendro.get_complete_christoffel(chi)
        [R, Rt, Rphi, CalGt] = dendro.compute_ricci(Gt, chi)

        a_rhs = l1 * dendro.lie(b, a) - 2 * a * K

        b_rhs = [(Rational(3, 4) * (lf0 + lf1 * a) * B[i] +
                  l2 * dendro.vec_j_ad_j(b, b[i])) for i in dendro.e_i]

        gt_rhs = dendro.lie(b, gt, weight) - 2 * a * At

        chi_rhs = dendro.lie(b, chi, weight) + Rational(2, 3) * (chi * a * K)

        AikAkj = Matrix([
            sum([
                At[i, k] *
                sum([dendro.inv_metric[k, l] * At[l, j] for l in dendro.e_i])
                for k in dendro.e_i
            ]) for i, j in dendro.e_ij
        ])

        At_rhs = dendro.lie(b, At, weight) + chi * dendro.trace_free(
            a * R - dendro.DiDj(a)) + a * (K * At - 2 * AikAkj.reshape(3, 3))

        K_rhs = dendro.lie(b, K) - dendro.laplacian(
            a, chi) + a * (K * K / 3 + dendro.sqr(At))

        At_UU = dendro.up_up(At)

        Gt_rhs = Matrix([sum(b[j]*ad(j,Gt[i]) for j in dendro.e_i) for i in dendro.e_i]) - \
                Matrix([sum(CalGt[j]*d(j,b[i]) for j in dendro.e_i) for i in dendro.e_i]) + \
                Rational(2,3)*Matrix([ CalGt[i] * sum(d(j,b[j]) for j in dendro.e_i)  for i in dendro.e_i ]) + \
                Matrix([sum([igt[j, k] * d2(j, k, b[i]) + igt[i, j] * d2(j, k, b[k])/3 for j, k in dendro.e_ij]) for i in dendro.e_i]) - \
                Matrix([sum([2*At_UU[i, j]*d(j, a) for j in dendro.e_i]) for i in dendro.e_i]) + \
                Matrix([sum([2*a*dendro.C2[i, j, k]*At_UU[j, k] for j,k in dendro.e_ij]) for i in dendro.e_i]) - \
                Matrix([sum([a*(3/chi*At_UU[i,j]*d(j, chi) + Rational(4,3)*dendro.inv_metric[i, j]*d(j, K)) for j in dendro.e_i]) for i in dendro.e_i])

        Gt_rhs = [item for sublist in Gt_rhs.tolist() for item in sublist]

        B_rhs = [
            (Gt_rhs[i] - eta_damp * B[i] + l3 * dendro.vec_j_ad_j(b, B[i]) -
             l4 * dendro.vec_j_ad_j(b, Gt[i])) for i in dendro.e_i
        ]

        ###################################################################
        # generate code
        ###################################################################

        outs = [a_rhs, b_rhs, gt_rhs, chi_rhs, At_rhs, K_rhs, Gt_rhs, B_rhs]
        vnames = [
            'a_rhs', 'b_rhs', 'gt_rhs', 'chi_rhs', 'At_rhs', 'K_rhs', 'Gt_rhs',
            'B_rhs'
        ]
        dendro.generate_cpu(outs, vnames, '[pp]')

    else:
        # note: these are just the symbolic vars that is being used to generate the
        # Gt_rhs by satges

        _Gt_rhs_s1 = dendro.vec3("Gt_rhs_s1_", "[pp]")
        _Gt_rhs_s2 = dendro.vec3("Gt_rhs_s2_", "[pp]")
        _Gt_rhs_s3 = dendro.vec3("Gt_rhs_s3_", "[pp]")
        _Gt_rhs_s4 = dendro.vec3("Gt_rhs_s4_", "[pp]")
        _Gt_rhs_s5 = dendro.vec3("Gt_rhs_s5_", "[pp]")
        _Gt_rhs_s6 = dendro.vec3("Gt_rhs_s6_", "[pp]")
        _Gt_rhs_s7 = dendro.vec3("Gt_rhs_s7_", "[pp]")
        _CalGt = dendro.vec3("CalGt", "[pp]")
        _Gt_rhs = dendro.vec3("Gt_rhs", "[pp]")

        # Gt_rhs staged vars that is being used to generate the code.
        At_UU = dendro.sym_3x3("At_UU", "[pp]")
        CalGt = dendro.vec3("CalGt", "[pp]")
        Gt_rhs_s1 = dendro.vec3("Gt_rhs_s1_", "[pp]")
        Gt_rhs_s2 = dendro.vec3("Gt_rhs_s2_", "[pp]")
        Gt_rhs_s3 = dendro.vec3("Gt_rhs_s3_", "[pp]")
        Gt_rhs_s4 = dendro.vec3("Gt_rhs_s4_", "[pp]")
        Gt_rhs_s5 = dendro.vec3("Gt_rhs_s5_", "[pp]")
        Gt_rhs_s6 = dendro.vec3("Gt_rhs_s6_", "[pp]")
        Gt_rhs_s7 = dendro.vec3("Gt_rhs_s7_", "[pp]")

        C1 = dendro.get_first_christoffel()
        C2 = dendro.get_second_christoffel()
        C2_spatial = dendro.get_complete_christoffel(chi)
        [R, Rt, Rphi, CalGt] = dendro.compute_ricci(Gt, chi)

        a_rhs = l1 * dendro.lie(b, a) - 2 * a * K

        b_rhs = [(Rational(3, 4) * (lf0 + lf1 * a) * B[i] +
                  l2 * dendro.vec_j_ad_j(b, b[i])) for i in dendro.e_i]

        gt_rhs = dendro.lie(b, gt, weight) - 2 * a * At

        chi_rhs = dendro.lie(b, chi, weight) + Rational(2, 3) * (chi * a * K)

        AikAkj = Matrix([
            sum([
                At[i, k] *
                sum([dendro.inv_metric[k, l] * At[l, j] for l in dendro.e_i])
                for k in dendro.e_i
            ]) for i, j in dendro.e_ij
        ])

        At_rhs = dendro.lie(b, At, weight) + chi * dendro.trace_free(
            a * R - dendro.DiDj(a)) + a * (K * At - 2 * AikAkj.reshape(3, 3))

        K_rhs = dendro.lie(b, K) - dendro.laplacian(
            a, chi) + a * (K * K / 3 + dendro.sqr(At))

        At_UU = dendro.up_up(At)

        Gt_rhs_s1 = ([
            sum(b[j] * ad(j, Gt[i]) for j in dendro.e_i) for i in dendro.e_i
        ])
        Gt_rhs_s2 = ([
            sum(_CalGt[j] * d(j, b[i]) for j in dendro.e_i) for i in dendro.e_i
        ])
        Gt_rhs_s3 = ([
            _CalGt[i] * sum(d(j, b[j]) for j in dendro.e_i) for i in dendro.e_i
        ])
        Gt_rhs_s4 = ([
            sum([
                igt[j, k] * d2(j, k, b[i]) + igt[i, j] * d2(j, k, b[k]) / 3
                for j, k in dendro.e_ij
            ]) for i in dendro.e_i
        ])
        Gt_rhs_s5 = ([
            sum([2 * At_UU[i, j] * d(j, a) for j in dendro.e_i])
            for i in dendro.e_i
        ])
        Gt_rhs_s6 = ([
            sum([
                2 * a * dendro.C2[i, j, k] * At_UU[j, k]
                for j, k in dendro.e_ij
            ]) for i in dendro.e_i
        ])
        Gt_rhs_s7 = ([
            sum([
                a * (3 / chi * At_UU[i, j] * d(j, chi) +
                     Rational(4, 3) * dendro.inv_metric[i, j] * d(j, K))
                for j in dendro.e_i
            ]) for i in dendro.e_i
        ])

        Gt_rhs = Matrix(_Gt_rhs_s1) - \
            Matrix(_Gt_rhs_s2) + \
            Rational(2,3)*Matrix(_Gt_rhs_s3) + \
            Matrix(_Gt_rhs_s4) - \
            Matrix(_Gt_rhs_s5) + \
            Matrix(_Gt_rhs_s6) - \
            Matrix(_Gt_rhs_s7)

        Gt_rhs = [item for sublist in Gt_rhs.tolist() for item in sublist]

        B_rhs = [
            (Gt_rhs[i] - eta_damp * B[i] + l3 * dendro.vec_j_ad_j(b, B[i]) -
             l4 * dendro.vec_j_ad_j(b, Gt[i])) for i in dendro.e_i
        ]

        outs = [
            a_rhs, b_rhs, gt_rhs, chi_rhs, At_rhs, K_rhs, CalGt, Gt_rhs_s1,
            Gt_rhs_s2, Gt_rhs_s3, Gt_rhs_s4, Gt_rhs_s5, Gt_rhs_s6, Gt_rhs_s7,
            Gt_rhs, B_rhs
        ]
        vnames = [
            'a_rhs', 'b_rhs', 'gt_rhs', 'chi_rhs', 'At_rhs', 'K_rhs', 'CalGt',
            'Gt_rhs_s1_', 'Gt_rhs_s2_', 'Gt_rhs_s3_', 'Gt_rhs_s4_',
            'Gt_rhs_s5_', 'Gt_rhs_s6_', 'Gt_rhs_s7_', 'Gt_rhs', 'B_rhs'
        ]

        ###################################################################
        # generate code
        ###################################################################

        numVars = len(outs)
        for i in range(0, numVars):
            dendro.generate_separate([outs[i]], [vnames[i]], '[pp]')
Ejemplo n.º 3
0
#!/usr/bin/env/ python3

import dendro
from sympy import *

###################################################################
# initialize
###################################################################

# Declare variables.
# These include the BSSN variables that we need for the Psi4
# calculation.
chi = dendro.scalar("chi", "[pp]")
K = dendro.scalar("K", "[pp]")
Gt = dendro.vec3("Gt", "[pp]")
gt = dendro.sym_3x3("gt", "[pp]")
At = dendro.sym_3x3("At", "[pp]")

# Specify the operators needed for computing first and second derivatives
d = dendro.set_first_derivative('grad')  # first argument is direction
d2 = dendro.set_second_derivative('grad2')  # first 2 arguments are directions
ad = dendro.set_advective_derivative('agrad')  # first argument is direction

# Metric related quantities, i.e. the metric and its inverse
dendro.set_metric(gt)
igt = dendro.get_inverse_metric()

# Christoffels, Ricci, et al
C1 = dendro.get_first_christoffel()
C2 = dendro.get_second_christoffel()
from sympy import *
from sympy.physics.vector.vector import Vector
from sympy.printing.dot import dotprint
###################################################################
# initialize
###################################################################

l1, l2, l3, l4, eta = symbols('lambda[0] lambda[1] lambda[2] lambda[3] eta')
lf0, lf1 = symbols('lambda_f[0] lambda_f[1]')

# declare variables
a = dendro.scalar("alpha", "[pp]")
chi = dendro.scalar("chi", "[pp]")
K = dendro.scalar("K", "[pp]")

Gt = dendro.vec3("Gt", "[pp]")
b = dendro.vec3("beta", "[pp]")
B = dendro.vec3("B", "[pp]")

gt = dendro.sym_3x3("gt", "[pp]")
At = dendro.sym_3x3("At", "[pp]")

# note: these are just the symbolic vars that is being used to generate the
# Gt_rhs by satges

_Gt_rhs_s1 = dendro.vec3("Gt_rhs_s1_", "[pp]")
_Gt_rhs_s2 = dendro.vec3("Gt_rhs_s2_", "[pp]")
_Gt_rhs_s3 = dendro.vec3("Gt_rhs_s3_", "[pp]")
_Gt_rhs_s4 = dendro.vec3("Gt_rhs_s4_", "[pp]")
_Gt_rhs_s5 = dendro.vec3("Gt_rhs_s5_", "[pp]")
_Gt_rhs_s6 = dendro.vec3("Gt_rhs_s6_", "[pp]")
Ejemplo n.º 5
0
import dendro
from sympy import *

###################################################################
# initialize
###################################################################

l1, l2, l3, l4, eta = symbols('lambda[0] lambda[1] lambda[2] lambda[3] eta')
lf0, lf1 = symbols('lambda_f[0] lambda_f[1]')

# declare variables
a = dendro.scalar("alpha")
chi = dendro.scalar("chi")
K = dendro.scalar("K")

Gt = dendro.vec3("Gt")
b = dendro.vec3("beta")
B = dendro.vec3("B")

gt = dendro.sym_3x3("gt")
At = dendro.sym_3x3("At")

Gt_rhs = dendro.vec3("Gt_rhs")

# Lie derivative weight
weight = -2 / 3
weight_Gt = 2 / 3

# specify the functions for computing first and second derivatives
d = dendro.set_first_derivative('grad')  # first argument is direction
d2 = dendro.set_second_derivative('grad2')  # first 2 arguments are directions
import dendro
from sympy import *

###################################################################
# initialize
###################################################################

l1, l2, l3, l4, eta = symbols('lambda[0] lambda[1] lambda[2] lambda[3] eta')
lf0, lf1 = symbols('lambda_f[0] lambda_f[1]')

# declare variables
a = dendro.scalar("alpha")
chi = dendro.scalar("chi")
K = dendro.scalar("K")

Gt = dendro.vec3("Gt")
b = dendro.vec3("beta")
B = dendro.vec3("B")

gt = dendro.sym_3x3("gt")
At = dendro.sym_3x3("At")

Gt_rhs = dendro.vec3("Gt_rhs")

# Lie derivative weight
weight = -2 / 3
weight_Gt = 2 / 3

# specify the functions for computing first and second derivatives
d = dendro.set_first_derivative('grad')  # first argument is direction
d2 = dendro.set_second_derivative('grad2')  # first 2 arguments are directions
Ejemplo n.º 7
0
#!/usr/bin/env/ python3

import dendro
from sympy import *

###################################################################
# initialize
###################################################################

# Declare variables.
# These include the BSSN variables that we need for the Psi4
# calculation.
chi = dendro.scalar("chi", "[pp]")
K = dendro.scalar("K", "[pp]")
Gt = dendro.vec3("Gt", "[pp]")
gt = dendro.sym_3x3("gt", "[pp]")
At = dendro.sym_3x3("At", "[pp]")

# Define some symbolic variables that will be used to stage the
# calculation of the constraints.
_ham_s1 = dendro.scalar("ham_s1_", "[pp]")
_ham_s2 = dendro.scalar("ham_s2_", "[pp]")
_mom_s1 = dendro.vec3("mom_s1_", "[pp]")
_mom_s2 = dendro.vec3("mom_s2_", "[pp]")
_mom_s3 = dendro.vec3("mom_s3_", "[pp]")

# Now for the same variables that will be used to generate the code
ham_s1 = dendro.scalar("ham_s1_", "[pp]")
ham_s2 = dendro.scalar("ham_s2_", "[pp]")
mom_s1 = dendro.scalar("mom_s1_", "[pp]")
Ejemplo n.º 8
0
#!/usr/bin/env/ python3

import dendro
from sympy import *

###################################################################
# initialize
###################################################################

# Declare variables.
# These include the BSSN variables that we need for the Psi4
# calculation.
chi = dendro.scalar("chi", "[pp]")
K = dendro.scalar("K", "[pp]")
Gt = dendro.vec3("Gt", "[pp]")
gt = dendro.sym_3x3("gt", "[pp]")
At = dendro.sym_3x3("At", "[pp]")
b = dendro.vec3("beta", "[pp]")
a = dendro.scalar("alpha", "[pp]")

# declare reference metric related vars
# TODO : this is not really evolution variables... but somewhat need to be defined
#a_ref   = dendro.scalar("alpha_ref", "[pp]")
#b_ref   = dendro.vec3("beta_ref", "[pp]")
#f_ref  = dendro.sym_3x3("f_ref", "[pp]")

# Alternative way (same as in evolution eqs part)
a_ref = 1
b_ref = Matrix([[0, 0, 0]])
f_ref = eye(3)
Ejemplo n.º 9
0
###############################################################################
import dendro
from sympy import *
from sympy.physics.vector.vector import Vector
from sympy.printing.dot import dotprint
###################################################################
# initialize
###################################################################

l1, l2, l3, l4, eta = symbols('lambda[0] lambda[1] lambda[2] lambda[3] eta')
lf0, lf1 = symbols('lambda_f[0] lambda_f[1]')

# declare variables
RccSc   = dendro.scalar("RccSc", "[pp]")

Vaux  = dendro.vec3("Vaux", "[pp]")

gm  = dendro.sym_3x3("gm", "[pp]")
Rcct  = dendro.sym_3x3("Rcct", "[pp]")

# Lie derivative weight
weight = -Rational(2,3)
weight_Gt = Rational(2,3)

# specify the functions for computing first and second derivatives
d = dendro.set_first_derivative('grad')    # first argument is direction
d2s = dendro.set_second_derivative('grad2')  # first 2 arguments are directions
ad = dendro.set_advective_derivative('agrad')  # first argument is direction
kod = dendro.set_kreiss_oliger_dissipation('kograd')

d2 = dendro.d2