RBend.cpp 49.4 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// ------------------------------------------------------------------------
// $RCSfile: RBend.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: RBend
//   Defines the abstract interface for a rectangular bend magnet.
//
// ------------------------------------------------------------------------
// Class category: AbsBeamline
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:32:31 $
// $Author: fci $
//
// ------------------------------------------------------------------------

#include "AbsBeamline/RBend.h"
22
#include "Algorithms/PartBunch.h"
gsell's avatar
gsell committed
23
#include "AbsBeamline/BeamlineVisitor.h"
24
#include "Utilities/Options.h"
25
#include "Fields/Fieldmap.h"
gsell's avatar
gsell committed
26 27 28
#include <iostream>
#include <fstream>

kraus's avatar
kraus committed
29 30
extern Inform *gmsg;

gsell's avatar
gsell committed
31 32 33 34 35 36 37
// Class RBend
// ------------------------------------------------------------------------

int RBend::RBend_counter_m = 0;

RBend::RBend():
    Component(),
38 39
    pusher_m(),
    fileName_m(""),
gsell's avatar
gsell committed
40 41 42
    fieldmap_m(NULL),
    fast_m(false),
    angle_m(0.0),
43 44 45 46
    aperture_m(0.0),
    designEnergy_m(0.0),
    designRadius_m(0.0),
    fieldAmplitude_m(0.0),
47 48
    bX_m(0.0),
    bY_m(0.0),
49 50
    entranceAngle_m(0.0),
    exitAngle_m(0.0),
51
    fieldIndex_m(0.0),
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
    elementEdge_m(0.0),
    startField_m(0.0),
    endField_m(0.0),
    reinitialize_m(false),
    recalcRefTraj_m(false),
    length_m(0.0),
    gap_m(0.0),
    refTrajMapSize_m(0),
    refTrajMapStepSize_m(0.0),
    entranceParameter1_m(0.0),
    entranceParameter2_m(0.0),
    entranceParameter3_m(0.0),
    exitParameter1_m(0.0),
    exitParameter2_m(0.0),
    exitParameter3_m(0.0),
    xOriginEngeEntry_m(0.0),
    zOriginEngeEntry_m(0.0),
    deltaBeginEntry_m(0.0),
    deltaEndEntry_m(0.0),
    polyOrderEntry_m(0),
    xExit_m(0.0),
    zExit_m(0.0),
    xOriginEngeExit_m(0.0),
    zOriginEngeExit_m(0.0),
    deltaBeginExit_m(0.0),
    deltaEndExit_m(0.0),
    polyOrderExit_m(0),
    cosEntranceAngle_m(1.0),
    sinEntranceAngle_m(0.0),
    exitEdgeAngle_m(0.0),
    cosExitAngle_m(1.0),
    sinExitAngle_m(0.0) {

gsell's avatar
gsell committed
85
    setElType(isDipole);
86

gsell's avatar
gsell committed
87 88 89 90 91
}


RBend::RBend(const RBend &right):
    Component(right),
92 93
    pusher_m(right.pusher_m),
    fileName_m(right.fileName_m),
gsell's avatar
gsell committed
94 95 96
    fieldmap_m(right.fieldmap_m),
    fast_m(right.fast_m),
    angle_m(right.angle_m),
97 98 99 100
    aperture_m(right.aperture_m),
    designEnergy_m(right.designEnergy_m),
    designRadius_m(right.designRadius_m),
    fieldAmplitude_m(right.fieldAmplitude_m),
101 102
    bX_m(right.bX_m),
    bY_m(right.bY_m),
103 104
    entranceAngle_m(right.entranceAngle_m),
    exitAngle_m(right.exitAngle_m),
105
    fieldIndex_m(right.fieldIndex_m),
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    elementEdge_m(right.elementEdge_m),
    startField_m(right.startField_m),
    endField_m(right.endField_m),
    reinitialize_m(right.reinitialize_m),
    recalcRefTraj_m(right.recalcRefTraj_m),
    length_m(right.length_m),
    gap_m(right.gap_m),
    refTrajMapX_m(right.refTrajMapX_m),
    refTrajMapY_m(right.refTrajMapY_m),
    refTrajMapZ_m(right.refTrajMapZ_m),
    refTrajMapSize_m(right.refTrajMapSize_m),
    refTrajMapStepSize_m(right.refTrajMapStepSize_m),
    entranceParameter1_m(right.entranceParameter1_m),
    entranceParameter2_m(right.entranceParameter2_m),
    entranceParameter3_m(right.entranceParameter3_m),
    exitParameter1_m(right.exitParameter1_m),
    exitParameter2_m(right.exitParameter2_m),
    exitParameter3_m(right.exitParameter3_m),
    xOriginEngeEntry_m(right.xOriginEngeEntry_m),
    zOriginEngeEntry_m(right.zOriginEngeEntry_m),
    deltaBeginEntry_m(right.deltaBeginEntry_m),
    deltaEndEntry_m(right.deltaEndEntry_m),
    polyOrderEntry_m(right.polyOrderEntry_m),
    xExit_m(right.xExit_m),
    zExit_m(right.zExit_m),
    xOriginEngeExit_m(right.xOriginEngeExit_m),
    zOriginEngeExit_m(right.zOriginEngeExit_m),
    deltaBeginExit_m(right.deltaBeginExit_m),
    deltaEndExit_m(right.deltaEndExit_m),
    polyOrderExit_m(right.polyOrderExit_m),
    cosEntranceAngle_m(right.cosEntranceAngle_m),
    sinEntranceAngle_m(right.sinEntranceAngle_m),
    exitEdgeAngle_m(right.exitEdgeAngle_m),
    cosExitAngle_m(right.cosExitAngle_m),
    sinExitAngle_m(right.sinExitAngle_m) {

gsell's avatar
gsell committed
142 143
    setElType(isDipole);

144
}
gsell's avatar
gsell committed
145

Steve Russell's avatar
Steve Russell committed
146
RBend::RBend(const std::string &name):
gsell's avatar
gsell committed
147
    Component(name),
148 149
    pusher_m(),
    fileName_m(""),
