38 real** offload_array) {
42 real* coeff_array = (
real*)malloc(2 * NSIZE_COMP2D * offload_data->
n_modes
43 * offload_data->
nrho * offload_data->
ntime
48 int datasize = offload_data->
nrho * offload_data->
ntime;
49 int n_modes = offload_data->
n_modes;
50 for(
int j=0; j<offload_data->
n_modes; j++) {
54 &coeff_array[NSIZE_COMP2D * datasize * j],
55 &(*offload_array)[j*datasize],
65 &coeff_array[NSIZE_COMP2D * datasize * (n_modes + j)],
66 &(*offload_array)[(n_modes + j)*datasize],
77 *offload_array = coeff_array;
91 for(
int j=0; j<n_modes; j++) {
93 "(n,m) = (%2.d,%2.d) Amplitude = %3.3g Frequency = %3.3g"
95 offload_data->
nmode[j], offload_data->
mmode[j],
110 real** offload_array) {
111 free(*offload_array);
123 real* offload_array) {
125 mhddata->n_modes = offload_data->
n_modes;
127 int n_modes = offload_data->
n_modes;
128 int datasize = NSIZE_COMP2D * offload_data->
nrho * offload_data->
ntime;
130 for(
int j=0; j<mhddata->n_modes; j++) {
131 mhddata->nmode[j] = offload_data->
nmode[j];
132 mhddata->mmode[j] = offload_data->
mmode[j];
133 mhddata->amplitude_nm[j] = offload_data->
amplitude_nm[j];
134 mhddata->omega_nm[j] = offload_data->
omega_nm[j];
135 mhddata->phase_nm[j] = offload_data->
phase_nm[j];
138 &(offload_array[j*datasize]),
145 &(offload_array[(n_modes + j)*datasize]),
197 if(!err && isinside) {
201 int iterations = mhddata->n_modes;
204 for(
int i=0; i<10; i++) {
209 for(
int i = 0; i < iterations; i++){
212 real a_da[6], phi_dphi[6];
221 phi_dphi[1] *= rho[1];
224 real mhdarg = mhddata->nmode[i] * ptz[8]
225 - mhddata->mmode[i] * ptz[4]
226 - mhddata->omega_nm[i] * t
227 + mhddata->phase_nm[i];
228 real sinmhd = sin(mhdarg);
229 real cosmhd = cos(mhdarg);
232 mhd_dmhd[0] += a_da[0] * mhddata->amplitude_nm[i] * cosmhd;
233 mhd_dmhd[5] += phi_dphi[0] * mhddata->amplitude_nm[i] * cosmhd;
236 mhd_dmhd[1] += a_da[0] * mhddata->amplitude_nm[i]
237 * mhddata->omega_nm[i] * sinmhd
238 + a_da[2] * mhddata->amplitude_nm[i] * cosmhd;
239 mhd_dmhd[6] += phi_dphi[0] * mhddata->amplitude_nm[i]
240 * mhddata->omega_nm[i] * sinmhd
241 + phi_dphi[2] * mhddata->amplitude_nm[i] * cosmhd;
244 mhd_dmhd[2] += mhddata->amplitude_nm[i]
245 * ( a_da[1] * ptz[1] * cosmhd
246 + a_da[0] * mhddata->mmode[i] * ptz[5] * sinmhd
247 - a_da[0] * mhddata->nmode[i] * ptz[9] * sinmhd);
248 mhd_dmhd[7] += mhddata->amplitude_nm[i]
249 * ( phi_dphi[1] * ptz[1] * cosmhd
250 + phi_dphi[0] * mhddata->mmode[i] * ptz[5] * sinmhd
251 - phi_dphi[0] * mhddata->nmode[i] * ptz[9] * sinmhd);
254 mhd_dmhd[3] += (1/r) * mhddata->amplitude_nm[i]
255 * ( a_da[1] * ptz[2] * cosmhd
256 + a_da[0] * mhddata->mmode[i] * ptz[6] * sinmhd
257 - a_da[0] * mhddata->nmode[i] * ptz[10] * sinmhd);
258 mhd_dmhd[8] += (1/r) * mhddata->amplitude_nm[i]
259 * ( phi_dphi[1] * ptz[2] * cosmhd
260 + phi_dphi[0] * mhddata->mmode[i] * ptz[6] * sinmhd
261 - phi_dphi[0] * mhddata->nmode[i] * ptz[10] * sinmhd);
264 mhd_dmhd[4] += mhddata->amplitude_nm[i]
265 * ( a_da[1] * ptz[3] * cosmhd
266 + a_da[0] * mhddata->mmode[i] * ptz[7] * sinmhd
267 - a_da[0] * mhddata->nmode[i] * ptz[11] * sinmhd);
268 mhd_dmhd[9] += mhddata->amplitude_nm[i]
269 * ( phi_dphi[1] * ptz[3] * cosmhd
270 + phi_dphi[0] * mhddata->mmode[i] * ptz[7] * sinmhd
271 - phi_dphi[0] * mhddata->nmode[i] * ptz[11] * sinmhd);
275 if(!isinside || interperr) {
276 for(
int i=0; i<10; i++) {
338 curlB[0] = B_dB[10]/r - B_dB[7];
339 curlB[1] = B_dB[3] - B_dB[9];
340 curlB[2] = (B[1] - B_dB[2])/r + B_dB[5];
343 gradalpha[0] = mhd_dmhd[2];
344 gradalpha[1] = mhd_dmhd[3];
345 gradalpha[2] = mhd_dmhd[4];
347 real gradalphacrossB[3];
351 pert_field[0] = mhd_dmhd[0]*curlB[0] + gradalphacrossB[0];
352 pert_field[1] = mhd_dmhd[0]*curlB[1] + gradalphacrossB[1];
353 pert_field[2] = mhd_dmhd[0]*curlB[2] + gradalphacrossB[2];
355 pert_field[3] = -mhd_dmhd[7] - B[0]*mhd_dmhd[1];
356 pert_field[4] = -mhd_dmhd[8] - B[1]*mhd_dmhd[1];
357 pert_field[5] = -mhd_dmhd[9] - B[2]*mhd_dmhd[1];
358 pert_field[6] = mhd_dmhd[5];
361 pert_field[0] += B[0];
362 pert_field[1] += B[1];
363 pert_field[2] += B[2];
a5err B_field_eval_rho(real rho[2], real psi, B_field_data *Bdata)
Evaluate normalized poloidal flux rho and its psi derivative.
a5err B_field_eval_B_dB(real B_dB[15], real r, real phi, real z, real t, B_field_data *Bdata)
Evaluate magnetic field and its derivatives.
Header file for B_field.c.
Main header file for ASCOT5.
a5err boozer_eval_psithetazeta(real psithetazeta[12], int *isinside, real r, real phi, real z, B_field_data *Bdata, boozer_data *boozerdata)
Evaluate Boozer coordinates and partial derivatives.
Header file for boozer.c.
unsigned long int a5err
Simulation error flag.
Spline interpolation library.
DECLARE_TARGET_END a5err interp2Dcomp_eval_df(real *f_df, interp2D_data *str, real x, real y)
Evaluate interpolated value and 1st and 2nd derivatives of 2D field.
int interp2Dcomp_init_coeff(real *c, real *f, int n_x, int n_y, int bc_x, int bc_y, real x_min, real x_max, real y_min, real y_max)
Calculate bicubic spline interpolation coefficients for scalar 2D data.
void interp2Dcomp_init_spline(interp2D_data *str, real *c, int n_x, int n_y, int bc_x, int bc_y, real x_min, real x_max, real y_min, real y_max)
Initialize a bicubic spline.
#define math_cross(a, b, c)
Calculate cross product for 3D vectors c = a x b.
#define MHD_INCLUDE_ALL
includemode parameter to include all modes (default)
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.
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.
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
Magnetic field simulation data.
Boozer parameters on the target.
MHD parameters on the target.
MHD parameters that will be offloaded to target.
real omega_nm[MHD_MODES_MAX_NUM]
int nmode[MHD_MODES_MAX_NUM]
real amplitude_nm[MHD_MODES_MAX_NUM]
int mmode[MHD_MODES_MAX_NUM]
real phase_nm[MHD_MODES_MAX_NUM]