25 int* moden,
int* modem,
real* amplitude_nm,
32 data->
nmode = (
int*) malloc(nmode *
sizeof(
int));
33 data->
mmode = (
int*) malloc(nmode *
sizeof(
int));
39 for(
int i = 0; i < nmode; i++) {
40 data->
nmode[i] = moden[i];
41 data->
mmode[i] = modem[i];
48 rhomin, rhomax, tmin, tmax);
50 print_err(
"Error: Failed to initialize splines.\n");
55 rhomin, rhomax, tmin, tmax);
57 print_err(
"Error: Failed to initialize splines.\n");
70 for(
int i = 0; i < nmode; i++) {
72 "(n,m) = (%2.d,%2.d) Amplitude = %3.3g Frequency = %3.3g"
87 for(
int i = 0; i < data->
n_modes; i++) {
150 if(!err && isinside) {
154 int iterations = mhddata->n_modes;
157 for(
int i=0; i<10; i++) {
162 for(
int i = 0; i < iterations; i++){
165 real a_da[6], phi_dphi[6];
174 phi_dphi[1] *= rho[1];
177 real mhdarg = mhddata->nmode[i] * ptz[8]
178 - mhddata->mmode[i] * ptz[4]
179 - mhddata->omega_nm[i] * t
180 + mhddata->phase_nm[i];
181 real sinmhd = sin(mhdarg);
182 real cosmhd = cos(mhdarg);
185 mhd_dmhd[0] += a_da[0] * mhddata->amplitude_nm[i] * cosmhd;
186 mhd_dmhd[5] += phi_dphi[0] * mhddata->amplitude_nm[i] * cosmhd;
189 mhd_dmhd[1] += a_da[0] * mhddata->amplitude_nm[i]
190 * mhddata->omega_nm[i] * sinmhd
191 + a_da[2] * mhddata->amplitude_nm[i] * cosmhd;
192 mhd_dmhd[6] += phi_dphi[0] * mhddata->amplitude_nm[i]
193 * mhddata->omega_nm[i] * sinmhd
194 + phi_dphi[2] * mhddata->amplitude_nm[i] * cosmhd;
197 mhd_dmhd[2] += mhddata->amplitude_nm[i]
198 * ( a_da[1] * ptz[1] * cosmhd
199 + a_da[0] * mhddata->mmode[i] * ptz[5] * sinmhd
200 - a_da[0] * mhddata->nmode[i] * ptz[9] * sinmhd);
201 mhd_dmhd[7] += mhddata->amplitude_nm[i]
202 * ( phi_dphi[1] * ptz[1] * cosmhd
203 + phi_dphi[0] * mhddata->mmode[i] * ptz[5] * sinmhd
204 - phi_dphi[0] * mhddata->nmode[i] * ptz[9] * sinmhd);
207 mhd_dmhd[3] += (1/r) * mhddata->amplitude_nm[i]
208 * ( a_da[1] * ptz[2] * cosmhd
209 + a_da[0] * mhddata->mmode[i] * ptz[6] * sinmhd
210 - a_da[0] * mhddata->nmode[i] * ptz[10] * sinmhd);
211 mhd_dmhd[8] += (1/r) * mhddata->amplitude_nm[i]
212 * ( phi_dphi[1] * ptz[2] * cosmhd
213 + phi_dphi[0] * mhddata->mmode[i] * ptz[6] * sinmhd
214 - phi_dphi[0] * mhddata->nmode[i] * ptz[10] * sinmhd);
217 mhd_dmhd[4] += mhddata->amplitude_nm[i]
218 * ( a_da[1] * ptz[3] * cosmhd
219 + a_da[0] * mhddata->mmode[i] * ptz[7] * sinmhd
220 - a_da[0] * mhddata->nmode[i] * ptz[11] * sinmhd);
221 mhd_dmhd[9] += mhddata->amplitude_nm[i]
222 * ( phi_dphi[1] * ptz[3] * cosmhd
223 + phi_dphi[0] * mhddata->mmode[i] * ptz[7] * sinmhd
224 - phi_dphi[0] * mhddata->nmode[i] * ptz[11] * sinmhd);
228 if(!isinside || interperr) {
229 for(
int i=0; i<10; i++) {
291 curlB[0] = B_dB[10]/r - B_dB[7];
292 curlB[1] = B_dB[3] - B_dB[9];
293 curlB[2] = (B[1] - B_dB[2])/r + B_dB[5];
296 gradalpha[0] = mhd_dmhd[2];
297 gradalpha[1] = mhd_dmhd[3];
298 gradalpha[2] = mhd_dmhd[4];
300 real gradalphacrossB[3];
304 pert_field[0] = mhd_dmhd[0]*curlB[0] + gradalphacrossB[0];
305 pert_field[1] = mhd_dmhd[0]*curlB[1] + gradalphacrossB[1];
306 pert_field[2] = mhd_dmhd[0]*curlB[2] + gradalphacrossB[2];
308 pert_field[3] = -mhd_dmhd[7] - B[0]*mhd_dmhd[1];
309 pert_field[4] = -mhd_dmhd[8] - B[1]*mhd_dmhd[1];
310 pert_field[5] = -mhd_dmhd[9] - B[2]*mhd_dmhd[1];
311 pert_field[6] = mhd_dmhd[5];
314 pert_field[0] += B[0];
315 pert_field[1] += B[1];
316 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 interp2Dcomp_setup(interp2D_data *str, 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)
Set up splines to interpolate 2D scalar data.
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.
#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)
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.
void mhd_nonstat_offload(mhd_nonstat_data *data)
Offload data to the accelerator.
int mhd_nonstat_init(mhd_nonstat_data *data, int nmode, int nrho, int ntime, real rhomin, real rhomax, real tmin, real tmax, int *moden, int *modem, real *amplitude_nm, real *omega_nm, real *phase_nm, real *alpha, real *phi)
Load MHD data.
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.
#define print_err(...)
Print to standard error.
Magnetic field simulation data.
Data for mapping between the cylindrical and Boozer coordinates.
Bicubic interpolation struct.
interp2D_data * phi_nm
2D splines (rho,time) for each mode's electric eigenfunction
interp2D_data * alpha_nm
2D splines (rho,time) for each mode's magnetic eigenfunction