aboutsummaryrefslogtreecommitdiff
path: root/teukolsky_data.h
blob: 786554e5c13dc49050a2e912fea157d5cdd9e248 (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
/*
 * Copyright 2017 Anton Khirnov <anton@khirnov.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef TEUKOLSKY_DATA_H
#define TEUKOLSKY_DATA_H

#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>

/**
 * API usage:
 *
 * First, allocate the solver context with td_context_alloc(). All interaction
 * with the solver is done through this context.
 *
 * Fill any fields in the context that are described as settable by the caller.
 * Call td_solve() to solve the equation determined by the option values.
 *
 * The metric/extrinsic curvature can be evaluated with td_eval_metric()/td_eval_curv().
 *
 * Finally, free the solver context with td_context_free().
 */

/**
 * Identifies the specific initial data family to use.
 */
enum TDFamily {
    /**
     * Time-antisymmetric initial data with a cubic radial term multiplied by an
     * exponential and a quadrupole angular term.
     * Similar to that used in Abrahams&Evans PhysRevD v49,n8 (1994).
     * Conformally flat spatial metric.
     *  r       /   x         x  3 \        /    x  2  \
     * K  =  a | 3 ---  - 2 (---)   | * exp| - (---)    | sin(2θ)
     *  θ       \   L         L    /        \    L     /
     */
    TD_FAMILY_TIME_ANTISYM_CUBIC = 0,
    /**
     * Time-antisymmetric initial data with a linear radial term multiplied by
     * an exponential and a quadrupole angular term.
     * Conformally flat spatial metric.
     *  r       x       /    x  2  \
     * K  = a  ---  exp| - (---)    | sin(2θ)
     *  θ       L       \    L     /
     */
    TD_FAMILY_TIME_ANTISYM_LINEAR,
};

typedef struct TDContext {
    /**
     *  Solver internals, not to be accessed by the caller
     */
    void *priv;

    /********************************
     *  options, set by the caller  *
     ********************************/

    /**
     * A callback that will be used to print diagnostic messages.
     *
     * Defaults to fprintf(stderr, ...)
     */
    void (*log_callback)(const struct TDContext *td, int level,
                         const char *fmt, va_list);

    /**
     * Arbitrary user data, e.g. to be used by the log callback.
     */
    void *opaque;

    /********************************
     *  initial data parameters     *
     ********************************/

    /**
     * The amplitude in the I function.
     * Defaults to 1.
     */
    double amplitude;

    /********************************
     *        solver options        *
     ********************************/

    /**
     * The number of basis functions in each direction.
     * [0] - radial, [1] - angular
     */
    unsigned int nb_coeffs[2];

    /**
     * The scaling factor used in the basis functions.
     * [0] - radial, [1] - angular
     */
    double basis_scale_factor[2];

    /**
     * Maximum number of Newton iterations.
     */
    unsigned int max_iter;

    /**
     * Absolute tolerance. The solver is deemed to have converged
     * after maximum difference between iterations is below this bound.
     */
    double atol;

    /**
     * Number of threads to use for parallelization. Set to 0 to automatically
     * detect according to the number of CPU cores.
     */
    unsigned int nb_threads;

    double *coeffs[3];

    unsigned int solution_branch;

    enum TDFamily family;
} TDContext;

/**
 * Allocate and initialize the solver.
 */
TDContext *td_context_alloc(void);

/**
 * Free the solver and everything associated with it.
 */
void td_context_free(TDContext **td);

/**
 * Solve the equation for the conformal factor ψ and export the expansion coefficients in the
 * context.
 *
 * @return >= 0 on success, a negative error code on failure
 */
int td_solve(TDContext *td, double *coeffs_init[3]);

/**
 * Evaluate the conformal factor ψ at the specified points in spherical
 * coordinates { r, θ, φ } (since the spacetime is axially symmetric, φ is
 * disregarded).
 *
 * @param td the solver context
 * @param nb_coords number of elements in the r and theta arrays
 * @param r values of r coordinates
 * @param theta values of θ coordinates
 * @param diff_order order of the derivatives of the metric to evaluate. The
 *   first element specifies the derivative wrt r, the second
 *   wrt θ. I.e. diff_order[i] = { 0, 0 } evaluates ψ itself,
 *   diff_order = { 0, 1 } evaluates ∂ψ/∂θ etc.
 * @param out a nb_coords-sized array into which the values of the ψ will be
 *   written. out[i] is the value of ψ at the spacetime point { r[i], θ[i], 0 }
 *
 * @return >= 0 on success, a negative error code on failure.
 */
int td_eval_psi(const TDContext *td,
                size_t nb_coords, const double *r, const double *theta,
                const unsigned int diff_order[2],
                double *out);
/**
 * Same as td_eval_psi(), except K_{r}^r ('rr' component of the mixed-index
 * extrinsic curvature tensor) is evaluated.
 */
int td_eval_krr(const TDContext *td,
                size_t nb_coords, const double *r, const double *theta,
                const unsigned int diff_order[2],
                double *out);
/**
 * Same as td_eval_psi(), except K_{φ}^φ ('φφ' component of the mixed-index
 * extrinsic curvature tensor) is evaluated.
 */
int td_eval_kpp(const TDContext *td,
                size_t nb_coords, const double *r, const double *theta,
                const unsigned int diff_order[2],
                double *out);
/**
 * Same as td_eval_psi(), except K_{r}^θ ('rθ' component of the mixed-index
 * extrinsic curvature tensor) is evaluated.
 */
int td_eval_krt(const TDContext *td,
                size_t nb_coords, const double *r, const double *theta,
                const unsigned int diff_order[2],
                double *out);
/**
 * Compute the values of lapse that would make the spacetime slice maximal.
 * Parameters are the same as for td_eval_psi().
 */
int td_eval_lapse(const TDContext *td,
                  size_t nb_coords, const double *r, const double *theta,
                  const unsigned int diff_order[2],
                  double *out);

#endif /* TEUKOLSKY_DATA_H */