gsell's avatar
gsell committed
150 151 152
    fieldmap_m(NULL),
    fast_m(false),
    angle_m(0.0),
153 154 155 156
    aperture_m(0.0),
    designEnergy_m(0.0),
    designRadius_m(0.0),
    fieldAmplitude_m(0.0),
157 158
    bX_m(0.0),
    bY_m(0.0),
159 160
    entranceAngle_m(0.0),
    exitAngle_m(0.0),
161
    fieldIndex_m(0.0),
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
    elementEdge_m(0.0),
    startField_m(0.0),
    endField_m(0.0),
    reinitialize_m(false),
    recalcRefTraj_m(false),
    length_m(0.0),
    gap_m(0.0),
    refTrajMapSize_m(0),
    refTrajMapStepSize_m(0.0),
    entranceParameter1_m(0.0),
    entranceParameter2_m(0.0),
    entranceParameter3_m(0.0),
    exitParameter1_m(0.0),
    exitParameter2_m(0.0),
    exitParameter3_m(0.0),
    xOriginEngeEntry_m(0.0),
    zOriginEngeEntry_m(0.0),
    deltaBeginEntry_m(0.0),
    deltaEndEntry_m(0.0),
    polyOrderEntry_m(0),
    xExit_m(0.0),
    zExit_m(0.0),
    xOriginEngeExit_m(0.0),
    zOriginEngeExit_m(0.0),
    deltaBeginExit_m(0.0),
    deltaEndExit_m(0.0),
    polyOrderExit_m(0),
    cosEntranceAngle_m(1.0),
    sinEntranceAngle_m(0.0),
    exitEdgeAngle_m(0.0),
    cosExitAngle_m(1.0),
    sinExitAngle_m(0.0) {

gsell's avatar
gsell committed
195 196
    setElType(isDipole);

197
}
gsell's avatar
gsell committed
198 199 200 201 202 203 204 205

RBend::~RBend() {
}

void RBend::accept(BeamlineVisitor &visitor) const {
    visitor.visitRBend(*this);
}

206 207 208 209
/*
 * OPAL-MAP methods
 * ================
 */
gsell's avatar
gsell committed
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
double RBend::getNormalComponent(int n) const {
    return getField().getNormalComponent(n);
}

double RBend::getSkewComponent(int n) const {
    return getField().getSkewComponent(n);
}

void RBend::setNormalComponent(int n, double v) {
    getField().setNormalComponent(n, v);
}

void RBend::setSkewComponent(int n, double v) {
    getField().setSkewComponent(n, v);
}

226 227 228
/*
 * BET methods.
 */
gsell's avatar
gsell committed
229 230 231 232 233 234 235 236 237 238 239
void RBend::addKR(int i, double t, Vector_t &K) {
    Inform msg("RBend::addK()");

    Vector_t tmpE(0.0, 0.0, 0.0);
    Vector_t tmpB(0.0, 0.0, 0.0);
    Vector_t tmpE_diff(0.0, 0.0, 0.0);
    Vector_t tmpB_diff(0.0, 0.0, 0.0);
    double pz = RefPartBunch_m->getZ(i) - startField_m - ds_m;
    const Vector_t tmpA(RefPartBunch_m->getX(i) - dx_m, RefPartBunch_m->getY(i) - dy_m, pz);

    DiffDirection zdir(DZ);
240 241
    fieldmap_m->getFieldstrength(tmpA, tmpE, tmpB);
    fieldmap_m->getFieldDerivative(tmpA, tmpE_diff, tmpB_diff, zdir);
gsell's avatar
gsell committed
242 243 244

    double g = RefPartBunch_m->getGamma(i);

245
    if(fabs(fieldAmplitude_m * tmpB_diff(2)) > 0.1) {
gsell's avatar
gsell committed
246
        double cf = Physics::q_e * tmpB(2) / (g * Physics::EMASS);
247
        K += Vector_t(-pow(cf * fieldAmplitude_m * tmpB(0), 2) / 3.0, -pow(cf * fieldAmplitude_m * tmpB(1), 2) / 3.0, 0.0);
gsell's avatar
gsell committed
248 249 250 251 252 253 254 255 256 257
    }
}

void RBend::addKT(int i, double t, Vector_t &K) {
    Inform msg("RBend::addK()");

    Vector_t tmpE(0.0, 0.0, 0.0);
    Vector_t tmpB(0.0, 0.0, 0.0);
    double pz = RefPartBunch_m->getZ(i) - startField_m - ds_m;
    const Vector_t tmpA(RefPartBunch_m->getX(i) - dx_m, RefPartBunch_m->getY(i) - dy_m, pz);
258
    fieldmap_m->getFieldstrength(tmpA, tmpE, tmpB);
gsell's avatar
gsell committed
259 260 261 262

    double b = RefPartBunch_m->getBeta(i);
    double g = 1 / sqrt(1 - b * b);

263
    double cf = -Physics::q_e * Physics::c * b * tmpB(2) * fieldAmplitude_m / (g * Physics::EMASS);
gsell's avatar
gsell committed
264 265 266 267 268
    Vector_t temp(cf * tmpB(1), cf * tmpB(0), 0.0);

    //FIXME: K += ??
}

269 270 271 272 273 274 275 276 277 278

/*
 * OPAL-T Methods.
 * ===============
 */

/*
 *  This function merely repackages the field arrays as type Vector_t and calls
 *  the equivalent method but with the Vector_t data types.
 */
279
bool RBend::apply(const size_t &i, const double &t, double E[], double B[]) {
280 281 282 283 284

    Vector_t Ev(0.0, 0.0, 0.0);
    Vector_t Bv(0.0, 0.0, 0.0);
    if(apply(RefPartBunch_m->R[i], RefPartBunch_m->get_rmean(), t, Ev, Bv))
        return true;
gsell's avatar
gsell committed
285 286 287 288 289 290 291 292 293 294 295

    E[0] = Ev(0);
    E[1] = Ev(1);
    E[2] = Ev(2);
    B[0] = Bv(0);
    B[1] = Bv(1);
    B[2] = Bv(2);

    return false;
}

