145 real* offload_array) {
146 Bdata->R0 = offload_data->
R0;
147 Bdata->z0 = offload_data->
z0;
148 Bdata->raxis = offload_data->
raxis;
149 Bdata->zaxis = offload_data->
zaxis;
150 Bdata->B_phi0 = offload_data->
B_phi0;
151 Bdata->psi0 = offload_data->
psi0;
152 Bdata->psi1 = offload_data->
psi1;
153 Bdata->psi_mult = offload_data->
psi_mult;
155 Bdata->Nripple = offload_data->
Nripple;
156 Bdata->a0 = offload_data->
a0;
157 Bdata->delta0 = offload_data->
delta0;
158 Bdata->alpha0 = offload_data->
alpha0;
160 Bdata->psi_coeff = offload_data->
psi_coeff;
238 real* C = Bdata->psi_coeff;
251 psi_dpsi[1] = ( Bdata->psi_mult / (r * Bdata->R0) ) *
253 + C[12] * (r/2 + r*logr)
255 + C[2] * (2*r*logr + r)
256 + C[3] * (4*r3 - 8*r*z2)
257 + C[4] * (12*r3*logr + 3*r3 - 30*r*z2 - 24*r*logr*z2)
258 + C[5] * (6*r5 - 48*r3*z2 + 16*r*z4)
259 + C[6] * (-400*r*z4 -240*r*logr*z4 + 720*r3*logr*z2 + 480*r3*z2
262 + C[9] * (-6*z*r*logr - 3*z*r)
263 + C[10] * (12*z*r3 - 8*z3*r)
264 + C[11] * (-120*z*r3-160*z3*r*logr-80*z3*r+240*z*r3*logr) );
269 ( Bdata->psi_mult / (r * Bdata->R0) ) *
272 + C[4] * (-18*r2*z - 24*r2*logr*z + 8*z3)
273 + C[5] * (-24*r4*z + 32*r2*z3)
274 + C[6] * (48*z5 - 560*r2*z3 - 480*r2*logr*z3 +360*r4*logr*z
278 + C[9] * (3*z2 - 3*r2*logr)
279 + C[10] * (3*r4 - 12*z2*r2)
280 + C[11] * (40*z4 - 45*r4 - 240*z2*r2*logr + 60*r4*logr) );
334 real* C = Bdata->psi_coeff;
350 + C[4] * (-18*r2*z - 24*r2*logr*z + 8*z3)
351 + C[5] * (-24*r4*z + 32*r2*z3)
352 + C[6] * (48*z5 - 560*r2*z3 - 480*r2*logr*z3 +360*r4*logr*z
356 + C[9] * (3*z2 - 3*r2*logr)
357 + C[10] * (3*r4 - 12*z2*r2)
358 + C[11] * (40*z4 - 45*r4 - 240*z2*r2*logr + 60*r4*logr);
359 B[0] *= -Bdata->psi_mult / (r * Bdata->R0 * Bdata->R0);
362 B[1] = Bdata->B_phi0 / r;
365 B[2] = (1-C[12]) * (r3/2)
366 + C[12] * (r/2 + r*logr)
368 + C[2] * (2*r*logr + r)
369 + C[3] * (4*r3 - 8*r*z2)
370 + C[4] * (12*r3*logr + 3*r3 - 30*r*z2 - 24*r*logr*z2)
371 + C[5] * (6*r5 - 48*r3*z2 + 16*r*z4)
372 + C[6] * (-400*r*z4 -240*r*logr*z4 + 720*r3*logr*z2 + 480*r3*z2
375 + C[9] * (-6*z*r*logr - 3*z*r)
376 + C[10] * (12*z*r3 - 8*z3*r)
377 + C[11] * (-120*z*r3-160*z3*r*logr-80*z3*r+240*z*r3*logr);
378 B[2] *= Bdata->psi_mult / (r * Bdata->R0 * Bdata->R0);
381 if(Bdata->Nripple > 0) {
384 real radius = sqrt( ( r - Bdata->R0 ) * ( r - Bdata->R0 )
385 + ( z - Bdata->z0 ) * ( z - Bdata->z0 ));
386 real theta = atan2( z - Bdata->z0, r - Bdata->R0 );
387 real delta = Bdata->delta0 * exp(-0.5*theta*theta)
388 * pow( radius / Bdata->a0, Bdata->alpha0 );
389 B[1] = B[1] * ( 1 + delta * cos(Bdata->Nripple * phi) );
409 real* C = Bdata->psi_coeff;
414 real B_phi0 = Bdata->B_phi0;
415 real psi_mult = Bdata->psi_mult;
426 real logr = log(r/R0);
434 real B0 = C[2] * (-2*z) / R02
435 + C[3] * (-8*r2*z) / R04
436 + C[4] * (-18*r2*z - 24*r2*logr*z + 8*z3) / R04
437 + C[5] * (-24*r4*z + 32*r2*z3) / R06
438 + C[6] * (48*z5 - 560*r2*z3 - 480*r2*logr*z3 +360*r4*logr*z
442 + C[9] * (3*z2 - 3*r2*logr) / R03
443 + C[10] * (3*r4 - 12*z2*r2) / R05
444 + C[11] * (40*z4 - 45*r4 - 240*z2*r2*logr + 60*r4*logr) / R05;
446 real B1 = C[3] * (-16*r*z) / R04
447 + C[4] * (-60*r*z - 48*r*logr*z) / R04
448 + C[5] * (-96*r3*z + 64*r*z3) / R06
449 + C[6] * (-1600*r*z3 - 960*r*logr*z3 +1440*r3*logr*z
452 + C[9] * (-6*r*logr - 3*r) / R03
453 + C[10] * (12*r3 - 24*z2*r) / R05
454 + C[11] * (-120*r3 - 480*z2*r*logr -240*z2*r +240*r3*logr)/R05;
455 B1 = -B0 / r - B1 * psi_mult / r;
457 real B3 = C[2] * (-2) / R02
458 + C[3] * (-8*r2) / R04
459 + C[4] * (-18*r2 - 24*r2*logr + 24*z2) / R04
460 + C[5] * (-24*r4 + 96*r2*z2) / R06
461 + C[6] * (240*z4 - 1680*r2*z2 - 1440*r2*logr*z2 + 360*r4*logr
464 + C[10] * (-24*z*r2) / R05
465 + C[11] * (160*z3 - 480*z*r2*logr) / R05;
469 real B4 = B_phi0 * R0 / r;
470 real B5 = -B_phi0 * R0 / r2;
475 real B8 = (1-C[12]) * (r3/2) / R04
476 + C[12] * (r/2 + r*logr) / R02
478 + C[2] * (2*r*logr + r) / R02
479 + C[3] * (4*r3 - 8*r*z2) / R04
480 + C[4] * (12*r3*logr + 3*r3 - 30*r*z2 - 24*r*logr*z2) / R04
481 + C[5] * (6*r5 - 48*r3*z2 + 16*r*z4) / R06
482 + C[6] * (-400*r*z4 -240*r*logr*z4 + 720*r3*logr*z2 + 480*r3*z2
483 -90*r5*logr - 15*r5) / R06
484 + C[8] * (2*z*r) / R03
485 + C[9] * (-6*z*r*logr - 3*z*r) / R03
486 + C[10] * (12*z*r3 - 8*z3*r) / R05
487 + C[11] * (-120*z*r3-160*z3*r*logr-80*z3*r+240*z*r3*logr) / R05;
489 real B9 = (1-C[12]) * (3*r2/2) / R04
490 + C[12] * (1.5 + logr) / R02
492 + C[2] * (2*logr + 3) / R02
493 + C[3] * (12*r2 - 8*z2) / R04
494 + C[4] * (36*r2*logr + 21*r2 - 54*z2 - 24*logr*z2) / R04
495 + C[5] * (30*r4 - 144*r2*z2 + 16*z4) / R06
496 + C[6] * (-640*z4 - 240*logr*z4 + 2160*r2*logr*z2 + 2160*r2*z2
497 -450*r4*logr -165*r4) / R06
499 + C[9] * (-6*z*logr - 9*z) / R03
500 + C[10] * (36*z*r2 - 8*z3) / R05
501 + C[11] * (-120*z*r2 - 160*z3*logr -240*z3 +720*z*r2*logr)/R05;
502 B9 = B9 * psi_mult / r - B8 / r;
504 real B11 = -B1 - B0 / r;
507 if(Bdata->Nripple > 0) {
508 real radius = sqrt( ( r - R0 ) * ( r - R0 )
509 + ( z - z0 ) * ( z - z0 ));
510 real theta = atan2( z - z0, r - R0 );
511 real delta = Bdata->delta0 * exp(-0.5*theta*theta)
512 * pow( radius / Bdata->a0, Bdata->alpha0 );
515 real Bpert = Bphi * delta * cos(Bdata->Nripple * phi);
517 B6 += - Bphi * delta * Bdata->Nripple * sin(Bdata->Nripple * phi);
519 real dBpertdR = Bpert * (
520 ( (r - R0) /radius) * ( Bdata->alpha0 / radius )
521 + ( (z - z0) /(radius*radius) ) * theta
524 real dBpertdz = Bpert * (
525 ( (z - z0) /radius) * ( Bdata->alpha0 / radius )
526 - ( (r - R0) /(radius*radius) ) * theta
529 B5 += B5 * Bpert / Bphi + dBpertdR;