ASCOT5
Loading...
Searching...
No Matches
N0_3D.c
Go to the documentation of this file.
1
5#include <stdlib.h>
6#include <stdio.h>
7#include <math.h>
8#include <string.h>
9#include "../math.h"
10#include "../ascot5.h"
11#include "../error.h"
12#include "../print.h"
13#include "N0_3D.h"
14#include "../linint/linint.h"
15
22 int n_r, real r_min, real r_max,
23 int n_phi, real phi_min, real phi_max,
24 int n_z, real z_min, real z_max,
25 int n_species, int* anum, int* znum, int* maxwellian,
26 real* density, real* temperature) {
27 data->n_species = n_species;
28 data->anum = (int*) malloc(n_species * sizeof(int));
29 data->znum = (int*) malloc(n_species * sizeof(int));
30 data->maxwellian = (int*) malloc(n_species * sizeof(int));
31 data->n0 = (linint3D_data*) malloc( n_species * sizeof(linint3D_data) );
32 data->t0 = (linint3D_data*) malloc( n_species * sizeof(linint3D_data) );
33 for(int i = 0; i < data->n_species; i++) {
34 data->anum[i] = anum[i];
35 data->znum[i] = znum[i];
36 data->maxwellian[i] = maxwellian[i];
37
38 real* c = (real*) malloc(n_r * n_phi * n_z * sizeof(real));
39 for(int i = 0; i < n_r * n_phi * n_z; i++) {
40 c[i] = density[i];
41 }
42 linint3D_init(&data->n0[i], c, n_r, n_phi, n_z,
44 r_min, r_max, phi_min, phi_max, z_min, z_max);
45 c = (real*) malloc(n_r * n_phi * n_z * sizeof(real));
46 for(int i = 0; i < n_r * n_phi * n_z; i++) {
47 c[i] = temperature[i];
48 }
49 linint3D_init(&data->t0[i], c, n_r, n_phi, n_z,
51 r_min, r_max, phi_min, phi_max, z_min, z_max);
52 }
53 print_out(VERBOSE_IO, "\n3D neutral density and temperature (N0_3D)\n");
54 print_out(VERBOSE_IO, "Grid: nR = %4.d Rmin = %3.3f Rmax = %3.3f\n",
55 n_r,
56 r_min, r_max);
57 print_out(VERBOSE_IO, " nz = %4.d zmin = %3.3f zmax = %3.3f\n",
58 n_z,
59 z_min, z_max);
60 print_out(VERBOSE_IO, " nphi = %4.d phimin = %3.3f phimax = %3.3f\n",
61 n_phi,
62 phi_min, phi_max);
64 " Number of neutral species = %d\n",
65 data->n_species);
66 print_out(VERBOSE_IO, "Species Z/A (Maxwellian)\n");
67 for(int i=0; i < data->n_species; i++) {
69 " %3d/%3d (%1d) \n",
70 data->znum[i], data->anum[i], data->maxwellian[i]);
71 }
72
73 return 0;
74}
75
82 free(data->anum);
83 free(data->znum);
84 free(data->maxwellian);
85 for(int i = 0; i < data->n_species; i++) {
86 free(data->n0->c);
87 free(data->t0->c);
88 }
89}
90
97 //TODO: Implement
98}
99
114a5err N0_3D_eval_n0(real* n0, real r, real phi, real z, N0_3D_data* ndata) {
115 a5err err = 0;
116 int interperr = 0; /* If error happened during interpolation */
117 for(int i=0; i<ndata->n_species; i++) {
118 interperr += linint3D_eval_f(&n0[i], &ndata->n0[i], r, phi, z);
119 }
120
121 if(interperr) {
122 return error_raise(ERR_INPUT_EVALUATION, __LINE__, EF_N0_3D);
123 }
124
125 return err;
126}
127
142a5err N0_3D_eval_t0(real* t0, real r, real phi, real z, N0_3D_data* ndata) {
143 a5err err = 0;
144 int interperr = 0; /* If error happened during interpolation */
145 for(int i=0; i<ndata->n_species; i++) {
146 interperr += linint3D_eval_f(&t0[i], &ndata->t0[i], r, phi, z);
147 }
148
149 if(interperr) {
150 return error_raise(ERR_INPUT_EVALUATION, __LINE__, EF_N0_3D);
151 }
152
153 return err;
154}
155
164 return ndata->n_species;
165}
int N0_3D_init(N0_3D_data *data, int n_r, real r_min, real r_max, int n_phi, real phi_min, real phi_max, int n_z, real z_min, real z_max, int n_species, int *anum, int *znum, int *maxwellian, real *density, real *temperature)
Initialize neutral data.
Definition N0_3D.c:21
a5err N0_3D_eval_n0(real *n0, real r, real phi, real z, N0_3D_data *ndata)
Evaluate neutral density.
Definition N0_3D.c:114
int N0_3D_get_n_species(N0_3D_data *ndata)
Return number of neutral species.
Definition N0_3D.c:163
a5err N0_3D_eval_t0(real *t0, real r, real phi, real z, N0_3D_data *ndata)
Evaluate neutral temperature.
Definition N0_3D.c:142
void N0_3D_offload(N0_3D_data *data)
Offload data to the accelerator.
Definition N0_3D.c:96
void N0_3D_free(N0_3D_data *data)
Free allocated resources.
Definition N0_3D.c:81
Header file for N0_3D.c.
Main header file for ASCOT5.
double real
Definition ascot5.h:85
Error module for ASCOT5.
unsigned long int a5err
Simulation error flag.
Definition error.h:17
@ EF_N0_3D
Definition error.h:34
@ ERR_INPUT_EVALUATION
Definition error.h:63
static DECLARE_TARGET_SIMD a5err error_raise(error_type type, int line, error_file file)
Raise a new error.
Definition error.h:86
@ NATURALBC
Definition interp.h:37
@ PERIODICBC
Definition interp.h:38
Linear interpolation library.
DECLARE_TARGET_END int linint3D_eval_f(real *f, linint3D_data *str, real x, real y, real z)
Evaluate interpolated value of 3D scalar field.
Definition linint3D.c:70
void linint3D_init(linint3D_data *str, real *c, int n_x, int n_y, int n_z, int bc_x, int bc_y, int bc_z, real x_min, real x_max, real y_min, real y_max, real z_min, real z_max)
Initialize linear interpolation struct for scalar 3D data.
Definition linint3D.c:29
Header file for math.c.
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
Definition print.h:31
@ VERBOSE_IO
Definition print.h:20
3D neutral parameters on the target
Definition N0_3D.h:14
int * maxwellian
Definition N0_3D.h:18
linint3D_data * t0
Definition N0_3D.h:21
int n_species
Definition N0_3D.h:15
int * anum
Definition N0_3D.h:16
linint3D_data * n0
Definition N0_3D.h:20
int * znum
Definition N0_3D.h:17
3D interpolation struct.
Definition linint.h:50
real * c
Definition linint.h:66