96 real Bnorm = sqrt(B_dB[0]*B_dB[0] + B_dB[4]*B_dB[4] + B_dB[8]*B_dB[8]);
100 real rpz[3] = {r, phi, z};
101 real prpz[3] = {pr, pphi, pz};
110 real bhat[3] = { B_dBxyz[0]/Bnorm, B_dBxyz[4]/Bnorm, B_dBxyz[8]/Bnorm };
114 gradB[0] = (bhat[0]*B_dBxyz[1] + bhat[1]*B_dBxyz[5] + bhat[2]*B_dBxyz[9]);
115 gradB[1] = (bhat[0]*B_dBxyz[2] + bhat[1]*B_dBxyz[6] + bhat[2]*B_dBxyz[10]);
116 gradB[2] = (bhat[0]*B_dBxyz[3] + bhat[1]*B_dBxyz[7] + bhat[2]*B_dBxyz[11]);
119 real curlB[3] = {B_dBxyz[10]-B_dBxyz[7],
120 B_dBxyz[3]-B_dBxyz[9],
121 B_dBxyz[5]-B_dBxyz[2]};
130 nablabhat[0] = (B_dBxyz[1] - gradB[0] * bhat[0]) / Bnorm;
131 nablabhat[1] = (B_dBxyz[2] - gradB[0] * bhat[1]) / Bnorm;
132 nablabhat[2] = (B_dBxyz[3] - gradB[0] * bhat[2]) / Bnorm;
133 nablabhat[3] = (B_dBxyz[5] - gradB[1] * bhat[0]) / Bnorm;
134 nablabhat[4] = (B_dBxyz[6] - gradB[1] * bhat[1]) / Bnorm;
135 nablabhat[5] = (B_dBxyz[7] - gradB[1] * bhat[2]) / Bnorm;
136 nablabhat[6] = (B_dBxyz[9] - gradB[2] * bhat[0]) / Bnorm;
137 nablabhat[7] = (B_dBxyz[10] - gradB[2] * bhat[1]) / Bnorm;
138 nablabhat[8] = (B_dBxyz[11] - gradB[2] * bhat[2]) / Bnorm;
144 ( bhat[0] * B_dBxyz[1] +
145 bhat[1] * B_dBxyz[5] +
146 bhat[2] * B_dBxyz[9] -
math_dot(bhat, gradB) * bhat[0] ) / Bnorm;
148 ( bhat[0] * B_dBxyz[2] +
149 bhat[1] * B_dBxyz[6] +
150 bhat[2] * B_dBxyz[10] -
math_dot(bhat, gradB) * bhat[1] ) / Bnorm;
152 ( bhat[0] * B_dBxyz[3] +
153 bhat[1] * B_dBxyz[7] +
154 bhat[2] * B_dBxyz[11] -
math_dot(bhat, gradB) * bhat[2] ) / Bnorm;
158 pxyz[0] * bhat[0] + pxyz[1] * bhat[1] + pxyz[2] * bhat[2];
161 real pperp[3] = {pxyz[0] - ppar0 * bhat[0],
162 pxyz[1] - ppar0 * bhat[1],
163 pxyz[2] - ppar0 * bhat[2]};
164 real mu0 =
math_dot(pperp, pperp) / ( 2 * mass * Bnorm );
168 perphat[0] = - perphat[0];
169 perphat[1] = - perphat[1];
170 perphat[2] = - perphat[2];
178 -0.5 * ( 2 * ( rhohat[0] * perphat[0] * nablabhat[0] +
179 rhohat[1] * perphat[1] * nablabhat[4] +
180 rhohat[2] * perphat[2] * nablabhat[8] ) +
181 ( rhohat[0] * perphat[1] + rhohat[1] * perphat[0] ) *
182 ( nablabhat[1] + nablabhat[3] ) +
183 ( rhohat[0] * perphat[2] + rhohat[2] * perphat[0] ) *
184 ( nablabhat[2] + nablabhat[6] ) +
185 ( rhohat[1] * perphat[2] + rhohat[2] * perphat[1] ) *
186 ( nablabhat[5] + nablabhat[7] ) );
192 perphat[0] * perphat[0] * nablabhat[0] +
193 perphat[1] * perphat[0] * nablabhat[3] +
194 perphat[2] * perphat[0] * nablabhat[6] +
195 perphat[0] * perphat[1] * nablabhat[1] +
196 perphat[1] * perphat[1] * nablabhat[4] +
197 perphat[2] * perphat[1] * nablabhat[7] +
198 perphat[0] * perphat[2] * nablabhat[2] +
199 perphat[1] * perphat[2] * nablabhat[5] +
200 perphat[2] * perphat[2] * nablabhat[8]
203 rhohat[0] * rhohat[0] * nablabhat[0] +
204 rhohat[0] * rhohat[1] * nablabhat[3] +
205 rhohat[0] * rhohat[2] * nablabhat[6] +
206 rhohat[1] * rhohat[0] * nablabhat[1] +
207 rhohat[1] * rhohat[1] * nablabhat[4] +
208 rhohat[1] * rhohat[2] * nablabhat[7] +
209 rhohat[2] * rhohat[0] * nablabhat[2] +
210 rhohat[2] * rhohat[1] * nablabhat[5] +
211 rhohat[2] * rhohat[2] * nablabhat[8]
215 real e1[3] = {0, 0, 1};
224 rho0 = sqrt( ( 2* mass * mu0 ) / Bnorm ) / fabs(charge);
229 XYZ[0] = xyz[0] - rho0 * rhohat[0];
230 XYZ[1] = xyz[1] - rho0 * rhohat[1];
231 XYZ[2] = xyz[2] - rho0 * rhohat[2];
247 ppar1 = -ppar0 * rho0 *
math_dot(rhohat, kappa) +
248 ( mass * mu0 / charge ) * ( tau + a1ddotgradb );
251 real ppar2 = ppar0 * ppar0;
252 real temp[3] = { mu0 * gradB[0] + ppar2 * kappa[0] / mass,
253 mu0 * gradB[1] + ppar2 * kappa[1] / mass,
254 mu0 * gradB[2] + ppar2 * kappa[2] / mass };
257 mu1 = ( rho0 / Bnorm ) *
math_dot(rhohat, temp) -
258 ( ppar0 * mu0 / ( charge * Bnorm ) ) *
259 ( tau + a1ddotgradb );
263 real bx2by2 = bhat[0] * bhat[0] + bhat[1] * bhat[1];
264 real b1x = -bhat[0]*bhat[2]/bx2by2;
265 real b2x = -bhat[1]/(bx2by2*bx2by2);
266 real b1y = -bhat[1]*bhat[2]/bx2by2;
267 real b2y = -bhat[0]/(bx2by2*bx2by2);
270 b1x * ( nablabhat[1] + b2x * ( nablabhat[0] + nablabhat[1] ) ) +
271 b1y * ( nablabhat[0] + b2y * ( nablabhat[0] + nablabhat[1] ) );
273 b1x * ( nablabhat[4] + b2x * ( nablabhat[3] + nablabhat[4] ) ) +
274 b1y * ( nablabhat[3] + b2y * ( nablabhat[3] + nablabhat[4] ) );
276 b1x * ( nablabhat[7] + b2x * ( nablabhat[6] + nablabhat[7] ) ) +
277 b1y * ( nablabhat[6] + b2y * ( nablabhat[6] + nablabhat[7] ) );
279 temp[0] = gradB[0] + kappa[0] * ( ppar2 / mass ) / (2 * mu0);
280 temp[1] = gradB[1] + kappa[1] * ( ppar2 / mass ) / (2 * mu0);
281 temp[2] = gradB[2] + kappa[2] * ( ppar2 / mass ) / (2 * mu0);
284 zeta1 = -rho0 *
math_dot(rhohat, Rvec) +
285 ( ppar0 / ( charge * Bnorm ) ) * a2ddotgradb +
286 ( rho0 / Bnorm ) *
math_dot(perphat, temp);
291 *ppar = ppar0 + ppar1;
292 *mu = fabs(mu0 + mu1);
293 *zeta = zeta0 + zeta1;
335 real Bnorm = sqrt(B_dB[0]*B_dB[0] + B_dB[4]*B_dB[4] + B_dB[8]*B_dB[8]);
339 real RPZ[3] = {R, Phi, Z};
346 real bhat[3] = { B_dBxyz[0]/Bnorm, B_dBxyz[4]/Bnorm, B_dBxyz[8]/Bnorm };
350 gradB[0] = (bhat[0]*B_dBxyz[1] + bhat[1]*B_dBxyz[5] + bhat[2]*B_dBxyz[9]);
351 gradB[1] = (bhat[0]*B_dBxyz[2] + bhat[1]*B_dBxyz[6] + bhat[2]*B_dBxyz[10]);
352 gradB[2] = (bhat[0]*B_dBxyz[3] + bhat[1]*B_dBxyz[7] + bhat[2]*B_dBxyz[11]);
355 real curlB[3] = {B_dBxyz[10]-B_dBxyz[7],
356 B_dBxyz[3]-B_dBxyz[9],
357 B_dBxyz[5]-B_dBxyz[2]};
366 nablabhat[0] = (B_dBxyz[1] - gradB[0] * bhat[0]) / Bnorm;
367 nablabhat[1] = (B_dBxyz[2] - gradB[0] * bhat[1]) / Bnorm;
368 nablabhat[2] = (B_dBxyz[3] - gradB[0] * bhat[2]) / Bnorm;
369 nablabhat[3] = (B_dBxyz[5] - gradB[1] * bhat[0]) / Bnorm;
370 nablabhat[4] = (B_dBxyz[6] - gradB[1] * bhat[1]) / Bnorm;
371 nablabhat[5] = (B_dBxyz[7] - gradB[1] * bhat[2]) / Bnorm;
372 nablabhat[6] = (B_dBxyz[9] - gradB[2] * bhat[0]) / Bnorm;
373 nablabhat[7] = (B_dBxyz[10] - gradB[2] * bhat[1]) / Bnorm;
374 nablabhat[8] = (B_dBxyz[11] - gradB[2] * bhat[2]) / Bnorm;
380 ( bhat[0] * B_dBxyz[1] +
381 bhat[1] * B_dBxyz[5] +
382 bhat[2] * B_dBxyz[9] -
math_dot(bhat, gradB) * bhat[0] ) / Bnorm;
384 ( bhat[0] * B_dBxyz[2] +
385 bhat[1] * B_dBxyz[6] +
386 bhat[2] * B_dBxyz[10] -
math_dot(bhat, gradB) * bhat[1] ) / Bnorm;
388 ( bhat[0] * B_dBxyz[3] +
389 bhat[1] * B_dBxyz[7] +
390 bhat[2] * B_dBxyz[11] -
math_dot(bhat, gradB) * bhat[2] ) / Bnorm;
393 real e1[3] = {0, 0, 1};
402 rho0 = sqrt( ( 2* mass * mu ) / Bnorm ) / fabs(charge);
411 rhohat[0] = c * e1[0] - s * e2[0];
412 rhohat[1] = c * e1[1] - s * e2[1];
413 rhohat[2] = c * e1[2] - s * e2[2];
415 perphat[0] = -s * e1[0] - c * e2[0];
416 perphat[1] = -s * e1[1] - c * e2[1];
417 perphat[2] = -s * e1[2] - c * e2[2];
422 -0.5 * ( 2 * ( rhohat[0] * perphat[0] * nablabhat[0] +
423 rhohat[1] * perphat[1] * nablabhat[4] +
424 rhohat[2] * perphat[2] * nablabhat[8] ) +
425 ( rhohat[0] * perphat[1] + rhohat[1] * perphat[0] ) *
426 ( nablabhat[1] + nablabhat[3] ) +
427 ( rhohat[0] * perphat[2] + rhohat[2] * perphat[0] ) *
428 ( nablabhat[2] + nablabhat[6] ) +
429 ( rhohat[1] * perphat[2] + rhohat[2] * perphat[1] ) *
430 ( nablabhat[5] + nablabhat[7] ) );
436 perphat[0] * perphat[0] * nablabhat[0] +
437 perphat[1] * perphat[0] * nablabhat[3] +
438 perphat[2] * perphat[0] * nablabhat[6] +
439 perphat[0] * perphat[1] * nablabhat[1] +
440 perphat[1] * perphat[1] * nablabhat[4] +
441 perphat[2] * perphat[1] * nablabhat[7] +
442 perphat[0] * perphat[2] * nablabhat[2] +
443 perphat[1] * perphat[2] * nablabhat[5] +
444 perphat[2] * perphat[2] * nablabhat[8]
447 rhohat[0] * rhohat[0] * nablabhat[0] +
448 rhohat[0] * rhohat[1] * nablabhat[3] +
449 rhohat[0] * rhohat[2] * nablabhat[6] +
450 rhohat[1] * rhohat[0] * nablabhat[1] +
451 rhohat[1] * rhohat[1] * nablabhat[4] +
452 rhohat[1] * rhohat[2] * nablabhat[7] +
453 rhohat[2] * rhohat[0] * nablabhat[2] +
454 rhohat[2] * rhohat[1] * nablabhat[5] +
455 rhohat[2] * rhohat[2] * nablabhat[8]
461 ppar1 = -ppar * rho0 *
math_dot(rhohat, kappa) +
462 ( mass * mu / charge ) * ( tau + a1ddotgradb );
465 real ppar2 = ppar * ppar;
467 { mu * gradB[0] + ppar2 * kappa[0] / mass,
468 mu * gradB[1] + ppar2 * kappa[1] / mass,
469 mu * gradB[2] + ppar2 * kappa[2] / mass };
472 mu1 = ( rho0 / Bnorm ) *
math_dot(rhohat, temp) -
473 ( ppar * mu / ( charge * Bnorm ) ) *
474 ( tau + a1ddotgradb );
477 temp[0] = gradB[0] + kappa[0] * ppar2 / (2 * mass * mu);
478 temp[1] = gradB[1] + kappa[1] * ppar2 / (2 * mass * mu);
479 temp[2] = gradB[2] + kappa[2] * ppar2 / (2 * mass * mu);
482 real bx2by2 = bhat[0] * bhat[0] + bhat[1] * bhat[1];
483 real b1x = -bhat[0]*bhat[2]/bx2by2;
484 real b2x = -bhat[1]/(bx2by2*bx2by2);
485 real b1y = -bhat[1]*bhat[2]/bx2by2;
486 real b2y = -bhat[0]/(bx2by2*bx2by2);
489 b1x * ( nablabhat[1] + b2x * ( nablabhat[0] + nablabhat[1] ) ) +
490 b1y * ( nablabhat[0] + b2y * ( nablabhat[0] + nablabhat[1] ) );
492 b1x * ( nablabhat[4] + b2x * ( nablabhat[3] + nablabhat[4] ) ) +
493 b1y * ( nablabhat[3] + b2y * ( nablabhat[3] + nablabhat[4] ) );
495 b1x * ( nablabhat[7] + b2x * ( nablabhat[6] + nablabhat[7] ) ) +
496 b1y * ( nablabhat[6] + b2y * ( nablabhat[6] + nablabhat[7] ) );
499 zeta1 = -rho0 *
math_dot(rhohat, Rvec) +
500 ( ppar / ( charge * Bnorm ) ) * a2ddotgradb +
501 ( rho0 / Bnorm ) *
math_dot(perphat, temp);
515 rhohat[0] = c * e1[0] - s * e2[0];
516 rhohat[1] = c * e1[1] - s * e2[1];
517 rhohat[2] = c * e1[2] - s * e2[2];
522 xyz[0] = XYZ[0] + rho0 * rhohat[0];
523 xyz[1] = XYZ[1] + rho0 * rhohat[1];
524 xyz[2] = XYZ[2] + rho0 * rhohat[2];