296
bool RBend::apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) {
gsell's avatar
gsell committed
297

298 299 300 301 302
    if(designRadius_m > 0.0) {

        // Shift position to magnet frame.
        Vector_t X = RefPartBunch_m->X[i];
        X(2) += startField_m - elementEdge_m;
gsell's avatar
gsell committed
303

304 305 306 307 308 309
        /*
         * Add in transverse bend displacements. (ds is already
         * accounted for.)
         */
        X(0) -= dx_m;
        X(1) -= dy_m;
gsell's avatar
gsell committed
310

311 312 313 314 315
        // Get field from field map.
        Vector_t eField(0.0, 0.0, 0.0);
        Vector_t bField(0.0, 0.0, 0.0);
        CalculateMapField(X, eField, bField);
        bField *= fieldAmplitude_m;
gsell's avatar
gsell committed
316

317 318 319 320 321
        B(0) += bField(0);
        B(1) += bField(1);
        B(2) += bField(2);

    }
gsell's avatar
gsell committed
322 323 324 325

    return false;
}

326 327 328 329 330
bool RBend::apply(const Vector_t &R,
                  const Vector_t &centroid,
                  const double &t,
                  Vector_t &E,
                  Vector_t &B) {
gsell's avatar
gsell committed
331

332
    if(designRadius_m > 0.0) {
gsell's avatar
gsell committed
333

334 335
        int index = static_cast<int>
                    (std::floor((R(2) - startField_m) / refTrajMapStepSize_m));
gsell's avatar
gsell committed
336

337
        if(index > 0 && index + 1 < refTrajMapSize_m) {
gsell's avatar
gsell committed
338

339 340 341 342 343 344 345 346
            // Find indices for position in pre-computed central trajectory map.
            double lever = (R(2) - startField_m) / refTrajMapStepSize_m - index;
            double x = (1.0 - lever) * refTrajMapX_m.at(index)
                       + lever * refTrajMapX_m.at(index + 1);
            double y = (1.0 - lever) * refTrajMapY_m.at(index)
                       + lever * refTrajMapY_m.at(index + 1);
            double z = (1.0 - lever) * refTrajMapZ_m.at(index)
                       + lever * refTrajMapZ_m.at(index + 1);
gsell's avatar
gsell committed
347

348 349 350 351 352
            // Adjust position relative to pre-computed central trajectory map.
            Vector_t X(0.0, 0.0, 0.0);
            X(0) = R(0) + x;
            X(1) = R(1) + y;
            X(2) = z;
gsell's avatar
gsell committed
353

354 355 356
            Vector_t tempE(0.0, 0.0, 0.0);
            Vector_t tempB(0.0, 0.0, 0.0);
            Vector_t XInBendFrame = RotateToBendFrame(X);
gsell's avatar
gsell committed
357

358 359 360 361 362 363
            /*
             * Add in transverse bend displacements. (ds is already
             * accounted for.)
             */
            XInBendFrame(0) -= dx_m;
            XInBendFrame(1) -= dy_m;
gsell's avatar
gsell committed
364

365 366
            CalculateMapField(XInBendFrame, tempE, tempB);
            tempB = fieldAmplitude_m * RotateOutOfBendFrame(tempB);
gsell's avatar
gsell committed
367

368 369 370
            B(0) += tempB(0);
            B(1) += tempB(1);
            B(2) += tempB(2);
gsell's avatar
gsell committed
371

372 373
        }
    }
Steve Russell's avatar
Steve Russell committed
374

375
    return false;
gsell's avatar
gsell committed
376

377
}
gsell's avatar
gsell committed
378

379 380 381
bool RBend::bends() const {
    return true;
}
gsell's avatar
gsell committed
382

383 384 385
void RBend::finalise() {
    online_m = false;
}
gsell's avatar
gsell committed
386

kraus's avatar
kraus committed
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
void RBend::goOnline(const double &) {

    // Check if we need to reinitialize the bend field amplitude.
    if(reinitialize_m) {
        reinitialize_m = Reinitialize();
        recalcRefTraj_m = false;
    }

    /*
     * Always recalculate the reference trajectory on first call even
     * if we do not reinitialize the bend. The reference trajectory
     * has to be calculated at the same energy as the actual beam or
     * we do not get accurate values for the magnetic field in the output
     * file.
     */
    if(recalcRefTraj_m) {
        double angleX = 0.0;
        double angleY = 0.0;
        CalculateRefTrajectory(angleX, angleY);
        recalcRefTraj_m = false;
    }

    online_m = true;
}

412 413 414 415
void RBend::getDimensions(double &sBegin, double &sEnd) const {
    sBegin = startField_m;
    sEnd = endField_m;
}
gsell's avatar
gsell committed
416

417 418
ElementBase::ElementType RBend::getType() const {
    return RBEND;
419
}
gsell's avatar
gsell committed
420

421
void RBend::initialise(PartBunch *bunch, double &startField, double &endField, const double &scaleFactor) {
gsell's avatar
gsell committed
422

kraus's avatar
kraus committed
423
    Inform msg("RBend ", *gmsg);
gsell's avatar
gsell committed
424

425
    if(InitializeFieldMap(msg)) {
gsell's avatar
gsell committed
426

427 428 429 430 431 432 433 434
        SetupPusher(bunch);
        ReadFieldMap(msg);
        SetupBendGeometry(msg, startField, endField);
        double bendAngleX = 0.0;
        double bendAngleY = 0.0;
        CalculateRefTrajectory(bendAngleX, bendAngleY);
        recalcRefTraj_m = true;
        Print(msg, bendAngleX, bendAngleY);
gsell's avatar
gsell committed
435

436
        // Pass start and end of field to calling function.
Steve Russell's avatar
Steve Russell committed
437 438
        startField = startField_m;
        endField = endField_m;
gsell's avatar
gsell committed
439 440

    } else {
kraus's avatar
kraus committed
441 442 443
        ERRORMSG("There is something wrong with your field map \""
                 << fileName_m
                 << "\"");
444
        endField = startField - 1.0e-3;
gsell's avatar
gsell committed
445 446 447
    }
}

