Commit 06df9215 authored by adelmann's avatar adelmann 🎗
Browse files

In OPAL several different TRACK's can performed within one simulation (does...

In OPAL several different TRACK's can performed within one simulation (does not hold for OPAL-cycl yet) this together with 
the restart capabilities calls for a delicate logic.

Different tracks, looks like: 

.....

TRACK, LINE= Injector, BEAM=beam1, MAXSTEPS=100, DT=1.0e-12, ZSTOP=0.14;  
 RUN, METHOD = "PARALLEL-T", BEAM = beam1, FIELDSOLVER = Fs1, DISTRIBUTION = Dist1;
ENDTRACK;

TRACK,LINE= Injector, BEAM=beam1, MAXSTEPS=50, DT=1.0e-11, ZSTOP=0.20;
 RUN, METHOD = "PARALLEL-T", BEAM=beam1, FIELDSOLVER=Fs1;
ENDTRACK;
STOP;

A run with the arguments -restart -1 will continue a track from the last dump in the h5 file. Other the from the last track will
at the moment certainly fail in the general case. 

Changes: 

- The h5 attribute TrackStep is not longer available anymore. Two new attributes: LocalTrackStep and GlobalTrackStep are introduced instead.

- LocalTrackStep refers to the track step in a track command (0 ... 99 and 0... 49 in teh above example), where the GlobalTrackStep is the 
accumulated number of steps i.e. 0 ... 149, shown in OPAL's screen output. Both local and global track steps are also written into the h5 file 
in order to properly restart the simulation.

- The PartBunch object has get/set and increment functions:

    inline void setGlobalTrackStep(long long n) {globalTrackStep_m = n;}
    inline long long getGlobalTrackStep() const {return globalTrackStep_m;}

    inline void setLocalTrackStep(long long n) {localTrackStep_m = n;}
    inline long long getLocalTrackStep() const {return localTrackStep_m;}
    inline void incLocalTrackStep() {localTrackStep_m++; globalTrackStep_m++;)

        
- In OPAL-cyc getTrackStep is replace by getLocalTrackStep assuming we only have one TRACK in the simulation.

- In the ParallelTTracker at the end of the main loop (in execute()) obsolet code is removed (cleanup monitors etc.)
  
For details see the diff :-)

Still some work todo: 

a) Need to remove: setLastStep in ParallelTTracker.cpp and in general

    getInstance()->getLastStep()
    getInstance()->getRestartStep() maybe not!

b) The get/set and increment functions could very well be in an other class!

c) ParallelPlate tests are broken but maybe also because of other changes need to fix this 
   together with Chuang and Achim

