Commit c63d4873 authored by frey_m's avatar frey_m
Browse files

fix computePathLength

parent c2e4095d
......@@ -23,10 +23,13 @@ MultiBunchHandler::MultiBunchHandler(PartBunchBase<double, 3> *beam,
, radiusLastTurn_m(0.0)
, radiusThisTurn_m(0.0)
, bunchCount_m(1)
, injTime_m(0.0)
, injPathlength_m(0.0)
, injAzimuth_m(0.0)
{
binfo_m.reserve(numBunch);
for (int i = 0; i < beam->getNumBunch(); ++i) {
binfo_m.push_back(beaminfo_t(0.0, 0.0, 0));
binfo_m.push_back(beaminfo_t(beam->getT(), beam->getLPath(), 0.0));
}
this->setBinning(binning);
......@@ -144,9 +147,9 @@ void MultiBunchHandler::saveBunch(PartBunchBase<double, 3> *beam,
h5wrapper.close();
// injection values
double time = beam->getT();
double lpath = beam->getLPath();
binfo_m.push_back(beaminfo_t(time, azimuth, lpath));
injTime_m = beam->getT();
injPathlength_m = beam->getLPath();
injAzimuth_m = azimuth;
*gmsg << "Done." << endl;
IpplTimings::stopTimer(saveBunchTimer);
......@@ -224,6 +227,8 @@ bool MultiBunchHandler::readBunch(PartBunchBase<double, 3> *beam,
beam->boundp();
binfo_m.push_back(beaminfo_t(injTime_m, injPathlength_m, injAzimuth_m));
*gmsg << "Done." << endl;
IpplTimings::stopTimer(readBunchTimer);
......
......@@ -13,14 +13,14 @@
class MultiBunchHandler {
public:
struct beaminfo_t {
beaminfo_t(double t,
double theta,
double lpath)
beaminfo_t(const double& t,
const double& lpath,
const double& theta)
: time(t)
, azimuth(theta)
, prevAzimuth(-1.0)
, pathlength(lpath) {
};
, pathlength(lpath)
{ };
double time;
double azimuth;
......@@ -140,6 +140,11 @@ private:
// each list entry belongs to a bunch
std::vector<beaminfo_t> binfo_m;
// injection values
double injTime_m;
double injPathlength_m;
double injAzimuth_m;
};
......
......@@ -253,7 +253,11 @@ double ParallelCyclotronTracker::computePathLengthUpdate(const double& dt,
allreduce(dotP, 1, std::plus<double>());
dotP /= itsBunch_m->getTotalNumPerBunch(bunchNr);
size_t n = itsBunch_m->getTotalNum();
if ( bunchNr > -1 )
n = itsBunch_m->getTotalNumPerBunch(bunchNr);
dotP /= double(n);
} else if ( itsBunch_m->getLocalNum() == 0 ) {
// here we are in Options::GLOBAL mode
......@@ -2143,7 +2147,6 @@ bool ParallelCyclotronTracker::deleteParticle(bool flagNeedUpdate){
for (short i = 0; i < bunchCount; ++i) {
itsBunch_m->setTotalNumPerBunch(totalnum[i], i);
std::cout << "deleteParticle: " << i << " " << totalnum[i] << std::endl;
}
size_t sum = std::accumulate(totalnum.begin(),
......@@ -2545,13 +2548,7 @@ void ParallelCyclotronTracker::bunchDumpStatData(){
globalToLocal(itsBunch_m->P, phi, psi);
}
for (short b = 0; b < mbHandler_m->getNumBunch(); ++b) {
bool isOk = mbHandler_m->calcBunchBeamParameters(itsBunch_m, b);
const MultiBunchHandler::beaminfo_t& binfo = mbHandler_m->getBunchInfo(b);
if (isOk) {
itsDataSink->writeMultiBunchStatistics(itsBunch_m, binfo);
}
}
itsDataSink->writeMultiBunchStatistics(itsBunch_m, mbHandler_m.get());
if(Options::psDumpFrame != Options::GLOBAL) {
localToGlobal(itsBunch_m->R, phi, psi, meanR);
......
......@@ -270,7 +270,7 @@ void DataSink::writeImpactStatistics(PartBunchBase<double, 3> *beam, long long &
void DataSink::writeMultiBunchStatistics(PartBunchBase<double, 3> *beam,
const beaminfo_t& binfo) {
MultiBunchHandler* mbhandler_p) {
/// Start timer.
IpplTimings::startTimer(StatMarkerTimer_m);
......@@ -279,7 +279,7 @@ void DataSink::writeMultiBunchStatistics(PartBunchBase<double, 3> *beam,
// if new bunch in machine --> generate new writer for it
short bunch = mbWriter_m.size();
while ( bunch < beam->getNumBunch() ) {
while ( bunch < mbhandler_p->getNumBunch() ) {
std::stringstream ss;
ss << fn << "-bunch-"
<< std::setw(4) << std::setfill('0') << bunch << ".smb";
......@@ -289,8 +289,12 @@ void DataSink::writeMultiBunchStatistics(PartBunchBase<double, 3> *beam,
++bunch;
}
for (auto& mb : mbWriter_m) {
mb->write(beam, binfo);
for (short b = 0; b < mbhandler_p->getNumBunch(); ++b) {
bool isOk = mbhandler_p->calcBunchBeamParameters(beam, b);
const MultiBunchHandler::beaminfo_t& binfo = mbhandler_p->getBunchInfo(b);
if (isOk) {
mbWriter_m[b]->write(beam, binfo);
}
}
for (size_t i = 0; i < sddsWriter_m.size(); ++i)
......
......@@ -117,9 +117,7 @@ public:
* @param binfo is the beam info
*/
void writeMultiBunchStatistics(PartBunchBase<double, 3> *beam,
const beaminfo_t& binfo);
MultiBunchDump* getMultiBunchWriter(short bunchNr);
MultiBunchHandler* mbhandler);
private:
DataSink(const DataSink &) { }
......@@ -134,7 +132,7 @@ private:
h5Writer_t h5Writer_m;
statWriter_t statWriter_m;
std::vector<sddsWriter_t> sddsWriter_m;
std::list<mbWriter_t> mbWriter_m;
std::vector<mbWriter_t> mbWriter_m;
static std::string convertToString(int number);
......@@ -154,14 +152,6 @@ std::string DataSink::convertToString(int number) {
}
inline
MultiBunchDump* DataSink::getMultiBunchWriter(short bunchNr) {
assert(bunchNr > -1 && bunchNr < (short)mbWriter_m.size());
std::list<mbWriter_t>::iterator it = mbWriter_m.begin();
std::advance(it, bunchNr);
return (it->get());
}
#endif // DataSink_H_
// vi: set et ts=4 sw=4 sts=4:
......
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