24 real rhomin,
real rhomax,
int* moden,
int* modem,
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];
49 print_err(
"Error: Failed to initialize splines.\n");
55 print_err(
"Error: Failed to initialize splines.\n");
66 for(
int i = 0; i < nmode; i++) {
68 "(n,m) = (%2.d,%2.d) Amplitude = %3.3g Frequency = %3.3g"
83 for(
int i = 0; i < data->
n_modes; i++) {
146 if(!err && isinside) {
151 for(
int i=0; i<10; i++) {
156 for(
int i = 0; i < mhddata->n_modes; i++){
159 real a_da[3], phi_dphi[3];
168 phi_dphi[1] *= rho[1];
171 real mhdarg = mhddata->nmode[i] * ptz[8]
172 - mhddata->mmode[i] * ptz[4]
173 - mhddata->omega_nm[i] * t
174 + mhddata->phase_nm[i];
175 real sinmhd = sin(mhdarg);
176 real cosmhd = cos(mhdarg);
179 mhd_dmhd[0] += a_da[0] * mhddata->amplitude_nm[i] * cosmhd;
180 mhd_dmhd[5] += phi_dphi[0] * mhddata->amplitude_nm[i] * cosmhd;
183 mhd_dmhd[1] += a_da[0] * mhddata->amplitude_nm[i]
184 * mhddata->omega_nm[i] * sinmhd;
185 mhd_dmhd[6] += phi_dphi[0] * mhddata->amplitude_nm[i]
186 * mhddata->omega_nm[i] * sinmhd;
189 mhd_dmhd[2] += mhddata->amplitude_nm[i]
190 * ( a_da[1] * ptz[1] * cosmhd
191 + a_da[0] * mhddata->mmode[i] * ptz[5] * sinmhd
192 - a_da[0] * mhddata->nmode[i] * ptz[9] * sinmhd);
193 mhd_dmhd[7] += mhddata->amplitude_nm[i]
194 * ( phi_dphi[1] * ptz[1] * cosmhd
195 + phi_dphi[0] * mhddata->mmode[i] * ptz[5] * sinmhd
196 - phi_dphi[0] * mhddata->nmode[i] * ptz[9] * sinmhd);
199 mhd_dmhd[3] += (1/r) * mhddata->amplitude_nm[i]
200 * ( a_da[1] * ptz[2] * cosmhd
201 + a_da[0] * mhddata->mmode[i] * ptz[6] * sinmhd
202 - a_da[0] * mhddata->nmode[i] * ptz[10] * sinmhd);
203 mhd_dmhd[8] += (1/r) * mhddata->amplitude_nm[i]
204 * ( phi_dphi[1] * ptz[2] * cosmhd
205 + phi_dphi[0] * mhddata->mmode[i] * ptz[6] * sinmhd
206 - phi_dphi[0] * mhddata->nmode[i] * ptz[10] * sinmhd);
209 mhd_dmhd[4] += mhddata->amplitude_nm[i]
210 * ( a_da[1] * ptz[3] * cosmhd
211 + a_da[0] * mhddata->mmode[i] * ptz[7] * sinmhd
212 - a_da[0] * mhddata->nmode[i] * ptz[11] * sinmhd);
213 mhd_dmhd[9] += mhddata->amplitude_nm[i]
214 * ( phi_dphi[1] * ptz[3] * cosmhd
215 + phi_dphi[0] * mhddata->mmode[i] * ptz[7] * sinmhd
216 - phi_dphi[0] * mhddata->nmode[i] * ptz[11] * sinmhd);
220 if(!isinside || interperr) {
221 for(
int i=0; i<10; i++) {
259 real t,
int pertonly,
int includemode,
265 err =
mhd_stat_eval(mhd_dmhd, r, phi, z, t, includemode, boozerdata,
281 curlB[0] = B_dB[10]/r - B_dB[7];
282 curlB[1] = B_dB[3] - B_dB[9];
283 curlB[2] = (B[1] - B_dB[2])/r + B_dB[5];
286 gradalpha[0] = mhd_dmhd[2];
287 gradalpha[1] = mhd_dmhd[3];
288 gradalpha[2] = mhd_dmhd[4];
290 real gradalphacrossB[3];
294 pert_field[0] = mhd_dmhd[0]*curlB[0] + gradalphacrossB[0];
295 pert_field[1] = mhd_dmhd[0]*curlB[1] + gradalphacrossB[1];
296 pert_field[2] = mhd_dmhd[0]*curlB[2] + gradalphacrossB[2];
298 pert_field[3] = -mhd_dmhd[7] - B[0]*mhd_dmhd[1];
299 pert_field[4] = -mhd_dmhd[8] - B[1]*mhd_dmhd[1];
300 pert_field[5] = -mhd_dmhd[9] - B[2]*mhd_dmhd[1];
301 pert_field[6] = mhd_dmhd[5];
304 pert_field[0] += B[0];
305 pert_field[1] += B[1];
306 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_setup(interp1D_data *str, real *f, int n_x, int bc_x, real x_min, real x_max)
Set up splines to interpolate 1D scalar data.
a5err interp1Dcomp_eval_df(real *f_df, interp1D_data *str, real x)
Evaluate interpolated value of 1D and its 1st and 2nd derivatives.
#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_offload(mhd_stat_data *data)
Offload data to the accelerator.
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.
int mhd_stat_init(mhd_stat_data *data, int nmode, int nrho, real rhomin, real rhomax, int *moden, int *modem, real *amplitude_nm, real *omega_nm, real *phase_nm, real *alpha, real *phi)
Load MHD data.
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.
void mhd_stat_free(mhd_stat_data *data)
Free allocated resources.
Header file for mhd_stat.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.
Cubic interpolation struct.
MHD stat parameters on the target.
interp1D_data * alpha_nm
1D splines (rho) for each mode's magnetic eigenfunction
interp1D_data * phi_nm
1D splines (rho) for each mode's electric eigenfunction