448 449
double RBend::GetBendAngle() const {
    return angle_m;
gsell's avatar
gsell committed
450 451
}

452 453
double RBend::GetBendRadius() const {
    return designRadius_m;
gsell's avatar
gsell committed
454 455
}

456 457
double RBend::GetEffectiveCenter() const {
    return elementEdge_m + designRadius_m * angle_m / 2.0;
Steve Russell's avatar
Steve Russell committed
458 459
}

460 461
double RBend::GetEffectiveLength() const {
    return designRadius_m * angle_m;
gsell's avatar
gsell committed
462 463
}

464 465
std::string RBend::GetFieldMapFN() const {
    return fileName_m;
Steve Russell's avatar
Steve Russell committed
466 467
}

468 469
double RBend::GetStartElement() const {
    return elementEdge_m;
Steve Russell's avatar
Steve Russell committed
470 471
}

472 473
void RBend::SetAperture(double aperture) {
    aperture_m = std::abs(aperture);
gsell's avatar
gsell committed
474 475
}

476 477
void RBend::SetBendAngle(double angle) {
    angle_m = angle;
gsell's avatar
gsell committed
478 479
}

480 481
void RBend::SetBeta(double beta) {
    Orientation_m(1) = beta;
gsell's avatar
gsell committed
482 483
}

484 485
void RBend::SetDesignEnergy(double energy) {
    designEnergy_m = std::abs(energy);
gsell's avatar
gsell committed
486 487
}

488 489
void RBend::SetEntranceAngle(double entranceAngle) {
    entranceAngle_m = entranceAngle;
gsell's avatar
gsell committed
490 491
}

492 493 494
void RBend::SetFieldAmplitude(double k0, double k0s) {
    bY_m = k0;
    bX_m = k0s;
gsell's avatar
gsell committed
495 496
}

497 498
void RBend::SetFieldMapFN(std::string fileName) {
    fileName_m = fileName;
gsell's avatar
gsell committed
499 500
}

501 502
void RBend::SetFullGap(double gap) {
    gap_m = gap;
gsell's avatar
gsell committed
503 504
}

505
void RBend::SetK1(double k1) {
506
    fieldIndex_m = k1;
gsell's avatar
gsell committed
507 508
}

509 510 511
void RBend::SetLength(double length) {
    length_m = length;
}
Steve Russell's avatar
Steve Russell committed
512

513 514 515
void RBend::SetRotationAboutZ(double rotation) {
    Orientation_m(2) = rotation;
}
Steve Russell's avatar
Steve Russell committed
516

517
void RBend::AdjustFringeFields(double ratio) {
Steve Russell's avatar
Steve Russell committed
518

519 520
    double delta = std::abs(entranceParameter1_m - entranceParameter2_m);
    entranceParameter1_m = entranceParameter2_m - delta * ratio;
Steve Russell's avatar
Steve Russell committed
521

522 523
    delta = std::abs(entranceParameter2_m - entranceParameter3_m);
    entranceParameter3_m = entranceParameter2_m + delta * ratio;
Steve Russell's avatar
Steve Russell committed
524

525 526
    delta = std::abs(exitParameter1_m - exitParameter2_m);
    exitParameter1_m = exitParameter2_m - delta * ratio;
Steve Russell's avatar
Steve Russell committed
527

528 529
    delta = std::abs(exitParameter2_m - exitParameter3_m);
    exitParameter3_m = exitParameter2_m + delta * ratio;
Steve Russell's avatar
Steve Russell committed
530 531 532

}

533
double RBend::CalculateBendAngle() {
Steve Russell's avatar
Steve Russell committed
534 535

    const double mass = RefPartBunch_m->getM();
536
    const double gamma = designEnergy_m / mass + 1.0;
Steve Russell's avatar
Steve Russell committed
537
    const double betaGamma = sqrt(pow(gamma, 2.0) - 1.0);
538
    const double beta = betaGamma / gamma;
Steve Russell's avatar
Steve Russell committed
539 540 541
    const double deltaT = RefPartBunch_m->getdT();

    // Integrate through field for initial angle.
542 543 544 545
    Vector_t X(0.0, 0.0, startField_m - elementEdge_m);
    Vector_t P(0.0, 0.0, betaGamma);
    double deltaS = 0.0;
    double bendLength = endField_m - startField_m;
Steve Russell's avatar
Steve Russell committed
546

547
    while(deltaS < bendLength) {
Steve Russell's avatar
Steve Russell committed
548 549 550 551 552

        X /= Vector_t(Physics::c * deltaT);
        pusher_m.push(X, P, deltaT);
        X *= Vector_t(Physics::c * deltaT);

553 554 555 556
        Vector_t eField(0.0, 0.0, 0.0);
        Vector_t bField(0.0, 0.0, 0.0);
        CalculateMapField(X, eField, bField);
        bField = fieldAmplitude_m * bField;
Steve Russell's avatar
Steve Russell committed
557 558

        X /= Vector_t(Physics::c * deltaT);
559
        pusher_m.kick(X, P, eField, bField, deltaT);
Steve Russell's avatar
Steve Russell committed
560 561 562 563

        pusher_m.push(X, P, deltaT);
        X *= Vector_t(Physics::c * deltaT);

564 565
        deltaS += deltaT * beta * Physics::c;

Steve Russell's avatar
Steve Russell committed
566 567
    }

568
    double angle =  -atan2(P(0), P(2));
Steve Russell's avatar
Steve Russell committed
569 570

    return angle;
571

Steve Russell's avatar
Steve Russell committed
572 573
}

574 575 576 577 578
void RBend::CalcCentralField(Vector_t R,
                             double deltaX,
                             double angle,
                             Vector_t &B) {

579 580 581 582 583 584
    double nOverRho = fieldIndex_m / designRadius_m;
    double expFactor = exp(-nOverRho * deltaX);
    double bxBzFactor = nOverRho * expFactor * R(1);
    B(0) = -bxBzFactor * cos(angle);
    B(1) = expFactor * (1.0 - pow(nOverRho * R(1), 2.0) / 2.0);
    B(2) = -bxBzFactor * sin(angle);
585 586 587 588 589 590 591 592

}

