summaryrefslogtreecommitdiff
path: root/src/basis.c
blob: 5ea043ee53a4b05442465de41d3a8e9999194e69 (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
#include <math.h>

#include "maximal_slicing_axi.h"

static double sb_even_eval(double coord, int idx)
{
    double val = (coord == 0.0) ? M_PI_2 : atan(SCALE_FACTOR / fabs(coord));

    idx *= 2;   // even only

    return sin((idx + 1) * val);
}

static double sb_even_eval_diff1(double coord, int idx)
{
    double val = (coord == 0.0) ? M_PI_2 : atan(SCALE_FACTOR / fabs(coord));

    idx *= 2;   // even only

    return - SCALE_FACTOR * (idx + 1) * SGN(coord) * cos((idx + 1) * val) / (SQR(SCALE_FACTOR) + SQR(coord));
}

static double sb_even_eval_diff2(double coord, int idx)
{
    double val = (coord == 0.0) ? M_PI_2 : atan(SCALE_FACTOR / fabs(coord));

    idx *= 2;   // even only

    return SCALE_FACTOR * (idx + 1) * SGN(coord) * (2 * fabs(coord) * cos((idx + 1) * val) - SCALE_FACTOR * (idx + 1) * sin((idx + 1) * val)) / SQR(SQR(SCALE_FACTOR) + SQR(coord));
}

static double sb_even_colloc_point(int order, int idx)
{
    double t;

    idx = order - idx - 1;
    //order *= 2;

    //t = (idx + 2) * M_PI / (order + 4);
    t = (idx + 2) * M_PI / (2 * order + 2);
    return SCALE_FACTOR / tan(t);
}

const BasisSet msa_sb_even_basis = {
    .eval         = sb_even_eval,
    .eval_diff1   = sb_even_eval_diff1,
    .eval_diff2   = sb_even_eval_diff2,
    .colloc_point = sb_even_colloc_point,
};

static double tb_even_eval(double coord, int idx)
{
    double val = (coord == 0.0) ? M_PI_2 : atan(SCALE_FACTOR / fabs(coord));

    idx++;
    idx *= 2;   // even only

    return cos(idx * val) - 1.0;
}

static double tb_even_eval_diff1(double coord, int idx)
{
    double val = (coord == 0.0) ? M_PI_2 : atan(SCALE_FACTOR / fabs(coord));

    idx++;
    idx *= 2;   // even only

    return SCALE_FACTOR * idx * SGN(coord) * sin(idx * val) / (SQR(SCALE_FACTOR) + SQR(coord));
}

static double tb_even_eval_diff2(double coord, int idx)
{
    double val = (coord == 0.0) ? M_PI_2 : atan(SCALE_FACTOR / fabs(coord));

    idx++;
    idx *= 2;   // even only

    return -SCALE_FACTOR * idx * SGN(coord) * (2 * fabs(coord) * sin(idx * val) + SCALE_FACTOR * idx * cos(idx * val)) / SQR(SQR(SCALE_FACTOR) + SQR(coord));
}

static double tb_even_colloc_point(int order, int idx)
{
    double t;

    idx = order - idx - 1;
    //order *= 2;

    //t = (idx + 2) * M_PI / (order + 4);
    t = (idx + 3) * M_PI / (2 * (order + 2));
    return SCALE_FACTOR / tan(t);
}

const BasisSet msa_tb_even_basis = {
    .eval         = tb_even_eval,
    .eval_diff1   = tb_even_eval_diff1,
    .eval_diff2   = tb_even_eval_diff2,
    .colloc_point = tb_even_colloc_point,
};

static double full_eval(double coord, int idx)
{
    double val = (coord == 0.0) ? M_PI_2 : atan(SCALE_FACTOR / fabs(coord));
    int flag = idx & 1;

    idx /= 2;

    if (flag) return sin((2 * idx + 1) * 4 * val);
    else      return cos((2 * idx + 2) * 4 * val) - 1;
}

static double full_eval_diff1(double coord, int idx)
{
    double val = (coord == 0.0) ? M_PI_2 : atan(SCALE_FACTOR / fabs(coord));
    int flag = idx & 1;

    idx /= 2;

    if (flag) {
        idx = 2 * idx + 1;
        return -4 * idx * SCALE_FACTOR * cos(idx * 4 * val) / (SQR(SCALE_FACTOR) + SQR(coord));
    } else {
        idx = 2 * (idx + 1);
        return 4 * idx * SCALE_FACTOR * sin(idx * 4 * val) / (SQR(SCALE_FACTOR) + SQR(coord));
    }
}

static double full_eval_diff2(double coord, int idx)
{
    double val = (coord == 0.0) ? M_PI_2 : atan(SCALE_FACTOR / fabs(coord));
    int flag = idx & 1;

    idx /= 2;

    if (flag) {
        idx = 2 * idx + 1;
        return (16 * SQR(idx * SCALE_FACTOR) * cos(idx * 4 * val) - 4 * idx * SCALE_FACTOR * sin(idx * 4 * val) * 2 * coord) / SQR(SQR(SCALE_FACTOR) + SQR(coord));
    } else {
        idx = 2 * (idx + 1);
        return (-16 * SQR(idx * SCALE_FACTOR) * sin(idx * 4 * val) - 4 * idx * SCALE_FACTOR * cos(idx * 4 * val) * 2 * coord) / SQR(SQR(SCALE_FACTOR) + SQR(coord));
    }
}

static double full_colloc_point(int order, int idx)
{
    double t;

    idx = order - idx - 1;

    t = (idx + 0.5) * M_PI / (2 * order);

    return SCALE_FACTOR / tan(t);

}

const BasisSet msa_full_basis = {
    .eval         = full_eval,
    .eval_diff1   = full_eval_diff1,
    .eval_diff2   = full_eval_diff2,
    .colloc_point = full_colloc_point,
};

static double cheb_eval(double coord, int idx)
{
    return cos(2 * idx * acos(coord / SCALE_FACTOR));
}

static double cheb_eval_diff1(double coord, int idx)
{
    return 2 * idx * sin(2 * idx * acos(coord / SCALE_FACTOR)) / sqrt(SQR(SCALE_FACTOR) - SQR(coord));
}

static double cheb_eval_diff2(double coord, int idx)
{
    double t = acos(coord / SCALE_FACTOR);
    return 2 * idx * (cos(2 * idx * t) * 2 * idx / (SQR(SCALE_FACTOR) - SQR(coord)) + sin(2 * idx * t) * coord / pow(SQR(SCALE_FACTOR) - SQR(coord), 1.5));
}

static double cheb_colloc_point(int order, int idx)
{
    return SCALE_FACTOR * cos((idx + 0.01) * M_PI / (4 * order + 4));
}

const BasisSet msa_cheb_basis = {
    .eval       = cheb_eval,
    .eval_diff1 = cheb_eval_diff1,
    .eval_diff2 = cheb_eval_diff2,
    .colloc_point = cheb_colloc_point,
};