ASCOT5
Loading...
Searching...
No Matches
plasma_1D.c
Go to the documentation of this file.
1
8#include <stdio.h>
9#include <stdlib.h>
10#include <math.h>
11#include "../ascot5.h"
12#include "../error.h"
13#include "../consts.h"
14#include "../print.h"
15#include "plasma_1D.h"
16
17
40 real** offload_array) {
41
42 int n_rho = offload_data->n_rho;
43 int n_ions = offload_data->n_species -1;
44 print_out(VERBOSE_IO, "\n1D plasma profiles (P_1D)\n");
46 "Min rho = %1.2le, Max rho = %1.2le,"
47 " Number of rho grid points = %d,"
48 " Number of ion species = %d\n",
49 (*offload_array)[0], (*offload_array)[n_rho-1], n_rho, n_ions);
51 "Species Z/A charge [e]/mass [amu] Density [m^-3] at Min/Max rho"
52 " Temperature [eV] at Min/Max rho\n");
53 for(int i=0; i < n_ions; i++) {
55 " %3d /%3d %3d /%7.3f %1.2le/%1.2le "
56 " %1.2le/%1.2le \n",
57 offload_data->znum[i], offload_data->anum[i],
58 (int)round(offload_data->charge[i+1]/CONST_E),
59 offload_data->mass[i+1]/CONST_U,
60 (*offload_array)[n_rho*(4+i)],
61 (*offload_array)[n_rho*(5+i) - 1],
62 (*offload_array)[n_rho*2] / CONST_E,
63 (*offload_array)[n_rho*3-1] / CONST_E);
64 }
66 "[electrons] %3d /%7.3f %1.2le/%1.2le "
67 " %1.2le/%1.2le \n",
69 (*offload_array)[n_rho*3],
70 (*offload_array)[n_rho*4 - 1],
71 (*offload_array)[n_rho] / CONST_E,
72 (*offload_array)[n_rho*2-1] / CONST_E);
73 real quasineutrality = 0;
74 for(int k = 0; k <n_rho; k++) {
75 real ele_qdens = (*offload_array)[n_rho*3 + k] * CONST_E;
76 real ion_qdens = 0;
77 for(int i=0; i < n_ions; i++) {
78 ion_qdens +=
79 (*offload_array)[n_rho*(4+i) + k] * offload_data->charge[i+1];
80 }
81 quasineutrality = fmax( quasineutrality,
82 fabs( 1 - ion_qdens / ele_qdens ) );
83 }
84 print_out(VERBOSE_IO, "Quasi-neutrality is (electron / ion charge density)"
85 " %.2f\n", 1+quasineutrality);
86 return 0;
87}
88
98 real** offload_array) {
99 free(*offload_array);
100 *offload_array = NULL;
101}
102
115 plasma_1D_offload_data* offload_data,
116 real* offload_array) {
117
118 pls_data->n_rho = offload_data->n_rho;
119 pls_data->n_species = offload_data->n_species;
120
121 for(int i = 0; i < pls_data->n_species; i++) {
122 pls_data->mass[i] = offload_data->mass[i];
123 pls_data->charge[i] = offload_data->charge[i];
124 pls_data->znum[i] = offload_data->znum[i];
125 pls_data->anum[i] = offload_data->anum[i];
126 }
127 pls_data->rho = &offload_array[0];
128 pls_data->temp = &offload_array[pls_data->n_rho];
129 pls_data->dens = &offload_array[pls_data->n_rho*3];
130}
131
145a5err plasma_1D_eval_temp(real* temp, real rho, int species,
146 plasma_1D_data* pls_data) {
147
148 a5err err = 0;
149 if(rho < pls_data->rho[0]) {
151 }
152 else if(rho >= pls_data->rho[pls_data->n_rho-1]) {
154 }
155 else {
156 int i_rho = 0;
157 while(i_rho < pls_data->n_rho - 1 && pls_data->rho[i_rho] <= rho) {
158 i_rho++;
159 }
160 i_rho--;
161 real t_rho = (rho - pls_data->rho[i_rho])
162 / (pls_data->rho[i_rho+1] - pls_data->rho[i_rho]);
163
164 real p1 = pls_data->temp[species*pls_data->n_rho + i_rho];
165 real p2 = pls_data->temp[species*pls_data->n_rho + i_rho+1];
166 temp[0] = p1 + t_rho * (p2 - p1);
167 }
168
169 return err;
170}
171
185a5err plasma_1D_eval_dens(real* dens, real rho, int species,
186 plasma_1D_data* pls_data) {
187
188 a5err err = 0;
189 if(rho < pls_data->rho[0]) {
191 }
192 else if(rho >= pls_data->rho[pls_data->n_rho-1]) {
194 }
195 else {
196 int i_rho = 0;
197 while(i_rho < pls_data->n_rho - 1 && pls_data->rho[i_rho] <= rho) {
198 i_rho++;
199 }
200 i_rho--;
201 real t_rho = (rho - pls_data->rho[i_rho])
202 / (pls_data->rho[i_rho+1] - pls_data->rho[i_rho]);
203
204 real p1 = pls_data->dens[species*pls_data->n_rho + i_rho];
205 real p2 = pls_data->dens[species*pls_data->n_rho + i_rho+1];
206 dens[0] = p1 + t_rho * (p2 - p1);
207 }
208
209 return err;
210}
211
226 plasma_1D_data* pls_data) {
227 a5err err = 0;
228 if(rho < pls_data->rho[0]) {
230 }
231 else if(rho >= pls_data->rho[pls_data->n_rho-1]) {
233 }
234 else {
235 int i_rho = 0;
236 while(i_rho < pls_data->n_rho-1 && pls_data->rho[i_rho] <= rho) {
237 i_rho++;
238 }
239 i_rho--;
240
241 real t_rho = (rho - pls_data->rho[i_rho])
242 / (pls_data->rho[i_rho+1] - pls_data->rho[i_rho]);
243
244 real p1, p2;
245 for(int i = 0; i < pls_data->n_species; i++) {
246 p1 = pls_data->dens[i*pls_data->n_rho + i_rho];
247 p2 = pls_data->dens[i*pls_data->n_rho + i_rho+1];
248 dens[i] = p1 + t_rho * (p2 - p1);
249
250 if(i < 2) {
251 /* Electron and ion temperature */
252 p1 = pls_data->temp[i*pls_data->n_rho + i_rho];
253 p2 = pls_data->temp[i*pls_data->n_rho + i_rho+1];
254 temp[i] = p1 + t_rho * (p2 - p1);
255 }
256 else {
257 /* Temperature is same for all ion species */
258 temp[i] = temp[1];
259 }
260 }
261 }
262
263 return err;
264}
Main header file for ASCOT5.
double real
Definition ascot5.h:85
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_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.
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_1D.h:27
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
1D plasma parameters that will be offloaded to target
Definition plasma_1D.h:13
int znum[MAX_SPECIES]
Definition plasma_1D.h:20
real charge[MAX_SPECIES]
Definition plasma_1D.h:18
real mass[MAX_SPECIES]
Definition plasma_1D.h:17
int anum[MAX_SPECIES]
Definition plasma_1D.h:19