Commit e2cd9a1d authored by frey_m's avatar frey_m
Browse files

Closes #272

modified:   Algorithms/ParallelCyclotronTracker.cpp
modified:   Algorithms/ParallelCyclotronTracker.h
modified:   Track/TrackRun.cpp
parent c68a41b2
......@@ -266,6 +266,22 @@ void ParallelCyclotronTracker::setMultiBunchMode(const std::string& mbmode)
"MBMODE name \"" + mbmode + "\" unknown.");
}
void ParallelCyclotronTracker::setMultiBunchBinning(std::string binning) {
binning = Util::toUpper(binning);
if ( binning.compare("BUNCH") == 0 ) {
*gmsg << "Use 'BUNCH' injection for binnning." << endl;
binningType_m = MB_BINNING::BUNCH;
} else if ( binning.compare("GAMMA") == 0 ) {
*gmsg << "Use 'GAMMA' for binning." << endl;
binningType_m = MB_BINNING::GAMMA;
} else {
throw OpalException("ParallelCyclotronTracker::setMultiBunchBinning()",
"MB_BINNING name \"" + binning + "\" unknown.");
}
}
/**
*
*
......@@ -1374,7 +1390,7 @@ void ParallelCyclotronTracker::MtsTracker() {
// recalculate bingamma and reset the BinID for each particles according to its current gamma
if((itsBunch_m->weHaveBins()) && BunchCount_m > 1) {
if(step_m % Options::rebinFreq == 0) {
itsBunch_m->resetPartBinID2(eta_m);
updateParticleBins_m();
}
}
......@@ -1411,7 +1427,7 @@ void ParallelCyclotronTracker::MtsTracker() {
if (itsBunch_m->weHaveBins() && BunchCount_m > 1 &&
step_m % Options::rebinFreq == 0)
{
itsBunch_m->resetPartBinID2(eta_m);
updateParticleBins_m();
}
}
......@@ -1802,6 +1818,23 @@ bool ParallelCyclotronTracker::readOneBunchFromFile(const size_t BinID) {
return true;
}
void ParallelCyclotronTracker::updateParticleBins_m() {
switch ( binningType_m ) {
case MB_BINNING::GAMMA:
itsBunch_m->resetPartBinID2(eta_m);
break;
case MB_BINNING::BUNCH:
/*
* do nothing
*/
break;
default:
itsBunch_m->resetPartBinID2(eta_m);
}
}
double ParallelCyclotronTracker::getHarmonicNumber() const {
if (opalRing_m != NULL)
return opalRing_m->getHarmonicNumber();
......@@ -2215,7 +2248,8 @@ void ParallelCyclotronTracker::borisExternalFields(double h) {
// destroy particles if they are marked as Bin=-1 in the plugin elements or out of global apeture
bool const flagNeedUpdate = deleteParticle();
if(itsBunch_m->weHaveBins() && flagNeedUpdate) itsBunch_m->resetPartBinID2(eta_m);
if(itsBunch_m->weHaveBins() && flagNeedUpdate)
updateParticleBins_m();
}
......@@ -2938,7 +2972,7 @@ std::tuple<double, double, double> ParallelCyclotronTracker::initializeTracking_
initDistInGlobalFrame();
if ( OpalData::getInstance()->inRestartRun() && numBunch_m > 1)
itsBunch_m->resetPartBinID2(eta_m);
updateParticleBins_m();
turnnumber_m = 1;
......@@ -3268,12 +3302,12 @@ void ParallelCyclotronTracker::bunchMode_m(double& t, const double dt, bool& dum
// If particles were deleted, recalculate bingamma and reset BinID for remaining particles
if(itsBunch_m->weHaveBins() && flagNeedUpdate)
itsBunch_m->resetPartBinID2(eta_m);
updateParticleBins_m();
// Recalculate bingamma and reset the BinID for each particles according to its current gamma
if (itsBunch_m->weHaveBins() && BunchCount_m > 1 && step_m % Options::rebinFreq == 0)
{
itsBunch_m->resetPartBinID2(eta_m);
updateParticleBins_m();
}
// Some status output for user after each turn
......@@ -3585,7 +3619,7 @@ void ParallelCyclotronTracker::injectBunch_m(bool& flagTransition) {
case MB_MODE::FORCE:
case MB_MODE::AUTO:
readOneBunchFromFile(BunchCount_m - 1);
itsBunch_m->resetPartBinID2(eta_m);
updateParticleBins_m();
break;
case MB_MODE::NONE:
// do nothing
......
......@@ -66,7 +66,12 @@ public:
FORCE = 1,
AUTO = 2
};
// multi-bunch binning type
enum class MB_BINNING {
GAMMA = 0,
BUNCH = 1
};
typedef std::vector<double> dvector_t;
typedef std::vector<int> ivector_t;
......@@ -210,6 +215,9 @@ public:
/// set the working sub-mode for multi-bunch mode: "FORCE" or "AUTO"
void setMultiBunchMode(const std::string& mbmode);
// set binning type
void setMultiBunchBinning(std::string binning);
/// set the scale for binning in multi-bunch mode
void setMultiBunchEta(const double& eta) { eta_m = eta; };
......@@ -292,6 +300,10 @@ private:
// 1 for FORCE,
// 2 for AUTO
MB_MODE multiBunchMode_m;
// 0 for GAMMA (default),
// 1 for BUNCH
MB_BINNING binningType_m;
// control parameter for AUTO multi-bunch mode
double CoeffDBunches_m;
......@@ -381,6 +393,8 @@ private:
bool readOneBunchFromFile(const size_t BeamCount);
void saveOneBunch();
void updateParticleBins_m();
bool checkGapCross(Vector_t Rold, Vector_t Rnew, RFCavity * rfcavity, double &DistOld);
bool RFkick(RFCavity * rfcavity, const double t, const double dt, const int Pindex);
......
......@@ -77,6 +77,7 @@ namespace {
MBMODE, // The working way for multi-bunch mode for OPAL-cycl: "FORCE" or "AUTO"
PARAMB, // The control parameter for "AUTO" mode of multi-bunch,
MB_ETA, // The scale parameter for binning in multi-bunch mode
MB_BINNING, // The binning type in multi-bunch mode
BEAM, // The beam to track
FIELDSOLVER, // The field solver attached
BOUNDARYGEOMETRY, // The boundary geometry
......@@ -109,11 +110,14 @@ TrackRun::TrackRun():
("MBMODE", "The working way for multi-bunch mode for OPAL-cycl: FORCE or AUTO ", "FORCE");
itsAttr[PARAMB] = Attributes::makeReal
("PARAMB", " Control parameter to define when to start multi-bunch mode, only available in \"AUTO\" mode ", 5.0);
("PARAMB", "Control parameter to define when to start multi-bunch mode, only available in \"AUTO\" mode ", 5.0);
itsAttr[MB_ETA] = Attributes::makeReal("MB_ETA",
"The scale parameter for binning in multi-bunch mode",
0.01);
itsAttr[MB_BINNING] = Attributes::makeString
("MB_BINNING", "The scale parameter for binning in multi-bunch mode", "GAMMA");
itsAttr[BEAM] = Attributes::makeString
("BEAM", "Name of beam ", "BEAM");
......@@ -844,8 +848,12 @@ void TrackRun::setupCyclotronTracker(){
std::string mbmode = Util::toUpper(Attributes::getString(itsAttr[MBMODE]));
itsTracker->setMultiBunchMode(mbmode);
}
dynamic_cast<ParallelCyclotronTracker*>(itsTracker)->setMultiBunchEta(Attributes::getReal(itsAttr[MB_ETA]));
ParallelCyclotronTracker* tracker_p = dynamic_cast<ParallelCyclotronTracker*>(itsTracker);
tracker_p->setMultiBunchEta(Attributes::getReal(itsAttr[MB_ETA]));
tracker_p->setMultiBunchBinning(Attributes::getString(itsAttr[MB_BINNING]));
}
}
......
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