36 #include <boost/filesystem.hpp>
37 #include <boost/regex.hpp>
43 : isMultiBunch_m(false)
50 : isMultiBunch_m(numBunch > 1)
54 "Can not restart when HDF5 is disabled");
57 this->
init(restart, h5wrapper, numBunch);
65 :
DataSink(h5wrapper, false, numBunch)
77 double refPr,
double refPt,
double refPz,
78 double refR,
double refTheta,
double refZ,
79 double azimuth,
double elevation,
bool local)
const
83 return h5Writer_m->writePhaseSpace(beam, FDext, meanEnergy, refPr, refPt, refPz,
84 refR, refTheta, refZ, azimuth, elevation, local);
89 double sposHead,
double sposRef,
90 double sposTail)
const
95 h5Writer_m->writePhaseSpace(beam, FDext, sposHead, sposRef, sposTail);
100 const double& azimuth)
const
107 const losses_t &losses,
const double& azimuth)
const
121 double sposHead,
double sposRef,
double sposTail)
const
125 statWriter_m->write(beam, FDext, sposHead, sposRef, sposTail);
155 std::string ftrn = fn + std::string(
"triangle") +
convertToString(temp) + std::string(
".dat");
164 double t = beam->
getT();
165 double t_step = t * 1.0e9;
166 double* prPartLossZ =
new double[bg.
getnr() (2)];
167 double* sePartLossZ =
new double[bg.
getnr() (2)];
168 double* fePartLossZ =
new double[bg.
getnr() (2)];
169 fidtr <<
"# Time/ns" << std::setw(18) <<
"Triangle_ID" << std::setw(18)
170 <<
"Xcoordinates (m)" << std::setw(18)
171 <<
"Ycoordinates (m)" << std::setw(18)
172 <<
"Zcoordinates (m)" << std::setw(18)
173 <<
"Primary part. charge (C)" << std::setw(40)
174 <<
"Field emit. part. charge (C)" << std::setw(40)
175 <<
"Secondary emit. part. charge (C)" << std::setw(40) <<
endl;
176 for(
int i = 0; i < Geo_nr(2) ; i++) {
182 && (bg.
TriBarycenters_m[j](2) < (Geo_hr(2)*i + Geo_hr(2) + Geo_mincoords[2]))) {
193 fidtr << t_step << std::setw(18) << j << std::setw(18)
201 fid <<
"# Delta_Z/m" << std::setw(18)
202 <<
"Zcoordinates (m)" << std::setw(18)
203 <<
"Primary part. charge (C)" << std::setw(40)
204 <<
"Field emit. part. charge (C)" << std::setw(40)
205 <<
"Secondary emit. part. charge (C)" << std::setw(40) <<
"t" <<
endl;
208 for(
int i = 0; i < Geo_nr(2) ; i++) {
209 double primaryPLoss = -prPartLossZ[i];
210 double secondaryPLoss = -sePartLossZ[i];
211 double fieldemissionPLoss = -fePartLossZ[i];
215 fid << Geo_hr(2) << std::setw(18)
216 << Geo_mincoords[2] + Geo_hr(2)*i << std::setw(18)
217 << primaryPLoss << std::setw(40)
218 << fieldemissionPLoss << std::setw(40)
219 << secondaryPLoss << std::setw(40) << t <<
endl;
222 delete[] prPartLossZ;
223 delete[] sePartLossZ;
224 delete[] fePartLossZ;
236 size_t numberOfFieldEmittedParticles,
bool nEmissionMode, std::string fn) {
240 double Npart_d = 0.0;
249 std::string ffn = fn + std::string(
".dat");
256 fid << std::setiosflags(std::ios::scientific);
257 double t = beam->
getT() * 1.0e9;
261 fid <<
"#Time/ns" << std::setw(18) <<
"#Geometry impacts" << std::setw(18) <<
"tot_sey" << std::setw(18)
262 <<
"TotalCharge" << std::setw(18) <<
"PartNum" <<
" numberOfFieldEmittedParticles " <<
endl;
264 fid << t << std::setw(18) << impact << std::setw(18) << sey_num << std::setw(18) << charge
265 << std::setw(18) << Npart_d << std::setw(18) << numberOfFieldEmittedParticles <<
endl;
269 fid <<
"#Time/ns" << std::setw(18) <<
"#Geometry impacts" << std::setw(18) <<
"tot_sey" << std::setw(18)
270 <<
"ParticleNumber" <<
" numberOfFieldEmittedParticles " <<
endl;
272 fid << t << std::setw(18) << impact << std::setw(18) << sey_num
273 << std::setw(18) << double(Npart) << std::setw(18) << numberOfFieldEmittedParticles <<
endl;
284 for (
short b = 0; b < mbhandler_p->
getNumBunch(); ++b) {
301 for (
short b = 0; b < mbhandler_p->
getNumBunch(); ++b) {
309 unsigned int linesToRewind = 0;
320 for (std::vector<mbWriter_t>::reverse_iterator rit =
mbWriter_m.rbegin();
323 if ((*rit)->exists()) {
324 linesToRewind = (*rit)->rewindToSpos(spos);
325 (*rit)->replaceVersionString();
336 if ( linesToRewind > 0 ) {
391 while (bunch < numBunch) {
392 std::string fname = fn + std::string(
"-bunch-") +
std::vector< double > TriFEPartloss_m
static std::string convertToString(int number, int setw=5)
core of the envelope tracker based on Rene Bakkers BET implementation
std::unique_ptr< H5Writer > h5Writer_t
void writeMultiBunchStatistics(PartBunchBase< double, 3 > *beam, MultiBunchHandler *mbhandler)
void writeGeomToVtk(std::string fn)
void setInform(Inform &inform)
The base class for all OPAL exceptions.
bool inRestartRun()
true if we do a restart run
void changeH5Wrapper(H5PartWrapper *h5wrapper)
bool calcBunchBeamParameters(PartBunchBase< double, 3 > *beam, short bunchNr)
IpplTimings::TimerRef StatMarkerTimer_m
Timer to track statistics write time.
size_t getTotalNum() const
void writeGeomToVtk(BoundaryGeometry &bg, std::string fn)
bool reduce(Communicate &, InputIterator, InputIterator, OutputIterator, const ReduceOp &, bool *IncludeVal=0)
static OpalData * getInstance()
DataSink()
Default constructor.
void writeImpactStatistics(PartBunchBase< double, 3 > *beam, long long int &step, size_t &impact, double &sey_num, size_t numberOfFieldEmittedParticles, bool nEmissionMode, std::string fn)
std::unique_ptr< SDDSWriter > sddsWriter_t
static void startTimer(TimerRef t)
double getChargePerParticle() const
get the macro particle charge
std::vector< double > TriSePartloss_m
bool enableHDF5
If true HDF5 files are written.
std::vector< double > TriPrPartloss_m
void dumpH5(PartBunchBase< double, 3 > *beam, Vector_t FDext[]) const
std::vector< mbWriter_t > mbWriter_m
std::vector< sddsWriter_t > sddsWriter_m
double getCharge() const
get the total charge per simulation particle
unsigned int lossWrCounter_m
needed to create index for vtk file
const bool isMultiBunch_m
std::unique_ptr< MultiBunchDump > mbWriter_t
beaminfo_t & getBunchInfo(short bunchNr)
void writePartlossZASCII(PartBunchBase< double, 3 > *beam, BoundaryGeometry &bg, std::string fn)
void init(bool restart=false, H5PartWrapper *h5wrapper=nullptr, short numBunch=1)
void setMultiBunchInitialPathLengh(MultiBunchHandler *mbhandler_p)
void dumpSDDS(PartBunchBase< double, 3 > *beam, Vector_t FDext[], const double &azimuth=-1) const
short getNumBunch() const
void initMultiBunchDump(short numBunch)
std::vector< Vector_t > TriBarycenters_m
static TimerRef getTimer(const char *nm)
static void stopTimer(TimerRef t)
std::string getInputBasename()
get input file name without extension
StatWriter::losses_t losses_t
statWriter_t statWriter_m
Inform & endl(Inform &inf)
void storeCavityInformation()
Write cavity information from H5 file.
std::unique_ptr< StatWriter > statWriter_t