d) Make sure the restart works in OPAL-cycl we do not have yet a regression test for that.
parent 7af55a0b
......@@ -105,7 +105,8 @@ PartBunch::PartBunch(const PartData *ref):
binemitted_m(nullptr),
lPath_m(0.0),
stepsPerTurn_m(0),
trackStep_m(0),
localTrackStep_m(0),
globalTrackStep_m(0),
numBunch_m(1),
SteptoLastInj_m(0),
partPerNode_m(nullptr),
......@@ -201,7 +202,8 @@ PartBunch::PartBunch(const PartBunch &rhs):
binemitted_m(nullptr),
lPath_m(rhs.lPath_m),
stepsPerTurn_m(rhs.stepsPerTurn_m),
trackStep_m(rhs.trackStep_m),
localTrackStep_m(rhs.localTrackStep_m),
globalTrackStep_m(rhs.globalTrackStep_m),
numBunch_m(rhs.numBunch_m),
SteptoLastInj_m(rhs.SteptoLastInj_m),
partPerNode_m(nullptr),
......@@ -260,7 +262,8 @@ PartBunch::PartBunch(const std::vector<Particle> &rhs, const PartData *ref):
binemitted_m(nullptr),
lPath_m(0.0),
stepsPerTurn_m(0),
trackStep_m(0),
localTrackStep_m(0),
globalTrackStep_m(0),
numBunch_m(1),
SteptoLastInj_m(0),
partPerNode_m(nullptr),
......@@ -404,7 +407,7 @@ void PartBunch::resetIfScan()
*/
{
dt = 0.0;
trackStep_m = 0;
localTrackStep_m = 0;
}
......
......@@ -368,11 +368,17 @@ public:
void setStepsPerTurn(int n);
int getStepsPerTurn() const;
void setTrackStep(long long n);
long long getTrackStep() const;
/// step in multiple TRACK commands
inline void setGlobalTrackStep(long long n) {globalTrackStep_m = n;}
inline long long getGlobalTrackStep() const {return globalTrackStep_m;}
void setNumBunch(int n);
int getNumBunch() const;
/// step in a TRACK command
inline void setLocalTrackStep(long long n) {localTrackStep_m = n;}
inline void incTrackSteps() {globalTrackStep_m++;localTrackStep_m++;}
inline long long getLocalTrackStep() const {return localTrackStep_m;}
inline void setNumBunch(int n);
inline int getNumBunch() const;
void setSteptoLastInj(int n);
int getSteptoLastInj();
......@@ -600,8 +606,11 @@ private:
/// steps per turn for OPAL-cycl
int stepsPerTurn_m;
/// current track step
long long trackStep_m;
/// step in a TRACK command
long long localTrackStep_m;
/// if multiple TRACK commands
long long globalTrackStep_m;
/// current bunch number
int numBunch_m;
......@@ -1138,16 +1147,6 @@ int PartBunch::getStepsPerTurn() const {
return stepsPerTurn_m;
}
inline
void PartBunch::setTrackStep(long long n) {
trackStep_m = n;
}
inline
long long PartBunch::getTrackStep() const {
return trackStep_m;
}
inline
void PartBunch::setNumBunch(int n) {
numBunch_m = n;
......
......@@ -123,7 +123,7 @@ struct OpalDataImpl {
BoundaryGeometry *bg_m;
vector<MaxPhasesT> maxPhases_m;
std::vector<MaxPhasesT> maxPhases_m;
// The cartesian mesh
Mesh_t *mesh_m;
......@@ -133,6 +133,9 @@ struct OpalDataImpl {
// The particle layout
Layout_t *PL_m;
// the accumulated (over all TRACKs) number of steps
unsigned long long maxTrackSteps;
};
......@@ -148,7 +151,6 @@ OpalDataImpl::OpalDataImpl():
PL_m = 0;
}
OpalDataImpl::~OpalDataImpl() {
// Make sure the main directory is cleared before the directories
// for tables and expressions are deleted.
......@@ -190,6 +192,19 @@ void OpalData::deleteInstance() {
isInstatiated = false;
}
unsigned long long OpalData::getMaxTrackSteps() {
return p->maxTrackSteps;
}
void OpalData::setMaxTrackSteps(unsigned long long s) {
p->maxTrackSteps = s;
}
void OpalData::incMaxTrackSteps(unsigned long long s) {
p->maxTrackSteps += s;
}
OpalData::OpalData() {
p = new OpalDataImpl();
......@@ -200,6 +215,7 @@ OpalData::OpalData() {
p->hasSLBunchAllocated_m = false;
p->gPhaseShift_m = 0.0;
p->maxPhases_m.clear();
p->maxTrackSteps = 0;
}
OpalData::~OpalData() {
......@@ -218,6 +234,8 @@ void OpalData::reset() {
p->maxPhases_m.clear();
}
bool OpalData::inRestartRun() {
return p->isRestart;
}
......@@ -317,11 +335,11 @@ void OpalData::setMaxPhase(string elName, double phi) {
p->maxPhases_m.push_back(MaxPhasesT(elName, phi));
}
vector<MaxPhasesT>::iterator OpalData::getFirstMaxPhases() {
std::vector<MaxPhasesT>::iterator OpalData::getFirstMaxPhases() {
return p->maxPhases_m.begin();
}
vector<MaxPhasesT>::iterator OpalData::getLastMaxPhases() {
std::vector<MaxPhasesT>::iterator OpalData::getLastMaxPhases() {
return p->maxPhases_m.end();
}
......
......@@ -19,6 +19,7 @@
// ------------------------------------------------------------------------
#include "AbstractObjects/ObjectFunction.h"
#include "Algorithms/PBunchDefs.h"
#include <iosfwd>
#include <string>
#include <vector>
......@@ -216,13 +217,17 @@ public:
std::vector<MaxPhasesT>::iterator getLastMaxPhases();
int getNumberOfMaxPhases();
Mesh_t* getMesh();
FieldLayout_t* getFieldLayout();
Layout_t* getLayout();
Mesh_t* getMesh();
FieldLayout_t* getFieldLayout();
Layout_t* getLayout();
void setMesh(Mesh_t *mesh);
void setFieldLayout(FieldLayout_t *fieldlayout);
void setLayout(Layout_t *layout);
void setMesh(Mesh_t *mesh);
void setFieldLayout(FieldLayout_t *fieldlayout);
void setLayout(Layout_t *layout);
unsigned long long getMaxTrackSteps();
void setMaxTrackSteps(unsigned long long s);
void incMaxTrackSteps(unsigned long long s);
private:
......
......@@ -888,7 +888,7 @@ void ParallelCyclotronTracker::Tracker_LF() {
// get data from h5 file for restart run
if(OpalData::getInstance()->inRestartRun()) {
restartStep0_m = itsBunch->getTrackStep();
restartStep0_m = itsBunch->getLocalTrackStep();
step_m = restartStep0_m;
if (numBunch_m > 1) itsBunch->resetPartBinID2(eta_m);
*gmsg << "* Restart at integration step " << restartStep0_m << endl;
......@@ -1323,7 +1323,7 @@ void ParallelCyclotronTracker::Tracker_LF() {
itsBunch->setSteptoLastInj(SteptoLastInj);
itsBunch->setTrackStep((step_m + 1));
itsBunch->setLocalTrackStep((step_m + 1));
extE_m = Vector_t(0.0, 0.0, 0.0);
extB_m = Vector_t(0.0, 0.0, 0.0);
......@@ -1440,7 +1440,7 @@ void ParallelCyclotronTracker::Tracker_RK4() {
// get data from h5 file for restart run
if(OpalData::getInstance()->inRestartRun()) {
restartStep0_m = itsBunch->getTrackStep();
restartStep0_m = itsBunch->getLocalTrackStep();
step_m = restartStep0_m;
if (numBunch_m > 1) itsBunch->resetPartBinID2(eta_m);
*gmsg << "* Restart at integration step " << restartStep0_m << endl;
......@@ -2310,7 +2310,7 @@ void ParallelCyclotronTracker::Tracker_RK4() {
|| (doDumpAfterEachTurn && dumpEachTurn && initialTotalNum_m != 2)) {
IpplTimings::startTimer(DumpTimer_m);
itsBunch->setTrackStep((step_m + 1));
itsBunch->setLocalTrackStep((step_m + 1));
extE_m = Vector_t(0.0, 0.0, 0.0);
extB_m = Vector_t(0.0, 0.0, 0.0);
......@@ -2839,7 +2839,7 @@ void ParallelCyclotronTracker::Tracker_MTS() {
// get data from h5 file for restart run
if(OpalData::getInstance()->inRestartRun()) {
restartStep0_m = itsBunch->getTrackStep();
restartStep0_m = itsBunch->getLocalTrackStep();
step_m = restartStep0_m;
if (numBunch_m > 1) itsBunch->resetPartBinID2(eta_m);
*gmsg << "* Restart at integration step " << restartStep0_m << endl;
......@@ -3119,7 +3119,7 @@ void ParallelCyclotronTracker::Tracker_MTS() {
{
IpplTimings::startTimer(DumpTimer_m);
itsBunch->setSteptoLastInj(SteptoLastInj);
itsBunch->setTrackStep((step_m + 1));
itsBunch->setLocalTrackStep((step_m + 1));
//--------------------- calculate mean coordinates of bunch -------------------------------//
//------------ and calculate the external field at the mass of bunch -----------------------//
......@@ -3420,7 +3420,7 @@ void ParallelCyclotronTracker::initTrackOrbitFile() {
if(myNode_m == 0) {
if(OpalData::getInstance()->inRestartRun()) {
outfTrackOrbit_m.open(f.c_str(), ios::app);
outfTrackOrbit_m << "# Restart at integration step " << itsBunch->getTrackStep() << endl;
outfTrackOrbit_m << "# Restart at integration step " << itsBunch->getLocalTrackStep() << endl;
} else {
outfTrackOrbit_m.open(f.c_str());
outfTrackOrbit_m << "# ID x [mm] px [rad] y [mm] py [rad] z [mm] pz [rad]" << endl;
......
......@@ -91,7 +91,7 @@ ParallelTTracker::ParallelTTracker(const Beamline &beamline,
numRefs_m(-1),
gunSubTimeSteps_m(-1),
emissionSteps_m(std::numeric_limits<unsigned int>::max()),
maxSteps_m(0),
localTrackSteps_m(0),
maxNparts_m(0),
numberOfFieldEmittedParticles_m(std::numeric_limits<size_t>::max()),
bends_m(0),
......@@ -144,7 +144,7 @@ ParallelTTracker::ParallelTTracker(const Beamline &beamline,
numRefs_m(-1),
gunSubTimeSteps_m(-1),
emissionSteps_m(numeric_limits<unsigned int>::max()),
maxSteps_m(maxSTEPS),
localTrackSteps_m(maxSTEPS),
maxNparts_m(0),
numberOfFieldEmittedParticles_m(numeric_limits<size_t>::max()),
bends_m(0),
......@@ -331,7 +331,7 @@ double ParallelTTracker::schottkyLoop(double rescale_coeff) {
size_t totalParticles_f = 0;
for(; step < maxSteps_m; ++step) {
for(; step < localTrackSteps_m; ++step) {
global_EOL = true; // check if any particle hasn't reached the end of the field from the last element
itsOpalBeamline_m.resetStatus();
......@@ -614,7 +614,7 @@ double ParallelTTracker::schottkyLoop(double rescale_coeff) {
Stop simulation if beyond zStop_m
*/
if(sposRef > zStop_m) {
maxSteps_m = step;
localTrackSteps_m = step;
}
} else {
INFOMSG("Step " << step << " no emission yet " << " t= " << t << " [s]" << endl);
......@@ -988,7 +988,7 @@ void ParallelTTracker::executeAutoPhase(int numRefs, double zStop) {
Vector_t rmin, rmax;
size_t maxStepsSave = maxSteps_m;
size_t maxStepsSave = localTrackSteps_m;
size_t step = 0;
int dtfraction = 2;
itsBunch->dt = itsBunch->getdT() / dtfraction; // need to fix this and make the factor 2 selectable
......@@ -1038,9 +1038,7 @@ void ParallelTTracker::executeAutoPhase(int numRefs, double zStop) {
double cavity_start = 0.0;
Component *cavity = NULL;
for(; step < maxSteps_m * dtfraction; ++step) {
itsBunch->setTrackStep(step);
for(; step < localTrackSteps_m * dtfraction; ++step) {
// let's do a drifting step to probe if the particle will reach element in next step
Vector_t R_drift = itsBunch->R[0] + itsBunch->P[0] / sqrt(1.0 + dot(itsBunch->P[0],
......@@ -1213,14 +1211,14 @@ void ParallelTTracker::executeAutoPhase(int numRefs, double zStop) {
double sposRef = itsBunch->R[0](2);
if(sposRef > zStop)
maxSteps_m = floor(step / dtfraction);
localTrackSteps_m = floor(step / dtfraction);
if(!(step % 1000)) {
INFOMSG("step = " << step << ", spos = " << sposRef << " [m], t= " << itsBunch->getT() << " [s], "
<< "E= " << getEnergyMeV(itsBunch->P[0]) << " [MeV] " << endl);
}
}
maxSteps_m = maxStepsSave;
localTrackSteps_m = maxStepsSave;
scaleFactor_m = scaleFactorSave;
itsBunch->setT(tSave);
}
......@@ -1275,16 +1273,16 @@ void ParallelTTracker::execute() {
doAutoPhasing();
numParticlesInSimulation_m = itsBunch->getTotalNum();
msg << "totalParticle_i= " << numParticlesInSimulation_m << endl;
OPALTimer::Timer myt1;
setTime();
setLastStep();
dumpPhaseSpaceOnScan();
double t = itsBunch->getT();
unsigned long long step = OpalData::getInstance()->getLastStep();
unsigned long long step = itsBunch->getLocalTrackStep();
msg << "Track start at: " << myt1.time() << ", t= " << t << "; zstop at: " << zStop_m << " [m]" << endl;
......@@ -1294,7 +1292,7 @@ void ParallelTTracker::execute() {
doSchottyRenormalization();
msg << "Executing ParallelTTracker, initial DT " << itsBunch->getdT() << " [s];\n"
<< "max integration steps " << maxSteps_m << ", next step= " << step << endl;
<< "max integration steps " << localTrackSteps_m << ", next step= " << step << endl;
// itsBeamline_m.accept(*this);
// itsOpalBeamline_m.prepareSections();
......@@ -1317,7 +1315,7 @@ void ParallelTTracker::execute() {
wakeStatus_m = false;
surfaceStatus_m = false;
for(; step < maxSteps_m; ++step) {
for(; step < localTrackSteps_m; ++step) {
bends_m = 0;
numberOfFieldEmittedParticles_m = 0;
......@@ -1354,13 +1352,13 @@ void ParallelTTracker::execute() {
if(hasEndOfLineReached()) break;
double margin = 10.0;
double margin = 0.1;
switchElements(margin);
// free the memory allocated in monitors
Vector_t rmin(0.0), rmax(0.0);
itsBunch->get_bounds(rmin, rmax);
itsOpalBeamline_m.switchElementsOff(rmin(2) - margin, "Monitor");
itsBunch->incTrackSteps();
}
if(numParticlesInSimulation_m > minBinEmitted_m) {
itsBunch->boundp();
numParticlesInSimulation_m = itsBunch->getTotalNum();
......@@ -1370,7 +1368,6 @@ void ParallelTTracker::execute() {
writePhaseSpace((step + 1), itsBunch->get_sPos(), doDump);
msg << "Dump phase space of last step" << endl;
OPALTimer::Timer myt3;
OpalData::getInstance()->setLastStep(step);
itsOpalBeamline_m.switchElementsOff();
msg << "done executing ParallelTTracker at " << myt3.time() << endl;
}
......@@ -2069,7 +2066,6 @@ void ParallelTTracker::handleBends() {
RefPartR_suv_m += RefPartP_suv_m * recpgamma / 2. * Physics::c * itsBunch->getdT();
}
itsBunch->RefPart_R = RefPartR_zxy_m;
itsBunch->RefPart_P = RefPartP_zxy_m;
}
......@@ -2116,7 +2112,7 @@ void ParallelTTracker::dumpStats(long long step) {
if(numParticlesInSimulation_m == 0) {
msg << myt2.time() << " "
<< "Step " << setw(6) << step << "; "
<< "Step " << setw(6) << itsBunch->getGlobalTrackStep() << "; "
<< " -- no emission yet -- "
<< "t= " << scientific << setprecision(3) << setw(10) << itsBunch->getT() << " [s]"
<< endl;
......@@ -2147,7 +2143,7 @@ void ParallelTTracker::dumpStats(long long step) {
size_t totalParticles_f = numParticlesInSimulation_m;
if(totalParticles_f <= minBinEmitted_m) {
msg << myt2.time() << " "
<< "Step " << setw(6) << step << "; "
<< "Step " << setw(6) << itsBunch->getGlobalTrackStep() << "; "
<< "only " << setw(4) << totalParticles_f << " particles emitted; "
<< "t= " << scientific << setprecision(3) << setw(10) << itsBunch->getT() << " [s] "
<< "E=" << fixed << setprecision(3) << setw(9) << meanEnergy << meanEnergyUnit
......@@ -2157,7 +2153,7 @@ void ParallelTTracker::dumpStats(long long step) {
"there seems to be something wrong with the position of the bunch!");
} else {
msg << myt2.time() << " "
<< "Step " << setw(6) << step << " "
<< "Step " << setw(6) << itsBunch->getGlobalTrackStep() << " "
<< "at " << fixed << setprecision(3) << setw(8) << sposPrint << sposUnit
<< "t= " << scientific << setprecision(3) << setw(10) << itsBunch->getT() << " [s] "
<< "E=" << fixed << setprecision(3) << setw(9) << meanEnergy << meanEnergyUnit
......@@ -2182,11 +2178,11 @@ void ParallelTTracker::dumpStats(long long step) {
// If we are dealing with field emission and secondary emission, set upper
// limit of particle number in simulation to prevent memory overflow.
if(numParticlesInSimulation_m > maxNparts_m)
maxSteps_m = step;
localTrackSteps_m = step;
}
if(sposRef > zStop_m)
maxSteps_m = step;
localTrackSteps_m = step;
}
......@@ -2309,28 +2305,12 @@ void ParallelTTracker::setTime() {
}
}
void ParallelTTracker::setLastStep() {
if(OpalData::getInstance()->inRestartRun()) {
int prevDumpFreq = OpalData::getInstance()->getRestartDumpFreq();
long long last_step = OpalData::getInstance()->getRestartStep() * prevDumpFreq + 1;
OpalData::getInstance()->setLastStep(last_step);
} else if(OpalData::getInstance()->hasBunchAllocated()) {
/*
we are in a follow up track; maxSteps is the number of steps
that should be performed with the current track
*/
maxSteps_m += OpalData::getInstance()->getLastStep();
} else
OpalData::getInstance()->setLastStep(0);
}
// Note: setLastStep is not needed anymore with the new local,global track step logic
void ParallelTTracker::dumpPhaseSpaceOnScan() {
if(Options::scan && OpalData::getInstance()->hasBunchAllocated()) {
maxSteps_m -= OpalData::getInstance()->getLastStep();
localTrackSteps_m -= OpalData::getInstance()->getLastStep();
OpalData::getInstance()->setLastStep(0);
if(itsBunch->getLocalNum() != 0)
writePhaseSpace(0, 0.0); // write initial phase space
......
......@@ -306,8 +306,8 @@ private:
unsigned int emissionSteps_m;
/// The maximal number of steps the system is integrated
unsigned long long maxSteps_m;
/// The maximal number of steps the system is integrated per TRACK
unsigned long long localTrackSteps_m;
size_t maxNparts_m;
size_t numberOfFieldEmittedParticles_m;
......@@ -388,7 +388,7 @@ private:
void handleRestartRun();
void prepareEmission();
void setTime();
void setLastStep();
// Note: setLastStep is not needed anymore with the new local,global track step logic
void dumpPhaseSpaceOnScan();
void initializeBoundaryGeometry();
void doBinaryRepartition(long long step);
......
......@@ -1646,7 +1646,6 @@ void Distribution::doRestartEnvelope(EnvelopeBunch &beam, size_t Np, int restart
}
}
rc = H5SetStep(H5file, restartStep);
if(rc != H5_SUCCESS)
ERRORMSG("H5 rc= " << rc << " in " << __FILE__ << " @ line " << __LINE__ << endl);
......@@ -1678,9 +1677,17 @@ void Distribution::doRestartEnvelope(EnvelopeBunch &beam, size_t Np, int restart
ERRORMSG("H5 rc= " << rc << " in " << __FILE__ << " @ line " << __LINE__ << endl);
OpalData::getInstance()->setGlobalPhaseShift(dPhiGlobal);
//~ void *varray = malloc(N * sizeof(double));
//~ double *farray = (double *)varray;
//~ h5_int64_t *larray = (h5_int64_t *)varray;
h5_int64_t ltstep;
rc = H5ReadStepAttribInt64(H5file, "LocalTrackStep", &ltstep);
if(rc != H5_SUCCESS)
ERRORMSG("H5 rc= " << rc << " in " << __FILE__ << " @ line " << __LINE__ << endl);
beam.setLocalTrackStep((long long)ltstep);
h5_int64_t gtstep;
rc = H5ReadStepAttribInt64(H5file, "GlobalTrackStep", &gtstep);
if(rc != H5_SUCCESS)
ERRORMSG("H5 rc= " << rc << " in " << __FILE__ << " @ line " << __LINE__ << endl);
beam.setGlobalTrackStep((long long)gtstep);
std::unique_ptr<char[]> varray(new char[(N)*sizeof(double)]);
double *farray = reinterpret_cast<double *>(varray.get());
......@@ -1752,9 +1759,6 @@ void Distribution::doRestartEnvelope(EnvelopeBunch &beam, size_t Np, int restart
for(unsigned long int n = 0; n < (unsigned int) N; ++n)
beam.LastSection[n] = (short) larray[n];
//~ if(farray)
//~ free(farray);
Ippl::Comm->barrier();
rc = H5CloseFile(H5file);
if(rc != H5_SUCCESS)
......@@ -3251,7 +3255,7 @@ void Distribution::doRestart(PartBunch &beam, size_t Np, int restartStep) {
ERRORMSG("H5 rc= " << rc << " in " << __FILE__ << " @ line " << __LINE__ << endl);
int N = (int)H5PartGetNumParticles(H5file);
h5_int64_t totalSteps = H5GetNumSteps(H5file);
// h5_int64_t totalSteps = H5GetNumSteps(H5file);
int numberOfParticlesPerNode = (int) floor((double) N / Ippl::getNodes());
long long starti = Ippl::myNode() * numberOfParticlesPerNode;
......@@ -3281,10 +3285,17 @@ void Distribution::doRestart(PartBunch &beam, size_t Np, int restartStep) {
ERRORMSG("H5 rc= " << rc << " in " << __FILE__ << " @ line " << __LINE__ << endl);
OpalData::getInstance()->setGlobalPhaseShift(dPhiGlobal);
//~ void *varray = malloc(N * sizeof(double));
//~ // double *farray = (double *)varray;
//~ h5_float64_t *farray = (h5_float64_t *)varray;
//~ h5_int64_t *larray = (h5_int64_t *)varray;
h5_int64_t ltstep;
rc = H5ReadStepAttribInt64(H5file, "LocalTrackStep", &ltstep);
if(rc != H5_SUCCESS)
ERRORMSG("H5 rc= " << rc << " in " << __FILE__ << " @ line " << __LINE__ << endl);
beam.setLocalTrackStep((long long)ltstep);
h5_int64_t gtstep;
rc = H5ReadStepAttribInt64(H5file, "GlobalTrackStep", &gtstep);
if(rc != H5_SUCCESS)
ERRORMSG("H5 rc= " << rc << " in " << __FILE__ << " @ line " << __LINE__ << endl);
beam.setGlobalTrackStep((long long)gtstep);
std::unique_ptr<char[]> varray(new char[(N)*sizeof(double)]);
h5_float64_t *farray = reinterpret_cast<h5_float64_t *>(varray.get());
......@@ -3341,24 +3352,19 @@ void Distribution::doRestart(PartBunch &beam, size_t Np, int restartStep) {
for(unsigned long int n = 0; n < (unsigned int) N; ++n)
beam.LastSection[n] = (short) larray[n];
// m2all << "View set N= " << N << " partciles created and read in" << endl;
Ippl::Comm->barrier();
rc = H5CloseFile(H5file);
if(rc != H5_SUCCESS)
ERRORMSG("H5 rc= " << rc << " in " << __FILE__ << " @ line " << __LINE__ << endl);
// if(farray) {
// free(farray);
// }
// m2all << "File closed " << endl;
beam.boundp();
IpplTimings::stopTimer(beam.distrReload_m);
*gmsg << "total number of particles in the h5 file = " << N << " NBunch= " << beam.getTotalNum() << " total steps " << totalSteps
<< " restart step= " << restartStep << " time of restart = " << actualT << " phishift= " << OpalData::getInstance()->getGlobalPhaseShift() << endl;
*gmsg << "Total number of particles in the h5 file = " << N << " NPerBunch= " << beam.getTotalNum()
<< " Global step " << gtstep << " Local step " << ltstep << endl
<< " restart step= " << restartStep << " time of restart = " << actualT
<< " phishift= " << OpalData::getInstance()->getGlobalPhaseShift() << endl;
}
......@@ -3427,23 +3433,23 @@ void Distribution::doRestart_cycl(PartBunch &beam, size_t Np, int restartStep, c
const int localN = (int)H5PartGetNumParticles(H5file);
assert(localN >= 0);
// debug
// Inform *gmsgAll;
// gmsgAll = new Inform("Message",INFORM_ALL_NODES);
// *gmsgAll<< "total number of particles on this node = " <<localN <<endl;
// end debug
double actualT;
rc = H5ReadStepAttribFloat64(H5file, "TIME", &actualT);
if(rc != H5_SUCCESS)
ERRORMSG("H5 rc= " << rc << " in " << __FILE__ << " @ line " << __LINE__ << endl);
beam.setT(actualT);
h5_int64_t tstep;
rc = H5ReadStepAttribInt64(H5file, "TrackStep", &tstep);
h5_int64_t ltstep;
rc = H5ReadStepAttribInt64(H5file, "LocalTrackStep", &ltstep);