Commit 553c5f6a authored by Andreas Adelmann's avatar Andreas Adelmann
Browse files

first stab to add time dependent frequency, voltage and phases

parent ca07981d
......@@ -63,7 +63,14 @@ RFCavity::RFCavity():
RNormal_m(nullptr),
VrNormal_m(nullptr),
DvDr_m(nullptr),
num_points_m(0) {
num_points_m(0),
phase_td_m(nullptr),
amplitude_td_m(nullptr),
frequency_td_m(nullptr),
phase_name_m(""),
amplitude_name_m(""),
frequency_name_m("")
{
setElType(isRF);
}
......@@ -91,7 +98,14 @@ RFCavity::RFCavity(const RFCavity &right):
RNormal_m(nullptr),
VrNormal_m(nullptr),
DvDr_m(nullptr),
num_points_m(right.num_points_m) {
num_points_m(right.num_points_m),
phase_td_m(right.phase_td_m),
amplitude_td_m(right.amplitude_td_m),
frequency_td_m(right.frequency_td_m),
phase_name_m(right.phase_name_m),
amplitude_name_m(right.amplitude_name_m),
frequency_name_m(right.frequency_name_m) {
setElType(isRF);
std::vector<string>::const_iterator fname_it;
......@@ -140,6 +154,9 @@ RFCavity::RFCavity(const std::string &name):
RNormal_m(nullptr),
VrNormal_m(nullptr),
DvDr_m(nullptr),
phase_td_m(nullptr),
amplitude_td_m(nullptr),
frequency_td_m(nullptr),
// RNormal_m(std::nullptr_t(NULL)),
// VrNormal_m(std::nullptr_t(NULL)),
// DvDr_m(std::nullptr_t(NULL)),
......@@ -159,6 +176,39 @@ RFCavity::~RFCavity() {
}
std::shared_ptr<AbstractTimeDependence> RFCavity::getAmplitudeModel() const {
return amplitude_td_m;
}
std::shared_ptr<AbstractTimeDependence> RFCavity::getPhaseModel() const {
return phase_td_m;
}
std::shared_ptr<AbstractTimeDependence> RFCavity::getFrequencyModel() const {
return frequency_td_m;
}
void RFCavity::setAmplitudeModel(std::shared_ptr<AbstractTimeDependence> amplitude_td) {
amplitude_td_m = amplitude_td;
}
void RFCavity::setPhaseModel(std::shared_ptr<AbstractTimeDependence> phase_td) {
phase_td_m = phase_td;
}
void RFCavity::setFrequencyModel(std::shared_ptr<AbstractTimeDependence> frequency_td) {
INFOMSG("frequency_td " << frequency_td << endl);
frequency_td_m = frequency_td;
}
void RFCavity::setFrequencyModelName(std::string name) {
frequency_name_m=name;
}
void RFCavity::accept(BeamlineVisitor &visitor) const {
visitor.visitRFCavity(*this);
}
......@@ -546,6 +596,9 @@ void RFCavity::initialise(PartBunch *bunch, const double &scaleFactor) {
sinAngle_m = sin(angle_m / 180.0 * pi);
cosAngle_m = cos(angle_m / 180.0 * pi);
if (frequency_td_m)
*gmsg << "* timedependent frequency model " << frequency_name_m << endl;
*gmsg << "* Cavity voltage data read successfully!" << endl;
}
......@@ -1033,4 +1086,4 @@ pair<double, double> RFCavity::trackOnAxisParticle(const double &p0,
const double tErr = (z - zend) / (Physics::c * beta);
return pair<double, double>(p, t - tErr);
}
\ No newline at end of file
}
......@@ -21,7 +21,7 @@
//
// ------------------------------------------------------------------------
#include "Algorithms/AbstractTimeDependence.h"
#include "AbsBeamline/Component.h"
#include "Physics/Physics.h"
......@@ -162,6 +162,30 @@ public:
virtual void getDimensions(double &zBegin, double &zEnd) const;
virtual std::shared_ptr<AbstractTimeDependence> getAmplitudeModel() const;
virtual std::shared_ptr<AbstractTimeDependence> getPhaseModel() const;
virtual std::shared_ptr<AbstractTimeDependence> getFrequencyModel() const;
virtual void setAmplitudeModel(std::shared_ptr<AbstractTimeDependence> time_dep);
void setAmplitudeModelName(std::string name) {amplitude_name_m=name;}
std::string getAmplitudeModelName() { return amplitude_name_m;}
virtual void setPhaseModel(std::shared_ptr<AbstractTimeDependence> time_dep);
void setPhaseModelName(std::string name) {phase_name_m=name;}
std::string getPhaseModelName() { return phase_name_m;}
virtual void setFrequencyModel(std::shared_ptr<AbstractTimeDependence> time_dep);
virtual void setFrequencyModelName(std::string name);
std::string getFrequencyModelName() { return frequency_name_m;}
protected:
std::shared_ptr<AbstractTimeDependence> phase_td_m;
std::string phase_name_m;
std::shared_ptr<AbstractTimeDependence> amplitude_td_m;
std::string amplitude_name_m;
std::shared_ptr<AbstractTimeDependence> frequency_td_m;
std::string frequency_name_m;
private:
std::string filename_m; /**< The name of the inputfile*/
std::vector<std::string> multiFilenames_m;
......
#include "Algorithms/PolynomialTimeDependence.h"
Inform &PolynomialTimeDependence::print(Inform &os) {
Inform::FmtFlags_t ff = os.flags();
os << std::scientific;
for (unsigned int i=0; i<this->coeffs.size(); i++)
os << "c" << i << "= " << this->coeffs[i] << " ";
os << endl;
os.flags(ff);
return os;
}
......@@ -3,7 +3,7 @@
#include <vector>
#include <iostream>
#include "Ippl.h"
#include "Algorithms/AbstractTimeDependence.h"
class PolynomialTimeDependence : public AbstractTimeDependence {
......@@ -18,6 +18,8 @@ class PolynomialTimeDependence : public AbstractTimeDependence {
return d;
}
Inform &print(Inform &os);
private:
std::vector<double> coeffs;
};
......@@ -32,5 +34,11 @@ double PolynomialTimeDependence::getValue(double time) {
return x;
}
inline
Inform &operator<<(Inform &os, PolynomialTimeDependence &p) {
return p.print(os);
}
#endif
......@@ -18,7 +18,8 @@
#include <Algorithms/Ctunes.hpp>
#include "Algorithms/ParallelCyclotronTracker.h"
#include "Algorithms/PolynomialTimeDependence.h"
#include "Elements/OpalPolynomialTimeDependence.h"
#include <cfloat>
#include <iostream>
#include <fstream>
......@@ -50,6 +51,8 @@
#include "AbsBeamline/Stripper.h"
#include "AbsBeamline/VariableRFCavity.h"
#include "AbstractObjects/Element.h"
#include "Elements/OpalBeamline.h"
#include "AbsBeamline/Ring.h"
......@@ -813,12 +816,31 @@ void ParallelCyclotronTracker::visitRFCavity(const RFCavity &as) {
double pdis = elptr->getPerpenDistance();
*gmsg << "* Cavity Shift distance= " << pdis << " [mm] " << endl;
double phi0 = elptr->getPhi0();
*gmsg << "* Initial RF phase (t=0)= " << phi0 << " [deg] " << endl;
std::shared_ptr<AbstractTimeDependence> freq_atd = nullptr;
std::shared_ptr<AbstractTimeDependence> ampl_atd = nullptr;
std::shared_ptr<AbstractTimeDependence> phase_atd = nullptr;
if (elptr->getFrequencyModelName() != "") {
freq_atd = AbstractTimeDependence::getTimeDependence(elptr->getFrequencyModelName());
*gmsg << "* Variable frequency RF Model name " << elptr->getFrequencyModelName() << endl;
}
if (elptr->getAmplitudeModelName() != "") {
ampl_atd = AbstractTimeDependence::getTimeDependence(elptr->getAmplitudeModelName());
*gmsg << "* Variable amplitude RF Model name " << elptr->getAmplitudeModelName() << endl;
}
if (elptr->getPhaseModelName() != "") {
phase_atd = AbstractTimeDependence::getTimeDependence(elptr->getPhaseModelName());
*gmsg << "* Variable phase RF Model name " << elptr->getPhaseModelName() << endl;
}
// read cavity voltage profile data from file.
elptr->initialise(itsBunch, 1.0);
// elptr->initialise(itsBunch, 1.0, freq_atd, ampl_atd, phase_atd);
elptr->initialise(itsBunch, 1.0, freq_atd);
double BcParameter[8];
for(int i = 0; i < 8; i++)
......
......@@ -18,6 +18,7 @@
#include "Elements/OpalCavity.h"
#include "AbstractObjects/Attribute.h"
#include "Algorithms/AbstractTimeDependence.h"
#include "Attributes/Attributes.h"
#include "BeamlineCore/RFCavityRep.h"
#include "Structure/OpalWake.h"
......@@ -26,7 +27,7 @@
extern Inform *gmsg;
// Class OpalCavity
// Class OpalCavity for OPAL-cycl
// ------------------------------------------------------------------------
OpalCavity::OpalCavity():
......@@ -78,6 +79,14 @@ OpalCavity::OpalCavity():
itsAttr[DY] = Attributes::makeReal
("DY", "Misalignment in y direction",0.0);
// attibutes for timedependent values
itsAttr[PHASE_MODEL] = Attributes::makeString("PHASE_MODEL",
"The name of the phase time dependence model.");
itsAttr[AMPLITUDE_MODEL] = Attributes::makeString("AMPLITUDE_MODEL",
"The name of the amplitude time dependence model.");
itsAttr[FREQUENCY_MODEL] = Attributes::makeString("FREQUENCY_MODEL",
"The name of the frequency time dependence model.");
registerRealAttribute("VOLT");
registerRealAttribute("FREQ");
registerRealAttribute("LAG");
......@@ -93,6 +102,11 @@ OpalCavity::OpalCavity():
registerRealAttribute("DX");
registerRealAttribute("DY");
// attibutes for timedependent values
registerStringAttribute("PHASE_MODEL");
registerStringAttribute("AMPLITUDE_MODEL");
registerStringAttribute("FREQUENCY_MODEL");
setElement((new RFCavityRep("RFCAVITY"))->makeAlignWrapper());
}
......@@ -122,6 +136,19 @@ void OpalCavity::fillRegisteredAttributes(const ElementBase &base, ValueFlag fla
if(flag != ERROR_FLAG) {
const RFCavityRep *rfc =
dynamic_cast<const RFCavityRep *>(base.removeWrappers());
std::shared_ptr<AbstractTimeDependence> phase_model = rfc->getPhaseModel();
std::shared_ptr<AbstractTimeDependence> freq_model = rfc->getFrequencyModel();
std::shared_ptr<AbstractTimeDependence> amp_model = rfc->getAmplitudeModel();
std::string phase_name = AbstractTimeDependence::getName(phase_model);
std::string amp_name = AbstractTimeDependence::getName(amp_model);
std::string freq_name = AbstractTimeDependence::getName(freq_model);
attributeRegistry["PHASE_MODEL"]->setString(phase_name);
attributeRegistry["AMPLITUDE_MODEL"]->setString(amp_name);
attributeRegistry["FREQUENCY_MODEL"]->setString(freq_name);
attributeRegistry["VOLT"]->setReal(rfc->getAmplitude());
attributeRegistry["FREQ"]->setReal(rfc->getFrequency());
attributeRegistry["LAG"]->setReal(rfc->getPhase());
......@@ -136,6 +163,7 @@ void OpalCavity::fillRegisteredAttributes(const ElementBase &base, ValueFlag fla
void OpalCavity::update() {
using Physics::two_pi;
RFCavityRep *rfc =
dynamic_cast<RFCavityRep *>(getElement()->removeWrappers());
......@@ -215,6 +243,10 @@ void OpalCavity::update() {
rfc->setGapWidth(gapwidth);
rfc->setPhi0(phi0);
rfc->setPhaseModelName(Attributes::getString(itsAttr[PHASE_MODEL]));
rfc->setAmplitudeModelName(Attributes::getString(itsAttr[AMPLITUDE_MODEL]));
rfc->setFrequencyModelName(Attributes::getString(itsAttr[FREQUENCY_MODEL]));
// Transmit "unknown" attributes.
OpalElement::updateUnknown(rfc);
}
......@@ -52,6 +52,9 @@ public:
PDIS, // perpendicular distance from symmetric line of cavity gap to machine center
GAPWIDTH, // constant gap width of cavity
PHI0, // initial phase of cavity
PHASE_MODEL, // time dependent parameter
AMPLITUDE_MODEL,// time dependent parameter
FREQUENCY_MODEL,// time dependent parameter
DX, // Misalignment: translation in x direction
DY, // Misalignment: translation in y direction
SIZE
......
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