ASCOT5
Loading...
Searching...
No Matches
plasma_1Dt.c
Go to the documentation of this file.
1
5#include <stdio.h>
6#include <stdlib.h>
7#include <math.h>
8#include "../ascot5.h"
9#include "../error.h"
10#include "../consts.h"
11#include "../print.h"
12#include "plasma_1Dt.h"
13
14
37 real** offload_array) {
38
39 int n_rho = offload_data->n_rho;
40 int n_time = offload_data->n_time;
41 int n_ions = offload_data->n_species -1;
42 print_out(VERBOSE_IO, "\n1D plasma profiles (P_1Dt)\n");
44 "Min rho = %1.2le, Max rho = %1.2le,"
45 " Number of rho grid points = %d\n",
46 (*offload_array)[0], (*offload_array)[n_rho-1], n_rho);
48 "Min time = %1.2le, Max time = %1.2le,"
49 " Number of time points = %d\n",
50 (*offload_array)[n_rho], (*offload_array)[n_rho+n_time-1],n_time);
52 "Number of ion species = %d\n", n_ions);
54 "Species Z/A charge [e]/mass [amu] "
55 "Density [m^-3] at Min/Max rho(t=t0)"
56 " Temperature [eV] at Min/Max rho(t=t0)\n");
57 for(int i=0; i < n_ions; i++) {
59 " %3d /%3d %3d /%7.3f %1.2le/%1.2le "
60 " %1.2le/%1.2le \n",
61 offload_data->znum[i], offload_data->anum[i],
62 (int)round(offload_data->charge[i+1]/CONST_E),
63 offload_data->mass[i+1]/CONST_U,
64 (*offload_array)[2*n_rho*n_time + n_time + n_rho*(3+i)],
65 (*offload_array)[2*n_rho*n_time + n_time + n_rho*(4+i) - 1],
66 (*offload_array)[n_time + n_rho*2] / CONST_E,
67 (*offload_array)[n_time + n_rho*3-1] / CONST_E);
68 }
70 "[electrons] %3d /%7.3f %1.2le/%1.2le "
71 "%1.2le/%1.2le \n",
73 (*offload_array)[2*n_rho*n_time + n_time + n_rho*1],
74 (*offload_array)[2*n_rho*n_time + n_time + n_rho*2 - 1],
75 (*offload_array)[n_time + n_rho*1] / CONST_E,
76 (*offload_array)[n_time + n_rho*2 - 1] / CONST_E);
77 real quasineutrality = 0;
78 for(int k = 0; k <n_rho; k++) {
79 real ele_qdens =
80 (*offload_array)[2*n_rho*n_time + n_time + n_rho + k] * CONST_E;
81 real ion_qdens = 0;
82 for(int i=0; i < n_ions; i++) {
83 int idx = 2*n_rho*n_time + n_time + n_rho * (2+1) + k;
84 ion_qdens +=
85 (*offload_array)[idx] * offload_data->charge[i+1];
86 }
87 quasineutrality = fmax( quasineutrality,
88 fabs( 1 - ion_qdens / ele_qdens ) );
89 }
90 print_out(VERBOSE_IO, "Quasi-neutrality is (electron / ion charge density)"
91 " %.2f\n", 1+quasineutrality);
92 return 0;
93}
94
104 real** offload_array) {
105 free(*offload_array);
106 *offload_array = NULL;
107}
108
121 plasma_1Dt_offload_data* offload_data,
122 real* offload_array) {
123
124 pls_data->n_rho = offload_data->n_rho;
125 pls_data->n_time = offload_data->n_time;
126 pls_data->n_species = offload_data->n_species;
127
128 for(int i = 0; i < pls_data->n_species; i++) {
129 pls_data->mass[i] = offload_data->mass[i];
130 pls_data->charge[i] = offload_data->charge[i];
131 }
132 pls_data->rho = &offload_array[0];
133 pls_data->time = &offload_array[pls_data->n_rho];
134 pls_data->temp = &offload_array[pls_data->n_rho+pls_data->n_time];
135 pls_data->dens = &offload_array[pls_data->n_rho+pls_data->n_time
136 +2*pls_data->n_rho*pls_data->n_time];
137}
138
153a5err plasma_1Dt_eval_temp(real* temp, real rho, real t, int species,
154 plasma_1Dt_data* pls_data) {
155
156 real temp_dens[MAX_SPECIES], temp_temp[MAX_SPECIES];
157
158 a5err err = plasma_1Dt_eval_densandtemp(temp_dens, temp_temp, rho, t,
159 pls_data);
160
161 *temp = temp_temp[species];
162
163 return err;
164
165}
166
181a5err plasma_1Dt_eval_dens(real* dens, real rho, real t, int species,
182 plasma_1Dt_data* pls_data) {
183 real temp_dens[MAX_SPECIES], temp_temp[MAX_SPECIES];
184
185 a5err err = plasma_1Dt_eval_densandtemp(temp_dens, temp_temp, rho, t,
186 pls_data);
187
188 *dens = temp_dens[species];
189
190 return err;
191
192}
193
209 plasma_1Dt_data* pls_data) {
210
211 a5err err = 0;
212 if(rho < pls_data->rho[0]) {
214 }
215 else if(rho >= pls_data->rho[pls_data->n_rho-1]) {
217 }
218 else {
219 int i_rho = 0;
220 while(i_rho < pls_data->n_rho-1 && pls_data->rho[i_rho] <= rho) {
221 i_rho++;
222 }
223 i_rho--;
224
225 real t_rho = (rho - pls_data->rho[i_rho])
226 / (pls_data->rho[i_rho+1] - pls_data->rho[i_rho]);
227
228 int i_time = 0;
229 while(i_time < pls_data->n_time-1 && pls_data->time[i_time] <= t) {
230 i_time++;
231 }
232 i_time--;
233
234 real t_time = (t - pls_data->time[i_time])
235 / (pls_data->time[i_time+1] - pls_data->time[i_time]);
236
237 if(i_time < 0) {
238 /* time < t[0], use first profile */
239 i_time = 0;
240 t_time = 0;
241 }
242 else if(i_time >= pls_data->n_time-2) {
243 /* time > t[n_time-1], use last profile */
244 i_time = pls_data->n_time-2;
245 t_time = 1;
246 }
247
248 for(int i = 0; i < pls_data->n_species; i++) {
249 real p11, p12, p21, p22, p1, p2;
250
251 p11 = pls_data->dens[i_time*pls_data->n_species*pls_data->n_rho
252 + i*pls_data->n_rho
253 + i_rho];
254 p12 = pls_data->dens[i_time*pls_data->n_species*pls_data->n_rho
255 + i*pls_data->n_rho
256 + i_rho + 1];
257 p21 = pls_data->dens[(i_time+1)*pls_data->n_species*pls_data->n_rho
258 + i*pls_data->n_rho
259 + i_rho];
260 p22 = pls_data->dens[(i_time+1)*pls_data->n_species*pls_data->n_rho
261 + i*pls_data->n_rho
262 + i_rho + 1];
263
264 p1 = p11 + t_rho * (p12 - p11);
265 p2 = p21 + t_rho * (p22 - p21);
266
267 dens[i] = p1 + t_time * (p2 - p1);
268
269 if(i < 2) {
270 /* Electron and ion temperature */
271 p11 = pls_data->temp[i_time*2*pls_data->n_rho
272 + i*pls_data->n_rho
273 +i_rho];
274 p12 = pls_data->temp[i_time*2*pls_data->n_rho
275 + i*pls_data->n_rho
276 + i_rho + 1];
277 p21 = pls_data->temp[(i_time+1)*2*pls_data->n_rho
278 + i*pls_data->n_rho
279 + i_rho];
280 p22 = pls_data->temp[(i_time+1)*2*pls_data->n_rho
281 + i*pls_data->n_rho
282 + i_rho + 1];
283
284 p1 = p11 + t_rho * (p12 - p11);
285 p2 = p21 + t_rho * (p22 - p21);
286
287 temp[i] = p1 + t_time * (p2 - p1);
288 }
289 else {
290 /* Temperature is same for all ion species */
291 temp[i] = temp[1];
292 }
293 }
294 }
295
296 return err;
297}
Main header file for ASCOT5.
double real
Definition ascot5.h:85
#define MAX_SPECIES
Maximum number of plasma species.
Definition ascot5.h:95
Header file containing physical and mathematical constants.
#define CONST_U
Atomic mass unit in kilograms [kg]
Definition consts.h:29
#define CONST_M_E
Electron mass [kg]
Definition consts.h:38
#define CONST_E
Elementary charge [C]
Definition consts.h:32
Error module for ASCOT5.
unsigned long int a5err
Simulation error flag.
Definition error.h:17
@ EF_PLASMA_1D
Definition error.h:40
@ 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
Header file for math.c.
void plasma_1Dt_free_offload(plasma_1Dt_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
Definition plasma_1Dt.c:103
int plasma_1Dt_init_offload(plasma_1Dt_offload_data *offload_data, real **offload_array)
Initialize 1Dt plasma data and check inputs.
Definition plasma_1Dt.c:36
a5err plasma_1Dt_eval_densandtemp(real *dens, real *temp, real rho, real t, plasma_1Dt_data *pls_data)
Evaluate plasma density and temperature for all species.
Definition plasma_1Dt.c:208
a5err plasma_1Dt_eval_temp(real *temp, real rho, real t, int species, plasma_1Dt_data *pls_data)
Evaluate plasma temperature.
Definition plasma_1Dt.c:153
a5err plasma_1Dt_eval_dens(real *dens, real rho, real t, int species, plasma_1Dt_data *pls_data)
Evaluate plasma density.
Definition plasma_1Dt.c:181
void plasma_1Dt_init(plasma_1Dt_data *pls_data, plasma_1Dt_offload_data *offload_data, real *offload_array)
Initialize magnetic field data struct on target.
Definition plasma_1Dt.c:120
Header file for plasma_1Dt.c.
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
Definition print.h:31
@ VERBOSE_IO
Definition print.h:20
1D plasma parameters on the target
Definition plasma_1Dt.h:28
real charge[MAX_SPECIES]
Definition plasma_1Dt.h:34
real mass[MAX_SPECIES]
Definition plasma_1Dt.h:33
1D plasma parameters that will be offloaded to target
Definition plasma_1Dt.h:13
int znum[MAX_SPECIES]
Definition plasma_1Dt.h:21
real mass[MAX_SPECIES]
Definition plasma_1Dt.h:18
real charge[MAX_SPECIES]
Definition plasma_1Dt.h:19
int anum[MAX_SPECIES]
Definition plasma_1Dt.h:20