aboutsummaryrefslogtreecommitdiff
path: root/src/driver/BH_diagnostics.cc
blob: ca411f8839a980d4e51a6076be8f0d6bf7b81635 (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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
// BH_diagnostics.cc -- compute/print BH diagnostics
// $Header$
//
// BH_diagnostics::BH_diagnostics - initialize a  struct BH_diagnostics
//
// compute_BH_diagnostics - compute BH diagnostics
/// surface_integral - compute surface integral over a patch system
//
// print_BH_diagnostics - print a summary of BH diagnostics
//
// setup_BH_diagnostics_output_file - create/initialize BH-diagnostics file
// output_BH_diagnostics_fn - append BH diagnostics to file
//

#include <stdio.h>
#include <assert.h>
#include <math.h>

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

#include "config.h"
#include "stdc.h"
#include "../jtutil/util.hh"
#include "../jtutil/array.hh"
#include "../jtutil/cpm_map.hh"
#include "../jtutil/linear_map.hh"
using jtutil::error_exit;

#include "../patch/coords.hh"
#include "../patch/grid.hh"
#include "../patch/fd_grid.hh"
#include "../patch/patch.hh"
#include "../patch/patch_edge.hh"
#include "../patch/patch_interp.hh"
#include "../patch/ghost_zone.hh"
#include "../patch/patch_system.hh"

#include "../elliptic/Jacobian.hh"

#include "../gr/gfns.hh"
#include "../gr/gr.hh"

#include "horizon_sequence.hh"
#include "driver.hh"

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

//
// prototypes for functions local to this file
//

namespace {
fp surface_integral(const patch_system& ps, int src_gfn,
		    enum patch::integration_method method);
	  }

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

//
// This function initializes a  struct BH_diagnostics  to all zeros.
//
BH_diagnostics::BH_diagnostics()
	: centroid_x(0.0), centroid_y(0.0), centroid_z(0.0),
	  mean_radius(0.0),
	  circumference_xy(0.0), circumference_xz(0.0), circumference_yz(0.0),
	  area(0.0),
	  m_irreducible(0.0)
{ }

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

//
// Given that an apparent horizon has been found, this function computes
// various black hole diagnostics.
//
// Inputs (gridfns)
// h		# ghosted
// one		# nominal
// global_[xyz]	# nominal
//
void compute_BH_diagnostics
	(const patch_system& ps,
	 const struct BH_diagnostics_info& BH_diagnostics_info,
	 const struct verbose_info& verbose_info,
	 struct BH_diagnostics& BH_diagnostics)
{
//
// compute raw surface integrals
//
fp integral_one = surface_integral(ps, gfns::gfn__one,
				   BH_diagnostics_info.integral_method);
fp integral_h = surface_integral(ps, gfns::gfn__h,
				 BH_diagnostics_info.integral_method);
fp integral_x = surface_integral(ps, gfns::gfn__global_x,
				 BH_diagnostics_info.integral_method);
fp integral_y = surface_integral(ps, gfns::gfn__global_y,
				 BH_diagnostics_info.integral_method);
fp integral_z = surface_integral(ps, gfns::gfn__global_z,
				 BH_diagnostics_info.integral_method);

//
// adjust integrals to take into account patch system not covering full sphere
//
switch	(ps.type())
	{
case patch_system::patch_system__full_sphere:
	break;
case patch_system::patch_system__plus_z_hemisphere:
	integral_one *= 2.0;
	integral_h *= 2.0;
	integral_x *= 2.0;
	integral_y *= 2.0;
	integral_z = integral_one * ps.origin_z();
	break;
case patch_system::patch_system__plus_xy_quadrant_mirrored:
case patch_system::patch_system__plus_xy_quadrant_rotating:
	integral_one *= 4.0;
	integral_h *= 4.0;
	integral_x = integral_one * ps.origin_x();
	integral_y = integral_one * ps.origin_y();
	integral_z *= 4.0;
	break;
case patch_system::patch_system__plus_xz_quadrant_rotating:
	integral_one *= 4.0;
	integral_h *= 4.0;
	integral_x = integral_one * ps.origin_x();
	integral_y *= 4.0;
	integral_z = integral_one * ps.origin_z();
	break;
case patch_system::patch_system__plus_xyz_octant_mirrored:
case patch_system::patch_system__plus_xyz_octant_rotating:
	integral_one *= 8.0;
	integral_h *= 8.0;
	integral_x = integral_one * ps.origin_x();
	integral_y = integral_one * ps.origin_y();
	integral_z = integral_one * ps.origin_z();
	break;
default:
	CCTK_VWarn(-1, __LINE__, __FILE__, CCTK_THORNSTRING,
"\n"
"   compute_BH_diagnostics(): unknown ps.type()=(int)%d!\n"
"                             (this should never happen!)"
,
		   int(ps.type()));				/*NOTREACHED*/
	}

BH_diagnostics.centroid_x = integral_x / integral_one;
BH_diagnostics.centroid_y = integral_y / integral_one;
BH_diagnostics.centroid_z = integral_z / integral_one;

BH_diagnostics.area = integral_one;
BH_diagnostics.circumference_xy = ps.xy_circumference
    (gfns::gfn__h,
     gfns::gfn__g_dd_11, gfns::gfn__g_dd_12, gfns::gfn__g_dd_13,
			 gfns::gfn__g_dd_22, gfns::gfn__g_dd_23,
					     gfns::gfn__g_dd_33,
     BH_diagnostics_info.integral_method);
BH_diagnostics.circumference_xz = ps.xz_circumference
    (gfns::gfn__h,
     gfns::gfn__g_dd_11, gfns::gfn__g_dd_12, gfns::gfn__g_dd_13,
			 gfns::gfn__g_dd_22, gfns::gfn__g_dd_23,
					     gfns::gfn__g_dd_33,
     BH_diagnostics_info.integral_method);
BH_diagnostics.circumference_yz = ps.yz_circumference
    (gfns::gfn__h,
     gfns::gfn__g_dd_11, gfns::gfn__g_dd_12, gfns::gfn__g_dd_13,
			 gfns::gfn__g_dd_22, gfns::gfn__g_dd_23,
					     gfns::gfn__g_dd_33,
     BH_diagnostics_info.integral_method);
BH_diagnostics.mean_radius = integral_h / integral_one;
BH_diagnostics.m_irreducible = sqrt(BH_diagnostics.area / (16.0*PI));
}

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

//
// This function computes the surface integral of a gridfn over the
// horizon.
//
namespace {
fp surface_integral(const patch_system& ps, int src_gfn,
		    enum patch::integration_method method)
{
return ps.integrate_gridfn
	   (src_gfn,
	    gfns::gfn__h,
	    gfns::gfn__g_dd_11, gfns::gfn__g_dd_12, gfns::gfn__g_dd_13,
				gfns::gfn__g_dd_22, gfns::gfn__g_dd_23,
						    gfns::gfn__g_dd_33,
	    method);
}
	  }

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

//
// This function prints a summary of the BH diagnostics, using CCTK_VInfo().
//
void print_BH_diagnostics(const struct BH_diagnostics& BH_diagnostics,
			  int N_horizons, int hn,
			  const struct verbose_info& verbose_info)
{
if (verbose_info.print_physics_details)
   then {
	CCTK_VInfo(CCTK_THORNSTRING,
		   "AH %d/%d: r=%g at (%f,%f,%f)",
		   hn, N_horizons,
		   double(BH_diagnostics.mean_radius),
		   double(BH_diagnostics.centroid_x),
		   double(BH_diagnostics.centroid_y),
		   double(BH_diagnostics.centroid_z));
	CCTK_VInfo(CCTK_THORNSTRING,
		   "AH %d/%d: area=%.10g m_irreducible=%.10g",
		   hn, N_horizons,
		   double(BH_diagnostics.area),
		   double(BH_diagnostics.m_irreducible));
	}
}

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

//
// This function creates a BH-diagnostics output file, writes a suitable
// header comment, and returns a stdio file pointer which can be used to
// append data to the file.
//
FILE* setup_BH_diagnostics_output_file(const struct IO_info& IO_info,
				       int N_horizons, int hn)
{
const int N_file_name_buffer = 200;
char file_name_buffer[N_file_name_buffer];

snprintf(file_name_buffer, N_file_name_buffer,
	 "%s.ah%d.%s",
	 IO_info.BH_diagnostics_base_file_name,
	 hn, IO_info.BH_diagnostics_file_name_extension);
FILE *fileptr = fopen(file_name_buffer, "w");
if (fileptr == NULL)
   then CCTK_VWarn(-1, __LINE__, __FILE__, CCTK_THORNSTRING,
"\n"
"   setup_BH_diagnostics_output_file():\n"
"        can't open BH-diagnostics output file\n"
"        \"%s\"!"
		   ,
		   file_name_buffer);				/*NOTREACHED*/

fprintf(fileptr, "# apparent horizon %d/%d\n", hn, N_horizons);
fprintf(fileptr, "#\n");
fprintf(fileptr, "# column 1 = cctk_iteration\n");
fprintf(fileptr, "# column 2 = cctk_time\n");
fprintf(fileptr, "# column 3 = centroid_x\n");
fprintf(fileptr, "# column 4 = centroid_y\n");
fprintf(fileptr, "# column 5 = centroid_z\n");
fprintf(fileptr, "# column 6 = mean radius\n");
fprintf(fileptr, "# column 7 = xy-plane circumference\n");
fprintf(fileptr, "# column 8 = xz-plane circumference\n");
fprintf(fileptr, "# column 9 = yz-plane circumference\n");
fprintf(fileptr, "# column 10 = area\n");
fprintf(fileptr, "# column 11 = m_irreducible\n");
fflush(fileptr);

return fileptr;
}

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

//
// This function appends a BH-diagnostics line to a data file.  It
// attempts to ensure that the newly-written line is flushed to disk,
// so the output file can be examined while the Cactus run is still in
// progress.
//
// (The "_fn" in the function name is to distinguish it from the Cactus
// parameter  output_BH_diagnostics .)
//
// Arguments:
// BH_diagnostics = The BH diagnostics to be written
// fileptr = The stdio file pointer to append to
//
void output_BH_diagnostics_fn(const struct BH_diagnostics& BH_diagnostics,
			      const struct IO_info& IO_info,
			      int hn, FILE* fileptr)
{
assert(fileptr != NULL);

fprintf(fileptr,
//  cctk_iteration        mean radius                     area    m_irreducible
//  ==  cctk_time         ======  {xy,xz,yz}-plane        ======  ======
//  ==  ====  centroid_[xyz]      circumferences          ======  ======
//  ==  ====  ==========  ======  ======================  ======  ======
   "%d\t%.3f\t%f\t%f\t%f\t%#.10g\t%#.10g\t%#.10g\t%#.10g\t%#.10g\t%#.10g\n",
	IO_info.time_iteration, double(IO_info.time),
	BH_diagnostics.centroid_x, BH_diagnostics.centroid_y,
				   BH_diagnostics.centroid_z,
	BH_diagnostics.mean_radius,
	BH_diagnostics.circumference_xy, BH_diagnostics.circumference_xz,
					 BH_diagnostics.circumference_yz,
	BH_diagnostics.area,
	BH_diagnostics.m_irreducible);

fflush(fileptr);
}