aboutsummaryrefslogtreecommitdiff
path: root/src/gr/horizon_function.cc
blob: 42e8f1d4f7e9312debbefae820c98762954c3197 (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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
// horizon_function.cc -- evaluate LHS function H(h)
// $Id$
//
// <<<prototypes>>>
// horizon_function - top-level driver
/// xyz_posns_and_deriv_coeffs - init xyz posns of grid points, xyz deriv coeffs
/// interpolate_geometry - interpolate $g_{ij}$, $K_{ij}$ from Cactus 3-D grid
//

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

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

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

#include "../config.hh"

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

#include "gfn.hh"
#include "AHFinderDirect.hh"

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

//
// ***** static data structures *****
//

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

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

namespace {
void xyz_posns_and_deriv_coeffs(patch_system& ps);
void interpolate_geometry(patch_system& ps,
			  const struct cactus_grid_info& cgi,
			  const struct geometry_interpolator_info& ii);
void compute_H(patch_system& ps);
	  };

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

//
// This function computes the LHS function H(h).
//
// Inputs (angular gridfns, on ghosted grid):
// ... defined on ghosted grid
// ... only values on nominal grid are actually used as input
//	h				# shape of trial surface
//
// Inputs (Cactus 3-D gridfns):
//	gxx,gxy,gxz,gyy,gyz,gzz		# 3-metric $g_{ij}$
//	kxx,kxy,kxz,kyy,kyz,kzz		# extrinsic curvature $K_{ij}$
//
// Outputs (angular gridfns, all on the nominal grid):
//	## computed directly from h
//	xx,yy,zz			# xyz positions of grid points
//	X_ud_*, X_udd_*			# xyz derivative coefficients
//	## interpolated from 3-D Cactus grid
//	g_dd_{11,12,13,22,23,33}			# $g_{ij}$
//	K_dd_{11,12,13,22,23,33}			# $K_{ij}$
//	partial_d_g_dd_{1,2,3}{11,12,13,22,23,33}	# $\partial_k g_{ij}$
//	## computed by Maple-generated code
//	g_uu_{11,12,13,22,23,33}	# $g^{ij}$
//	K				# $K$
//	K_dd_{11,12,13,22,23,33}	# $K^{ij}$
//	partial_d_ln_sqrt_g_d		# $\partial_i \ln \sqrt{g}$
//	partial_d_g_uu_{1,2,3}{11,12,13,22,23,33}	# $\partial_k g^{ij}$
//	H				# $H = H(h)$
//
void horizon_function(patch_system& ps,
		      const struct cactus_grid_info& cgi,
		      const struct geometry_interpolator_info& ii)
{
CCTK_VInfo(CCTK_THORNSTRING, "   horizon function");

// fill in values of ghosted gridfns in ghost zones
ps.synchronize_ghost_zones(ghosted_gfns::gfn__h, ghosted_gfns::gfn__h);

// compute xyz positions of grid points and xyz derivative coeffs
xyz_posns_and_deriv_coeffs(ps);

// interpolate $g_{ij}$, $K_{ij}$ --> $g_{ij}$, $K_{ij}$, $\partial_k g_{ij}$
interpolate_geometry(ps, cgi, ii);

// compute remaining gridfns --> $H$
// by algebraic ops and angular finite differencing
compute_H(ps);
}

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

//
// This function computes
// - the xyz positions of the grid points (gridfns xx, yy, and zz)
// - the xyz derivative coefficients (gridfns X_ud and X_udd).
// on the nominal grid.
//
namespace {
void xyz_posns_and_deriv_coeffs(patch_system& ps)
{
CCTK_VInfo(CCTK_THORNSTRING, "      xyz positions and derivative coefficients");

	for (int pn = 0 ; pn < ps.N_patches() ; ++pn)
	{
	patch& p = ps.ith_patch(pn);

		for (int irho = p.min_irho() ; irho <= p.max_irho() ; ++irho)
		{
		for (int isigma = p.min_isigma() ;
		     isigma <= p.max_isigma() ;
		     ++isigma)
		{
		const fp r
			= p.ghosted_gridfn(ghosted_gfns::gfn__h, irho,isigma);
		const fp rho = p.rho_of_irho(irho);
		const fp sigma = p.sigma_of_isigma(isigma);
		fp x, y, z;
		p.xyz_of_r_rho_sigma(r,rho,sigma, x,y,z);

		// xyz positions of grid points
		p.gridfn(nominal_gfns::gfn__xx, irho,isigma) = x;
		p.gridfn(nominal_gfns::gfn__yy, irho,isigma) = y;
		p.gridfn(nominal_gfns::gfn__zz, irho,isigma) = z;

		// 1st derivative coefficient gridfns X_ud
		p.gridfn(nominal_gfns::gfn__X_ud_11, irho,isigma)
			= p.partial_rho_wrt_x(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_ud_12, irho,isigma)
			= p.partial_rho_wrt_y(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_ud_13, irho,isigma)
			= p.partial_rho_wrt_z(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_ud_21, irho,isigma)
			= p.partial_sigma_wrt_x(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_ud_22, irho,isigma)
			= p.partial_sigma_wrt_y(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_ud_23, irho,isigma)
			= p.partial_sigma_wrt_z(x,y,z);

		// 2nd derivative coefficient gridfns X_udd
		p.gridfn(nominal_gfns::gfn__X_udd_111, irho,isigma)
			= p.partial2_rho_wrt_xx(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_udd_112, irho,isigma)
			= p.partial2_rho_wrt_xy(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_udd_113, irho,isigma)
			= p.partial2_rho_wrt_xz(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_udd_122, irho,isigma)
			= p.partial2_rho_wrt_yy(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_udd_123, irho,isigma)
			= p.partial2_rho_wrt_yz(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_udd_133, irho,isigma)
			= p.partial2_rho_wrt_zz(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_udd_211, irho,isigma)
			= p.partial2_sigma_wrt_xx(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_udd_212, irho,isigma)
			= p.partial2_sigma_wrt_xy(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_udd_213, irho,isigma)
			= p.partial2_sigma_wrt_xz(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_udd_222, irho,isigma)
			= p.partial2_sigma_wrt_yy(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_udd_223, irho,isigma)
			= p.partial2_sigma_wrt_yz(x,y,z);
		p.gridfn(nominal_gfns::gfn__X_udd_233, irho,isigma)
			= p.partial2_sigma_wrt_zz(x,y,z);
		}
		}
	}
}
	  }

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

//
// This function interpolates the Cactus $g_{ij}$ and $K_{ij}$, and
// the spatial derivatives $\partial_k g_{ij}$, to the trial horizon
// surface position given by h.
//
// Inputs (angular gridfns, on ghosted grid):
// ... defined on ghosted grid
// ... only values on nominal grid are actually used as input
//	h				# shape of trial surface
//
// Inputs (angular gridfns, all on the nominal grid):
//	xx,yy,zz			# xyz positions of grid points
//
// Inputs (Cactus 3-D gridfns):
//	gxx,gxy,gxz,gyy,gyz,gzz		# 3-metric $g_{ij}$
//	kxx,kxy,kxz,kyy,kyz,kzz		# extrinsic curvature $K_{ij}$
//
// Inputs (angular gridfns, all on the nominal grid):
//	## computed directly from h
//	xx,yy,zz			# xyz positions
//
// Outputs (angular gridfns, all on the nominal grid):
//	g_dd_{11,12,13,22,23,33}			# $g_{ij}$
//	K_dd_{11,12,13,22,23,33}			# $K_{ij}$
//	partial_d_g_dd_{1,2,3}{11,12,13,22,23,33}	# $\partial_k g_{ij}$
//
// On the first call this function also modifies the interpolator
// parameter table.
//
namespace {
void interpolate_geometry(patch_system& ps,
			  const struct cactus_grid_info& cgi,
			  const struct geometry_interpolator_info& gii)
{
CCTK_VInfo(CCTK_THORNSTRING,
	   "      interpolate $g_{ij}$, $K_{ij}$ from Cactus 3-D grid");

int status;

const int N_interp_points = ps.N_grid_points();
const int interp_coords_type_code = CCTK_VARIABLE_REAL;
const void* const interp_coords[N_GRID_DIMS]
  = {
    static_cast<const void*>(ps.gridfn_data(nominal_gfns::gfn__xx)),
    static_cast<const void*>(ps.gridfn_data(nominal_gfns::gfn__yy)),
    static_cast<const void*>(ps.gridfn_data(nominal_gfns::gfn__zz)),
    };

const int N_INPUT_ARRAYS = 12;
const CCTK_INT input_array_type_codes[N_INPUT_ARRAYS]
	= {
	  // $g_{ij}$
	  CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL,
			      CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL,
						  CCTK_VARIABLE_REAL,
	    // $K_{ij}$
	  CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL,
			      CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL,
						  CCTK_VARIABLE_REAL,
	  };
const void* const input_arrays[N_INPUT_ARRAYS]
	= {
	  static_cast<const void*>(cgi.g_dd_11_data),
	  static_cast<const void*>(cgi.g_dd_12_data),
	  static_cast<const void*>(cgi.g_dd_13_data),
	  static_cast<const void*>(cgi.g_dd_22_data),
	  static_cast<const void*>(cgi.g_dd_23_data),
	  static_cast<const void*>(cgi.g_dd_33_data),
	  static_cast<const void*>(cgi.K_dd_11_data),
	  static_cast<const void*>(cgi.K_dd_12_data),
	  static_cast<const void*>(cgi.K_dd_13_data),
	  static_cast<const void*>(cgi.K_dd_22_data),
	  static_cast<const void*>(cgi.K_dd_23_data),
	  static_cast<const void*>(cgi.K_dd_33_data),
	  };

const int N_OUTPUT_ARRAYS = 30;

const CCTK_INT output_array_type_codes[N_OUTPUT_ARRAYS]
	= {
 // $g_{ij}$         $\partial_x g_{ij}$ $\partial_y g_{ij}$ $\partial_z g_{ij}$
 CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL,
 CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL,
 CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL,
 CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL,
 CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL,
 CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL,
 // $K_{ij}$
 CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL,
		     CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL,
					 CCTK_VARIABLE_REAL,
	  };
const CCTK_INT operand_indices[N_OUTPUT_ARRAYS]
	= {
	  0, 0, 0, 0,		// g_dd_11
	  1, 1, 1, 1,		// g_dd_12
	  2, 2, 2, 2,		// g_dd_13
	  3, 3, 3, 3,		// g_dd_22
	  4, 4, 4, 4,		// g_dd_23
	  5, 5, 5, 5,		// g_dd_33
	   6,  7,  8,		// K_dd_{11,12,13}
	       9, 10,		// K_dd_{22,23}
		  11,		// K_dd_33
	  };
#define DERIV(x)	x
const CCTK_INT operation_codes[N_OUTPUT_ARRAYS]
	= {
	  DERIV(0), DERIV(1), DERIV(2), DERIV(3),	// g_dd_11
	  DERIV(0), DERIV(1), DERIV(2), DERIV(3),	// g_dd_12
	  DERIV(0), DERIV(1), DERIV(2), DERIV(3),	// g_dd_13
	  DERIV(0), DERIV(1), DERIV(2), DERIV(3),	// g_dd_22
	  DERIV(0), DERIV(1), DERIV(2), DERIV(3),	// g_dd_23
	  DERIV(0), DERIV(1), DERIV(2), DERIV(3),	// g_dd_33
	  DERIV(0), DERIV(0), DERIV(0),			// K_dd_{11,12,13}
		    DERIV(0), DERIV(0),			// K_dd_{22,23}
			      DERIV(0),			// K_dd_{33}
	  };
void* const output_arrays[N_OUTPUT_ARRAYS]
  = {
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__g_dd_11)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_111)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_211)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_311)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__g_dd_12)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_112)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_212)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_312)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__g_dd_13)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_113)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_213)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_313)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__g_dd_22)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_122)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_222)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_322)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__g_dd_23)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_123)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_223)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_323)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__g_dd_33)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_133)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_233)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__partial_d_g_dd_333)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__K_dd_11)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__K_dd_12)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__K_dd_13)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__K_dd_22)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__K_dd_23)),
    static_cast<void*>(ps.gridfn_data(nominal_gfns::gfn__K_dd_33)),
    };

