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
46 real** offload_array) {
47 int err = 0;
48
49 switch(offload_data->type) {
50
51 case mhd_type_stat:
52 err = mhd_stat_init_offload(&(offload_data->stat), offload_array);
53 offload_data->offload_array_length =
54 offload_data->stat.offload_array_length;
55 break;
56
58 err = mhd_nonstat_init_offload(&(offload_data->nonstat),
59 offload_array);
60 offload_data->offload_array_length =
61 offload_data->nonstat.offload_array_length;
62 break;
63
64 default:
65 /* Unregonized input. Produce error. */
66 print_err("Error: Unregonized MHD type.");
67 err = 1;
68 break;
69 }
70
71 if(!err) {
72 print_out(VERBOSE_IO, "Estimated memory usage %.1f MB\n",
73 offload_data->offload_array_length
74 * sizeof(real) / (1024.0*1024.0) );
75 }
76
77 return err;
78}
79
91 real** offload_array) {
92 switch(offload_data->type) {
93
94 case mhd_type_stat:
95 mhd_stat_free_offload(&(offload_data->stat), offload_array);
96 break;
97
99 mhd_nonstat_free_offload(&(offload_data->nonstat), offload_array);
100 break;
101 }
102}
103
121int mhd_init(mhd_data* mhddata, mhd_offload_data* offload_data,
122 real* offload_array) {
123 int err = 0;
124
125 switch(offload_data->type) {
126
127 case mhd_type_stat:
128 mhd_stat_init(&(mhddata->stat), &(offload_data->stat),
129 offload_array);
130 break;
131
132 case mhd_type_nonstat:
133 mhd_nonstat_init(&(mhddata->nonstat), &(offload_data->nonstat),
134 offload_array);
135 break;
136
137 default:
138 /* Unregonized input. Produce error. */
139 print_err("Error: Unregonized electric field type.\n");
140 err = 1;
141 break;
142 }
143 mhddata->type = offload_data->type;
144
145 return err;
146}
147
178a5err mhd_eval(real mhd_dmhd[10], real r, real phi, real z, real t,
179 int includemode, boozer_data* boozerdata, mhd_data* mhddata,
180 B_field_data* Bdata) {
181 a5err err = 0;
182
183 switch(mhddata->type) {
184
185 case mhd_type_stat:
186 err = mhd_stat_eval(mhd_dmhd, r, phi, z, t, includemode,
187 boozerdata, &(mhddata->stat), Bdata);
188 break;
189
190 case mhd_type_nonstat:
191 err = mhd_nonstat_eval(mhd_dmhd, r, phi, z, t, includemode,
192 boozerdata, &(mhddata->nonstat), Bdata);
193 break;
194
195 default:
196 /* Unregonized input. Produce error. */
197 err = error_raise( ERR_UNKNOWN_INPUT, __LINE__, EF_MHD );
198 break;
199 }
200
201 return err;
202}
203
234a5err mhd_perturbations(real pert_field[7], real r, real phi, real z,
235 real t, int pertonly, int includemode,
236 boozer_data* boozerdata, mhd_data* mhddata,
237 B_field_data* Bdata) {
238 a5err err = 0;
239
240 switch(mhddata->type) {
241
242 case mhd_type_stat:
243 err = mhd_stat_perturbations(pert_field, r, phi, z, t, pertonly,
244 includemode, boozerdata,
245 &(mhddata->stat), Bdata);
246 break;
247
248 case mhd_type_nonstat:
249 err = mhd_nonstat_perturbations(pert_field, r, phi, z, t, pertonly,
250 includemode, boozerdata,
251 &(mhddata->nonstat), Bdata);
252 break;
253
254 default:
255 /* Unregonized input. Produce error. */
256 err = error_raise( ERR_UNKNOWN_INPUT, __LINE__, EF_MHD );
257 break;
258 }
259
260 return err;
261}
262
271 int val = 0;
272 switch(mhddata->type) {
273 case mhd_type_stat:
274 val = mhddata->stat.n_modes;
275 break;
276 case mhd_type_nonstat:
277 val = mhddata->nonstat.n_modes;
278 break;
279 }
280 return val;
281}
282
290const int* mhd_get_nmode(mhd_data* mhddata) {
291 const int* val = NULL;
292 switch(mhddata->type) {
293 case mhd_type_stat:
294 val = mhddata->stat.nmode;
295 break;
296 case mhd_type_nonstat:
297 val = mhddata->nonstat.nmode;
298 break;
299 }
300 return val;
301}
302
310const int* mhd_get_mmode(mhd_data* mhddata) {
311 const int* val = NULL;
312 switch(mhddata->type) {
313 case mhd_type_stat:
314 val = mhddata->stat.mmode;
315 break;
316 case mhd_type_nonstat:
317 val = mhddata->nonstat.mmode;
318 break;
319 }
320 return val;
321}
322
331 const real* val = NULL;
332 switch(mhddata->type) {
333 case mhd_type_stat:
334 val = mhddata->stat.amplitude_nm;
335 break;
336 case mhd_type_nonstat:
337 val = mhddata->nonstat.amplitude_nm;
338 break;
339 }
340 return val;
341}
342
351 const real* val = NULL;
352 switch(mhddata->type) {
353 case mhd_type_stat:
354 val = mhddata->stat.omega_nm;
355 break;
356 case mhd_type_nonstat:
357 val = mhddata->nonstat.omega_nm;
358 break;
359 }
360 return val;
361}
362
370const real* mhd_get_phase(mhd_data* mhddata) {
371 const real* val = NULL;
372 switch(mhddata->type) {
373 case mhd_type_stat:
374 val = mhddata->stat.phase_nm;
375 break;
376 case mhd_type_nonstat:
377 val = mhddata->nonstat.phase_nm;
378 break;
379 }
380 return val;
381}
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:270
const real * mhd_get_amplitude(mhd_data *mhddata)
Return mode amplitudes.
Definition mhd.c:330
const int * mhd_get_nmode(mhd_data *mhddata)
Return mode toroidal numbers.
Definition mhd.c:290
int mhd_init(mhd_data *mhddata, mhd_offload_data *offload_data, real *offload_array)
Initialize MHD data struct on target.
Definition mhd.c:121
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:234
const int * mhd_get_mmode(mhd_data *mhddata)
Return mode poloidal numbers.
Definition mhd.c:310
const real * mhd_get_frequency(mhd_data *mhddata)
Return mode frequencies.
Definition mhd.c:350
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:178
const real * mhd_get_phase(mhd_data *mhddata)
Return mode phases.
Definition mhd.c:370
int mhd_init_offload(mhd_offload_data *offload_data, real **offload_array)
Load MHD data and prepare parameters.
Definition mhd.c:45
void mhd_free_offload(mhd_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
Definition mhd.c:90
Header file for mhd.c.
@ mhd_type_stat
Definition mhd.h:28
@ mhd_type_nonstat
Definition mhd.h:29
void mhd_nonstat_init(mhd_nonstat_data *mhddata, mhd_nonstat_offload_data *offload_data, real *offload_array)
Initialize MHD data struct on target.
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.
int mhd_nonstat_init_offload(mhd_nonstat_offload_data *offload_data, real **offload_array)
Load MHD data and prepare parameters for offload.
Definition mhd_nonstat.c:37
void mhd_nonstat_free_offload(mhd_nonstat_offload_data *offload_data, real **offload_array)
Free offload array.
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_free_offload(mhd_stat_offload_data *offload_data, real **offload_array)
Free offload array.
Definition mhd_stat.c:100
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:299
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:174
int mhd_stat_init_offload(mhd_stat_offload_data *offload_data, real **offload_array)
Load MHD data and prepare parameters for offload.
Definition mhd_stat.c:37
void mhd_stat_init(mhd_stat_data *mhddata, mhd_stat_offload_data *offload_data, real *offload_array)
Initialize MHD data struct on target.
Definition mhd_stat.c:112
Header file for mhd_stat.c.
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
Magnetic field simulation data.
Definition B_field.h:63
Boozer parameters on the target.
Definition boozer.h:29
MHD simulation data.
Definition mhd.h:57
MHD offload data.
Definition mhd.h:41
mhd_type type
Definition mhd.h:42
int offload_array_length
Definition mhd.h:45
mhd_nonstat_offload_data nonstat
Definition mhd.h:44
mhd_stat_offload_data stat
Definition mhd.h:43