Commit 8ae42603 authored by snuverink_j's avatar snuverink_j
Browse files

Resolve "Octupole magnet strengths are set using the formula for Decapoles"

parent b0ddbe1b
// ------------------------------------------------------------------------
// $RCSfile: Multipole.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
// //
// Class: Multipole // Class Multipole
// Defines the abstract interface for a Multipole magnet. // The MULTIPOLE element defines a thick multipole.
// //
// ------------------------------------------------------------------------ // Copyright (c) 2012-2021, Paul Scherrer Institut, Villigen PSI, Switzerland
// Class category: AbsBeamline // All rights reserved
// ------------------------------------------------------------------------
// //
// $Date: 2000/03/27 09:32:31 $ // This file is part of OPAL.
// $Author: fci $ //
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
// //
// ------------------------------------------------------------------------
#include "AbsBeamline/Multipole.h" #include "AbsBeamline/Multipole.h"
#include "Algorithms/PartBunchBase.h" #include "Algorithms/PartBunchBase.h"
#include "AbsBeamline/BeamlineVisitor.h" #include "AbsBeamline/BeamlineVisitor.h"
#include "Fields/Fieldmap.h" #include "Fields/Fieldmap.h"
#include "Physics/Physics.h" #include "Physics/Physics.h"
#include "Utilities/GeneralClassicException.h"
extern Inform *gmsg;
namespace{ namespace{
enum { enum {
...@@ -36,8 +33,16 @@ namespace{ ...@@ -36,8 +33,16 @@ namespace{
}; };
} }
// Class Multipole namespace {
// ------------------------------------------------------------------------ unsigned int factorial(unsigned int n) {
static int fact[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320,
362880, 3628800, 39916800, 479001600};
if (n > 12) {
throw GeneralClassicException("Multipole::factorial", "Factorial can't be larger than 12");
}
return fact[n];
}
}
Multipole::Multipole(): Multipole::Multipole():
Multipole("") Multipole("")
...@@ -107,18 +112,9 @@ void Multipole::setNormalComponent(int n, double v, double vError) { ...@@ -107,18 +112,9 @@ void Multipole::setNormalComponent(int n, double v, double vError) {
NormalComponents[n - 1] = (v + vError) / 2; NormalComponents[n - 1] = (v + vError) / 2;
NormalComponentErrors[n - 1] = NormalComponents[n - 1]; NormalComponentErrors[n - 1] = NormalComponents[n - 1];
break; break;
case SEXTUPOLE:
NormalComponents[n - 1] = (v + vError) / 2;
NormalComponentErrors[n - 1] = vError / 2;
break;
case OCTUPOLE:
case DECAPOLE:
NormalComponents[n - 1] = (v + vError) / 24;
NormalComponentErrors[n - 1] = vError / 24;
break;
default: default:
NormalComponents[n - 1] = (v + vError); NormalComponents[n - 1] = (v + vError) / factorial(n-1);
NormalComponentErrors[n - 1] = vError; NormalComponentErrors[n - 1] = vError / factorial(n-1);
} }
} }
...@@ -133,24 +129,12 @@ void Multipole::setSkewComponent(int n, double v, double vError) { ...@@ -133,24 +129,12 @@ void Multipole::setSkewComponent(int n, double v, double vError) {
} }
switch(n-1) { switch(n-1) {
case DIPOLE: case DIPOLE:
SkewComponents[n - 1] = (v + vError) / 2; SkewComponents[n - 1] = (v + vError) / 2;
SkewComponentErrors[n - 1] = SkewComponents[n - 1]; SkewComponentErrors[n - 1] = SkewComponents[n - 1];
break; break;
case SEXTUPOLE:
SkewComponents[n - 1] = (v + vError) / 2;
SkewComponentErrors[n - 1] = vError / 2;
break;
case OCTUPOLE:
SkewComponents[n - 1] = (v + vError) / 6;
SkewComponentErrors[n - 1] = vError / 6;
break;
case DECAPOLE:
SkewComponents[n - 1] = (v + vError) / 24;
SkewComponentErrors[n - 1] = vError / 24;
break;
default: default:
SkewComponents[n - 1] = (v + vError); SkewComponents[n - 1] = (v + vError) / factorial(n-1);
SkewComponentErrors[n - 1] = vError; SkewComponentErrors[n - 1] = vError / factorial(n-1);
} }
} }
...@@ -371,7 +355,7 @@ bool Multipole::isInside(const Vector_t &r) const { ...@@ -371,7 +355,7 @@ bool Multipole::isInside(const Vector_t &r) const {
} }
bool Multipole::isFocusing(unsigned int component) const { bool Multipole::isFocusing(unsigned int component) const {
if (component >= NormalComponents.size()) throw GeneralClassicException("Multipole::isFocusing", "component to big"); if (component >= NormalComponents.size()) throw GeneralClassicException("Multipole::isFocusing", "component too big");
return NormalComponents[component] * std::pow(-1, component + 1) * RefPartBunch_m->getChargePerParticle() > 0.0; return NormalComponents[component] * std::pow(-1, component + 1) * RefPartBunch_m->getChargePerParticle() > 0.0;
} }
#ifndef CLASSIC_Multipole_HH
#define CLASSIC_Multipole_HH
// ------------------------------------------------------------------------
// $RCSfile: Multipole.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
// Description:
// ------------------------------------------------------------------------
// Class category: AbsBeamline
// ------------------------------------------------------------------------
// //
// $Date: 2000/03/27 09:32:31 $ // Class Multipole
// $Author: fci $ // The MULTIPOLE element defines a thick multipole.
//
// Copyright (c) 2012-2021, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
// //
// ------------------------------------------------------------------------
#ifndef CLASSIC_Multipole_HH
#define CLASSIC_Multipole_HH
#include "AbsBeamline/Component.h" #include "AbsBeamline/Component.h"
#include "BeamlineGeometry/StraightGeometry.h" #include "BeamlineGeometry/StraightGeometry.h"
...@@ -96,10 +97,10 @@ public: ...@@ -96,10 +97,10 @@ public:
size_t getMaxNormalComponentIndex() const; size_t getMaxNormalComponentIndex() const;
size_t getMaxSkewComponentIndex() const; size_t getMaxSkewComponentIndex() const;
//set number of slices for map tracking //set number of slices for map tracking
void setNSlices(const std::size_t& nSlices); void setNSlices(const std::size_t& nSlices);
//set number of slices for map tracking //set number of slices for map tracking
std::size_t getNSlices() const; std::size_t getNSlices() const;
...@@ -162,4 +163,4 @@ size_t Multipole::getMaxSkewComponentIndex() const { ...@@ -162,4 +163,4 @@ size_t Multipole::getMaxSkewComponentIndex() const {
return SkewComponents.size(); return SkewComponents.size();
} }
#endif // CLASSIC_Multipole_HH #endif // CLASSIC_Multipole_HH
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment