Commit 14904608 authored by kraus's avatar kraus Committed by kraus
Browse files

determine design energy at bends after a run of the AutophaseTracker

parent af1a4084
......@@ -23,6 +23,7 @@
#include "AbsBeamline/BeamlineVisitor.h"
#include "Utilities/Options.h"
#include "Fields/Fieldmap.h"
#include "AbstractObjects/OpalData.h"
#include <iostream>
#include <fstream>
......@@ -423,10 +424,12 @@ void RBend::initialise(PartBunch *bunch, double &startField, double &endField, c
Inform msg("RBend ", *gmsg);
if(InitializeFieldMap(msg)) {
retrieveDesignEnergy(startField);
SetupPusher(bunch);
ReadFieldMap(msg);
SetupBendGeometry(msg, startField, endField);
double bendAngleX = 0.0;
double bendAngleY = 0.0;
CalculateRefTrajectory(bendAngleX, bendAngleY);
......@@ -1657,4 +1660,13 @@ bool RBend::TreatAsDrift(Inform &msg) {
} else
return false;
}
void RBend::retrieveDesignEnergy(double startField) {
energyEvolution_t::iterator it = OpalData::getInstance()->getFirstEnergyData();
energyEvolution_t::iterator end = OpalData::getInstance()->getLastEnergyData();
for (; it != end; ++ it) {
if ((*it).first > startField) break;
designEnergy_m = (*it).second;
}
}
\ No newline at end of file
......@@ -298,6 +298,7 @@ private:
void SetFieldBoundaries(double startField, double endField);
void SetupPusher(PartBunch *bunch);
bool TreatAsDrift(Inform &msg);
void retrieveDesignEnergy(double startField);
BorisPusher pusher_m; /// Pusher used to integrate reference particle
/// through the bend.
......
......@@ -24,6 +24,7 @@
#include "AbsBeamline/BeamlineVisitor.h"
#include "Utilities/Options.h"
#include "Fields/Fieldmap.h"
#include "AbstractObjects/OpalData.h"
#include <iostream>
#include <fstream>
......@@ -382,10 +383,13 @@ void SBend::initialise(PartBunch *bunch,
Inform msg("SBend ", *gmsg);
if(InitializeFieldMap(msg)) {
retrieveDesignEnergy(startField);
msg << getName() << "\t" << "design energy: " << designEnergy_m << endl;
SetupPusher(bunch);
ReadFieldMap(msg);
SetupBendGeometry(msg, startField, endField);
double bendAngleX = 0.0;
double bendAngleY = 0.0;
CalculateRefTrajectory(bendAngleX, bendAngleY);
......@@ -1645,4 +1649,13 @@ bool SBend::TreatAsDrift(Inform &msg, double chordLength) {
} else
return false;
}
void SBend::retrieveDesignEnergy(double startField) {
energyEvolution_t::iterator it = OpalData::getInstance()->getFirstEnergyData();
energyEvolution_t::iterator end = OpalData::getInstance()->getLastEnergyData();
for (; it != end; ++ it) {
if ((*it).first > startField) break;
designEnergy_m = (*it).second;
}
}
\ No newline at end of file
......@@ -289,6 +289,7 @@ private:
void SetFieldBoundaries(double startField, double endField);
void SetupPusher(PartBunch *bunch);
bool TreatAsDrift(Inform &msg, double chordlength);
void retrieveDesignEnergy(double startField);
BorisPusher pusher_m; /// Pusher used to integrate reference particle
/// through the bend.
......
......@@ -124,6 +124,7 @@ struct OpalDataImpl {
BoundaryGeometry *bg_m;
std::vector<MaxPhasesT> maxPhases_m;
energyEvolution_t energyEvolution_m;
// The cartesian mesh
Mesh_t *mesh_m;
......@@ -382,6 +383,18 @@ int OpalData::getNumberOfMaxPhases() {
return p->maxPhases_m.size();
}
void OpalData::addEnergyData(double spos, double ekin) {
p->energyEvolution_m.insert(std::make_pair(spos, ekin));
}
energyEvolution_t::iterator OpalData::getFirstEnergyData() {
return p->energyEvolution_m.begin();
}
energyEvolution_t::iterator OpalData::getLastEnergyData() {
return p->energyEvolution_m.end();
}
// Mesh_t* OpalData::getMesh() {
// return p->mesh_m;
......@@ -731,4 +744,4 @@ std::vector<std::string> OpalData::getAllNames() {
//// /DTA
return result;
}
}
\ No newline at end of file
......@@ -22,6 +22,7 @@
#include <iosfwd>
#include <string>
#include <vector>
#include <map>
class PartBunch;
class EnvelopeBunch;
......@@ -34,6 +35,8 @@ class BoundaryGeometry;
// store element name, max phase
typedef std::pair<std::string, double > MaxPhasesT;
typedef std::map<double, double> energyEvolution_t;
typedef energyEvolution_t::value_type energyEvData_t;
......@@ -221,15 +224,19 @@ public:
///
BoundaryGeometry *getGlobalGeometry();
bool hasGlobalGeometry();
void setMaxPhase(std::string elName, double phi);
std::vector<MaxPhasesT>::iterator getFirstMaxPhases();
std::vector<MaxPhasesT>::iterator getLastMaxPhases();
int getNumberOfMaxPhases();
void addEnergyData(double spos, double ekin);
energyEvolution_t::iterator getFirstEnergyData();
energyEvolution_t::iterator getLastEnergyData();
unsigned long long getMaxTrackSteps();
void setMaxTrackSteps(unsigned long long s);
void incMaxTrackSteps(unsigned long long s);
......@@ -251,4 +258,4 @@ private:
//extern OpalData OPAL;
#endif // OPAL_OpalData_HH
#endif // OPAL_OpalData_HH
\ No newline at end of file
......@@ -375,6 +375,10 @@ double AutophaseTracker::optimizeCavityPhase(const std::shared_ptr<Component> &c
OpalData::getInstance()->setMaxPhase(cavity->getName(), Phimax);
double cavBegin, cavEnd;
cavity->getDimensions(cavBegin, cavEnd);
OpalData::getInstance()->addEnergyData(cavEnd, Emax * 1e6);
return Phimax + originalPhase;
}
......@@ -440,17 +444,28 @@ double AutophaseTracker::APtrack(const std::shared_ptr<Component> &cavity, doubl
void AutophaseTracker::sendCavityPhases() {
typedef std::vector<MaxPhasesT>::iterator iterator_t;
int tag = 101;
Message *mess = new Message();
putMessage(*mess, OpalData::getInstance()->getNumberOfMaxPhases());
iterator_t it = OpalData::getInstance()->getFirstMaxPhases();
iterator_t end = OpalData::getInstance()->getLastMaxPhases();
for(; it < end; ++ it) {
putMessage(*mess, (*it).first);
putMessage(*mess, (*it).second);
{
typedef std::vector<MaxPhasesT>::iterator iterator_t;
iterator_t it = OpalData::getInstance()->getFirstMaxPhases();
iterator_t end = OpalData::getInstance()->getLastMaxPhases();
for(; it != end; ++ it) {
putMessage(*mess, (*it).first);
putMessage(*mess, (*it).second);
}
}
{
typedef energyEvolution_t::iterator iterator_t;
iterator_t it = OpalData::getInstance()->getFirstEnergyData();
iterator_t end = OpalData::getInstance()->getLastEnergyData();
for(; it != end; ++ it) {
putMessage(*mess, (*it).first);
putMessage(*mess, (*it).second);
}
}
Ippl::Comm->broadcast_all(mess, tag);
......@@ -458,21 +473,33 @@ void AutophaseTracker::sendCavityPhases() {
}
void AutophaseTracker::receiveCavityPhases() {
typedef std::vector<MaxPhasesT>::iterator iterator_t;
int parent = 0;
int tag = 101;
int nData = 0;
Message *mess = Ippl::Comm->receive_block(parent, tag);
getMessage(*mess, nData);
for(int i = 0; i < nData; i++) {
std::string elName;
double maxPhi;
getMessage(*mess, elName);
getMessage(*mess, maxPhi);
OpalData::getInstance()->setMaxPhase(elName, maxPhi);
}
{
typedef std::vector<MaxPhasesT>::iterator iterator_t;
for(int i = 0; i < nData; i++) {
std::string elName;
double maxPhi;
getMessage(*mess, elName);
getMessage(*mess, maxPhi);
OpalData::getInstance()->setMaxPhase(elName, maxPhi);
}
}
{
typedef energyEvolution_t::iterator iterator_t;
for(int i = 0; i < nData; i++) {
double spos;
double maxEnergy;
getMessage(*mess, spos);
getMessage(*mess, maxEnergy);
OpalData::getInstance()->addEnergyData(spos, maxEnergy);
}
}
delete mess;
}
......@@ -541,4 +568,4 @@ void AutophaseTracker::save(const std::string &fname) {
}
out.close();
}
}
\ 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