38 for(i = 0; i <
NSIMD; i++) {
42 real k1[3], k2[3], k3[3], k4[3], k5[3], k6[3];
69 normB = (
math_normc(k1[0], k1[1], k1[2])) * direction;
75 for(
int j = 0; j < 3; j++) {
77 + h[i] * ( (1.0/5) * k1[j] );
81 t0 + (1.0/5)*h[i], Bdata);
83 normB = (
math_normc(k2[0], k2[1], k2[2])) * direction;
89 for(
int j = 0; j < 3; j++) {
97 t0 + (3.0/10)*h[i], Bdata);
99 normB = (
math_normc(k3[0], k3[1], k3[2])) * direction;
105 for(
int j = 0; j < 3; j++) {
110 + ( 6.0/5 ) * k3[j] );
114 t0 + (3.0/5)*h[i], Bdata);
116 normB = (
math_normc(k4[0], k4[1], k4[2])) * direction;
122 for(
int j = 0; j < 3; j++) {
128 + ( 35.0/27) * k4[j] );
134 normB = (
math_normc(k5[0], k5[1], k5[2])) * direction;
140 for(
int j = 0; j < 3; j++) {
143 ( 1631.0/55296 ) * k1[j]
144 + ( 175.0/512 ) * k2[j]
145 + ( 575.0/13824 ) * k3[j]
146 + (44275.0/110592) * k4[j]
147 + ( 253.0/4096 ) * k5[j] );
151 t0 + (7.0/8)*h[i], Bdata);
153 normB = (
math_normc(k6[0], k6[1], k6[2])) * direction;
164 for(
int j = 0; j < 3; j++) {
168 + (250.0/621 ) * k3[j]
169 + (125.0/594 ) * k4[j]
170 + (512.0/1771) * k6[j] );
172 real rk4 = yprev[j] +
174 ( 2825.0/27648) * k1[j]
175 + (18575.0/48384) * k3[j]
176 + (13525.0/55296) * k4[j]
177 + ( 277.0/14336) * k5[j]
178 + ( 1.0/4 ) * k6[j] );
180 real yerr = fabs(rk5[j] - rk4);
181 real ytol = fabs(yprev[j]) + fabs( k1[j] * h[i] ) + DBL_EPSILON;
182 err = fmax( err, yerr/ytol );
188 hnext[i] = 0.85*h[i]*pow(err,-0.2);
193 hnext[i] = -0.85*h[i]*pow(err,-0.25);
205 p->time[i] + h[i], Bdata);
208 p->B_r_dr[i] = B_dB[1];
209 p->B_r_dphi[i] = B_dB[2];
210 p->B_r_dz[i] = B_dB[3];
212 p->B_phi[i] = B_dB[4];
213 p->B_phi_dr[i] = B_dB[5];
214 p->B_phi_dphi[i] = B_dB[6];
215 p->B_phi_dz[i] = B_dB[7];
218 p->B_z_dr[i] = B_dB[9];
219 p->B_z_dphi[i] = B_dB[10];
220 p->B_z_dz[i] = B_dB[11];
227 p->time[i] + h[i], Bdata);
238 p->theta[i] += atan2( (R0-axisrz[0]) * (p->z[i]-axisrz[1])
239 - (z0-axisrz[1]) * (p->r[i]-axisrz[0]),
240 (R0-axisrz[0]) * (p->r[i]-axisrz[0])
241 + (z0-axisrz[1]) * (p->z[i]-axisrz[1]) );
272 for(i = 0; i <
NSIMD; i++) {
276 real k1[3], k2[3], k3[3], k4[3], k5[3], k6[3];
285 real t0 = p->time[i];
289 if(p->pitch[i] < 0) {
298 yprev[1] = p->phi[i];
303 p->z[i], p->time[i], pertonly,
307 k1[0] = pert_field[0];
308 k1[1] = pert_field[1];
309 k1[2] = pert_field[2];
311 normB = (
math_normc(k1[0], k1[1], k1[2])) * direction;
317 for(
int j = 0; j < 3; j++) {
319 + h[i] * ( (1.0/5) * k1[j] );
323 tempy[2], t0, pertonly,
327 k2[0] = pert_field[0];
328 k2[1] = pert_field[1];
329 k2[2] = pert_field[2];
331 normB = (
math_normc(k2[0], k2[1], k2[2])) * direction;
337 for(
int j = 0; j < 3; j++) {
341 + (9.0/40) * k2[j] );
345 tempy[2], t0, pertonly,
349 k3[0] = pert_field[0];
350 k3[1] = pert_field[1];
351 k3[2] = pert_field[2];
353 normB = (
math_normc(k3[0], k3[1], k3[2])) * direction;
359 for(
int j = 0; j < 3; j++) {
364 + ( 6.0/5 ) * k3[j] );
368 tempy[2], t0, pertonly,
372 k4[0] = pert_field[0];
373 k4[1] = pert_field[1];
374 k4[2] = pert_field[2];
376 normB = (
math_normc(k4[0], k4[1], k4[2])) * direction;
382 for(
int j = 0; j < 3; j++) {
388 + ( 35.0/27) * k4[j] );
392 tempy[2], t0, pertonly,
396 k5[0] = pert_field[0];
397 k5[1] = pert_field[1];
398 k5[2] = pert_field[2];
400 normB = (
math_normc(k5[0], k5[1], k5[2])) * direction;
406 for(
int j = 0; j < 3; j++) {
409 ( 1631.0/55296 ) * k1[j]
410 + ( 175.0/512 ) * k2[j]
411 + ( 575.0/13824 ) * k3[j]
412 + (44275.0/110592) * k4[j]
413 + ( 253.0/4096 ) * k5[j] );
417 tempy[2], t0, pertonly,
421 k6[0] = pert_field[0];
422 k6[1] = pert_field[1];
423 k6[2] = pert_field[2];
425 normB = (
math_normc(k6[0], k6[1], k6[2])) * direction;
436 for(
int j = 0; j < 3; j++) {
440 + (250.0/621 ) * k3[j]
441 + (125.0/594 ) * k4[j]
442 + (512.0/1771) * k6[j] );
444 real rk4 = yprev[j] +
446 ( 2825.0/27648) * k1[j]
447 + (18575.0/48384) * k3[j]
448 + (13525.0/55296) * k4[j]
449 + ( 277.0/14336) * k5[j]
450 + ( 1.0/4 ) * k6[j] );
452 real yerr = fabs(rk5[j] - rk4);
453 real ytol = fabs(yprev[j]) + fabs( k1[j] * h[i] ) + DBL_EPSILON;
454 err = fmax( err, yerr/ytol );
460 hnext[i] = 0.85*h[i]*pow(err,-0.2);
465 hnext[i] = -0.85*h[i]*pow(err,-0.25);
477 p->time[i] + h[i], Bdata);
480 p->B_r_dr[i] = B_dB[1];
481 p->B_r_dphi[i] = B_dB[2];
482 p->B_r_dz[i] = B_dB[3];
484 p->B_phi[i] = B_dB[4];
485 p->B_phi_dr[i] = B_dB[5];
486 p->B_phi_dphi[i] = B_dB[6];
487 p->B_phi_dz[i] = B_dB[7];
490 p->B_z_dr[i] = B_dB[9];
491 p->B_z_dphi[i] = B_dB[10];
492 p->B_z_dz[i] = B_dB[11];
499 p->time[i] + h[i], Bdata);
510 p->theta[i] += atan2( (R0-axisrz[0]) * (p->z[i]-axisrz[1])
511 - (z0-axisrz[1]) * (p->r[i]-axisrz[0]),
512 (R0-axisrz[0]) * (p->r[i]-axisrz[0])
513 + (z0-axisrz[1]) * (p->z[i]-axisrz[1]) );
a5err mhd_perturbations(real pert_field[7], real r, real phi, real z, real t, int pertonly, int includemode, boozer_data *boozerdata, mhd_data *mhddata, B_field_data *Bdata)
Evaluate perturbed fields Btilde, Etilde and potential Phi explicitly.
Header file for particle.c.
Struct representing NSIMD field line markers.