OpalRingDefinition.cpp 6.77 KB
Newer Older
1
/*
2 3
 *  Copyright (c) 2012, Chris Rogers
 *  All rights reserved.
4 5
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
6
 *  1. Redistributions of source code must retain the above copyright notice,
7 8 9
 *     this list of conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the documentation
10
 *     and/or other materials provided with the distribution.
11 12
 *  3. Neither the name of STFC nor the names of its contributors may be used to
 *     endorse or promote products derived from this software without specific
13 14
 *     prior written permission.
 *
15 16 17 18 19 20 21 22 23 24
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 26 27
 *  POSSIBILITY OF SUCH DAMAGE.
 */

kraus's avatar
kraus committed
28 29
#include "Elements/OpalRingDefinition.h"

30 31
#include <limits>

kraus's avatar
kraus committed
32
#include "AbsBeamline/Ring.h"
33
#include "Attributes/Attributes.h"
snuverink_j's avatar
snuverink_j committed
34
#include "Physics/Physics.h"
35 36 37

OpalRingDefinition::OpalRingDefinition() :
    OpalElement(SIZE, "RINGDEFINITION",
kraus's avatar
kraus committed
38
                "The \"RINGDEFINITION\" element defines basic ring parameters.") {
39

40
    itsAttr[HARMONIC_NUMBER] = Attributes::makeReal("HARMONIC_NUMBER",
kraus's avatar
kraus committed
41
                                                    "The assumed harmonic number of the ring (i.e. number of bunches in the ring on a given turn).");
adelmann's avatar
adelmann committed
42
    itsAttr[LAT_RINIT] = Attributes::makeReal("LAT_RINIT",
43
                                                  "The initial radius of the first element to be placed in the ring [m].");
adelmann's avatar
adelmann committed
44 45
    itsAttr[LAT_PHIINIT] = Attributes::makeReal("LAT_PHIINIT", "The initial angle around the ring of the first element to be placed. [deg]");
    itsAttr[LAT_THETAINIT] = Attributes::makeReal("LAT_THETAINIT", "The angle relative to the tangent of the ring for the first element to be placed [deg].");
46
    itsAttr[BEAM_PHIINIT] = Attributes::makeReal("BEAM_PHIINIT",
kraus's avatar
kraus committed
47
                                                 "The initial angle around the ring of the beam [deg].");
48
    itsAttr[BEAM_PRINIT] = Attributes::makeReal("BEAM_PRINIT",
kraus's avatar
kraus committed
49
                                                "An initial pr momentum offset of the beam.");
50
    itsAttr[BEAM_RINIT] = Attributes::makeReal("BEAM_RINIT",
51
                                               "The initial radius of the beam [m].");
52
    itsAttr[SYMMETRY] = Attributes::makeReal("SYMMETRY",
kraus's avatar
kraus committed
53
                                             "The rotational symmetry of the lattice.");
adelmann's avatar
adelmann committed
54
    itsAttr[SCALE] = Attributes::makeReal("SCALE", "Scale the fields by a multiplicative factor",1.0);
55 56 57
    // should be in RF cavity definition; this comes from cyclotron definition,
    // but not right
    itsAttr[RFFREQ] = Attributes::makeReal("RFFREQ",
kraus's avatar
kraus committed
58
                                           "The nominal RF frequency of the ring [MHz].");
59 60
    // I see also makeBool, but dont know how it works; no registerBoolAttribute
    itsAttr[IS_CLOSED] = Attributes::makeString("IS_CLOSED",
kraus's avatar
kraus committed
61
                                                "Set to 'false' to disable checking for closure of the ring");
ext-rogers_c's avatar
ext-rogers_c committed
62 63 64 65
    itsAttr[MIN_R] = Attributes::makeReal("MIN_R",
                                           "Minimum allowed radius during tracking [m]. If not defined, any radius is allowed. If MIN_R is defined, MAX_R must also be defined.");
    itsAttr[MAX_R] = Attributes::makeReal("MAX_R",
                                           "Maximum allowed radius during tracking [m]. If not defined, any radius is allowed. If MAX_R is defined, MIN_R must also be defined.");
66

adelmann's avatar
adelmann committed
67 68 69
    registerRealAttribute("LAT_RINIT");
    registerRealAttribute("LAT_PHIINIT");
    registerRealAttribute("LAT_THETAINIT");
70 71 72 73 74
    registerRealAttribute("BEAM_RINIT");
    registerRealAttribute("BEAM_PHIINIT");
    registerRealAttribute("BEAM_PRINIT");
    registerRealAttribute("HARMONIC_NUMBER");
    registerRealAttribute("SYMMETRY");
adelmann's avatar
adelmann committed
75
    registerRealAttribute("SCALE");
76 77
    registerRealAttribute("RFFREQ");
    registerStringAttribute("IS_CLOSED");
ext-rogers_c's avatar
ext-rogers_c committed
78 79 80
    registerRealAttribute("SCALE");
    registerRealAttribute("MIN_R");
    registerRealAttribute("MAX_R");
81

82 83
    registerOwnership();

kraus's avatar
kraus committed
84
    setElement((new Ring("RING"))->makeAlignWrapper());
85 86
}