void RBend::CalcEngeFunction(double zNormalized,
                             std::vector<double> engeCoeff,
                             int polyOrder,
                             double &engeFunc,
                             double &engeFuncDeriv,
593
                             double &engeFuncSecDerivNorm) {
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623

    double expSum = 0.0;
    double expSumDeriv = 0.0;
    double expSumSecDeriv = 0.0;

    if(polyOrder >= 2) {

        expSum = engeCoeff.at(0)
                 + engeCoeff.at(1) * zNormalized;
        expSumDeriv = engeCoeff.at(1);

        for(int index = 2; index <= polyOrder; index++) {
            expSum += engeCoeff.at(index) * pow(zNormalized, index);
            expSumDeriv += index * engeCoeff.at(index)
                           * pow(zNormalized, index - 1);
            expSumSecDeriv += index * (index - 1) * engeCoeff.at(index)
                              * pow(zNormalized, index - 2);
        }

    } else if(polyOrder == 1) {

        expSum = engeCoeff.at(0)
                 + engeCoeff.at(1) * zNormalized;
        expSumDeriv = engeCoeff.at(1);

    } else
        expSum = engeCoeff.at(0);

    double engeExp = exp(expSum);
    engeFunc = 1.0 / (1.0 + engeExp);
624

Jianjun Yang's avatar
Jianjun Yang committed
625
    if(!std::isnan(engeFunc)) {
626 627 628 629 630 631 632 633 634

        expSumDeriv /= gap_m;
        expSumSecDeriv /= pow(gap_m, 2.0);
        double engeExpDeriv = expSumDeriv * engeExp;
        double engeExpSecDeriv = (expSumSecDeriv + pow(expSumDeriv, 2.0))
                                 * engeExp;
        double engeFuncSq = pow(engeFunc, 2.0);

        engeFuncDeriv = -engeExpDeriv * engeFuncSq;
Jianjun Yang's avatar
Jianjun Yang committed
635
        if (std::isnan(engeFuncDeriv) || std::isinf(engeFuncDeriv))
636 637 638 639 640
            engeFuncDeriv = 0.0;

        engeFuncSecDerivNorm = -engeExpSecDeriv * engeFunc
                               + 2.0 * pow(engeExpDeriv, 2.0)
                                 * engeFuncSq;
Jianjun Yang's avatar
Jianjun Yang committed
641
        if (std::isnan(engeFuncSecDerivNorm) || std::isinf(engeFuncSecDerivNorm))
642 643
            engeFuncSecDerivNorm = 0.0;

644 645 646
    } else {
        engeFunc = 0.0;
        engeFuncDeriv = 0.0;
647
        engeFuncSecDerivNorm = 0.0;
648

649
    }
650 651 652 653 654 655 656 657 658
}

void RBend::CalcEntranceFringeField(Vector_t REntrance,
                                    double deltaX,
                                    Vector_t &B) {

    double zNormalized = -REntrance(2) / gap_m;
    double engeFunc = 0.0;
    double engeFuncDeriv = 0.0;
659
    double engeFuncSecDerivNorm = 0.0;
660 661 662 663 664 665

    CalcEngeFunction(zNormalized,
                     engeCoeffsEntry_m,
                     polyOrderEntry_m,
                     engeFunc,
                     engeFuncDeriv,
666
                     engeFuncSecDerivNorm);
667

668 669
    double nOverRho = fieldIndex_m / designRadius_m;
    double expFactor = exp(-nOverRho * deltaX);
670 671
    double trigFactor = pow(nOverRho, 2.0) + engeFuncSecDerivNorm;

672
    double bXEntrance = -engeFunc * nOverRho * expFactor* REntrance(1);
673 674
    double bYEntrance = expFactor * engeFunc
                        * (1.0  - trigFactor * pow(REntrance(1), 2.0) / 2.0);
675
    double bZEntrance = -expFactor * engeFuncDeriv * REntrance(1);
676 677 678 679 680 681 682 683 684 685 686 687

    B(0) = bXEntrance * cosEntranceAngle_m - bZEntrance * sinEntranceAngle_m;
    B(1) = bYEntrance;
    B(2) = bXEntrance * sinEntranceAngle_m + bZEntrance * cosEntranceAngle_m;

}

void RBend::CalcExitFringeField(Vector_t RExit, double deltaX, Vector_t &B) {

    double zNormalized = RExit(2) / gap_m;
    double engeFunc = 0.0;
    double engeFuncDeriv = 0.0;
688
    double engeFuncSecDerivNorm = 0.0;
689 690 691 692 693
    CalcEngeFunction(zNormalized,
                     engeCoeffsExit_m,
                     polyOrderExit_m,
                     engeFunc,
                     engeFuncDeriv,
694
                     engeFuncSecDerivNorm);
695

696 697
    double nOverRho = fieldIndex_m / designRadius_m;
    double expFactor = exp(-nOverRho * deltaX);
698 699
    double trigFactor = pow(nOverRho, 2.0) + engeFuncSecDerivNorm;

700
    double bXExit = -engeFunc * nOverRho * expFactor* RExit(1);
701 702
    double bYExit = expFactor * engeFunc
                    * (1.0 - trigFactor * pow(RExit(1), 2.0) / 2.0);
703
    double bZExit = expFactor * engeFuncDeriv * RExit(1);
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787

    B(0) = bXExit * cosExitAngle_m - bZExit * sinExitAngle_m;
    B(1) = bYExit;
    B(2) = bXExit * sinExitAngle_m + bZExit * cosExitAngle_m;
}

