aboutsummaryrefslogtreecommitdiff
path: root/eval_metric.c
blob: f499e32097ee9e6d1a3fd19eceb6d197dd80c506 (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
/*
 * Copyright 2016 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/>.
 */

#include <math.h>
#include <stddef.h>
#include <string.h>

#include "brill_data.h"
#include "internal.h"

#define GRID(arr) (arr[i * nb_coords_rho + j])


/* φφ components */

#define COMP phiphi

#define DIFF 0
#define DO_EVAL val = SQR(rrho) * psi4
#include "eval_metric_template.c"
#undef DIFF
#undef DO_EVAL

#define DIFF 3
#define DO_EVAL val = 4 * SQR(rrho) * psi3 * GRID(psi[3])
#include "eval_metric_template.c"
#undef DIFF
#undef DO_EVAL

#define DIFF 6
#define DO_EVAL val = 4 * SQR(rrho) * (GRID(psi[6]) * psi3 + 3 * psi2 * SQR(GRID(psi[3])))
#include "eval_metric_template.c"
#undef DIFF
#undef DO_EVAL

#define DIFF 1
#define DO_EVAL val = 2 * rrho * psi4 + 4 * SQR(rrho) * psi3 * GRID(psi[1])
#include "eval_metric_template.c"
#undef DIFF
#undef DO_EVAL

#define DIFF 4
#define DO_EVAL val =  8 * rrho * psi3 * GRID(psi[3]) +\
                      12 * SQR(rrho) * psi2 * GRID(psi[3]) * GRID(psi[1]) +\
                       4 * SQR(rrho) * psi3 * GRID(psi[4])
#include "eval_metric_template.c"
#undef DIFF
#undef DO_EVAL

#define DIFF 2
#define DO_EVAL val =  4 * SQR(rrho) * psi3 * GRID(psi[2]) +\
                      12 * SQR(rrho * ppsi * GRID(psi[1])) +\
                      16 * rrho * psi3 * GRID(psi[1]) + 2 * psi4
#include "eval_metric_template.c"
#undef DIFF
#undef DO_EVAL

#undef COMP

/* ρρ components */
#define COMP rhorho

#define DIFF 0
#define DO_EVAL val = base
#include "eval_metric_template.c"
#undef DIFF
#undef DO_EVAL

#define DIFF 3
#define DO_EVAL val = 2 * base * dqz
#include "eval_metric_template.c"
#undef DIFF
#undef DO_EVAL

#define DIFF 6
#define DO_EVAL val = 4 * SQR(dqz) * base + 2 * base * dq2z
#include "eval_metric_template.c"
#undef DIFF
#undef DO_EVAL

#define DIFF 1
#define DO_EVAL val = 2 * base * dqrho
#include "eval_metric_template.c"
#undef DIFF
#undef DO_EVAL

#define DIFF 4
#define DO_EVAL val = 4 * base * dqrho * dqz + 2 * base * dq2rho_z
#include "eval_metric_template.c"
#undef DIFF
#undef DO_EVAL

#define DIFF 2
#define DO_EVAL val = 4 * SQR(dqrho) * base + 2 * base * dq2rho
#include "eval_metric_template.c"
#undef DIFF
#undef DO_EVAL

#undef COMP

typedef void (*EvalMetricFunc)(const BDContext *bd, double *out, ptrdiff_t out_stride,
                               int nb_coords_rho, const double *rho,
                               int nb_coords_z,   const double *z,
                               double *psi[9], double *q[9]);

static const EvalMetricFunc eval_metric_phiphi[9] = {
    [0] = eval_metric_phiphi_0,
    [1] = eval_metric_phiphi_1,
    [2] = eval_metric_phiphi_2,
    [3] = eval_metric_phiphi_3,
    [4] = eval_metric_phiphi_4,
    [6] = eval_metric_phiphi_6,
};

static const EvalMetricFunc eval_metric_rhorho[9] = {
    [0] = eval_metric_rhorho_0,
    [1] = eval_metric_rhorho_1,
    [2] = eval_metric_rhorho_2,
    [3] = eval_metric_rhorho_3,
    [4] = eval_metric_rhorho_4,
    [6] = eval_metric_rhorho_6,
};

void bdi_eval_metric(const BDContext *bd,
                     const double *rho, int nb_coords_rho,
                     const double *z,   int nb_coords_z,
                     enum BDMetricComponent comp,
                     const unsigned int diff_order[2],
                     double *psi[9], double *q[9],
                     double *out, ptrdiff_t out_stride)
{
    int diff_idx = diff_order[0] * 3 + diff_order[1];
    const EvalMetricFunc *functab;

    if (comp != BD_METRIC_COMPONENT_RHORHO &&
        comp != BD_METRIC_COMPONENT_ZZ     &&
        comp != BD_METRIC_COMPONENT_PHIPHI) {
        memset(out, 0, out_stride * nb_coords_z * sizeof(*out));
        return;
    }

    functab = (comp == BD_METRIC_COMPONENT_PHIPHI) ?
              eval_metric_phiphi : eval_metric_rhorho;

    functab[diff_idx](bd, out, out_stride, nb_coords_rho, rho,
                      nb_coords_z, z, psi, q);
}