bool first_time = true;
if (first_time)
   then {
	// store derivative info in interpolator parameter table
	first_time = false;
	CCTK_VInfo(CCTK_THORNSTRING,
		   "         setting up derivative info for interpolator");

	status = Util_TableSetIntArray(gii.param_table_handle,
				       N_OUTPUT_ARRAYS, operand_indices,
				       "operand_indices");
	if (status < 0)
	   then error_exit(ERROR_EXIT,
"***** interpolate_geometry():\n"
"        unable to set operand_indices in interpolator parameter table!\n"
"        Util_TableSetIntArray() status=%d\n"
,
			   status);				/*NOTREACHED*/

	status = Util_TableSetIntArray(gii.param_table_handle,
				       N_OUTPUT_ARRAYS, operation_codes,
				       "operation_codes");
	if (status < 0)
	   then error_exit(ERROR_EXIT,
"***** interpolate_geometry():\n"
"        unable to set operation_codes in interpolator parameter table!\n"
"        Util_TableSetIntArray() status=%d\n"
,
			   status);				/*NOTREACHED*/
	}

CCTK_VInfo(CCTK_THORNSTRING,
	   "         calling interpolator (%d points)",
	   N_interp_points);
status = CCTK_InterpLocalUniform(N_GRID_DIMS,
				 gii.operator_handle, gii.param_table_handle,
				 cgi.coord_origin, cgi.coord_delta,
				 N_interp_points,
				    interp_coords_type_code,
				    interp_coords,
				 N_INPUT_ARRAYS,
				    cgi.gridfn_dims,
				    input_array_type_codes,
				    input_arrays,
				 N_OUTPUT_ARRAYS,
				    output_array_type_codes,
				    output_arrays);
