diff --git a/src/Structure/DataSink.cpp b/src/Structure/DataSink.cpp index 446203fc9b8fad247f6aaf7a6425c7d7a60ddffc..779c17993a769174f817c254bdd95b7fade0976b 100644 --- a/src/Structure/DataSink.cpp +++ b/src/Structure/DataSink.cpp @@ -41,9 +41,9 @@ #include "Utility/FieldDebugFunctions.h" #ifdef __linux__ - #include "MemoryProfiler.h" + #include "Structure/MemoryProfiler.h" #else - #include "MemoryWriter.h" + #include "Structure/MemoryWriter.h" #endif #ifdef ENABLE_AMR @@ -56,6 +56,7 @@ #include <sstream> + DataSink::DataSink() : isMultiBunch_m(false) { @@ -63,7 +64,7 @@ DataSink::DataSink() } -DataSink::DataSink(H5PartWrapper *h5wrapper, bool restart, short numBunch) +DataSink::DataSink(H5PartWrapper* h5wrapper, bool restart, short numBunch) : isMultiBunch_m(numBunch > 1) { if (restart && !Options::enableHDF5) { @@ -78,7 +79,7 @@ DataSink::DataSink(H5PartWrapper *h5wrapper, bool restart, short numBunch) } -DataSink::DataSink(H5PartWrapper *h5wrapper, short numBunch) +DataSink::DataSink(H5PartWrapper* h5wrapper, short numBunch) : DataSink(h5wrapper, false, numBunch) { } @@ -90,7 +91,7 @@ void DataSink::dumpH5(PartBunchBase<double, 3> *beam, Vector_t FDext[]) const { } -int DataSink::dumpH5(PartBunchBase<double, 3> *beam, Vector_t FDext[], double meanEnergy, +int DataSink::dumpH5(PartBunchBase<double, 3>* beam, Vector_t FDext[], double meanEnergy, double refPr, double refPt, double refPz, double refR, double refTheta, double refZ, double azimuth, double elevation, bool local) const @@ -102,15 +103,15 @@ int DataSink::dumpH5(PartBunchBase<double, 3> *beam, Vector_t FDext[], double me } -void DataSink::dumpSDDS(PartBunchBase<double, 3> *beam, Vector_t FDext[], +void DataSink::dumpSDDS(PartBunchBase<double, 3>* beam, Vector_t FDext[], const double& azimuth) const { this->dumpSDDS(beam, FDext, losses_t(), azimuth); } -void DataSink::dumpSDDS(PartBunchBase<double, 3> *beam, Vector_t FDext[], - const losses_t &losses, const double& azimuth) const +void DataSink::dumpSDDS(PartBunchBase<double, 3>* beam, Vector_t FDext[], + const losses_t& losses, const double& azimuth) const { beam->calcBeamParameters(); @@ -124,8 +125,9 @@ void DataSink::dumpSDDS(PartBunchBase<double, 3> *beam, Vector_t FDext[], beam->gatherLoadBalanceStatistics(); - for (size_t i = 0; i < sddsWriter_m.size(); ++i) + for (size_t i = 0; i < sddsWriter_m.size(); ++i) { sddsWriter_m[i]->write(beam); + } IpplTimings::stopTimer(StatMarkerTimer_m); } @@ -138,34 +140,34 @@ void DataSink::storeCavityInformation() { } -void DataSink::changeH5Wrapper(H5PartWrapper *h5wrapper) { +void DataSink::changeH5Wrapper(H5PartWrapper* h5wrapper) { if (!Options::enableHDF5) return; h5Writer_m->changeH5Wrapper(h5wrapper); } -void DataSink::writeGeomToVtk(BoundaryGeometry &bg, std::string fn) { +void DataSink::writeGeomToVtk(BoundaryGeometry& bg, const std::string& fn) { if (Ippl::myNode() == 0 && Options::enableVTK) { - bg.writeGeomToVtk (fn); + bg.writeGeomToVtk(fn); } } -void DataSink::writeImpactStatistics(const PartBunchBase<double, 3> *beam, long long &step, size_t &impact, double &sey_num, +void DataSink::writeImpactStatistics(const PartBunchBase<double, 3>* beam, long long& step, size_t& impact, double& sey_num, size_t numberOfFieldEmittedParticles, bool nEmissionMode, std::string fn) { double charge = 0.0; size_t Npart = 0; double Npart_d = 0.0; - if(!nEmissionMode) { + if (!nEmissionMode) { charge = -1.0 * beam->getCharge(); //reduce(charge, charge, OpAddAssign()); Npart_d = -1.0 * charge / beam->getChargePerParticle(); } else { Npart = beam->getTotalNum(); } - if(Ippl::myNode() == 0) { + if (Ippl::myNode() == 0) { std::string ffn = fn + std::string(".dat"); std::unique_ptr<Inform> ofp(new Inform(nullptr, ffn.c_str(), Inform::APPEND, 0)); @@ -173,9 +175,9 @@ void DataSink::writeImpactStatistics(const PartBunchBase<double, 3> *beam, long fid.precision(6); fid << std::setiosflags(std::ios::scientific); double t = beam->getT() * Units::s2ns; - if(!nEmissionMode) { + if (!nEmissionMode) { - if(step == 0) { + if (step == 0) { fid << "#Time/ns" << std::setw(18) << "#Geometry impacts" << std::setw(18) << "tot_sey" << std::setw(18) << "TotalCharge" << std::setw(18) << "PartNum" << " numberOfFieldEmittedParticles " << endl; } @@ -183,7 +185,7 @@ void DataSink::writeImpactStatistics(const PartBunchBase<double, 3> *beam, long << std::setw(18) << Npart_d << std::setw(18) << numberOfFieldEmittedParticles << endl; } else { - if(step == 0) { + if (step == 0) { fid << "#Time/ns" << std::setw(18) << "#Geometry impacts" << std::setw(18) << "tot_sey" << std::setw(18) << "ParticleNumber" << " numberOfFieldEmittedParticles " << endl; } @@ -194,7 +196,7 @@ void DataSink::writeImpactStatistics(const PartBunchBase<double, 3> *beam, long } -void DataSink::writeMultiBunchStatistics(PartBunchBase<double, 3> *beam, +void DataSink::writeMultiBunchStatistics(PartBunchBase<double, 3>* beam, MultiBunchHandler* mbhandler_p) { /// Start timer. IpplTimings::startTimer(StatMarkerTimer_m); diff --git a/src/Structure/DataSink.h b/src/Structure/DataSink.h index 80a8c19a1b9e8542d8b6ee30504c903c9c72fc81..e8e036fa70a32cabffd4e65f76609a874bee59a7 100644 --- a/src/Structure/DataSink.h +++ b/src/Structure/DataSink.h @@ -52,7 +52,7 @@ private: typedef std::unique_ptr<SDDSWriter> sddsWriter_t; typedef std::unique_ptr<H5Writer> h5Writer_t; typedef std::unique_ptr<MultiBunchDump> mbWriter_t; - + public: /** \brief Default constructor. * @@ -63,45 +63,44 @@ public: DataSink(H5PartWrapper *h5wrapper, bool restart, short numBunch); DataSink(H5PartWrapper *h5wrapper, short numBunch); - void dumpH5(PartBunchBase<double, 3> *beam, Vector_t FDext[]) const; - - int dumpH5(PartBunchBase<double, 3> *beam, Vector_t FDext[], double meanEnergy, + void dumpH5(PartBunchBase<double, 3>* beam, Vector_t FDext[]) const; + + int dumpH5(PartBunchBase<double, 3>* beam, Vector_t FDext[], double meanEnergy, double refPr, double refPt, double refPz, double refR, double refTheta, double refZ, double azimuth, double elevation, bool local) const; - - void dumpSDDS(PartBunchBase<double, 3> *beam, Vector_t FDext[], + + void dumpSDDS(PartBunchBase<double, 3>* beam, Vector_t FDext[], const double& azimuth = -1) const; - - void dumpSDDS(PartBunchBase<double, 3> *beam, Vector_t FDext[], - const losses_t &losses = losses_t(), const double& azimuth = -1) const; - + + void dumpSDDS(PartBunchBase<double, 3>* beam, Vector_t FDext[], + const losses_t& losses = losses_t(), const double& azimuth = -1) const; + /** \brief Write cavity information from H5 file */ void storeCavityInformation(); - - void changeH5Wrapper(H5PartWrapper *h5wrapper); - + + void changeH5Wrapper(H5PartWrapper* h5wrapper); + /** * Write geometry points and surface triangles to vtk file * * @param fn specifies the name of vtk file contains the geometry * */ - void writeGeomToVtk(BoundaryGeometry &bg, std::string fn); - //void writeGeoContourToVtk(BoundaryGeometry &bg, std::string fn); - - + void writeGeomToVtk(BoundaryGeometry& bg, const std::string& fn); + //void writeGeoContourToVtk(BoundaryGeometry& bg, std::string fn); + /** * Write impact number and outgoing secondaries in each time step * * @param fn specifies the name of vtk file contains the geometry * */ - void writeImpactStatistics(const PartBunchBase<double, 3> *beam, - long long int &step, - size_t &impact, - double &sey_num, + void writeImpactStatistics(const PartBunchBase<double, 3>* beam, + long long int& step, + size_t& impact, + double& sey_num, size_t numberOfFieldEmittedParticles, bool nEmissionMode, std::string fn); @@ -110,7 +109,7 @@ public: * @param beam * @param mbhandler is the multi-bunch handler */ - void writeMultiBunchStatistics(PartBunchBase<double, 3> *beam, + void writeMultiBunchStatistics(PartBunchBase<double, 3>* beam, MultiBunchHandler* mbhandler); /** @@ -130,7 +129,6 @@ private: H5PartWrapper* h5wrapper = nullptr, short numBunch = 1); - h5Writer_t h5Writer_m; statWriter_t statWriter_m; std::vector<sddsWriter_t> sddsWriter_m; @@ -157,5 +155,4 @@ std::string DataSink::convertToString(int number, int setw) { return ss.str(); } - #endif // DataSink_H_ diff --git a/src/Structure/LBalWriter.cpp b/src/Structure/LBalWriter.cpp index f71cdf280fe05f5e0f448d5318a699e739b30272..59580a3cd1cceff68f7a0b3bff97c899faaf684a 100644 --- a/src/Structure/LBalWriter.cpp +++ b/src/Structure/LBalWriter.cpp @@ -16,18 +16,18 @@ // You should have received a copy of the GNU General Public License // along with OPAL. If not, see <https://www.gnu.org/licenses/>. // -#include "LBalWriter.h" +#include "Structure/LBalWriter.h" -#include "OPALconfig.h" #include "AbstractObjects/OpalData.h" -#include "Utilities/Util.h" -#include "Utilities/Timer.h" -#include "Algorithms/PartBunchBase.h" -#include "Physics/Units.h" - #ifdef ENABLE_AMR #include "Algorithms/AmrPartBunch.h" #endif +#include "Algorithms/PartBunchBase.h" +#include "OPALconfig.h" +#include "Physics/Units.h" +#include "Utilities/Timer.h" +#include "Utilities/Util.h" + LBalWriter::LBalWriter(const std::string& fname, bool restart) : SDDSWriter(fname, restart) @@ -35,7 +35,7 @@ LBalWriter::LBalWriter(const std::string& fname, bool restart) #ifdef ENABLE_AMR -void LBalWriter::fillHeader(PartBunchBase<double, 3> * beam) { +void LBalWriter::fillHeader(PartBunchBase<double, 3>* beam) { #else void LBalWriter::fillHeader() { #endif @@ -71,11 +71,11 @@ void LBalWriter::fillHeader() { } #endif - if ( mode_m == std::ios::app ) + if ( mode_m == std::ios::app ) { return; + } OPALTimer::Timer simtimer; - std::string dateStr(simtimer.date()); std::string timeStr(simtimer.time()); @@ -88,24 +88,18 @@ void LBalWriter::fillHeader() { this->addDefaultParameters(); - this->addInfo("ascii", 1); } - +void LBalWriter::write(PartBunchBase<double, 3>* beam) { #ifdef ENABLE_AMR -void LBalWriter::write(PartBunchBase<double, 3> *beam) { - if ( AmrPartBunch* amrbeam = dynamic_cast<AmrPartBunch*>(beam) ) { amrbeam->gatherLevelStatistics(); } -#else -void LBalWriter::write(const PartBunchBase<double, 3> *beam) { #endif - - if ( Ippl::myNode() != 0 ) + if ( Ippl::myNode() != 0 ) { return; - + } #ifdef ENABLE_AMR this->fillHeader(beam); #else @@ -116,7 +110,7 @@ void LBalWriter::write(const PartBunchBase<double, 3> *beam) { this->writeHeader(); - columns_m.addColumnValue("t", beam->getT() * Units::s2ns); // 1 + columns_m.addColumnValue("t", beam->getT() * Units::s2ns); size_t nProcs = Ippl::getNodes(); for (size_t p = 0; p < nProcs; ++ p) { diff --git a/src/Structure/LBalWriter.h b/src/Structure/LBalWriter.h index ef769c519299f9da126a1e69eba7d9c099428890..f629b380238344cd569c5e72900dfea99a5d9c7b 100644 --- a/src/Structure/LBalWriter.h +++ b/src/Structure/LBalWriter.h @@ -19,26 +19,21 @@ #ifndef OPAL_LBAL_WRITER_H #define OPAL_LBAL_WRITER_H -#include "SDDSWriter.h" +#include "Structure/SDDSWriter.h" -class LBalWriter : public SDDSWriter { +class LBalWriter: public SDDSWriter { public: LBalWriter(const std::string& fname, bool restart); -#ifdef ENABLE_AMR - void write(PartBunchBase<double, 3> *beam); -#else - void write(const PartBunchBase<double, 3> *beam) override; -#endif + void write(PartBunchBase<double, 3>* beam) override; private: #ifdef ENABLE_AMR - void fillHeader(PartBunchBase<double, 3> *beam); + void fillHeader(PartBunchBase<double, 3>* beam); #else void fillHeader(); #endif }; - -#endif \ No newline at end of file +#endif diff --git a/src/Structure/MemoryProfiler.cpp b/src/Structure/MemoryProfiler.cpp index 34f9568849674416cb11c073330c0f014a9b5625..53dbc1ef3204b444c742ffdf30e7e1b3d43ffbc3 100644 --- a/src/Structure/MemoryProfiler.cpp +++ b/src/Structure/MemoryProfiler.cpp @@ -18,23 +18,22 @@ // You should have received a copy of the GNU General Public License // along with OPAL. If not, see <https://www.gnu.org/licenses/>. // -#include "MemoryProfiler.h" +#include "Structure/MemoryProfiler.h" -#ifdef __linux__ -#include <sys/types.h> -#include <unistd.h> -#endif - -#include "Utilities/Timer.h" -#include "Utilities/OpalException.h" #include "AbstractObjects/OpalData.h" #include "Algorithms/PartBunchBase.h" #include "Physics/Units.h" - -#include <boost/filesystem.hpp> +#include "Utilities/Timer.h" +#include "Utilities/OpalException.h" #include "Ippl.h" +#include <boost/filesystem.hpp> + +#ifdef __linux__ +#include <sys/types.h> +#include <unistd.h> +#endif #include <sstream> MemoryProfiler::MemoryProfiler(const std::string& fname, bool restart) @@ -197,7 +196,7 @@ void MemoryProfiler::compute(vm_t& vmMin, } -void MemoryProfiler::write(const PartBunchBase<double, 3> *beam) { +void MemoryProfiler::write(PartBunchBase<double, 3>* beam) { this->update(); diff --git a/src/Structure/MemoryProfiler.h b/src/Structure/MemoryProfiler.h index e35a46d9b367b84091e41697dcc3c4ba80cd1071..acb32dc90daddb3cac5c8fdf19196a63f9bb86be 100644 --- a/src/Structure/MemoryProfiler.h +++ b/src/Structure/MemoryProfiler.h @@ -21,23 +21,24 @@ #ifndef OPAL_MEMORY_PROFILER_H #define OPAL_MEMORY_PROFILER_H +#include "Structure/SDDSWriter.h" + #include <fstream> -#include <string> #include <map> +#include <string> #include <vector> -#include "SDDSWriter.h" -class MemoryProfiler : public SDDSWriter { +class MemoryProfiler: public SDDSWriter { /* Pay attention with units. /proc/[pid]/status returns values in * KiB (Kibibyte) although the units say kB. * KiB has base 2 not base 10 */ - + public: typedef std::vector<long double> vm_t; typedef std::vector<std::string> units_t; - + MemoryProfiler(const std::string& fname, bool restart); enum VirtualMemory { @@ -57,14 +58,14 @@ public: VMSWAP // VmSwap: Swapped-out virtual memory size by anonymous private pages; shmem swap usage is not // included (since Linux 2.6.34). }; - - void write(const PartBunchBase<double, 3> *beam) override; - + + void write(PartBunchBase<double, 3>* beam) override; + private: void header(); void update(); void compute(vm_t& vmMin, vm_t& vmMax, vm_t& vmAvg); - + private: std::map<std::string, int> procinfo_m; vm_t vmem_m; diff --git a/src/Structure/MemoryWriter.cpp b/src/Structure/MemoryWriter.cpp index bb26410d0e9a629e30e6733788350266d06624fa..ca775e733a2e128642a88be85018bfd0ffbcf5d5 100644 --- a/src/Structure/MemoryWriter.cpp +++ b/src/Structure/MemoryWriter.cpp @@ -18,12 +18,13 @@ // You should have received a copy of the GNU General Public License // along with OPAL. If not, see <https://www.gnu.org/licenses/>. // -#include "MemoryWriter.h" +#include "Structure/MemoryWriter.h" #include "AbstractObjects/OpalData.h" #include "Algorithms/PartBunchBase.h" -#include "Utilities/Timer.h" #include "Physics/Units.h" +#include "Utilities/Timer.h" + #include "Ippl.h" MemoryWriter::MemoryWriter(const std::string& fname, bool restart) @@ -61,7 +62,6 @@ void MemoryWriter::fillHeader() { std::string dateStr(simtimer.date()); std::string timeStr(simtimer.time()); - std::stringstream ss; ss << "Memory statistics '" @@ -72,13 +72,12 @@ void MemoryWriter::fillHeader() { this->addDefaultParameters(); - this->addInfo("ascii", 1); } -void MemoryWriter::write(const PartBunchBase<double, 3> *beam) -{ +void MemoryWriter::write(PartBunchBase<double, 3>* beam) { + IpplMemoryUsage::IpplMemory_p memory = IpplMemoryUsage::getInstance(); memory->sample(); @@ -114,4 +113,4 @@ void MemoryWriter::write(const PartBunchBase<double, 3> *beam) this->writeRow(); this->close(); -} \ No newline at end of file +} diff --git a/src/Structure/MemoryWriter.h b/src/Structure/MemoryWriter.h index 2f282683cfb5fc8b501bfb567c156fa30b326061..b55c9b12f322485f78512b7e7e4ef7e2efeaf703 100644 --- a/src/Structure/MemoryWriter.h +++ b/src/Structure/MemoryWriter.h @@ -21,17 +21,17 @@ #ifndef OPAL_MEMORY_WRITER_H #define OPAL_MEMORY_WRITER_H -#include "SDDSWriter.h" +#include "Structure/SDDSWriter.h" -class MemoryWriter : public SDDSWriter { +class MemoryWriter: public SDDSWriter { public: MemoryWriter(const std::string& fname, bool restart); - void write(const PartBunchBase<double, 3> *beam) override; + void write(PartBunchBase<double, 3>* beam) override; private: void fillHeader(); }; -#endif \ No newline at end of file +#endif diff --git a/src/Structure/SDDSWriter.cpp b/src/Structure/SDDSWriter.cpp index 579b7ff0e90946ae1dc14c271f98f1dcec8e81b7..73433b05a8ce83a5c4e50f181ba9c49a7c46701d 100644 --- a/src/Structure/SDDSWriter.cpp +++ b/src/Structure/SDDSWriter.cpp @@ -63,7 +63,6 @@ void SDDSWriter::rewindLines(size_t numberOfLines) { } fs.close(); - fs.open (fname_m.c_str(), std::fstream::out); if (!fs.is_open()) return; @@ -99,7 +98,6 @@ void SDDSWriter::replaceVersionString() { } fs.close(); - fs.open (fname_m.c_str(), std::fstream::out); if (!fs.is_open()) return; @@ -228,4 +226,4 @@ void SDDSWriter::addDefaultParameters() { addParameter("revision", "string", "git revision of opal", revision.str()); addParameter("flavor", "string", "OPAL flavor that wrote file", flavor); -} \ No newline at end of file +} diff --git a/src/Structure/SDDSWriter.h b/src/Structure/SDDSWriter.h index 39e1d1a4f85c3f1784334c6197335007bacdfbd5..5858415d66f91eeab7d27b8bb447d8941d5a667b 100644 --- a/src/Structure/SDDSWriter.h +++ b/src/Structure/SDDSWriter.h @@ -20,15 +20,15 @@ #define OPAL_SDDS_WRITER_H #include <fstream> -#include <string> -#include <queue> +#include <iomanip> #include <map> -#include <vector> -#include <tuple> -#include <utility> #include <ostream> -#include <iomanip> +#include <queue> #include <sstream> +#include <string> +#include <tuple> +#include <utility> +#include <vector> #include <boost/filesystem.hpp> @@ -58,12 +58,11 @@ public: std::string, std::string> cols_t; - SDDSWriter(const std::string& fname, bool restart); virtual ~SDDSWriter() { }; - virtual void write(const PartBunchBase<double, 3>* /*beam*/) { }; + virtual void write(PartBunchBase<double, 3>* /*beam*/) { }; /** \brief * delete the last 'numberOfLines' lines of the file 'fileName' @@ -77,7 +76,6 @@ public: bool exists() const; protected: - void addDescription(const std::string& text, const std::string& content); @@ -131,7 +129,6 @@ protected: bool hasColumns() const; private: - void writeDescription(); void writeParameters(); @@ -162,8 +159,7 @@ bool SDDSWriter::exists() const { inline void SDDSWriter::addDescription(const std::string& text, - const std::string& content) -{ + const std::string& content) { desc_m = std::make_pair(text, content); } @@ -172,8 +168,7 @@ template<typename T> void SDDSWriter::addParameter(const std::string& name, const std::string& type, const std::string& desc, - const T& value) -{ + const T& value) { params_m.push(std::make_tuple(name, type, desc)); std::stringstream ss; ss << value; @@ -208,4 +203,4 @@ bool SDDSWriter::hasColumns() const { return columns_m.hasColumns(); } -#endif \ No newline at end of file +#endif