aboutsummaryrefslogtreecommitdiff
path: root/internal.h
blob: 19e6d7ff7286a69a8b34bedda90d6584dbae2941 (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
/*
 * Copyright 2014-2015 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 BRILL_DATA_INTERNAL_H
#define BRILL_DATA_INTERNAL_H

#include <stddef.h>

#include "brill_data.h"

#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define SQR(x) ((x) * (x))

#define ARRAY_ELEMS(x) (sizeof(x) / sizeof(x[0]))
#define ALIGN(x, a) (((x)+(a)-1)&~((a)-1))

#define REQ_ALIGNMENT(x) (32 / sizeof(x))

/*
 * small number to avoid r=0 singularities
 */
#define EPS 1E-08

/* a set of basis functions */
typedef struct BasisSet {
    /* evaluate the idx-th basis function at the specified point*/
    double (*eval)      (double coord, int idx, double sf);
    /* evaluate the first derivative of the idx-th basis function at the specified point*/
    double (*eval_diff1)(double coord, int idx, double sf);
    /* evaluate the second derivative of the idx-th basis function at the specified point*/
    double (*eval_diff2)(double coord, int idx, double sf);
    /**
     * Get the idx-th collocation point for the specified order.
     * idx runs from 0 to order - 1 (inclusive)
     */
    double (*colloc_point)(int order, int idx, double sf);
} BasisSet;

typedef struct QFunc {
    double         (*q)(const BDContext *bd, double rho, double z);
    double    (*dq_rho)(const BDContext *bd, double rho, double z);
    double      (*dq_z)(const BDContext *bd, double rho, double z);
    double   (*d2q_rho)(const BDContext *bd, double rho, double z);
    double     (*d2q_z)(const BDContext *bd, double rho, double z);
    double (*d2q_rho_z)(const BDContext *bd, double rho, double z);
} QFunc;

typedef struct BDPriv {
    const BasisSet *basis[2];
    const QFunc    *q_func;

    int nb_colloc_points[2];
    int nb_coeffs[2];

    double *coeffs;
    ptrdiff_t coeffs_stride;
} BDPriv;

#define NB_COEFFS(s)        (s->nb_coeffs[0]        * s->nb_coeffs[1])
#define NB_COLLOC_POINTS(s) (s->nb_colloc_points[0] * s->nb_colloc_points[1])

extern const BasisSet bdi_sb_even_basis;

extern const QFunc bdi_q_func_gundlach;
extern const QFunc bdi_q_func_eppley;

int bdi_solve(BDContext *bd);

void bdi_log(const BDContext *bd, int level, const char *fmt, ...);
void bdi_log_default_callback(const BDContext *bd, int level,
                              const char *fmt, va_list vl);

#endif // BRILL_DATA_INTERNAL_H