void RBend::CalculateMapField(Vector_t R, Vector_t &E, Vector_t &B) {

    E = Vector_t(0.0);
    B = Vector_t(0.0);

    //    Vector_t REntrance(0.0, 0.0, 0.0);
    //    Vector_t RExit(0.0, 0.0, 0.0);
    //    if (IsPositionInEntranceField(R, REntrance)) {
    //        CalcEntranceFringeField(REntrance, 0.0, B);
    //    } else if (IsPositionInExitField(R, RExit)) {
    //        CalcExitFringeField(RExit, 0.0, B);
    //    } else {
    //        CalcCentralField(R, 0.0, 0.0, B);
    //    }

    double deltaXEntrance = 0.0;
    double deltaXExit = 0.0;
    bool inEntranceRegion = InMagnetEntranceRegion(R, deltaXEntrance);
    bool inExitRegion = InMagnetExitRegion(R, deltaXExit);

    if(!inEntranceRegion && !inExitRegion) {

        double deltaX = 0.0;
        double angle = 0.0;
        if(InMagnetCentralRegion(R, deltaX, angle)) {
            Vector_t REntrance(0.0, 0.0, 0.0);
            Vector_t RExit(0.0, 0.0, 0.0);
            if(IsPositionInEntranceField(R, REntrance))
                CalcEntranceFringeField(REntrance, deltaX, B);
            else if(IsPositionInExitField(R, RExit))
                CalcExitFringeField(RExit, deltaX, B);
            else
                CalcCentralField(R, deltaX, angle, B);

        }

    } else if(inEntranceRegion && !inExitRegion) {

        Vector_t REntrance(0.0, 0.0, 0.0);
        if(IsPositionInEntranceField(R, REntrance)) {
            CalcEntranceFringeField(REntrance, deltaXEntrance, B);
        } else if(REntrance(2) > 0.0)
            CalcCentralField(R, deltaXEntrance, 0.0, B);

    } else if(!inEntranceRegion && inExitRegion) {

        Vector_t RExit(0.0, 0.0, 0.0);
        if(IsPositionInExitField(R, RExit)) {
            CalcExitFringeField(RExit, deltaXExit, B);
        } else if(RExit(2) < 0.0)
            CalcCentralField(R, deltaXExit, angle_m, B);

    } else if(inEntranceRegion && inExitRegion) {

        /*
         * This is an unusual condition and should only happen with
         * a sector magnet that bends more than 180 degrees. Here, we
         * have the possibility that the particle sees both the
         * entrance and exit fringe fields.
         */
        Vector_t BEntrance(0.0, 0.0, 0.0);
        Vector_t REntrance(0.0, 0.0, 0.0);
        if(IsPositionInEntranceField(R, REntrance))
            CalcEntranceFringeField(REntrance, deltaXEntrance, BEntrance);

        Vector_t BExit(0.0, 0.0, 0.0);
        Vector_t RExit(0.0, 0.0, 0.0);
        if(IsPositionInExitField(R, RExit))
            CalcExitFringeField(RExit, deltaXExit, BExit);

        B(0) = BEntrance(0) + BExit(0);
        B(1) = BEntrance(1) + BExit(1);
        B(2) = BEntrance(2) + BExit(2);

    }
}

void RBend::CalculateRefTrajectory(double &angleX, double &angleY) {
Steve Russell's avatar
Steve Russell committed
788 789

    const double mass = RefPartBunch_m->getM();
790 791
    const double gamma = designEnergy_m / mass + 1.;
    const double betaGamma = sqrt(gamma * gamma - 1.);
Steve Russell's avatar
Steve Russell committed
792 793
    const double dt = RefPartBunch_m->getdT();

794 795
    Vector_t X(0.0, 0.0, startField_m - elementEdge_m);
    Vector_t P(0.0, 0.0, betaGamma);
Steve Russell's avatar
Steve Russell committed
796

797 798 799 800 801 802
    if(!refTrajMapX_m.empty())
        refTrajMapX_m.clear();
    if(!refTrajMapY_m.empty())
        refTrajMapY_m.clear();
    if(!refTrajMapZ_m.empty())
        refTrajMapZ_m.clear();
Steve Russell's avatar
Steve Russell committed
803

804 805 806
    refTrajMapX_m.push_back(X(0));
    refTrajMapY_m.push_back(X(1));
    refTrajMapZ_m.push_back(X(2));
Steve Russell's avatar
Steve Russell committed
807

808 809 810 811 812
    refTrajMapStepSize_m = betaGamma / gamma * Physics::c * dt;
    double deltaS = 0.0;
    double bendLength = endField_m - startField_m;

    while(deltaS < bendLength) {
Steve Russell's avatar
Steve Russell committed
813 814 815 816 817

        X /= Vector_t(Physics::c * dt);
        pusher_m.push(X, P, dt);
        X *= Vector_t(Physics::c * dt);

818 819 820
        Vector_t eField(0.0, 0.0, 0.0);
        Vector_t bField(0.0, 0.0, 0.0);
        Vector_t XInBendFrame = RotateToBendFrame(X);
Steve Russell's avatar
Steve Russell committed
821

822 823 824 825 826 827 828 829 830
        /*
         * Add in transverse bend displacements. (ds is already
         * accounted for.)
         */
        XInBendFrame(0) -= dx_m;
        XInBendFrame(1) -= dy_m;

        CalculateMapField(XInBendFrame, eField, bField);
        bField = fieldAmplitude_m * RotateOutOfBendFrame(bField);
Steve Russell's avatar
Steve Russell committed
831 832

        X /= Vector_t(Physics::c * dt);
833 834
        pusher_m.kick(X, P, eField, bField, dt);

Steve Russell's avatar
Steve Russell committed
835 836 837
        pusher_m.push(X, P, dt);
        X *= Vector_t(Physics::c * dt);

838 839 840 841 842
        refTrajMapX_m.push_back(X(0));
        refTrajMapY_m.push_back(X(1));
        refTrajMapZ_m.push_back(X(2));

        deltaS += refTrajMapStepSize_m;
Steve Russell's avatar
Steve Russell committed
843 844 845

    }

846
    refTrajMapSize_m = refTrajMapX_m.size();
Steve Russell's avatar
Steve Russell committed
847

848
    if(std::abs(Orientation_m(2)) == Physics::pi / 2.0
849 850 851 852
       || Orientation_m(2) == 3.0 * Physics::pi / 2.0)
        angleX = 0.0;
    else
        angleX = -atan2(P(0), P(2));
Steve Russell's avatar
Steve Russell committed
853

854 855 856 857 858
    if(Orientation_m(2) == 0.0
       || Orientation_m(2) == Physics::pi)
        angleY = 0.0;
    else
        angleY = atan2(P(1), P(2));
Steve Russell's avatar
Steve Russell committed
859 860

}
gsell's avatar
gsell committed
861

