ASCOT5
Loading...
Searching...
No Matches
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
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
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}
Main header file for ASCOT5.
double real
Definition ascot5.h:85
Spline interpolation library.
@ NATURALBC
Definition interp.h:37
@ PERIODICBC
Definition interp.h:38
int linint1D_eval_f(real *f, linint1D_data *str, real x)
Evaluate interpolated value of 1D scalar field.
Definition linint1D.c:47
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
Linear interpolation library.
real fmod(real x, real y)
Compute the modulus of two real numbers.
Definition math.c:22
Header file for math.c.
1D interpolation struct.
Definition linint.h:21
real x_max
Definition linint.h:25
real x_min
Definition linint.h:24
real * c
Definition linint.h:27
real x_grid
Definition linint.h:26