aboutsummaryrefslogtreecommitdiff
path: root/src/TwoPunctures.c
blob: e926b65af67ada9e2d87c904b8d486837d3756d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// TwoPunctures:  File  "TwoPunctures.c"

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include "cctk.h"
#include "cctk_Arguments.h"
#include "cctk_Parameters.h"
#include "TP_utilities.h"
#include "TwoPunctures.h"

static inline double pow2 (const double x)
{
  return x*x;
}

static inline double pow4 (const double x)
{
  return x*x*x*x;
}

// -------------------------------------------------------------------
void
TwoPunctures (CCTK_ARGUMENTS)
{
  DECLARE_CCTK_ARGUMENTS;
  DECLARE_CCTK_PARAMETERS;

  enum GRID_SETUP_METHOD { GSM_Taylor_expansion, GSM_evaluation };
  enum GRID_SETUP_METHOD gsm;

  int nvar = 1, n1 = npoints_A, n2 = npoints_B, n3 = npoints_phi;

  int i, j, k, ntotal = n1 * n2 * n3 * nvar;
  static double *F = NULL;
  static derivs u, v;
  double admMass;

  if (! F) {
    /* Solve only when called for the first time */
    F = dvector (0, ntotal - 1);
    allocate_derivs (&u, ntotal);
    allocate_derivs (&v, ntotal);

    CCTK_INFO ("Solving puncture equation");
    Newton (cctkGH, nvar, n1, n2, n3, v, Newton_tol, Newton_maxit);

    F_of_v (cctkGH, nvar, n1, n2, n3, v, F, u);
    
    /* print out ADM mass, eq.: \Delta M_ADM=2*r*u=4*b*V for A=1,B=0,phi=0 */
    admMass = (par_m_plus + par_m_minus
               - 4*par_b*PunctEvalAtArbitPosition(v.d0, 1, 0, 0, n1, n2, n3));
    CCTK_VInfo (CCTK_THORNSTRING, "ADM mass is %g\n", admMass);
  }

  if (CCTK_EQUALS(grid_setup_method, "Taylor expansion"))
  {
    gsm = GSM_Taylor_expansion;
  }
  else if (CCTK_EQUALS(grid_setup_method, "evaluation"))
  {
    gsm = GSM_evaluation;
  }
  else
  {
    CCTK_WARN (0, "internal error");
  }

  CCTK_INFO ("Interpolating result");
  if (CCTK_EQUALS(metric_type, "static conformal")) {
    if (CCTK_EQUALS(conformal_storage, "factor")) {
      *conformal_state = 1;
    } else if (CCTK_EQUALS(conformal_storage, "factor+derivs")) {
      *conformal_state = 2;
    } else if (CCTK_EQUALS(conformal_storage, "factor+derivs+2nd derivs")) {
      *conformal_state = 3;
    }
  } else {
    *conformal_state = 0;
  }

  for (k = 0; k < cctk_lsh[2]; ++k)
  {
    for (j = 0; j < cctk_lsh[1]; ++j)
    {
      for (i = 0; i < cctk_lsh[0]; ++i)
      {

	const int ind = CCTK_GFINDEX3D (cctkGH, i, j, k);
        
        const double r_plus
          = sqrt(pow2(x[ind] - par_b) + pow2(y[ind]) + pow2(z[ind]));
        const double r_minus
          = sqrt(pow2(x[ind] + par_b) + pow2(y[ind]) + pow2(z[ind]));
        
        double U;
        switch (gsm)
        {
        case GSM_Taylor_expansion:
          U = PunctTaylorExpandAtArbitPosition
            (0, nvar, n1, n2, n3, v, x[ind], y[ind], z[ind]);
          break;
        case GSM_evaluation:
          U = PunctIntPolAtArbitPosition
            (0, nvar, n1, n2, n3, v, x[ind], y[ind], z[ind]);
          break;
        default:
          assert (0);
        }
        const double psi1 = 1
          + 0.5 * par_m_plus / r_plus
          + 0.5 * par_m_minus / r_minus + U;
        double static_psi = 1;
        
        double Aij[3][3];
        BY_Aijofxyz (x[ind], y[ind], z[ind], Aij);

        if (*conformal_state > 0) {

          double xp, yp, zp, rp, ir;
          double s1, s3, s5;
          double p, px, py, pz, pxx, pxy, pxz, pyy, pyz, pzz;

          p = 1.0;
          px = py = pz = 0.0;
          pxx = pxy = pxz = 0.0;
          pyy = pyz = pzz = 0.0;

          /* first puncture */
          xp = x[ind] - par_b;
          yp = y[ind];
          zp = z[ind];
          rp = sqrt (xp*xp + yp*yp + zp*zp);
          ir = 1.0/rp;

          s1 = 0.5*par_m_plus*ir;
          s3 = -s1*ir*ir;
          s5 = -3.0*s3*ir*ir;

          p += s1;

          px += xp*s3;
          py += yp*s3;
          pz += zp*s3;

          pxx += xp*xp*s5 + s3;
          pxy += xp*yp*s5;
          pxz += xp*zp*s5;
          pyy += yp*yp*s5 + s3;
          pyz += yp*zp*s5;
          pzz += zp*zp*s5 + s3;

          /* second puncture */
          xp = x[ind] + par_b;
          yp = y[ind];
          zp = z[ind];
          rp = sqrt (xp*xp + yp*yp + zp*zp);
          ir = 1.0/rp;

          s1 = 0.5*par_m_minus*ir;
          s3 = -s1*ir*ir;
          s5 = -3.0*s3*ir*ir;

          p += s1;

          px += xp*s3;
          py += yp*s3;
          pz += zp*s3;

          pxx += xp*xp*s5 + s3;
          pxy += xp*yp*s5;
          pxz += xp*zp*s5;
          pyy += yp*yp*s5 + s3;
          pyz += yp*zp*s5;
          pzz += zp*zp*s5 + s3;

          if (*conformal_state >= 1) {
            static_psi = p;
            psi[ind] = static_psi;
          }
          if (*conformal_state >= 2) {
            psix[ind] = px / static_psi;
            psiy[ind] = py / static_psi;
            psiz[ind] = pz / static_psi;
          }
          if (*conformal_state >= 3) {
            psixx[ind] = pxx / static_psi;
            psixy[ind] = pxy / static_psi;
            psixz[ind] = pxz / static_psi;
            psiyy[ind] = pyy / static_psi;
            psiyz[ind] = pyz / static_psi;
            psizz[ind] = pzz / static_psi;
          }

        } /* if conformal-state > 0 */
          
        puncture_u[ind] = U;

        gxx[ind] = pow4 (psi1 / static_psi);
        gxy[ind] = 0;
        gxz[ind] = 0;
        gyy[ind] = pow4 (psi1 / static_psi);
        gyz[ind] = 0;
        gzz[ind] = pow4 (psi1 / static_psi);

        kxx[ind] = Aij[0][0] / pow2(psi1);
        kxy[ind] = Aij[0][1] / pow2(psi1);
        kxz[ind] = Aij[0][2] / pow2(psi1);
        kyy[ind] = Aij[1][1] / pow2(psi1);
        kyz[ind] = Aij[1][2] / pow2(psi1);
        kzz[ind] = Aij[2][2] / pow2(psi1);

      }
    }
  }

  if (0) {
    /* Keep the result around for the next time */
    free_dvector (F, 0, ntotal - 1);
    free_derivs (&u, ntotal);
    free_derivs (&v, ntotal);
  }
}