87
OpalRingDefinition* OpalRingDefinition::clone(const std::string &name) {
88 89 90 91 92 93 94
    return new OpalRingDefinition(name, this);
}

void OpalRingDefinition::print(std::ostream& out) const {
    OpalElement::print(out);
}

95
OpalRingDefinition::OpalRingDefinition(const std::string &name, OpalRingDefinition *parent):
96
    OpalElement(name, parent) {
kraus's avatar
kraus committed
97
    setElement((new Ring(name))->makeAlignWrapper());
98 99 100 101 102
}

OpalRingDefinition::~OpalRingDefinition() {}

void OpalRingDefinition::fillRegisteredAttributes
kraus's avatar
kraus committed
103
(const ElementBase &base, ValueFlag flag) {
104 105 106 107
    OpalElement::fillRegisteredAttributes(base, flag);
}

void OpalRingDefinition::update() {
kraus's avatar
kraus committed
108
    Ring *ring = dynamic_cast<Ring*>(getElement()->removeWrappers());
109
    double degree = Physics::pi/180.;
110
    double metres = 1e3;
111 112
    ring->setBeamPhiInit(Attributes::getReal(itsAttr[BEAM_PHIINIT]));
    ring->setBeamPRInit(Attributes::getReal(itsAttr[BEAM_PRINIT]));
113 114
    ring->setBeamRInit(Attributes::getReal(itsAttr[BEAM_RINIT])*metres);
    ring->setLatticeRInit(Attributes::getReal(itsAttr[LAT_RINIT])*metres);
115

adelmann's avatar
adelmann committed
116 117
    ring->setLatticePhiInit(Attributes::getReal(itsAttr[LAT_PHIINIT])*degree);
    ring->setLatticeThetaInit(Attributes::getReal(itsAttr[LAT_THETAINIT])*degree);
adelmann's avatar
adelmann committed
118
    ring->setSymmetry(Attributes::getReal(itsAttr[SYMMETRY]));
adelmann's avatar
adelmann committed
119
    ring->setScale(Attributes::getReal(itsAttr[SCALE]));
120

121 122 123
    ring->setHarmonicNumber(Attributes::getReal(itsAttr[HARMONIC_NUMBER]));
    ring->setRFFreq(Attributes::getReal(itsAttr[RFFREQ]));
    ring->setIsClosed(!(Attributes::getString(itsAttr[IS_CLOSED])=="FALSE"));
ext-rogers_c's avatar
ext-rogers_c committed
124 125
    double minR = -1;
    double maxR = -1;
adelmann's avatar
adelmann committed
126

ext-rogers_c's avatar
ext-rogers_c committed
127 128 129 130 131 132 133 134 135 136 137 138 139
    if (itsAttr[MIN_R]) {
        minR = Attributes::getReal(itsAttr[MIN_R]);
        if (!itsAttr[MAX_R]) {
            throw (""); // EXCEPTION
        }
    }
    if (itsAttr[MAX_R]) {
        maxR = Attributes::getReal(itsAttr[MAX_R]);
        if (!itsAttr[MIN_R]) {
            throw (""); // EXCEPTION
        }
        ring->setRingAperture(minR, maxR);
    }
140 141

    setElement(ring->makeWrappers());
142
}