ASCOT5
Loading...
Searching...
No Matches
plasma.c
Go to the documentation of this file.
1
23#include <stdio.h>
24#include <stdlib.h>
25#include "ascot5.h"
26#include "error.h"
27#include "print.h"
28#include "plasma.h"
29#include "plasma/plasma_1D.h"
30#include "plasma/plasma_1DS.h"
31#include "consts.h"
32
51 real** offload_array) {
52 int err = 0;
53
54 switch(offload_data->type) {
55
56 case plasma_type_1D:
57 err = plasma_1D_init_offload(&(offload_data->plasma_1D),
58 offload_array);
59 offload_data->offload_array_length =
60 offload_data->plasma_1D.offload_array_length;
61 break;
62
63 case plasma_type_1Dt:
64 err = plasma_1Dt_init_offload(&(offload_data->plasma_1Dt),
65 offload_array);
66 offload_data->offload_array_length =
67 offload_data->plasma_1Dt.offload_array_length;
68 break;
69
70 case plasma_type_1DS:
71 err = plasma_1DS_init_offload(&(offload_data->plasma_1DS),
72 offload_array);
73 offload_data->offload_array_length =
74 offload_data->plasma_1DS.offload_array_length;
75 break;
76
77 default:
78 /* Unregonized input. Produce error. */
79 print_err("Error: Unregonized plasma data type.");
80 err = 1;
81 break;
82 }
83 if(!err) {
84 print_out(VERBOSE_IO, "Estimated memory usage %.1f MB\n",
85 offload_data->offload_array_length
86 * sizeof(real) / (1024.0*1024.0) );
87 }
88
89 return err;
90}
91
103 real** offload_array) {
104 switch(offload_data->type) {
105 case plasma_type_1D:
107 &(offload_data->plasma_1D), offload_array);
108 break;
109
110 case plasma_type_1Dt:
112 &(offload_data->plasma_1Dt), offload_array);
113 break;
114
115 case plasma_type_1DS:
117 &(offload_data->plasma_1DS), offload_array);
118 break;
119 }
120}
121
135int plasma_init(plasma_data* pls_data, plasma_offload_data* offload_data,
136 real* offload_array) {
137 int err = 0;
138 switch(offload_data->type) {
139 case plasma_type_1D:
140 plasma_1D_init(&(pls_data->plasma_1D),
141 &(offload_data->plasma_1D), offload_array);
142 break;
143
144 case plasma_type_1Dt:
145 plasma_1Dt_init(&(pls_data->plasma_1Dt),
146 &(offload_data->plasma_1Dt), offload_array);
147 break;
148
149 case plasma_type_1DS:
150 plasma_1DS_init(&(pls_data->plasma_1DS),
151 &(offload_data->plasma_1DS), offload_array);
152 break;
153
154 default:
155 /* Unregonized input. Produce error. */
156 print_err("Error: Unregonized plasma data type.");
157 err = 1;
158 break;
159 }
160 pls_data->type = offload_data->type;
161
162 return err;
163}
164
184a5err plasma_eval_temp(real* temp, real rho, real r, real phi, real z, real t,
185 int species, plasma_data* pls_data) {
186 a5err err = 0;
187
188 switch(pls_data->type) {
189 case plasma_type_1D:
190 err = plasma_1D_eval_temp(temp, rho, species,
191 &(pls_data->plasma_1D));
192 break;
193
194 case plasma_type_1Dt:
195 err = plasma_1Dt_eval_temp(temp, rho, t, species,
196 &(pls_data->plasma_1Dt));
197 break;
198
199 case plasma_type_1DS:
200 err = plasma_1DS_eval_temp(temp, rho, species,
201 &(pls_data->plasma_1DS));
202 break;
203 }
204 if(err) {
205 /* In case of error, return some reasonable value to avoid further
206 complications */
207 temp[0] = 1e20;
208 }
209
210 return err;
211}
212
232a5err plasma_eval_dens(real* dens, real rho, real r, real phi, real z, real t,
233 int species, plasma_data* pls_data) {
234 a5err err = 0;
235
236 switch(pls_data->type) {
237 case plasma_type_1D:
238 err = plasma_1D_eval_dens(dens, rho, species,
239 &(pls_data->plasma_1D));
240 break;
241
242 case plasma_type_1Dt:
243 err = plasma_1Dt_eval_dens(dens, rho, t, species,
244 &(pls_data->plasma_1Dt));
245 break;
246
247 case plasma_type_1DS:
248 err = plasma_1DS_eval_dens(dens, rho, species,
249 &(pls_data->plasma_1DS));
250 break;
251 }
252
253 if(err) {
254 /* In case of error, return some reasonable value to avoid further
255 complications */
256 dens[0] = 1e20;
257 }
258 return err;
259}
260
281 real r, real phi, real z, real t,
282 plasma_data* pls_data) {
283 a5err err = 0;
284
285 switch(pls_data->type) {
286 case plasma_type_1D:
287 err = plasma_1D_eval_densandtemp(dens, temp,
288 rho, &(pls_data->plasma_1D));
289 break;
290
291 case plasma_type_1Dt:
292 err = plasma_1Dt_eval_densandtemp(dens, temp,
293 rho, t, &(pls_data->plasma_1Dt));
294 break;
295
296 case plasma_type_1DS:
297 err = plasma_1DS_eval_densandtemp(dens, temp,
298 rho, &(pls_data->plasma_1DS));
299 break;
300
301 default:
302 /* Unregonized input. Produce error. */
303 err = error_raise( ERR_UNKNOWN_INPUT, __LINE__, EF_PLASMA );
304 break;
305 }
306
307 if(err) {
308 /* In case of error, return some reasonable values to avoid further
309 complications */
310 for(int i=0; i<MAX_SPECIES; i++) {
311 dens[i] = 1e20;
312 temp[i] = 1e3;
313 }
314 }
315
316 return err;
317}
318
332 int n = 0;
333 switch(pls_data->type) {
334 case plasma_type_1D:
335 n = pls_data->plasma_1D.n_species;
336 break;
337
338 case plasma_type_1Dt:
339 n = pls_data->plasma_1Dt.n_species;
340 break;
341
342 case plasma_type_1DS:
343 n = pls_data->plasma_1DS.n_species;
344 break;
345 }
346
347 return n;
348}
349
362 const real* mass = NULL;
363 switch(pls_data->type) {
364 case plasma_type_1D:
365 mass = pls_data->plasma_1D.mass;
366 break;
367
368 case plasma_type_1Dt:
369 mass = pls_data->plasma_1Dt.mass;
370 break;
371
372 case plasma_type_1DS:
373 mass = pls_data->plasma_1DS.mass;
374 break;
375 }
376
377 return mass;
378}
379
392 const real* charge = NULL;
393 switch(pls_data->type) {
394 case plasma_type_1D:
395 charge = pls_data->plasma_1D.charge;
396 break;
397
398 case plasma_type_1Dt:
399 charge = pls_data->plasma_1Dt.charge;
400 break;
401
402 case plasma_type_1DS:
403 charge = pls_data->plasma_1DS.charge;
404 break;
405 }
406
407 return charge;
408}
409
420 const int* znum = NULL;
421 switch(pls_data->type) {
422 case plasma_type_1D:
423 znum = pls_data->plasma_1D.znum;
424 break;
425
426 case plasma_type_1Dt:
427 znum = pls_data->plasma_1Dt.znum;
428 break;
429
430 case plasma_type_1DS:
431 znum = pls_data->plasma_1DS.znum;
432 break;
433 }
434
435 return znum;
436}
437
448 const int* anum = NULL;
449 switch(pls_data->type) {
450 case plasma_type_1D:
451 anum = pls_data->plasma_1D.anum;
452 break;
453
454 case plasma_type_1Dt:
455 anum = pls_data->plasma_1Dt.anum;
456 break;
457
458 case plasma_type_1DS:
459 anum = pls_data->plasma_1DS.anum;
460 break;
461 }
462
463 return anum;
464}
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.
Error module for ASCOT5.
unsigned long int a5err
Simulation error flag.
Definition error.h:17
@ EF_PLASMA
Definition error.h:42
@ ERR_UNKNOWN_INPUT
Definition error.h:64
static DECLARE_TARGET_SIMD a5err error_raise(error_type type, int line, error_file file)
Raise a new error.
Definition error.h:86
const real * plasma_get_species_mass(plasma_data *pls_data)
Get mass of all plasma species.
Definition plasma.c:361
const int * plasma_get_species_znum(plasma_data *pls_data)
Get charge number of ion species.
Definition plasma.c:419
int plasma_get_n_species(plasma_data *pls_data)
Get the number of plasma species.
Definition plasma.c:331
const real * plasma_get_species_charge(plasma_data *pls_data)
Get charge of all plasma species.
Definition plasma.c:391
a5err plasma_eval_temp(real *temp, real rho, real r, real phi, real z, real t, int species, plasma_data *pls_data)
Evaluate plasma temperature.
Definition plasma.c:184
int plasma_init_offload(plasma_offload_data *offload_data, real **offload_array)
Load plasma data and prepare parameters.
Definition plasma.c:50
a5err plasma_eval_densandtemp(real *dens, real *temp, real rho, real r, real phi, real z, real t, plasma_data *pls_data)
Evaluate plasma density and temperature for all species.
Definition plasma.c:280
int plasma_init(plasma_data *pls_data, plasma_offload_data *offload_data, real *offload_array)
Initialize plasma data struct on target.
Definition plasma.c:135
a5err plasma_eval_dens(real *dens, real rho, real r, real phi, real z, real t, int species, plasma_data *pls_data)
Evaluate plasma density.
Definition plasma.c:232
const int * plasma_get_species_anum(plasma_data *pls_data)
Get atomic mass number of ion species.
Definition plasma.c:447
void plasma_free_offload(plasma_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
Definition plasma.c:102
Header file for plasma.c.
@ plasma_type_1D
Definition plasma.h:25
@ plasma_type_1Dt
Definition plasma.h:26
@ plasma_type_1DS
Definition plasma.h:27
void plasma_1DS_free_offload(plasma_1DS_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
Definition plasma_1DS.c:174
a5err plasma_1DS_eval_densandtemp(real *dens, real *temp, real rho, plasma_1DS_data *plasma_data)
Evaluate plasma density and temperature for all species.
Definition plasma_1DS.c:300
a5err plasma_1DS_eval_dens(real *dens, real rho, int species, plasma_1DS_data *plasma_data)
Evaluate plasma density.
Definition plasma_1DS.c:265
int plasma_1DS_init_offload(plasma_1DS_offload_data *offload_data, real **offload_array)
Initialize 1DS plasma data and check inputs.
Definition plasma_1DS.c:56
a5err plasma_1DS_eval_temp(real *temp, real rho, int species, plasma_1DS_data *plasma_data)
Evaluate plasma temperature.
Definition plasma_1DS.c:234
void plasma_1DS_init(plasma_1DS_data *plasma_data, plasma_1DS_offload_data *offload_data, real *offload_array)
Initialize magnetic field data struct on target.
Definition plasma_1DS.c:191
Header file for plasma_1DS.c.
void plasma_1D_init(plasma_1D_data *pls_data, plasma_1D_offload_data *offload_data, real *offload_array)
Initialize magnetic field data struct on target.
Definition plasma_1D.c:114
a5err plasma_1D_eval_dens(real *dens, real rho, int species, plasma_1D_data *pls_data)
Evaluate plasma density.
Definition plasma_1D.c:185
a5err plasma_1D_eval_densandtemp(real *dens, real *temp, real rho, plasma_1D_data *pls_data)
Evaluate plasma density and temperature for all species.
Definition plasma_1D.c:225
void plasma_1D_free_offload(plasma_1D_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
Definition plasma_1D.c:97
a5err plasma_1D_eval_temp(real *temp, real rho, int species, plasma_1D_data *pls_data)
Evaluate plasma temperature.
Definition plasma_1D.c:145
int plasma_1D_init_offload(plasma_1D_offload_data *offload_data, real **offload_array)
Initialize 1D plasma data and check inputs.
Definition plasma_1D.c:39
Header file for plasma_1D.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
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
Definition print.h:31
@ VERBOSE_IO
Definition print.h:20
#define print_err(...)
Print to standard error.
Definition print.h:42
real mass[MAX_SPECIES]
Definition plasma_1DS.h:33
real charge[MAX_SPECIES]
Definition plasma_1DS.h:34
int anum[MAX_SPECIES]
Definition plasma_1DS.h:35
int znum[MAX_SPECIES]
Definition plasma_1DS.h:36
real charge[MAX_SPECIES]
Definition plasma_1D.h:32
int anum[MAX_SPECIES]
Definition plasma_1D.h:33
real mass[MAX_SPECIES]
Definition plasma_1D.h:31
int znum[MAX_SPECIES]
Definition plasma_1D.h:34
real charge[MAX_SPECIES]
Definition plasma_1Dt.h:34
int znum[MAX_SPECIES]
Definition plasma_1Dt.h:36
int anum[MAX_SPECIES]
Definition plasma_1Dt.h:35
real mass[MAX_SPECIES]
Definition plasma_1Dt.h:33
Plasma simulation data.
Definition plasma.h:57
plasma_1D_data plasma_1D
Definition plasma.h:59
plasma_1Dt_data plasma_1Dt
Definition plasma.h:60
plasma_1DS_data plasma_1DS
Definition plasma.h:61
plasma_type type
Definition plasma.h:58
Plasma offload data.
Definition plasma.h:40
int offload_array_length
Definition plasma.h:45
plasma_1DS_offload_data plasma_1DS
Definition plasma.h:44
plasma_1D_offload_data plasma_1D
Definition plasma.h:42
plasma_1Dt_offload_data plasma_1Dt
Definition plasma.h:43
plasma_type type
Definition plasma.h:41