aboutsummaryrefslogtreecommitdiff
path: root/src/Misner_points.c
blob: a64907cff23c32f46bbe2278c70175ddd5402e95 (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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
 /*@@
   @file      Misner_points.c
   @date
   @author    Steve Brandt
   @desc
              This calculates the conformal factor for nbh black holes,
              with naked mass m0 = 2 csch(mu) each, and placed on a circle in the
              xy plane around the origin, of radius coth(mu).
              One of them sits on the positive x axis, the others are evenly spaced.
              Naked mass here corresponds to the term m0 / (2 |r - r0|) in the expansion.
   @history
   @hdate 6.May.2003
   @hauthor Jonathan Thornburg
   @hdesc code cleanup, add prototypes
   @endhistory
   @enddesc
 @@*/

#include <stdlib.h>
#include <stdio.h>

#include <math.h>

#include "cctk.h"
#include "cctk_Arguments.h"
#include "cctk_Parameters.h"

#include "IDAnalyticBH.h"

static const char *rcsid = "$Header$";

CCTK_FILEVERSION(CactusEinstein_IDAnalyticBH_Misner_points_c)

/******************************************************************************/

/*
 * data structures local to this file
 */

/* Basic data about a brill-lindquist black hole term. */
struct bhole {
  CCTK_REAL x,y;
  CCTK_REAL mass;

  /* i gives either the number of the seed
     black hole we are starting with, or
     the number of the seed black hole that
     was used to isometrize this term. */
  int i;

  /* isos points to an array of nbhole (or is it nbhole-1??)
     structures, malloc()-ed in  fill_iso() .
     At present this array is never freed, and in fact the pointers may
     be overwritten with other malloc()s in fill_iso() recursive calls! :( */
  struct bhole *isos;
};

/******************************************************************************/

/*
 * static data
 */

static int nbholes;

#define MAXBHOLES 10
/* The seed black holes. */
struct bhole bholes[MAXBHOLES];

/******************************************************************************/

/*
 * prototypes for functions local to this file
 */
static CCTK_REAL csch(CCTK_REAL theta);
static CCTK_REAL coth(CCTK_REAL theta);
static void iso(struct bhole *a1, struct bhole *a2, struct bhole *a3);
static void fill_iso(struct bhole *b, int n);
static CCTK_REAL eval_bh_psi(const struct bhole *b,
                             CCTK_REAL x, CCTK_REAL y, CCTK_REAL z);

/******************************************************************************/
/***** functions visible outside this file ************************************/
/******************************************************************************/

 /*@@
   @routine    Misner_init
   @date
   @author     Steve Brandt
   @desc
      Initialises the black holes then makes the isometry black holes
   @enddesc
   @calls
   @history
   @endhistory
@@*/
void Misner_init(int n, CCTK_REAL mu, int terms)
{

  int i;
  CCTK_REAL pi,ang;

  if (! ((nbholes=n) < MAXBHOLES))
    CCTK_VWarn (0, __LINE__, __FILE__,"IDAnalyticBH", "Number of black holes exceed maximum number of black holes");

  pi = 4.0*atan(1.);

  ang = 2.*pi/(n);

  for(i=0;i<n;i++)
  {
    bholes[i].x = coth(mu)*cos(ang*i);
    bholes[i].y = coth(mu)*sin(ang*i);
    bholes[i].mass = csch(mu);
    bholes[i].i = i;
    bholes[i].isos = 0;
  }

  CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
"\n"
"   Misner_init(): warning: about to call  fill_iso() ; at present\n"
"                  this routine seems to leak quasi-infinite amounts of\n"
"                  memory at the rate of O(100 megabytes/second) :( :( :(\n");

  for(i=0;i<n;i++)
    fill_iso(&bholes[i],terms);

}

/******************************************************************************/

 /*@@
   @routine    MisnerEvalPsi
   @date
   @author     Steve Brandt
   @desc
      Evaluate psi at a point
   @enddesc
   @calls      eval_bh_psi

   @history
   @hdate      6.May.2003
   @hauthor    Jonathan Thornburg <jthorn@aei.mpg.de>
   @hdesc      Return result directly rather than via a pointer argument.
   @endhistory
 @@*/
CCTK_REAL MisnerEvalPsi(CCTK_REAL x, CCTK_REAL y, CCTK_REAL z)
{
  int i;
  CCTK_REAL sum = 1.0;

  for(i=0;i<nbholes;i++)
  {
    sum += eval_bh_psi(&bholes[i],x,y,z);
  }

  return sum;
}

/******************************************************************************/
/***** functions local to this file *******************************************/
/******************************************************************************/

static CCTK_REAL csch(CCTK_REAL theta) {
  return 1.0/sinh(theta);
}

/******************************************************************************/

static CCTK_REAL coth(CCTK_REAL theta) {
  return cosh(theta)/sinh(theta);
}

/******************************************************************************/

 /*@@
   @routine    iso
   @date
   @author     Steve Brandt
   @desc
               Isometrize black hole a1 through hole a2
   @enddesc
   @calls      iso
   @history

   @endhistory

@@*/

static void iso(struct bhole *a1, struct bhole *a2, struct bhole *a3)
{
  CCTK_REAL rad,radtwo;
  radtwo=(
      (a1->x - a2->x)*(a1->x - a2->x)+
      (a1->y - a2->y)*(a1->y - a2->y)
    );
  rad=sqrt(radtwo);
  a3->mass = a1->mass*a2->mass/rad;
  a3->x = a2->x+(a2->mass*a2->mass)*(a1->x - a2->x)/radtwo;
  a3->y = a2->y+(a2->mass*a2->mass)*(a1->y - a2->y)/radtwo;
}

/******************************************************************************/

 /*@@
   @routine    fill_iso
   @date
   @author     Steve Brandt
   @desc
               Fills in the iso structure of a given black hole.
               Applies recursively to the number of terms desired.
   @enddesc
   @calls      fill_iso
   @history

   @endhistory

@@*/

static void fill_iso(struct bhole *b, int n)
{
  int i,j;
  if(n==0)
  {
    b->isos = 0;
    return;
  }
  b->isos = (struct bhole *)malloc(sizeof(struct bhole)*(nbholes-1));
  if (! (b->isos != 0))
    CCTK_VWarn (0, __LINE__, __FILE__,"IDAnalyticBH", "error in function fill_iso");
  for(j=0, i=0;i<nbholes;i++)
  {
    if(i != b->i) {
      iso(b,&bholes[i],&b->isos[j]);
      b->isos[j].i = i;
      fill_iso(&b->isos[j],n-1);
      j++;
    }
  }
}

/******************************************************************************/

 /*@@
   @routine    eval_bh_psi
   @date
   @author     Steve Brandt
   @desc

   @enddesc
   @calls      eval_bh_psi
   @history

   @endhistory

@@*/
static CCTK_REAL eval_bh_psi(const struct bhole *b,
                             CCTK_REAL x, CCTK_REAL y, CCTK_REAL z)
{
  int i;
  CCTK_REAL res;
  res = 0.0;
  if(b->isos != 0)
  {
    for(i=0;i<nbholes-1;i++)
    {
      res += eval_bh_psi(&b->isos[i],x,y,z);
    }
  }
  res += b->mass/sqrt(
      (x - b->x)*(x - b->x)+
      (y - b->y)*(y - b->y)+
      z*z
    );
  return res;
}