Peano
Loading...
Searching...
No Matches
TP_bindding.h
Go to the documentation of this file.
1#pragma once
2
4//#include "AbstractFiniteVolumeCCZ4.h"
5//The functions in this namespace works as binddings of two puncture library
6
7namespace TP_bindding {
8
9 //calculate the soccz4 quantites use the real physics quantities given in TP lib
10 inline void SOCCZ4Cal(double* __restrict__ Q){
11 // Input: the physical metric gamma_ij (Q[0..5]) and the physical
12 // extrinsic curvature K_ij (Q[6..11]), both as upper triangles.
13 // Output: the conformal metric, Aex, Kex and phi.
14 const double det = Q[0]*Q[3]*Q[5] - Q[0]*Q[4]*Q[4] - Q[1]*Q[1]*Q[5] + 2*Q[1]*Q[2]*Q[4] -Q[2]*Q[2]*Q[3];
15 const double invdet = 1./det;
16
17 // Inverse of the physical metric (symmetric, i.e. upper triangle only)
18 const double g_contr_11 = ( Q[3]*Q[5]-Q[4]*Q[4])*invdet;
19 const double g_contr_12 = -( Q[1]*Q[5]-Q[2]*Q[4])*invdet;
20 const double g_contr_13 = -(-Q[1]*Q[4]+Q[2]*Q[3])*invdet;
21 const double g_contr_22 = ( Q[0]*Q[5]-Q[2]*Q[2])*invdet;
22 const double g_contr_23 = -( Q[0]*Q[4]-Q[2]*Q[1])*invdet;
23 const double g_contr_33 = ( Q[0]*Q[3]-Q[1]*Q[1])*invdet;
24
25 const double phi=std::pow(det,-1./6.);
26 const double phi2=phi*phi;
27
28 const double* Kdown = Q + 6;
29 const double Kex = g_contr_11 * Kdown[0]
30 + g_contr_22 * Kdown[3]
31 + g_contr_33 * Kdown[5]
32 + 2.0 * ( g_contr_12 * Kdown[1]
33 + g_contr_13 * Kdown[2]
34 + g_contr_23 * Kdown[4] );
35
36 //now adjust the solution: Aex_ij = phi^2 (K_ij - 1/3 Kex gamma_ij)
37 for (int i=0;i<6;i++) {
38 Q[i+6]= phi2*(Q[i+6]-1./3. * Kex * Q[i]); //\tilde{A}_ij
39 Q[i]=phi2*Q[i]; //\tilde{\gamma}_ij
40 }
41
42 //Q[23]=Kex; Q[24]=std::log(phi); Q[16]=std::log(Q[16]);
43 const double np = 1.0;
44 Q[23]=Kex; Q[24]=std::pow(phi,np); //Q[16]=phi;
45 }
46
47 //use this to calculate the gradient
48 inline void GradientCal(const double* X, double* __restrict__ Q, double* LgradQ, int nVars, TP::TwoPunctures* tp, bool low_res=false)
49 {
50 constexpr double epsilon = 1e-4;
51 double Qp1[nVars],Qm1[nVars],Qp2[nVars],Qm2[nVars];
52
53 for (int d=0;d<3;d++)
54 {
55 double xp1[3]={X[0],X[1],X[2]}; double xp2[3]={X[0],X[1],X[2]};
56 double xm1[3]={X[0],X[1],X[2]}; double xm2[3]={X[0],X[1],X[2]};
57 xp1[d]+=epsilon; xp2[d]+=2*epsilon; xm1[d]-=epsilon; xm2[d]-=2*epsilon;
58
59 tp->Interpolate(xp1,Qp1, low_res); SOCCZ4Cal(Qp1);
60 tp->Interpolate(xp2,Qp2, low_res); SOCCZ4Cal(Qp2);
61 tp->Interpolate(xm1,Qm1, low_res); SOCCZ4Cal(Qm1);
62 tp->Interpolate(xm2,Qm2, low_res); SOCCZ4Cal(Qm2);
63
64 for (int i=0; i<nVars; i++) {
65 LgradQ[d*nVars+i] = ( 8.0*Qp1[i] - 8.0*Qm1[i] + Qm2[i] - Qp2[i] )/(12.0*epsilon);
66 }
67 }
68 }
69
70 //calculate the auxiliary variables using Q and its gradient
71 inline void AuxiliaryCal(double* __restrict__ Q, double* LgradQ, int nVars){
72 // LgradQ[d*nVars+i] is the derivative of entry i along axis d
73 auto gradQ = [&](int d, int i) { return LgradQ[d*nVars+i]; };
74
75 //here all quantites are coformal, i.e. with the tilde
76 const double invdet = 1./(Q[0]*Q[3]*Q[5] - Q[0]*Q[4]*Q[4] - Q[1]*Q[1]*Q[5] + 2*Q[1]*Q[2]*Q[4] -Q[2]*Q[2]*Q[3]);
77 const double g_contr_12 = -( Q[1]*Q[5]-Q[2]*Q[4])*invdet;
78 const double g_contr_13 = -(-Q[1]*Q[4]+Q[2]*Q[3])*invdet;
79 const double g_contr_23 = -( Q[0]*Q[4]-Q[2]*Q[1])*invdet;
80 const double g_contr[3][3] = {{(Q[3]*Q[5]-Q[4]*Q[4])*invdet, g_contr_12, g_contr_13},
81 {g_contr_12, (Q[0]*Q[5]-Q[2]*Q[2])*invdet, g_contr_23},
82 {g_contr_13, g_contr_23, (Q[0]*Q[3]-Q[1]*Q[1])*invdet}};
83
84 //A[i]=A_i=\partial_i \alpha
85 for (int i=0;i<3;i++) Q[25+i]=gradQ(i,16);
86
87 //B[i][j]=B_i^j=\partial_i \beta^j //the component order of this variable is different between fortran and C++!
88 for (int i=0;i<3;i++)
89 for (int j=0;j<3;j++) Q[28+i*3+j]=gradQ(i,17+j);
90
91 //D[k][i][j]=D_kij= 0.5 * \partial_k \tilde{\gamma}_ij
92 for (int i=0;i<3;i++)
93 for (int j=0;j<6;j++) Q[37+i*6+j]=0.5*gradQ(i,j);
94
95 //P[i]=P_i=\partial_i \phi
96 for (int i=0;i<3;i++) Q[55+i]=gradQ(i,24);
97
98 const double DD[3][3][3] = {
99 {{Q[37], Q[38], Q[39]}, {Q[38], Q[40], Q[41]}, {Q[39], Q[41], Q[42]}},
100 {{Q[43], Q[44], Q[45]}, {Q[44], Q[46], Q[47]}, {Q[45], Q[47], Q[48]}},
101 {{Q[49], Q[50], Q[51]}, {Q[50], Q[52], Q[53]}, {Q[51], Q[53], Q[54]}}};
102
103 // Christoffel symbols, symmetric in i and j: Christoffel_tilde_down[l][i][j]
104 // = D_ijl + D_jil - D_lij, raised to Christoffel_tilde[i][j][k]
105 double Christoffel_tilde_down[3][3][3];
106 double Christoffel_tilde[3][3][3];
107 for (int i = 0; i < 3; i++)
108 for (int j = i; j < 3; j++)
109 {
110 for (int l = 0; l < 3; l++)
111 {
112 Christoffel_tilde_down[l][i][j] = DD[i][j][l] + DD[j][i][l] - DD[l][i][j];
113 Christoffel_tilde_down[l][j][i] = Christoffel_tilde_down[l][i][j];
114 }
115 for (int k = 0; k < 3; k++)
116 {
117 double temp = 0;
118 for (int l = 0; l < 3; l++) temp += g_contr[k][l] * Christoffel_tilde_down[l][i][j];
119 Christoffel_tilde[i][j][k] = temp;
120 Christoffel_tilde[j][i][k] = temp;
121 }
122 }
123
124 // Ghat^i = gamma^jl Christoffel^i_jl, a contraction of two symmetric index pairs
125 for (int i = 0; i < 3; i++)
126 {
127 Q[13+i] += g_contr[0][0] * Christoffel_tilde[0][0][i]
128 + g_contr[1][1] * Christoffel_tilde[1][1][i]
129 + g_contr[2][2] * Christoffel_tilde[2][2][i]
130 + 2.0 * ( g_contr[0][1] * Christoffel_tilde[0][1][i]
131 + g_contr[0][2] * Christoffel_tilde[0][2][i]
132 + g_contr[1][2] * Christoffel_tilde[1][2][i] );
133 }
134 }
135}
136
void Interpolate(const double *const pos, double *Q, bool low_res=false)
void AuxiliaryCal(double *__restrict__ Q, double *LgradQ, int nVars)
Definition TP_bindding.h:71
void SOCCZ4Cal(double *__restrict__ Q)
Definition TP_bindding.h:10
void GradientCal(const double *X, double *__restrict__ Q, double *LgradQ, int nVars, TP::TwoPunctures *tp, bool low_res=false)
Definition TP_bindding.h:48