862 863 864 865 866 867 868 869 870 871 872 873 874
double RBend::EstimateFieldAdjustmentStep(double actualBendAngle,
        double mass,
        double betaGamma) {

    double amplitude1 = fieldAmplitude_m;
    double bendAngle1 = actualBendAngle;

    // Estimate field adjustment step.
    double effectiveLength = angle_m * designRadius_m;
    double fieldStep = (angle_m - bendAngle1) * betaGamma * mass / (2.0 * effectiveLength * Physics::c);
    if(pow(fieldAmplitude_m * effectiveLength * Physics::c / (betaGamma * mass), 2.0) < 1.0)
        fieldStep = (angle_m - bendAngle1) * betaGamma * mass / (2.0 * effectiveLength * Physics::c)
                    * std::sqrt(1.0 - pow(fieldAmplitude_m * effectiveLength * Physics::c / (betaGamma * mass), 2.0));
gsell's avatar
gsell committed
875

876
    fieldStep *= amplitude1 / std::abs(amplitude1);
gsell's avatar
gsell committed
877

878
    return fieldStep;
gsell's avatar
gsell committed
879

880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928
}

void RBend::FindBendEffectiveLength(double startField, double endField) {

    /*
     * Use an iterative procedure to set the width of the
     * default field map for the defined field amplitude
     * and bend angle.
     */
    SetEngeOriginDelta(0.0);
    SetFieldCalcParam(false);
    SetFieldBoundaries(startField, endField);

    double actualBendAngle = CalculateBendAngle();
    double error = std::abs(actualBendAngle - angle_m);
    if(error > 1.0e-6) {

        double deltaStep = 0.0;
        if(std::abs(actualBendAngle) < std::abs(angle_m))
            deltaStep = -gap_m / 2.0;
        else
            deltaStep = gap_m / 2.0;

        double delta1 = 0.0;
        double bendAngle1 = actualBendAngle;

        double delta2 = deltaStep;
        SetEngeOriginDelta(delta2);
        SetFieldCalcParam(false);
        SetFieldBoundaries(startField, endField);
        double bendAngle2 = CalculateBendAngle();

        if(std::abs(bendAngle1) > std::abs(angle_m)) {
            while(std::abs(bendAngle2) > std::abs(angle_m)) {
                delta2 += deltaStep;
                SetEngeOriginDelta(delta2);
                SetFieldCalcParam(false);
                SetFieldBoundaries(startField, endField);
                bendAngle2 = CalculateBendAngle();
            }
        } else {
            while(std::abs(bendAngle2) < std::abs(angle_m)) {
                delta2 += deltaStep;
                SetEngeOriginDelta(delta2);
                SetFieldCalcParam(false);
                SetFieldBoundaries(startField, endField);
                bendAngle2 = CalculateBendAngle();
            }
        }
gsell's avatar
gsell committed
929

930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
        // Now we should have the proper field map width bracketed.
        unsigned int iterations = 1;
        double delta = 0.0;
        error = std::abs(actualBendAngle - angle_m);
        while(error > 1.0e-6 && iterations < 100) {

            delta = (delta1 + delta2) / 2.0;
            SetEngeOriginDelta(delta);
            SetFieldCalcParam(false);
            SetFieldBoundaries(startField, endField);
            double newBendAngle = CalculateBendAngle();

            error = std::abs(newBendAngle - angle_m);

            if(error > 1.0e-6) {

                if(bendAngle1 - angle_m < 0.0) {

                    if(newBendAngle - angle_m < 0.0) {
                        bendAngle1 = newBendAngle;
                        delta1 = delta;
                    } else {
                        bendAngle2 = newBendAngle;
                        delta2 = delta;
                    }

                } else {

                    if(newBendAngle - angle_m < 0.0) {
                        bendAngle2 = newBendAngle;
                        delta2 = delta;
                    } else {
                        bendAngle1 = newBendAngle;
                        delta1 = delta;
                    }
                }
            }
            iterations++;
        }
    }
}
gsell's avatar
gsell committed
971

972 973 974 975 976 977 978 979 980 981 982 983 984
bool RBend::FindBendLength(Inform &msg,
                           double &bendLength,
                           bool &bendLengthFromMap) {

    /*
     * Find bend length. If this was not set by the user using the
     * L (length) attribute, infer it from the field map.
     */
    bendLength = length_m;
    if(bendLength > 0.0) {
        bendLengthFromMap = false;
        return true;
    } else {
gsell's avatar
gsell committed
985

986 987
        if(bendLength == 0.0)
            bendLength = exitParameter2_m - entranceParameter2_m;
gsell's avatar
gsell committed
988 989


990
        if(bendLength <= 0.0) {
kraus's avatar
kraus committed
991 992 993
            ERRORMSG("Magnet length inferred from field map is less than or equal"
                     " to zero. Check your bend magnet input."
                     << endl);
994 995 996
            return false;
        } else
            return true;
gsell's avatar
gsell committed
997 998 999 1000

    }
}

