34 int n_x,
int n_y,
int bc_x,
int bc_y,
44 x_grid = (x_max - x_min) / ( n_x - 1 * (bc_x ==
NATURALBC) );
51 y_grid = (y_max - y_min) / ( n_y - 1 * (bc_y ==
NATURALBC) );
58 real* f_x = malloc(n_x*
sizeof(
real));
59 real* f_y = malloc(n_y*
sizeof(
real));
60 real* c_x = malloc(n_x*NSIZE_COMP1D*
sizeof(
real));
61 real* c_y = malloc(n_y*NSIZE_COMP1D*
sizeof(
real));
63 if(f_x == NULL || f_y == NULL || c_x == NULL || c_y == NULL) {
72 for(
int i_y=0; i_y<n_y; i_y++) {
74 for(
int i_x=0; i_x<n_x; i_x++) {
75 f_x[i_x] = f[i_y*n_x+i_x];
78 for(
int i_x=0; i_x<n_x; i_x++) {
79 c[i_y*n_x*4 + i_x*4 ] = c_x[i_x*2];
80 c[i_y*n_x*4 + i_x*4 + 1] = c_x[i_x*2+1] / (x_grid*x_grid);
86 for(
int i_x=0; i_x<n_x; i_x++) {
89 for(
int i_y=0; i_y<n_y; i_y++) {
90 f_y[i_y] = f[i_y*n_x + i_x];
93 for(
int i_y=0; i_y<n_y; i_y++) {
94 c[i_y*n_x*4+i_x*4+2] = c_y[i_y*2+1]/(y_grid*y_grid);
98 for(
int i_y=0; i_y<n_y; i_y++) {
99 f_y[i_y] = c[i_y*n_x*4 + i_x*4 + 1];
102 for(
int i_y=0; i_y<n_y; i_y++) {
103 c[i_y*n_x*4 + i_x*4 + 3] = c_y[i_y*2 + 1] / (y_grid*y_grid);
131 int n_x,
int n_y,
int bc_x,
int bc_y,
138 real x_grid = (x_max - x_min) / ( n_x - 1 * (bc_x ==
NATURALBC) );
139 real y_grid = (y_max - y_min) / ( n_y - 1 * (bc_y ==
NATURALBC) );
175 int n_x,
int n_y,
int bc_x,
int bc_y,
177 real* c = (
real*) malloc(n_y*n_x*NSIZE_COMP2D*
sizeof(
real));
218 real dx3 = dx * (dx*dx - 1.0);
220 real dxi3 = dxi * (dxi*dxi - 1.0);
228 real dy3 = dy * (dy*dy - 1.0);
230 real dyi3 = dyi * (dyi*dyi - 1.0);
233 int n = i_y*str->
n_x*4+i_x*4;
241 x1 = -(str->
n_x-1)*x1;
247 y1 = -(str->
n_y-1)*y1;
255 dxi*(dyi*str->
c[n]+dy*str->
c[n+y1])
256 +dx*(dyi*str->
c[n+x1]+dy*str->
c[n+y1+x1]))
258 dxi3*(dyi*str->
c[n+1] + dy*str->
c[n+y1+1])
259 +dx3*(dyi*str->
c[n+x1+1] + dy*str->
c[n+y1+x1+1]))
261 dxi*(dyi3*str->
c[n+2]+dy3*str->
c[n+y1+2])
262 +dx*(dyi3*str->
c[n+x1+2]+dy3*str->
c[n+y1+x1+2]))
264 dxi3*(dyi3*str->
c[n+3]+dy3*str->
c[n+y1+3])
265 +dx3*(dyi3*str->
c[n+x1+3]+dy3*str->
c[n+y1+x1+3]));
310 real dx3 = dx * (dx*dx - 1.0);
311 real dx3dx = 3*dx*dx - 1;
313 real dxi3 = dxi * (dxi*dxi - 1.0);
314 real dxi3dx = -3*dxi*dxi + 1;
324 real dy3 = dy * (dy*dy - 1.0);
325 real dy3dy = 3*dy*dy - 1;
327 real dyi3 = dyi * (dyi*dyi - 1.0);
328 real dyi3dy = -3*dyi*dyi + 1;
333 int n = i_y*str->
n_x*4+i_x*4;
341 x1 = -(str->
n_x-1)*x1;
347 y1 = -(str->
n_y-1)*y1;
356 dxi*(dyi*str->
c[n]+dy*str->
c[n+y1])
357 +dx*(dyi*str->
c[n+x1]+dy*str->
c[n+y1+x1]))
359 dxi3*(dyi*str->
c[n+1] + dy*str->
c[n+y1+1])
360 +dx3*(dyi*str->
c[n+x1+1] + dy*str->
c[n+y1+x1+1]))
362 dxi*(dyi3*str->
c[n+2]+dy3*str->
c[n+y1+2])
363 +dx*(dyi3*str->
c[n+x1+2]+dy3*str->
c[n+y1+x1+2]))
365 dxi3*(dyi3*str->
c[n+3]+dy3*str->
c[n+y1+3])
366 +dx3*(dyi3*str->
c[n+x1+3]+dy3*str->
c[n+y1+x1+3]));
370 -(dyi*str->
c[n] +dy*str->
c[n+y1])
371 +(dyi*str->
c[n+x1]+dy*str->
c[n+y1+x1]))
373 dxi3dx*(dyi*str->
c[n+1] +dy*str->
c[n+y1+1])
374 +dx3dx*(dyi*str->
c[n+x1+1]+dy*str->
c[n+y1+x1+1]))
376 -(dyi3*str->
c[n+2] +dy3*str->
c[n+y1+2])
377 +(dyi3*str->
c[n+x1+2]+dy3*str->
c[n+y1+x1+2]))
379 dxi3dx*(dyi3*str->
c[n+3] +dy3*str->
c[n+y1+3])
380 +dx3dx*(dyi3*str->
c[n+x1+3]+dy3*str->
c[n+y1+x1+3]));
384 dxi*(-str->
c[n] +str->
c[n+y1])
385 +dx*(-str->
c[n+x1]+str->
c[n+y1+x1]))
387 dxi3*(-str->
c[n+1] +str->
c[n+y1+1])
388 +dx3*(-str->
c[n+x1+1]+str->
c[n+y1+x1+1]))
390 dxi*(dyi3dy*str->
c[n+2] +dy3dy*str->
c[n+y1+2])
391 +dx*(dyi3dy*str->
c[n+x1+2]+dy3dy*str->
c[n+y1+x1+2]))
393 dxi3*(dyi3dy*str->
c[n+3] +dy3dy*str->
c[n+y1+3])
394 +dx3*(dyi3dy*str->
c[n+x1+3]+dy3dy*str->
c[n+y1+x1+3]));
398 dxi*(dyi*str->
c[n+1] +dy*str->
c[n+y1+1])
399 +dx*(dyi*str->
c[n+x1+1]+dy*str->
c[n+y1+x1+1]))
401 dxi*(dyi3*str->
c[n+3] +dy3*str->
c[n+y1+3])
402 +dx*(dyi3*str->
c[n+x1+3]+dy3*str->
c[n+y1+x1+3]));
406 dxi*(dyi*str->
c[n+2] +dy*str->
c[n+y1+2])
407 +dx*(dyi*str->
c[n+x1+2]+dy*str->
c[n+y1+x1+2]))
409 dxi3*(dyi*str->
c[n+3] +dy*str->
c[n+y1+3])
410 +dx3*(dyi*str->
c[n+x1+3]+dy*str->
c[n+y1+x1+3]));
414 str->
c[n] -str->
c[n+y1]
415 -str->
c[n+x1]+str->
c[n+y1+x1])
417 dxi3dx*(-str->
c[n+1] +str->
c[n+y1+1])
418 +dx3dx*(-str->
c[n+x1+1]+str->
c[n+y1+x1+1]))
420 -(dyi3dy*str->
c[n+2] +dy3dy*str->
c[n+y1+2])
421 +(dyi3dy*str->
c[n+x1+2]+dy3dy*str->
c[n+y1+x1+2]))
423 dxi3dx*(dyi3dy*str->
c[n+3] +dy3dy*str->
c[n+y1+3])
424 +dx3dx*(dyi3dy*str->
c[n+x1+3]+dy3dy*str->
c[n+y1+x1+3]));
Main header file for ASCOT5.
unsigned long int a5err
Simulation error flag.
int interp2Dcomp_setup(interp2D_data *str, real *f, int n_x, int n_y, int bc_x, int bc_y, real x_min, real x_max, real y_min, real y_max)
Set up splines to interpolate 2D scalar data.
int interp2Dcomp_init_coeff(real *c, real *f, int n_x, int n_y, int bc_x, int bc_y, real x_min, real x_max, real y_min, real y_max)
Calculate bicubic spline interpolation coefficients for scalar 2D data.
void interp2Dcomp_init_spline(interp2D_data *str, real *c, int n_x, int n_y, int bc_x, int bc_y, real x_min, real x_max, real y_min, real y_max)
Initialize a bicubic spline.
a5err interp2Dcomp_eval_f(real *f, interp2D_data *str, real x, real y)
Evaluate interpolated value of a 2D field.
a5err interp2Dcomp_eval_df(real *f_df, interp2D_data *str, real x, real y)
Evaluate interpolated value and 1st and 2nd derivatives of 2D field.
Spline interpolation library.
real fmod(real x, real y)
Compute the modulus of two real numbers.
Header file for splineexpl.c and splinecomp.c.
void splinecomp(real *f, int n, int bc, real *c)
Calculate compact cubic spline interpolation coefficients in 1D.
Bicubic interpolation struct.