ASCOT5
Toggle main menu visibility
Loading...
Searching...
No Matches
linint
linint1D.c
Go to the documentation of this file.
1
5
#include <stdlib.h>
6
#include <
math.h
>
7
#include "
../ascot5.h
"
8
#include "
../math.h
"
9
#include "
../spline/interp.h
"
10
#include "
linint.h
"
11
22
void
linint1D_init
(
linint1D_data
* str,
real
* c,
23
int
n_x,
int
bc_x,
real
x_min,
real
x_max) {
24
25
real
x_grid = (x_max - x_min) / ( n_x - 1 * (bc_x ==
NATURALBC
) );
26
27
str->
n_x
= n_x;
28
str->
bc_x
= bc_x;
29
str->
x_min
= x_min;
30
str->
x_max
= x_max;
31
str->
x_grid
= x_grid;
32
str->
c
= c;
33
}
34
47
int
linint1D_eval_f
(
real
* f,
linint1D_data
* str,
real
x) {
48
49
/* Make sure periodic coordinates are within [max, min] region. */
50
if
(str->
bc_x
==
PERIODICBC
) {
51
x =
fmod
(x - str->
x_min
, str->
x_max
- str->
x_min
) + str->
x_min
;
52
x = x + (x < str->
x_min
) * (str->
x_max
- str->
x_min
);
53
}
54
55
/* index for x variable */
56
int
i_x = (x-str->
x_min
) / str->
x_grid
;
58
real
dx = ( x - (str->
x_min
+ i_x*str->
x_grid
)) / str->
x_grid
;
59
60
int
x1 = 1;
/* Index jump one x forward */
61
62
int
err = 0;
63
64
/* Enforce periodic BC or check that the coordinate is within the grid. */
65
if
( str->
bc_x
==
PERIODICBC
&& i_x == str->
n_x
-1 ) {
66
x1 = -(str->
n_x
-1)*x1;
67
}
68
else
if
( str->
bc_x
==
NATURALBC
&& !(x >= str->
x_min
&& x <= str->x_max) ) {
69
err = 1;
70
}
71
72
if
(!err) {
73
*f = str->
c
[i_x]*(1 - dx) + str->
c
[i_x+x1]*dx;
74
}
75
return
err;
76
}
ascot5.h
Main header file for ASCOT5.
real
double real
Definition
ascot5.h:85
interp.h
Spline interpolation library.
NATURALBC
@ NATURALBC
Definition
interp.h:37
PERIODICBC
@ PERIODICBC
Definition
interp.h:38
linint.h
Linear interpolation library.
linint1D_eval_f
int linint1D_eval_f(real *f, linint1D_data *str, real x)
Evaluate interpolated value of 1D scalar field.
Definition
linint1D.c:47
linint1D_init
void linint1D_init(linint1D_data *str, real *c, int n_x, int bc_x, real x_min, real x_max)
Initialize linear interpolation struct for scalar 1D data.
Definition
linint1D.c:22
fmod
real fmod(real x, real y)
Compute the modulus of two real numbers.
Definition
math.c:22
math.h
Header file for math.c.
linint1D_data
1D interpolation struct.
Definition
linint.h:21
linint1D_data::n_x
int n_x
Definition
linint.h:22
linint1D_data::bc_x
int bc_x
Definition
linint.h:23
linint1D_data::x_max
real x_max
Definition
linint.h:25
linint1D_data::x_min
real x_min
Definition
linint.h:24
linint1D_data::c
real * c
Definition
linint.h:27
linint1D_data::x_grid
real x_grid
Definition
linint.h:26
Generated on
for ASCOT5 by
1.18.0