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
25 real** offload_array) {
26 int N0_size = offload_data->n_r * offload_data->n_phi * offload_data->n_z;
27 int T0_size = offload_data->n_r * offload_data->n_phi * offload_data->n_z;
28
29 offload_data->offload_array_length = offload_data->n_species * N0_size
30 + offload_data->n_species * T0_size;
31
32 print_out(VERBOSE_IO, "\n3D neutral density and temperature (N0_3D)\n");
33 print_out(VERBOSE_IO, "Grid: nR = %4.d Rmin = %3.3f Rmax = %3.3f\n",
34 offload_data->n_r,
35 offload_data->r_min, offload_data->r_max);
36 print_out(VERBOSE_IO, " nz = %4.d zmin = %3.3f zmax = %3.3f\n",
37 offload_data->n_z,
38 offload_data->z_min, offload_data->z_max);
39 print_out(VERBOSE_IO, " nphi = %4.d phimin = %3.3f phimax = %3.3f\n",
40 offload_data->n_phi,
41 offload_data->phi_min, offload_data->phi_max);
43 " Number of neutral species = %d\n",
44 offload_data->n_species);
46 "Species Z/A (Maxwellian)\n");
47 for(int i=0; i < offload_data->n_species; i++) {
49 " %3d/%3d (%1d) \n",
50 (int)(offload_data->znum[i]),
51 (int)(offload_data->anum[i]),
52 (int)(offload_data->maxwellian[i]));
53 }
54
55 return 0;
56}
57
67 real** offload_array) {
68 free(*offload_array);
69 *offload_array = NULL;
70}
71
86void N0_3D_init(N0_3D_data* ndata, N0_3D_offload_data* offload_data,
87 real* offload_array) {
88 int N0_size = offload_data->n_r * offload_data->n_phi * offload_data->n_z;
89 int T0_size = offload_data->n_r * offload_data->n_phi * offload_data->n_z;
90 ndata->n_species = offload_data->n_species;
91 for(int i = 0; i < offload_data->n_species; i++) {
92 ndata->anum[i] = offload_data->anum[i];
93 ndata->znum[i] = offload_data->znum[i];
94 ndata->maxwellian[i] = offload_data->maxwellian[i];
95
97 &ndata->n0[i], &offload_array[i * N0_size],
98 offload_data->n_r, offload_data->n_phi, offload_data->n_z,
100 offload_data->r_min, offload_data->r_max,
101 offload_data->phi_min, offload_data->phi_max,
102 offload_data->z_min, offload_data->z_max);
103
105 &ndata->t0[i],
106 &offload_array[i * T0_size + offload_data->n_species * N0_size],
107 offload_data->n_r, offload_data->n_phi, offload_data->n_z,
109 offload_data->r_min, offload_data->r_max,
110 offload_data->phi_min, offload_data->phi_max,
111 offload_data->z_min, offload_data->z_max);
112 }
113}
114
129a5err N0_3D_eval_n0(real* n0, real r, real phi, real z, N0_3D_data* ndata) {
130 a5err err = 0;
131 int interperr = 0; /* If error happened during interpolation */
132 for(int i=0; i<ndata->n_species; i++) {
133 interperr += linint3D_eval_f(&n0[i], &ndata->n0[i], r, phi, z);
134 }
135
136 if(interperr) {
137 return error_raise(ERR_INPUT_EVALUATION, __LINE__, EF_N0_3D);
138 }
139
140 return err;
141}
142
157a5err N0_3D_eval_t0(real* t0, real r, real phi, real z, N0_3D_data* ndata) {
158 a5err err = 0;
159 int interperr = 0; /* If error happened during interpolation */
160 for(int i=0; i<ndata->n_species; i++) {
161 interperr += linint3D_eval_f(&t0[i], &ndata->t0[i], r, phi, z);
162 }
163
164 if(interperr) {
165 return error_raise(ERR_INPUT_EVALUATION, __LINE__, EF_N0_3D);
166 }
167
168 return err;
169}
170
179 return ndata->n_species;
180}
a5err N0_3D_eval_n0(real *n0, real r, real phi, real z, N0_3D_data *ndata)
Evaluate neutral density.
Definition N0_3D.c:129
int N0_3D_get_n_species(N0_3D_data *ndata)
Return number of neutral species.
Definition N0_3D.c:178
void N0_3D_free_offload(N0_3D_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
Definition N0_3D.c:66
a5err N0_3D_eval_t0(real *t0, real r, real phi, real z, N0_3D_data *ndata)
Evaluate neutral temperature.
Definition N0_3D.c:157
void N0_3D_init(N0_3D_data *ndata, N0_3D_offload_data *offload_data, real *offload_array)
Initialize neutral data on target.
Definition N0_3D.c:86
int N0_3D_init_offload(N0_3D_offload_data *offload_data, real **offload_array)
Initialize offload data.
Definition N0_3D.c:24
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:34
linint3D_data t0[MAX_SPECIES]
Definition N0_3D.h:42
linint3D_data n0[MAX_SPECIES]
Definition N0_3D.h:40
int znum[MAX_SPECIES]
Definition N0_3D.h:37
int n_species
Definition N0_3D.h:35
int maxwellian[MAX_SPECIES]
Definition N0_3D.h:38
int anum[MAX_SPECIES]
Definition N0_3D.h:36
3D neutral parameters on the host
Definition N0_3D.h:13
int znum[MAX_SPECIES]
Definition N0_3D.h:25
int maxwellian[MAX_SPECIES]
Definition N0_3D.h:26
int offload_array_length
Definition N0_3D.h:28
int anum[MAX_SPECIES]
Definition N0_3D.h:24