aboutsummaryrefslogtreecommitdiff
path: root/brill_data.h
blob: 125970beae555caf1541342f95de5b44fd6300fb (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
/*
 * Copyright 2014 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 <stdint.h>
#include <stddef.h>

enum BDQFuncType {
    /**
     * q(ρ, z) = A ρ^2 exp(-ρ^2 - z^2)
     */
    BD_Q_FUNC_GUNDLACH,
    /**
     * q(ρ, z) = A ρ^2 / (1 + r^n); where r^2 = ρ^2 + z^2
     */
    BD_Q_FUNC_EPPLEY,
};

typedef struct BDContext {
    /**
     *  private data
     */
    void *priv;

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

    /**
     * The choice of the q function in the exponent.
     * Defaults to BD_Q_FUNC_GUNDLACH.
     */
    enum BDQFuncType q_func_type;
    /**
     * The amplitude in the q function.
     * Defaults to 1.
     */
    double amplitude;
    /**
     * For BD_Q_FUNC_EPPLEY, the power in the denominator.
     * Must be >= 4.
     * Defaults to 5.
     */
    unsigned int eppley_n;

    /* the solver parameters */

    /**
     * The number of basis functions in the ρ direction.
     * Defaults to 80.
     */
    unsigned int nb_coeffs_rho;
    /**
     * The number of basis functions in the z direction. 0 means the same as
     * nb_coeffs_rho. Defaults to 0.
     * Using values other than 0 or nb_coeffs_rho is unsupported for now.
     */
    unsigned int nb_coeffs_z;

    /**
     * The difference between the number of collocation points and the number
     * of basis functions in the rho direction. I.e. the number of collocation
     * points used will be nb_coeffs_rho + overdet_rho.
     * Defaults to 0;
     */
    int overdet_rho;
    /**
     * Same as overdet_rho, but for the z direction.
     */
    int overdet_z;

    /**
     * The difference between the index of the collocation grid used for the ρ
     * direction and nb_coeffs_rho. The 'extra' collocation points furthest from
     * the origin are discarded.
     * Defaults to 3.
     */
    unsigned int colloc_grid_offset_rho;
    /**
     * Same as colloc_grid_offset_rho, but for the z direction.
     */
    unsigned int colloc_grid_offset_z;

    /**
     * The scaling factor used in the basis functions in the ρ direction.
     * Defaults to 3.
     */
    double basis_scale_factor_rho;
    /**
     * Same as basis_scale_factor_rho, but for the z direction
     */
    double basis_scale_factor_z;

    /**********
     * output *
     **********/
    /**
     * The coefficients of the solution expanded in the basis.
     * The ρ index increases along rows, z along columns.
     *
     * The data is owned and managed by this library and is read-only for
     * the caller.
     */
    double *psi_minus1_coeffs;
    /**
     * The number of array elements between two rows.
     */
    ptrdiff_t stride;
} BDContext;

BDContext *bd_context_alloc(void);

void bd_context_free(BDContext **bd);

int bd_solve(BDContext *bd);