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++) {
152 if(!err && isinside) {
156 int iterations = mhddata->n_modes;
159 for(
int i=0; i<10; i++) {
164 for(
int i = 0; i < iterations; i++){
167 real a_da[6], phi_dphi[6];
176 phi_dphi[1] *= rho[1];
179 real mhdarg = mhddata->nmode[i] * ptz[8]
180 - mhddata->mmode[i] * ptz[4]
181 - mhddata->omega_nm[i] * t
182 + mhddata->phase_nm[i];
183 real sinmhd = sin(mhdarg);
184 real cosmhd = cos(mhdarg);
187 mhd_dmhd[0] += a_da[0] * mhddata->amplitude_nm[i] * cosmhd;
188 mhd_dmhd[5] += phi_dphi[0] * mhddata->amplitude_nm[i] * cosmhd;
191 mhd_dmhd[1] += a_da[0] * mhddata->amplitude_nm[i]
192 * mhddata->omega_nm[i] * sinmhd
193 + a_da[2] * mhddata->amplitude_nm[i] * cosmhd;
194 mhd_dmhd[6] += phi_dphi[0] * mhddata->amplitude_nm[i]
195 * mhddata->omega_nm[i] * sinmhd
196 + phi_dphi[2] * mhddata->amplitude_nm[i] * cosmhd;
199 mhd_dmhd[2] += mhddata->amplitude_nm[i]
200 * ( a_da[1] * ptz[1] * cosmhd
201 + a_da[0] * mhddata->mmode[i] * ptz[5] * sinmhd
202 - a_da[0] * mhddata->nmode[i] * ptz[9] * sinmhd);
203 mhd_dmhd[7] += mhddata->amplitude_nm[i]
204 * ( phi_dphi[1] * ptz[1] * cosmhd
205 + phi_dphi[0] * mhddata->mmode[i] * ptz[5] * sinmhd
206 - phi_dphi[0] * mhddata->nmode[i] * ptz[9] * sinmhd);
209 mhd_dmhd[3] += (1/r) * mhddata->amplitude_nm[i]
210 * ( a_da[1] * ptz[2] * cosmhd
211 + a_da[0] * mhddata->mmode[i] * ptz[6] * sinmhd
212 - a_da[0] * mhddata->nmode[i] * ptz[10] * sinmhd);
213 mhd_dmhd[8] += (1/r) * mhddata->amplitude_nm[i]
214 * ( phi_dphi[1] * ptz[2] * cosmhd
215 + phi_dphi[0] * mhddata->mmode[i] * ptz[6] * sinmhd
216 - phi_dphi[0] * mhddata->nmode[i] * ptz[10] * sinmhd);
219 mhd_dmhd[4] += mhddata->amplitude_nm[i]
220 * ( a_da[1] * ptz[3] * cosmhd
221 + a_da[0] * mhddata->mmode[i] * ptz[7] * sinmhd
222 - a_da[0] * mhddata->nmode[i] * ptz[11] * sinmhd);
223 mhd_dmhd[9] += mhddata->amplitude_nm[i]
224 * ( phi_dphi[1] * ptz[3] * cosmhd
225 + phi_dphi[0] * mhddata->mmode[i] * ptz[7] * sinmhd
226 - phi_dphi[0] * mhddata->nmode[i] * ptz[11] * sinmhd);
230 if(!isinside || interperr) {
231 for(
int i=0; i<10; i++) {
293 curlB[0] = B_dB[10]/r - B_dB[7];
294 curlB[1] = B_dB[3] - B_dB[9];
295 curlB[2] = (B[1] - B_dB[2])/r + B_dB[5];
298 gradalpha[0] = mhd_dmhd[2];
299 gradalpha[1] = mhd_dmhd[3];
300 gradalpha[2] = mhd_dmhd[4];
302 real gradalphacrossB[3];
306 pert_field[0] = mhd_dmhd[0]*curlB[0] + gradalphacrossB[0];
307 pert_field[1] = mhd_dmhd[0]*curlB[1] + gradalphacrossB[1];
308 pert_field[2] = mhd_dmhd[0]*curlB[2] + gradalphacrossB[2];
310 pert_field[3] = -mhd_dmhd[7] - B[0]*mhd_dmhd[1];
311 pert_field[4] = -mhd_dmhd[8] - B[1]*mhd_dmhd[1];
312 pert_field[5] = -mhd_dmhd[9] - B[2]*mhd_dmhd[1];
313 pert_field[6] = mhd_dmhd[5];
316 pert_field[0] += B[0];
317 pert_field[1] += B[1];
318 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