Commit 429c45c9 authored by snuverink_j's avatar snuverink_j

Merge branch '344-probe-output' into 'master'

Resolve "Probe Output"

Closes #344

See merge request OPAL/src!161
parents 391a294d c4cad5a3
This diff is collapsed.
......@@ -28,6 +28,7 @@
#include "Steppers/Steppers.h"
class DataSink;
class PluginElement;
template <class T, unsigned Dim>
class PartBunchBase;
......@@ -213,6 +214,8 @@ private:
beamline_list FieldDimensions;
std::list<Component *> myElements;
Beamline *itsBeamline;
std::vector<PluginElement*> pluginElements_m;
std::vector<CavityCrossData> cavCrossDatas_m;
DataSink *itsDataSink;
......@@ -256,7 +259,7 @@ private:
// for each bunch we have a path length
double pathLength_m;
// Multi time step tracker
void MtsTracker();
void GenericTracker();
......@@ -401,7 +404,6 @@ private:
// Apply effects of RF Gap Crossings.
// Unit assumptions: [itsBunch_m->R] = m, [itsBunch_m->P] = 1, [h] = s, [c] = m/s, [itsBunch_m->getT()] = s
bool push(double h);
// Kick particles for time h
// The fields itsBunch_m->Bf, itsBunch_m->Ef are used to calculate the forces
bool kick(double h);
......@@ -413,7 +415,7 @@ private:
// apply the plugin elements: probe, collimator, stripper, septum
bool applyPluginElements(const double dt);
// destroy particles if they are marked as Bin=-1 in the plugin elements or out of global apeture
// destroy particles if they are marked as Bin=-1 in the plugin elements or out of global aperture
bool deleteParticle(bool = false);
void initTrackOrbitFile();
......@@ -456,7 +458,11 @@ private:
stepper::INTEGRATOR stepper_m;
void update_m(double& t, const double& dt, const bool& dumpEachTurn);
/// Check if turn done
bool isTurnDone();
/// Update time and path length, write to output files
void update_m(double& t, const double& dt, const bool& finishedTurn);
/*!
* @returns the time t [ns], time step dt [ns] and the azimuth angle [rad]
......@@ -468,13 +474,13 @@ private:
dvector_t& Tdeltz,
ivector_t& TturnNumber);
void seoMode_m(double& t, const double dt, bool& dumpEachTurn,
void seoMode_m(double& t, const double dt, bool& finishedTurn,
dvector_t& Ttime, dvector_t& Tdeltr,
dvector_t& Tdeltz, ivector_t& TturnNumber);
void singleMode_m(double& t, const double dt, bool& dumpEachTurn, double& oldReferenceTheta);
void singleMode_m(double& t, const double dt, bool& finishedTurn, double& oldReferenceTheta);
void bunchMode_m(double& t, const double dt, bool& dumpEachTurn);
void bunchMode_m(double& t, const double dt, bool& finishedTurn);
void gapCrossKick_m(size_t i, double t, double dt,
const Vector_t& Rold, const Vector_t& Pold);
......@@ -490,7 +496,7 @@ private:
const Vector_t& R,
const Vector_t& P,
const double& temp_meanTheta,
bool& dumpEachTurn);
bool& finishedTurn);
void computeSpaceChargeFields_m();
......@@ -520,7 +526,7 @@ private:
void updateAzimuthAndRadius();
/** multi-bunch mode: set the path length of each bunch in case of restart mode
*
*
* At creation of DataSink the lines are rewinded properly --> the last entry of
* the path length is therefore the initial path length at restart.
* @pre In order to work properly in restart mode, the lines in the multi-bunch
......
......@@ -71,7 +71,7 @@ void PluginElement::setOutputFN(std::string fn) {
filename_m = fn;
}
std::string PluginElement::getOutputFN() {
std::string PluginElement::getOutputFN() const {
if (filename_m == std::string(""))
return getName();
else
......@@ -227,4 +227,16 @@ int PluginElement::checkPoint(const double &x, const double &y) const {
}
}
return (cn & 1); // 0 if even (out), and 1 if odd (in)
}
void PluginElement::save() {
Options::OPENMODE mode = Options::openMode;
if (numPassages_m > 0) {
Options::openMode = Options::APPEND;
}
lossDs_m->save();
if (numPassages_m > 0) {
Options::openMode = mode;
}
numPassages_m++;
}
\ No newline at end of file
......@@ -50,7 +50,7 @@ public:
/// Set output filename
void setOutputFN(std::string fn);
/// Get output filename
std::string getOutputFN();
std::string getOutputFN() const;
/// Set dimensions and consistency checks
void setDimensions(double xstart, double xend, double ystart, double yend);
......@@ -65,6 +65,8 @@ public:
bool check(PartBunchBase<double, 3> *bunch, const int turnnumber, const double t, const double tstep);
/// Checks if coordinate is within element
int checkPoint(const double & x, const double & y) const;
/// Save output
void save();
protected:
/// Sets geometry geom_m with element width dist
......@@ -111,6 +113,7 @@ protected:
double A_m, B_m, R_m, C_m; ///< Geometric lengths used in calculations
std::unique_ptr<LossDataSink> lossDs_m; ///< Pointer to Loss instance
int numPassages_m = 0; ///< Number of turns (number of times save() method is called)
};
#endif // CLASSIC_PluginElement_HH
......@@ -121,8 +121,6 @@ SetStatistics::SetStatistics():
fac_m(0.0)
{ }
extern Inform *gmsg;
LossDataSink::LossDataSink(std::string elem, bool hdf5Save, ElementBase::ElementType type):
h5hut_mode_m(hdf5Save),
H5file_m(0),
......@@ -278,11 +276,11 @@ void LossDataSink::save(unsigned int numSets) {
fn_m = element_m + std::string(".loss");
INFOMSG(level2 << "Save " << fn_m << endl);
if (Options::openMode == Options::WRITE || !fs::exists(fn_m)) {
appendASCII();
} else {
openASCII();
writeHeaderASCII();
} else {
appendASCII();
}
writeHeaderASCII();
saveASCII();
closeASCII();
}
......@@ -329,10 +327,6 @@ bool LossDataSink::hasTimeAttribute() {
return tLoc > 0;
}
void LossDataSink::saveH5(unsigned int setIdx) {
size_t startIdx = 0;
size_t nLoc = x_m.size();
......@@ -390,36 +384,27 @@ void LossDataSink::saveASCII() {
ASCII output
*/
int tag = Ippl::Comm->next_tag(IPPL_APP_TAG3, IPPL_APP_CYCLE);
bool hasTime = hasTimeAttribute(); // reduce needed for the case when node 0 has no particles
if(Ippl::Comm->myNode() == 0) {
const unsigned partCount = x_m.size();
if (time_m.size() != 0) {
for(unsigned i = 0; i < partCount; i++) {
os_m << element_m << " ";
os_m << x_m[i] << " ";
os_m << y_m[i] << " ";
os_m << z_m[i] << " ";
os_m << px_m[i] << " ";
os_m << py_m[i] << " ";
os_m << pz_m[i] << " ";
os_m << id_m[i] << " ";
for(unsigned i = 0; i < partCount; i++) {
os_m << element_m << " ";
os_m << x_m[i] << " ";
os_m << y_m[i] << " ";
os_m << z_m[i] << " ";
os_m << px_m[i] << " ";
os_m << py_m[i] << " ";
os_m << pz_m[i] << " ";
os_m << id_m[i] << " ";
if (hasTime) {
os_m << turn_m[i] << " ";
os_m << bunchNum_m[i] << " ";
os_m << time_m[i] << " " << std::endl;
}
}
else {
for(unsigned i = 0; i < partCount; i++) {
os_m << element_m << " ";
os_m << x_m[i] << " ";
os_m << y_m[i] << " ";
os_m << z_m[i] << " ";
os_m << px_m[i] << " ";
os_m << py_m[i] << " ";
os_m << pz_m[i] << " ";
os_m << id_m[i] << " " << std::endl;
os_m << time_m[i];
}
os_m << std::endl;
}
int notReceived = Ippl::getNodes() - 1;
while(notReceived > 0) {
unsigned dataBlocks = 0;
......@@ -430,51 +415,36 @@ void LossDataSink::saveASCII() {
}
notReceived--;
rmsg->get(&dataBlocks);
if (time_m.size() != 0) {
for(unsigned i = 0; i < dataBlocks; i++) {
long id, turn;
double rx, ry, rz, px, py, pz, time;
rmsg->get(&id);
rmsg->get(&rx);
rmsg->get(&ry);
rmsg->get(&rz);
rmsg->get(&px);
rmsg->get(&py);
rmsg->get(&pz);
for(unsigned i = 0; i < dataBlocks; i++) {
long id;
size_t bunchNum, turn;
double rx, ry, rz, px, py, pz, time;
rmsg->get(&id);
rmsg->get(&rx);
rmsg->get(&ry);
rmsg->get(&rz);
rmsg->get(&px);
rmsg->get(&py);
rmsg->get(&pz);
if (hasTime) {
rmsg->get(&turn);
rmsg->get(&bunchNum);
rmsg->get(&time);
os_m << element_m << " ";
os_m << rx << " ";
os_m << ry << " ";
os_m << rz << " ";
os_m << px << " ";
os_m << py << " ";
os_m << pz << " ";
os_m << id << " ";
os_m << turn << " ";
os_m << time << std::endl;
}
}
else {
for(unsigned i = 0; i < dataBlocks; i++) {
long id;
double rx, ry, rz, px, py, pz;
rmsg->get(&id);
rmsg->get(&rx);
rmsg->get(&ry);
rmsg->get(&rz);
rmsg->get(&px);
rmsg->get(&py);
rmsg->get(&pz);
os_m << element_m << " ";
os_m << rx << " ";
os_m << ry << " ";
os_m << rz << " ";
os_m << px << " ";
os_m << py << " ";
os_m << pz << " ";
os_m << id << " " << std::endl;
os_m << element_m << " ";
os_m << rx << " ";
os_m << ry << " ";
os_m << rz << " ";
os_m << px << " ";
os_m << py << " ";
os_m << pz << " ";
os_m << id << " ";
if (hasTime) {
os_m << turn << " ";
os_m << bunchNum << " ";
os_m << time;
}
os_m << std::endl;
}
delete rmsg;
}
......@@ -482,31 +452,20 @@ void LossDataSink::saveASCII() {
Message *smsg = new Message();
const unsigned msgsize = x_m.size();
smsg->put(msgsize);
if (time_m.size() != 0) {
for(unsigned i = 0; i < msgsize; i++) {
smsg->put(id_m[i]);
smsg->put(x_m[i]);
smsg->put(y_m[i]);
smsg->put(z_m[i]);
smsg->put(px_m[i]);
smsg->put(py_m[i]);
smsg->put(pz_m[i]);
for(unsigned i = 0; i < msgsize; i++) {
smsg->put(id_m[i]);
smsg->put(x_m[i]);
smsg->put(y_m[i]);
smsg->put(z_m[i]);
smsg->put(px_m[i]);
smsg->put(py_m[i]);
smsg->put(pz_m[i]);
if (hasTime) {
smsg->put(turn_m[i]);
smsg->put(bunchNum_m[i]);
smsg->put(time_m[i]);
}
}
else {
for(unsigned i = 0; i < msgsize; i++) {
smsg->put(id_m[i]);
smsg->put(x_m[i]);
smsg->put(y_m[i]);
smsg->put(z_m[i]);
smsg->put(px_m[i]);
smsg->put(py_m[i]);
smsg->put(pz_m[i]);
}
}
bool res = Ippl::Comm->send(smsg, 0, tag);
if(! res)
ERRORMSG("LossDataSink Ippl::Comm->send(smsg, 0, tag) failed " << endl;);
......
......@@ -86,8 +86,6 @@ class LossDataSink {
std::set<SetStatistics> computeStatistics(unsigned int numSets);
// static void writeStatistics();
private:
void openASCII() {
if(Ippl::myNode() == 0) {
......@@ -106,7 +104,7 @@ private:
if(Ippl::myNode() == 0) {
os_m << "# Element " << element_m << " x (mm), y (mm), z (mm), px ( ), py ( ), pz ( ), id";
if (time_m.size() != 0) {
os_m << ", turn, time (ns) ";
os_m << ", turn, bunchNumber, time (ns) ";
}
os_m << std::endl;
}
......
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