Commit 588321eb authored by snuverink_j's avatar snuverink_j

throw exception when wake not a valid type; code cleanup and license header

parent 1dd61303
//
// Class CSRIGFWakeFunction
//
// Copyright (c) 2008 - 2020, 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/>.
//
#include "AbstractObjects/OpalData.h"
#include "Solvers/CSRIGFWakeFunction.hh"
#include "Solvers/RootFinderForCSR.h"
......@@ -14,8 +30,8 @@
#include <fstream>
#include <cmath>
CSRIGFWakeFunction::CSRIGFWakeFunction(const std::string &name, ElementBase *element, std::vector<Filter *> filters, const unsigned int &N):
WakeFunction(name, element, N),
CSRIGFWakeFunction::CSRIGFWakeFunction(const std::string &name, std::vector<Filter *> filters, const unsigned int &N):
WakeFunction(name, N),
filters_m(filters.begin(), filters.end()),
lineDensity_m(),
dlineDensitydz_m(),
......
//
// Class CSRIGFWakeFunction
//
// Copyright (c) 2008 - 2020, 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 CSRIGFWAKEFUNCTION_HH
#define CSRIGFWAKEFUNCTION_HH
......@@ -12,7 +28,7 @@ class ElementBase;
class CSRIGFWakeFunction: public WakeFunction {
public:
CSRIGFWakeFunction(const std::string &name, ElementBase *element, std::vector<Filter *> filters, const unsigned int &N);
CSRIGFWakeFunction(const std::string &name, std::vector<Filter *> filters, const unsigned int &N);
void apply(PartBunchBase<double, 3> *bunch);
......
//
// Class CSRWakeFunction
//
// Copyright (c) 2008 - 2020, 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/>.
//
#include "Solvers/CSRWakeFunction.hh"
#include "Solvers/RootFinderForCSR.h"
......@@ -16,8 +32,8 @@
#include <cmath>
CSRWakeFunction::CSRWakeFunction(const std::string &name, ElementBase *element, std::vector<Filter *> filters, const unsigned int &N):
WakeFunction(name, element, N),
CSRWakeFunction::CSRWakeFunction(const std::string &name, std::vector<Filter *> filters, const unsigned int &N):
WakeFunction(name, N),
filters_m(filters.begin(), filters.end()),
lineDensity_m(),
dlineDensitydz_m(),
......
//
// Class CSRWakeFunction
//
// Copyright (c) 2008 - 2020, 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 CSRWAKEFUNCTION_HH
#define CSRWAKEFUNCTION_HH
......@@ -12,7 +28,7 @@ class ElementBase;
class CSRWakeFunction: public WakeFunction {
public:
CSRWakeFunction(const std::string &name, ElementBase *element, std::vector<Filter *> filters, const unsigned int &N);
CSRWakeFunction(const std::string &name, std::vector<Filter *> filters, const unsigned int &N);
void apply(PartBunchBase<double, 3> *bunch);
......
//
// Class GreenWakeFunction
//
// Copyright (c) 2008 - 2020, 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/>.
//
#include "Solvers/GreenWakeFunction.hh"
#include "Algorithms/PartBunchBase.h"
#include "Utilities/GeneralClassicException.h"
......@@ -19,13 +35,10 @@
/**
* @brief just a Testfunction! Calculate the energy of the Wakefunction with the lambda
*
*
* @todo In this code one can only apply either the longitudinal wakefield or the transversal wakefield. One should implement that both wakefields can be applied to the particle beam
* @todo NBins must be set equal to MT of the fieldsolver. This should be changed. (the length of lineDensity_m must be NBins and not to MT)
*
* @param[in] ref
* @param[in] NBIN number of Bins
* @param[in] Z0 impedance of the tube
* @param[in] radius radius of the tube
......@@ -37,7 +50,6 @@
* @param[in] fname read wake from file
*/
GreenWakeFunction::GreenWakeFunction(const std::string &name,
ElementBase *element,
std::vector<Filter *> filters,
int NBIN,
double Z0,
......@@ -48,7 +60,7 @@ GreenWakeFunction::GreenWakeFunction(const std::string &name,
int direction,
bool constLength,
std::string fname):
WakeFunction(name, element, NBIN),
WakeFunction(name, NBIN),
lineDensity_m(),
//~ FftWField_m(0),
NBin_m(NBIN),
......@@ -510,4 +522,4 @@ void GreenWakeFunction::setWakeFromFile(int NBin_m, double spacing) {
const std::string GreenWakeFunction::getType() const {
return "GreenWakeFunction";
}
}
\ No newline at end of file
//
// Class GreenWakeFunction
//
// Copyright (c) 2008 - 2020, 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 GREENWAKEFUNCTION_HH
#define GREENWAKEFUNCTION_HH
......@@ -25,7 +41,6 @@ public:
//IFF: changed direction to int (was double)
//IFF: changed acMode to int (was double)
GreenWakeFunction(const std::string &name,
ElementBase *element,
std::vector<Filter *> filters,
int NBIN,
double Z0,
......
//
// Class WakeFunction
//
// Copyright (c) 2008 - 2020, 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 WAKEFUNCTION_HH
#define WAKEFUNCTION_HH
......@@ -11,7 +27,7 @@ class PartBunchBase;
class WakeFunction {
public:
WakeFunction(std::string name, ElementBase */*elref*/, unsigned int n):
WakeFunction(std::string name, unsigned int n):
nBins_m(n),
name_m(name) { };
......
// ------------------------------------------------------------------------
// $RCSfile: OpalWake.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.3.4.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: OpalWake
// Class OpalWake
// The class for the OPAL WAKE command.
//
// $Date: 2003/08/11 22:09:00 $
// $Author: A. Adelmann $
// Copyright (c) 2008 - 2020, 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/>.
//
// ------------------------------------------------------------------------
#include "Structure/OpalWake.h"
#include "Solvers/GreenWakeFunction.hh"
......@@ -20,19 +22,12 @@
#include "Solvers/CSRIGFWakeFunction.hh"
#include "AbstractObjects/OpalData.h"
#include "Attributes/Attributes.h"
#include "Physics/Physics.h"
#include "Utilities/OpalException.h"
#include "AbsBeamline/ElementBase.h"
#include "Utilities/OpalFilter.h"
extern Inform *gmsg;
using namespace Physics;
// Class OpalWake
// ------------------------------------------------------------------------
// The attributes of class OpalWake.
namespace {
enum {
......@@ -57,7 +52,7 @@ OpalWake::OpalWake():
"on an element."),
wf_m(0) {
itsAttr[TYPE] = Attributes::makeUpperCaseString
("TYPE", "Specifies the wake function: 1D-CSR, 1D-CSR-IGF, LONG-SHORT-RANGE, TRANSV-SHORT-RANGE, LONG-TRANSV-SHORT-RANGE");
("TYPE", "Specifies the wake function: 1D-CSR, 1D-CSR-IGF, LONG-SHORT-RANGE, TRANSV-SHORT-RANGE");
itsAttr[NBIN] = Attributes::makeReal
("NBIN", "Number of bins for the line density calculation");
......@@ -75,10 +70,10 @@ OpalWake::OpalWake():
("RADIUS", "The radius of the beam pipe [m]");
itsAttr[SIGMA] = Attributes::makeReal
("SIGMA", "Material constant dependant on the beam pipe material");
("SIGMA", "Material constant dependant on the beam pipe material");
itsAttr[TAU] = Attributes::makeReal
("TAU", "Material constant dependant on the beam pipe material");
("TAU", "Material constant dependant on the beam pipe material");
itsAttr[FILTERS] = Attributes::makeStringArray
("FILTERS", "List of filters to apply on line density");
......@@ -107,8 +102,7 @@ OpalWake::OpalWake(const std::string &name, OpalWake *parent):
OpalWake::~OpalWake() {
if (wf_m)
delete wf_m;
delete wf_m;
}
......@@ -149,14 +143,13 @@ void OpalWake::update() {
}
void OpalWake::initWakefunction(ElementBase &element) {
void OpalWake::initWakefunction(const ElementBase &element) {
*gmsg << "* ************* W A K E ************************************************************\n";
*gmsg << "OpalWake::initWakefunction ";
*gmsg << "for element " << element.getName() << "\n";
*gmsg << "* **********************************************************************************" << endl;
itsElement_m = &element;
std::vector<std::string> filters_str = Attributes::getStringArray(itsAttr[FILTERS]);
std::vector<Filter *> filters;
......@@ -168,8 +161,8 @@ void OpalWake::initWakefunction(ElementBase &element) {
filters.push_back(f->filter_m);
}
}
if (Attributes::getString(itsAttr[TYPE]) == "1D-CSR") {
std::string type = Attributes::getString(itsAttr[TYPE]);
if (type == "1D-CSR") {
if (filters.size() == 0 && Attributes::getReal(itsAttr[NBIN]) <= 7) {
throw OpalException("OpalWake::initWakeFunction",
......@@ -177,11 +170,10 @@ void OpalWake::initWakefunction(ElementBase &element) {
}
wf_m = new CSRWakeFunction(getOpalName(),
itsElement_m,
filters,
(int)(Attributes::getReal(itsAttr[NBIN])));
} else if (Attributes::getString(itsAttr[TYPE]) == "1D-CSR-IGF") {
} else if (type == "1D-CSR-IGF") {
if (filters.size() == 0 && Attributes::getReal(itsAttr[NBIN]) <= 7) {
throw OpalException("OpalWake::initWakeFunction",
......@@ -189,15 +181,13 @@ void OpalWake::initWakefunction(ElementBase &element) {
}
wf_m = new CSRIGFWakeFunction(getOpalName(),
itsElement_m,
filters,
(int)(Attributes::getReal(itsAttr[NBIN])));
} else if (Attributes::getString(itsAttr[TYPE]) == "LONG-SHORT-RANGE") {
} else if (type == "LONG-SHORT-RANGE") {
int acMode = Attributes::getString(itsAttr[CONDUCT]) == "DC"? 2: 1;
wf_m = new GreenWakeFunction(getOpalName(),
itsElement_m,
filters,
(int)(Attributes::getReal(itsAttr[NBIN])),
Attributes::getReal(itsAttr[Z0]),
......@@ -209,11 +199,10 @@ void OpalWake::initWakefunction(ElementBase &element) {
Attributes::getBool(itsAttr[CONST_LENGTH]),
Attributes::getString(itsAttr[FNAME]));
} else if (Attributes::getString(itsAttr[TYPE]) == "TRANSV-SHORT-RANGE") {
int acMode = Attributes::getString(itsAttr[CONDUCT]) == "DC"? 2: 1;
} else if (type == "TRANSV-SHORT-RANGE") {
int acMode = Attributes::getString(itsAttr[CONDUCT]) == "DC" ? 2: 1;
wf_m = new GreenWakeFunction(getOpalName(),
itsElement_m,
filters,
(int)(Attributes::getReal(itsAttr[NBIN])),
Attributes::getReal(itsAttr[Z0]),
......@@ -225,8 +214,12 @@ void OpalWake::initWakefunction(ElementBase &element) {
Attributes::getBool(itsAttr[CONST_LENGTH]),
Attributes::getString(itsAttr[FNAME]));
} else if (Attributes::getString(itsAttr[TYPE]) == "LONG-TRANSV-SHORT-RANGE") {
//FIXME: NOT IMPLEMENTED YET!!!
} else if (type == "LONG-TRANSV-SHORT-RANGE") {
throw OpalException("OpalWake::initWakeFunction",
"LONG-TRANSV-SHORT-RANGE wake is not implemented");
} else if (type.empty() == false) {
throw OpalException("OpalWake::initWakeFunction",
type + " is not a valid wake type");
} else {
wf_m = 0;
INFOMSG("no wakefunction attached" << endl);
......
#ifndef OPAL_Wake_HH
#define OPAL_Wake_HH
// ------------------------------------------------------------------------
// $RCSfile: OpalWake.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: OpalWake
// Class OpalWake
// The class for the OPAL WAKE command.
//
// ------------------------------------------------------------------------
// Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// $Date: 2000/03/27 09:33:44 $
// $Author: Andreas Adelmann $
// 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 OPAL_Wake_HH
#define OPAL_Wake_HH
#include "AbstractObjects/Definition.h"
#include "Algorithms/PartData.h"
class ElementBase;
class WakeFunction;
// Class OpalWake
// ------------------------------------------------------------------------
/// The WAKE definition.
// A WAKE definition is used by most physics commands to define the
// particle charge and the reference momentum, together with some other
// data.
class OpalWake: public Definition {
public:
......@@ -60,7 +52,7 @@ public:
int getNumberOfBins();
void initWakefunction(ElementBase &element);
void initWakefunction(const ElementBase &element);
WakeFunction *wf_m;
......@@ -72,16 +64,6 @@ private:
// Clone constructor.
OpalWake(const std::string &name, OpalWake *parent);
// The particle reference data.
PartData reference;
// The conversion from GeV to eV.
static const double energy_scale;
// the element the wake is attached to
ElementBase *itsElement_m;
};
inline std::ostream &operator<<(std::ostream &os, const OpalWake &b) {
......
......@@ -31,7 +31,7 @@ TEST(GreenWakeFunctionTest, TestApply)
std::vector<double> relativeErrorEnergy = {1e-9, 1};
for (int acmode : acmodes) {
GreenWakeFunction gwf("opal", nullptr, filters, nbin, Z0, radius, sigma, acmode, tau, 0, const_length, fname);
GreenWakeFunction gwf("opal", filters, nbin, Z0, radius, sigma, acmode, tau, 0, const_length, fname);
double spacing = 1e-6; //IFF: charge in testLambda.h in 1um spacings
// determine K and charge
......
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