38 real** offload_array) {
42 real* coeff_array = (
real*)malloc(2 * NSIZE_COMP1D * offload_data->
n_modes
43 * offload_data->
nrho *
sizeof(
real));
47 int datasize = offload_data->
nrho;
48 int n_modes = offload_data->
n_modes;
49 for(
int j=0; j<offload_data->
n_modes; j++) {
53 &coeff_array[NSIZE_COMP1D * datasize * j],
54 &(*offload_array)[j*datasize],
62 &coeff_array[NSIZE_COMP1D * datasize * (n_modes + j)],
63 &(*offload_array)[(n_modes + j)*datasize],
71 *offload_array = coeff_array;
82 for(
int j=0; j<n_modes; j++) {
84 "(n,m) = (%2.d,%2.d) Amplitude = %3.3g Frequency = %3.3g"
86 offload_data->
nmode[j], offload_data->
mmode[j],
101 real** offload_array) {
102 free(*offload_array);
113 real* offload_array) {
115 mhddata->n_modes = offload_data->
n_modes;
116 mhddata->rho_min = offload_data->
rho_min;
117 mhddata->rho_max = offload_data->
rho_max;
119 int n_modes = offload_data->
n_modes;
120 int datasize = NSIZE_COMP1D * offload_data->
nrho;
122 for(
int j=0; j<mhddata->n_modes; j++) {
123 mhddata->nmode[j] = offload_data->
nmode[j];
124 mhddata->mmode[j] = offload_data->
mmode[j];
125 mhddata->amplitude_nm[j] = offload_data->
amplitude_nm[j];
126 mhddata->omega_nm[j] = offload_data->
omega_nm[j];
127 mhddata->phase_nm[j] = offload_data->
phase_nm[j];
130 &(offload_array[j*datasize]),
136 &(offload_array[(n_modes + j)*datasize]),
187 if(!err && isinside) {
192 for(
int i=0; i<10; i++) {
197 for(
int i = 0; i < mhddata->n_modes; i++){
200 real a_da[3], phi_dphi[3];
209 phi_dphi[1] *= rho[1];
212 real mhdarg = mhddata->nmode[i] * ptz[8]
213 - mhddata->mmode[i] * ptz[4]
214 - mhddata->omega_nm[i] * t
215 + mhddata->phase_nm[i];
216 real sinmhd = sin(mhdarg);
217 real cosmhd = cos(mhdarg);
220 mhd_dmhd[0] += a_da[0] * mhddata->amplitude_nm[i] * cosmhd;
221 mhd_dmhd[5] += phi_dphi[0] * mhddata->amplitude_nm[i] * cosmhd;
224 mhd_dmhd[1] += a_da[0] * mhddata->amplitude_nm[i]
225 * mhddata->omega_nm[i] * sinmhd;
226 mhd_dmhd[6] += phi_dphi[0] * mhddata->amplitude_nm[i]
227 * mhddata->omega_nm[i] * sinmhd;
230 mhd_dmhd[2] += mhddata->amplitude_nm[i]
231 * ( a_da[1] * ptz[1] * cosmhd
232 + a_da[0] * mhddata->mmode[i] * ptz[5] * sinmhd
233 - a_da[0] * mhddata->nmode[i] * ptz[9] * sinmhd);
234 mhd_dmhd[7] += mhddata->amplitude_nm[i]
235 * ( phi_dphi[1] * ptz[1] * cosmhd
236 + phi_dphi[0] * mhddata->mmode[i] * ptz[5] * sinmhd
237 - phi_dphi[0] * mhddata->nmode[i] * ptz[9] * sinmhd);
240 mhd_dmhd[3] += (1/r) * mhddata->amplitude_nm[i]
241 * ( a_da[1] * ptz[2] * cosmhd
242 + a_da[0] * mhddata->mmode[i] * ptz[6] * sinmhd
243 - a_da[0] * mhddata->nmode[i] * ptz[10] * sinmhd);
244 mhd_dmhd[8] += (1/r) * mhddata->amplitude_nm[i]
245 * ( phi_dphi[1] * ptz[2] * cosmhd
246 + phi_dphi[0] * mhddata->mmode[i] * ptz[6] * sinmhd
247 - phi_dphi[0] * mhddata->nmode[i] * ptz[10] * sinmhd);
250 mhd_dmhd[4] += mhddata->amplitude_nm[i]
251 * ( a_da[1] * ptz[3] * cosmhd
252 + a_da[0] * mhddata->mmode[i] * ptz[7] * sinmhd
253 - a_da[0] * mhddata->nmode[i] * ptz[11] * sinmhd);
254 mhd_dmhd[9] += mhddata->amplitude_nm[i]
255 * ( phi_dphi[1] * ptz[3] * cosmhd
256 + phi_dphi[0] * mhddata->mmode[i] * ptz[7] * sinmhd
257 - phi_dphi[0] * mhddata->nmode[i] * ptz[11] * sinmhd);
261 if(!isinside || interperr) {
262 for(
int i=0; i<10; i++) {
300 real t,
int pertonly,
int includemode,
306 err =
mhd_stat_eval(mhd_dmhd, r, phi, z, t, includemode, boozerdata,
322 curlB[0] = B_dB[10]/r - B_dB[7];
323 curlB[1] = B_dB[3] - B_dB[9];
324 curlB[2] = (B[1] - B_dB[2])/r + B_dB[5];
327 gradalpha[0] = mhd_dmhd[2];
328 gradalpha[1] = mhd_dmhd[3];
329 gradalpha[2] = mhd_dmhd[4];
331 real gradalphacrossB[3];
335 pert_field[0] = mhd_dmhd[0]*curlB[0] + gradalphacrossB[0];
336 pert_field[1] = mhd_dmhd[0]*curlB[1] + gradalphacrossB[1];
337 pert_field[2] = mhd_dmhd[0]*curlB[2] + gradalphacrossB[2];
339 pert_field[3] = -mhd_dmhd[7] - B[0]*mhd_dmhd[1];
340 pert_field[4] = -mhd_dmhd[8] - B[1]*mhd_dmhd[1];
341 pert_field[5] = -mhd_dmhd[9] - B[2]*mhd_dmhd[1];
342 pert_field[6] = mhd_dmhd[5];
345 pert_field[0] += B[0];
346 pert_field[1] += B[1];
347 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.
int interp1Dcomp_init_coeff(real *c, real *f, int n_x, int bc_x, real x_min, real x_max)
Calculate cubic spline interpolation coefficients for scalar 1D data.
a5err interp1Dcomp_eval_df(real *f_df, interp1D_data *str, real x)
Evaluate interpolated value of 1D and its 1st and 2nd derivatives.
void interp1Dcomp_init_spline(interp1D_data *str, real *c, int n_x, int bc_x, real x_min, real x_max)
Initialize a cubic 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_stat_free_offload(mhd_stat_offload_data *offload_data, real **offload_array)
Free offload array.
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.
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.
int mhd_stat_init_offload(mhd_stat_offload_data *offload_data, real **offload_array)
Load MHD data and prepare parameters for offload.
void mhd_stat_init(mhd_stat_data *mhddata, mhd_stat_offload_data *offload_data, real *offload_array)
Initialize MHD data struct on target.
Header file for mhd_stat.c.
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
Magnetic field simulation data.
Boozer parameters on the target.
MHD stat parameters on the target.
MHD stat parameters that will be offloaded to target.
int mmode[MHD_MODES_MAX_NUM]
real phase_nm[MHD_MODES_MAX_NUM]
int nmode[MHD_MODES_MAX_NUM]
real amplitude_nm[MHD_MODES_MAX_NUM]
real omega_nm[MHD_MODES_MAX_NUM]