1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
void RBend::FindBendStrength(double mass,
                             double gamma,
                             double betaGamma,
                             double charge) {

    /*
     * Use an iterative procedure to set the magnet field amplitude
     * for the defined bend angle.
     */
    double actualBendAngle = CalculateBendAngle();
    double fieldStep = EstimateFieldAdjustmentStep(actualBendAngle,
                       mass,
                       betaGamma);
    double amplitude1 = fieldAmplitude_m;
    double bendAngle1 = actualBendAngle;

    double amplitude2 = fieldAmplitude_m + fieldStep;
    fieldAmplitude_m = amplitude2;
    double bendAngle2 = CalculateBendAngle();

    if(std::abs(bendAngle1) > std::abs(angle_m)) {
        while(std::abs(bendAngle2) > std::abs(angle_m)) {
            amplitude2 += fieldStep;
            fieldAmplitude_m = amplitude2;
            bendAngle2 = CalculateBendAngle();
        }
    } else {
        while(std::abs(bendAngle2) < std::abs(angle_m)) {
            amplitude2 += fieldStep;
            fieldAmplitude_m = amplitude2;
            bendAngle2 = CalculateBendAngle();
        }
    }
gsell's avatar
gsell committed
1034

1035 1036 1037 1038
    // Now we should have the proper field amplitude bracketed.
    unsigned int iterations = 1;
    double error = std::abs(actualBendAngle - angle_m);
    while(error > 1.0e-6 && iterations < 100) {
gsell's avatar
gsell committed
1039

1040 1041
        fieldAmplitude_m = (amplitude1 + amplitude2) / 2.0;
        double newBendAngle = CalculateBendAngle();
gsell's avatar
gsell committed
1042

1043
        error = std::abs(newBendAngle - angle_m);
gsell's avatar
gsell committed
1044

1045
        if(error > 1.0e-6) {
gsell's avatar
gsell committed
1046

1047
            if(bendAngle1 - angle_m < 0.0) {
gsell's avatar
gsell committed
1048

1049 1050 1051 1052 1053 1054 1055
                if(newBendAngle - angle_m < 0.0) {
                    bendAngle1 = newBendAngle;
                    amplitude1 = fieldAmplitude_m;
                } else {
                    bendAngle2 = newBendAngle;
                    amplitude2 = fieldAmplitude_m;
                }
gsell's avatar
gsell committed
1056

1057
            } else {
gsell's avatar
gsell committed
1058

1059 1060 1061 1062 1063 1064 1065 1066 1067
                if(newBendAngle - angle_m < 0.0) {
                    bendAngle2 = newBendAngle;
                    amplitude2 = fieldAmplitude_m;
                } else {
                    bendAngle1 = newBendAngle;
                    amplitude1 = fieldAmplitude_m;
                }
            }
        }
Steve Russell's avatar
Steve Russell committed
1068
        iterations++;
1069 1070
    }
}
gsell's avatar
gsell committed
1071

1072
bool RBend::FindIdealBendParameters(double bendLength) {
gsell's avatar
gsell committed
1073

1074 1075 1076 1077
    double refMass = RefPartBunch_m->getM();
    double refGamma = designEnergy_m / refMass + 1.0;
    double refBetaGamma = sqrt(pow(refGamma, 2.0) - 1.0);
    double refCharge = RefPartBunch_m->getQ();
gsell's avatar
gsell committed
1078

1079
    if(angle_m != 0.0) {
gsell's avatar
gsell committed
1080

1081 1082 1083
        if(angle_m < 0.0) {
            // Negative angle is a positive bend rotated 180 degrees.
            angle_m = std::abs(angle_m);
1084
            fieldIndex_m *= -1.0;
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
            Orientation_m(2) += Physics::pi;
        }
        designRadius_m = bendLength
                         / (sin(angle_m - entranceAngle_m) + sin(entranceAngle_m));
        fieldAmplitude_m = (refCharge / std::abs(refCharge))
                           * refBetaGamma * refMass
                           / (Physics::c * designRadius_m);
        exitAngle_m = angle_m - entranceAngle_m;

        return true;

1096
    } else if(bX_m == 0.0) {
1097 1098

        // Negative angle is a positive bend rotated 180 degrees.
1099 1100
        if((refCharge > 0.0 && bY_m < 0.0)
           || (refCharge < 0.0 && bY_m > 0.0)) {
1101
            fieldIndex_m *= -1.0;
1102 1103 1104
            Orientation_m(2) += Physics::pi;
        }

1105
        fieldAmplitude_m = refCharge * std::abs(bY_m / refCharge);
1106 1107 1108 1109 1110 1111 1112
        designRadius_m = std::abs(refBetaGamma * refMass / (Physics::c * fieldAmplitude_m));
        double angle = asin(bendLength / designRadius_m - sin(entranceAngle_m));
        angle_m = angle + entranceAngle_m;
        exitAngle_m = angle_m - entranceAngle_m;

        return false;

1113 1114 1115 1116
    } else {

        Orientation_m(2) += atan2(bX_m, bY_m);
        if(refCharge < 0.0) {
1117
            fieldIndex_m *= -1.0;
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
            Orientation_m(2) -= Physics::pi;
        }

        fieldAmplitude_m = refCharge
                           * std::abs(sqrt(pow(bY_m, 2.0) + pow(bX_m, 2.0))
                                      / refCharge);
        designRadius_m = std::abs(refBetaGamma * refMass / (Physics::c * fieldAmplitude_m));
        double angle = asin(bendLength / designRadius_m - sin(entranceAngle_m));
        angle_m = angle + entranceAngle_m;
        exitAngle_m = angle_m - entranceAngle_m;

        return false;
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
    }
}

void RBend::FindReferenceExitOrigin(double &x, double &z) {

    /*
      * Find x,z coordinates of reference trajectory as it passes exit edge
      * of the bend magnet. This assumes an entrance position of (x,z) = (0,0).
      */
    if(angle_m <= Physics::pi / 2.0) {
        x = - designRadius_m * (1.0 - std::cos(angle_m));
        z = designRadius_m * std::sin(angle_m);
    } else if(angle_m <= Physics::pi) {
        x = -designRadius_m * (1.0 + std::sin(angle_m - Physics::pi / 2.0));
        z = designRadius_m * std::cos(angle_m - Physics::pi / 2.0);
    } else if(angle_m <= 3.0 * Physics::pi / 2.0) {
        x = -designRadius_m * (2.0 - std::cos(angle_m - Physics::pi));
        z = -designRadius_m * std::sin(angle_m - Physics::pi);
    } else {
        x = -designRadius_m * (1.0 - std::cos(angle_m - 3.0 * Physics::pi / 2.0));
        z = -designRadius_m * std::sin(angle_m - 3.0 * Physics::pi / 2.0);
gsell's avatar
gsell committed
1151
    }
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 <