ASCOT5
Loading...
Searching...
No Matches
mhd.c
Go to the documentation of this file.
1
19#include <stdlib.h>
20#include "ascot5.h"
21#include "error.h"
22#include "print.h"
23#include "mhd.h"
24#include "B_field.h"
25#include "boozer.h"
26#include "mhd/mhd_stat.h"
27#include "mhd/mhd_nonstat.h"
28
34void mhd_free(mhd_data* data) {
35 switch(data->type) {
36 case mhd_type_stat:
37 mhd_stat_free(&data->stat);
38 break;
41 break;
42 }
43}
44
50void mhd_offload(mhd_data* data) {
51 switch(data->type) {
52 case mhd_type_stat:
53 mhd_stat_offload(&data->stat);
54 break;
57 break;
58 }
59}
60
91a5err mhd_eval(real mhd_dmhd[10], real r, real phi, real z, real t,
92 int includemode, boozer_data* boozerdata, mhd_data* mhddata,
93 B_field_data* Bdata) {
94 a5err err = 0;
95
96 switch(mhddata->type) {
97
98 case mhd_type_stat:
99 err = mhd_stat_eval(mhd_dmhd, r, phi, z, t, includemode,
100 boozerdata, &(mhddata->stat), Bdata);
101 break;
102
103 case mhd_type_nonstat:
104 err = mhd_nonstat_eval(mhd_dmhd, r, phi, z, t, includemode,
105 boozerdata, &(mhddata->nonstat), Bdata);
106 break;
107
108 default:
109 /* Unregonized input. Produce error. */
110 err = error_raise( ERR_UNKNOWN_INPUT, __LINE__, EF_MHD );
111 break;
112 }
113
114 return err;
115}
116
147a5err mhd_perturbations(real pert_field[7], real r, real phi, real z,
148 real t, int pertonly, int includemode,
149 boozer_data* boozerdata, mhd_data* mhddata,
150 B_field_data* Bdata) {
151 a5err err = 0;
152
153 switch(mhddata->type) {
154
155 case mhd_type_stat:
156 err = mhd_stat_perturbations(pert_field, r, phi, z, t, pertonly,
157 includemode, boozerdata,
158 &(mhddata->stat), Bdata);
159 break;
160
161 case mhd_type_nonstat:
162 err = mhd_nonstat_perturbations(pert_field, r, phi, z, t, pertonly,
163 includemode, boozerdata,
164 &(mhddata->nonstat), Bdata);
165 break;
166
167 default:
168 /* Unregonized input. Produce error. */
169 err = error_raise( ERR_UNKNOWN_INPUT, __LINE__, EF_MHD );
170 break;
171 }
172
173 return err;
174}
175
184 int val = 0;
185 switch(mhddata->type) {
186 case mhd_type_stat:
187 val = mhddata->stat.n_modes;
188 break;
189 case mhd_type_nonstat:
190 val = mhddata->nonstat.n_modes;
191 break;
192 }
193 return val;
194}
195
203const int* mhd_get_nmode(mhd_data* mhddata) {
204 const int* val = NULL;
205 switch(mhddata->type) {
206 case mhd_type_stat:
207 val = mhddata->stat.nmode;
208 break;
209 case mhd_type_nonstat:
210 val = mhddata->nonstat.nmode;
211 break;
212 }
213 return val;
214}
215
223const int* mhd_get_mmode(mhd_data* mhddata) {
224 const int* val = NULL;
225 switch(mhddata->type) {
226 case mhd_type_stat:
227 val = mhddata->stat.mmode;
228 break;
229 case mhd_type_nonstat:
230 val = mhddata->nonstat.mmode;
231 break;
232 }
233 return val;
234}
235
244 const real* val = NULL;
245 switch(mhddata->type) {
246 case mhd_type_stat:
247 val = mhddata->stat.amplitude_nm;
248 break;
249 case mhd_type_nonstat:
250 val = mhddata->nonstat.amplitude_nm;
251 break;
252 }
253 return val;
254}
255
264 const real* val = NULL;
265 switch(mhddata->type) {
266 case mhd_type_stat:
267 val = mhddata->stat.omega_nm;
268 break;
269 case mhd_type_nonstat:
270 val = mhddata->nonstat.omega_nm;
271 break;
272 }
273 return val;
274}
275
283const real* mhd_get_phase(mhd_data* mhddata) {
284 const real* val = NULL;
285 switch(mhddata->type) {
286 case mhd_type_stat:
287 val = mhddata->stat.phase_nm;
288 break;
289 case mhd_type_nonstat:
290 val = mhddata->nonstat.phase_nm;
291 break;
292 }
293 return val;
294}
Header file for B_field.c.
Main header file for ASCOT5.
double real
Definition ascot5.h:85
Header file for boozer.c.
Error module for ASCOT5.
unsigned long int a5err
Simulation error flag.
Definition error.h:17
@ EF_MHD
Definition error.h:49
@ 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
int mhd_get_n_modes(mhd_data *mhddata)
Return number of modes.
Definition mhd.c:183
const real * mhd_get_amplitude(mhd_data *mhddata)
Return mode amplitudes.
Definition mhd.c:243
const int * mhd_get_nmode(mhd_data *mhddata)
Return mode toroidal numbers.
Definition mhd.c:203
void mhd_offload(mhd_data *data)
Offload data to the accelerator.
Definition mhd.c:50
a5err mhd_perturbations(real pert_field[7], real r, real phi, real z, real t, int pertonly, int includemode, boozer_data *boozerdata, mhd_data *mhddata, B_field_data *Bdata)
Evaluate perturbed fields Btilde, Etilde and potential Phi explicitly.
Definition mhd.c:147
const int * mhd_get_mmode(mhd_data *mhddata)
Return mode poloidal numbers.
Definition mhd.c:223
const real * mhd_get_frequency(mhd_data *mhddata)
Return mode frequencies.
Definition mhd.c:263
a5err mhd_eval(real mhd_dmhd[10], real r, real phi, real z, real t, int includemode, boozer_data *boozerdata, mhd_data *mhddata, B_field_data *Bdata)
Evaluate the needed quantities from MHD mode for orbit following.
Definition mhd.c:91
void mhd_free(mhd_data *data)
Free allocated resources.
Definition mhd.c:34
const real * mhd_get_phase(mhd_data *mhddata)
Return mode phases.
Definition mhd.c:283
Header file for mhd.c.
@ mhd_type_stat
Definition mhd.h:25
@ mhd_type_nonstat
Definition mhd.h:26
a5err mhd_nonstat_perturbations(real pert_field[7], real r, real phi, real z, real t, int pertonly, int includemode, boozer_data *boozerdata, mhd_nonstat_data *mhddata, B_field_data *Bdata)
Evaluate mhd perturbed fields Btilde, Etilde and potential Phi for full orbit.
void mhd_nonstat_free(mhd_nonstat_data *data)
Free allocated resources.
Definition mhd_nonstat.c:86
void mhd_nonstat_offload(mhd_nonstat_data *data)
Offload data to the accelerator.
a5err mhd_nonstat_eval(real mhd_dmhd[10], real r, real phi, real z, real t, int includemode, boozer_data *boozerdata, mhd_nonstat_data *mhddata, B_field_data *Bdata)
Evaluate the needed quantities from MHD mode for orbit following.
Header file for mhd_nonstat.c.
void mhd_stat_offload(mhd_stat_data *data)
Offload data to the accelerator.
Definition mhd_stat.c:99
a5err mhd_stat_perturbations(real pert_field[7], real r, real phi, real z, real t, int pertonly, int includemode, boozer_data *boozerdata, mhd_stat_data *mhddata, B_field_data *Bdata)
Evaluate perturbed fields Btilde, Etilde and potential Phi explicitly.
Definition mhd_stat.c:258
a5err mhd_stat_eval(real mhd_dmhd[10], real r, real phi, real z, real t, int includemode, boozer_data *boozerdata, mhd_stat_data *mhddata, B_field_data *Bdata)
Evaluate the needed quantities from MHD mode for orbit following.
Definition mhd_stat.c:133
void mhd_stat_free(mhd_stat_data *data)
Free allocated resources.
Definition mhd_stat.c:82
Header file for mhd_stat.c.
Macros for printing console output.
Magnetic field simulation data.
Definition B_field.h:41
Data for mapping between the cylindrical and Boozer coordinates.
Definition boozer.h:16
MHD simulation data.
Definition mhd.h:35
mhd_type type
Definition mhd.h:36
mhd_stat_data stat
Definition mhd.h:37
mhd_nonstat_data nonstat
Definition mhd.h:38