if (status == CCTK_ERROR_INTERP_POINT_X_RANGE)
   then {
	// FIXME: should look at interpolator output table entries
	//	  and report *which* point is out-of-range
	error_exit(ERROR_EXIT,
"***** interpolate_geometry():\n"
"        point out of range when interpolating geometry info from 3-D grid!\n"
"        ==> the trial horizon surface is (at least partially)\n"
"            outside the grid and/or in an excised region\n");	/*NOTREACHED*/
	}
if (status < 0)
   then error_exit(ERROR_EXIT,
"***** interpolate_geometry(): error return from interpolator!\n"
"        CCTK_InterpLocalUniform() status=%d\n"
,
		   status);					/*NOTREACHED*/
}
	  }

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

//
// This function computes H(h) by a mixture of algebraic operations
// and (rho,sigma) finite differencing, on the angular grid.
//
namespace {
void compute_H(patch_system& ps)
{
CCTK_VInfo(CCTK_THORNSTRING, "      computing H(h)");

	for (int pn = 0 ; pn < ps.N_patches() ; ++pn)
	{
	patch& p = ps.ith_patch(pn);

		for (int irho = p.min_irho() ; irho <= p.max_irho() ; ++irho)
		{
		for (int isigma = p.min_isigma() ;
		     isigma <= p.max_isigma() ;
		     ++isigma)
		{
		// "call" the Maple-generated code
		// ... each file has a separate set of temporary variables,
		//     and so must be inside its own set of { } braces
		#include "cg.hh"
		  {
		#include "cg/inverse_metric.c"
		  }
		  {
		#include "cg/extrinsic_curvature_trace_raise.c"
		  }
		  {
		#include "cg/inverse_metric_gradient.c"
		  }
		  {
		#include "cg/metric_det_gradient.c"
		  }
		  {
		#include "cg/horizon_function.c"
		  }
		}
		}
	}
}
	  }