Commit 8493721d authored by kraus's avatar kraus
Browse files

Merge branch...

Merge branch '295-ParallelTTracker-crashes-when-using-particle-matter-integration-and-space-charge-solver-if-all-particles-are-in-material' into 'master'

Resolve "ParallelTTracker crashes when using particle matter integration and space charge solver if all particles are in material"

Closes #295

See merge request OPAL/src!70
parents 82e4991f 9285a69b
......@@ -797,9 +797,10 @@ void ParallelTTracker::computeParticleMatterInteraction(IndexMap::value_t elemen
//if max particles per node is 2, and only one degrader has particles set
//AllParticlesIn for this degrader to true
int maxPerNode = itsBunch_m->getLocalNum();
reduce(maxPerNode, maxPerNode, OpMaxAssign());
bool allParticlesInMat = (maxPerNode == 0 &&
unsigned int localNum = itsBunch_m->getLocalNum();
unsigned int totalNum = 0;
reduce(localNum, totalNum, OpAddAssign());
bool allParticlesInMat = (totalNum == 0 &&
degradersWithParticlesCount == 1);
if (allParticlesInMat) {
......@@ -808,7 +809,8 @@ void ParallelTTracker::computeParticleMatterInteraction(IndexMap::value_t elemen
}
auto boundingSphere = itsBunch_m->getLocalBoundingSphere();
unsigned redifusedParticles = 0;
unsigned int rediffusedParticles = 0;
unsigned int numEnteredParticles = 0;
for (auto it: activeParticleMatterInteractionHandlers_m) {
ElementBase* element = it->getElement();
CoordinateSystemTrafo refToLocalCSTrafo = (element->getMisalignment() *
......@@ -833,7 +835,8 @@ void ParallelTTracker::computeParticleMatterInteraction(IndexMap::value_t elemen
itsBunch_m->P[i] = localToRefCSTrafo.rotateTo(itsBunch_m->P[i]);
}
redifusedParticles += it->getRediffused();
rediffusedParticles += it->getRediffused();
numEnteredParticles += it->getNumEntered();
//if all particles where in material update time to time in degrader
if (it->getFlagAllParticlesIn()) {
double timeDifference = it->getTime() - itsBunch_m->getdT() - itsBunch_m->getT();
......@@ -853,8 +856,9 @@ void ParallelTTracker::computeParticleMatterInteraction(IndexMap::value_t elemen
//perform boundp only if there are particles in the bunch, or there are particles
//comming out of the degrader
if (maxPerNode > 0 || redifusedParticles > 0) {
if (itsBunch_m->hasFieldSolver()) {
if (numEnteredParticles > 0 || rediffusedParticles > 0) {
totalNum -= (numEnteredParticles + rediffusedParticles);
if (totalNum > minBinEmitted_m && itsBunch_m->hasFieldSolver()) {
itsBunch_m->boundp();
} else {
itsBunch_m->updateNumTotal();
......
......@@ -104,7 +104,6 @@ CollimatorPhysics::CollimatorPhysics(const std::string &name, ElementBase *eleme
rho_m(0.0),
X0_m(0.0),
I_m(0.0),
n_m(0.0),
bunchToMatStat_m(0),
stoppedPartStat_m(0),
rediffusedStat_m(0),
......@@ -491,7 +490,6 @@ void CollimatorPhysics::Material() {
X0_m = 65.19 / rho_m / 100;
I_m = 10 * Z_m;
n_m = rho_m / A_m * Avo;
A2_c = 2.590;
A3_c = 9.660e2;
......@@ -507,7 +505,6 @@ void CollimatorPhysics::Material() {
X0_m = 42.70 / rho_m / 100;
I_m = 10 * Z_m;
n_m = rho_m / A_m * Avo;
A2_c = 2.601;
A3_c = 1.701e3;
......@@ -523,7 +520,6 @@ void CollimatorPhysics::Material() {
X0_m = 42.70 / rho_m / 100;
I_m = 10 * Z_m;
n_m = rho_m / A_m * Avo;
A2_c = 2.601;
A3_c = 1.701e3;
......@@ -539,7 +535,6 @@ void CollimatorPhysics::Material() {
X0_m = 9.8 / rho_m / 100;
I_m = 10 * Z_m;
n_m = rho_m / A_m * Avo;
A2_c = 7.248;
A3_c = 9.545e3;
......@@ -560,7 +555,7 @@ void CollimatorPhysics::Material() {
X0_m = 39.95 / rho_m / 100;
I_m = 10 * Z_m;
n_m = rho_m / A_m * Avo;
A2_c = 3.350;
A3_c = 1683;
A4_c = 1900;
......@@ -576,7 +571,6 @@ void CollimatorPhysics::Material() {
X0_m = 24.01 / rho_m / 100;
I_m = 10 * Z_m;
n_m = rho_m / A_m * Avo;
A2_c = 4.739;
A3_c = 2.766e3;
......@@ -591,7 +585,6 @@ void CollimatorPhysics::Material() {
X0_m = 12.86 / rho_m / 100;
I_m = 10 * Z_m;
n_m = rho_m / A_m * Avo;
A2_c = 4.194;
A3_c = 4.649e3;
......@@ -606,7 +599,6 @@ void CollimatorPhysics::Material() {
X0_m = 16.16 / rho_m / 100;
I_m = 10 * Z_m;
n_m = rho_m / A_m * Avo;
A2_c = 5.489;
A3_c = 5.260e3;
......@@ -621,7 +613,6 @@ void CollimatorPhysics::Material() {
X0_m = 27.94 / rho_m / 100;
I_m = 10 * Z_m;
n_m = rho_m / A_m * Avo;
A2_c = 7.227;
A3_c = 1.121e4;
......@@ -636,7 +627,6 @@ void CollimatorPhysics::Material() {
X0_m = 37.99 / rho_m / 100;
I_m = 10 * Z_m;
n_m = rho_m / A_m * Avo;
A2_c = 3.350;
A3_c = 1.683e3;
......@@ -651,7 +641,6 @@ void CollimatorPhysics::Material() {
X0_m = 39.95 / rho_m / 100;
I_m = 10 * Z_m;
n_m = rho_m / A_m * Avo;
A2_c = 2.601;
A3_c = 1.701e3;
......@@ -666,7 +655,6 @@ void CollimatorPhysics::Material() {
X0_m = 6.46 / rho_m / 100;
I_m = 10 * Z_m;
n_m = rho_m / A_m * Avo;
A2_c = 5.458;
A3_c = 7.852e3;
......@@ -681,7 +669,6 @@ void CollimatorPhysics::Material() {
X0_m = 36.08 / rho_m / 100;
I_m = 10 * Z_m;
n_m = rho_m / A_m * Avo;
A2_c = 2.199;
A3_c = 2.393e3;
......
......@@ -41,7 +41,6 @@ typedef struct __align__(16) {
int Binincol;
double DTincol;
double Qincol;
long LastSecincol;
Vector_t Bfincol;
Vector_t Efincol;
} PART;
......@@ -54,18 +53,17 @@ typedef struct {
} PART_DKS;
#else
typedef struct {
int label;
unsigned localID;
Vector_t Rincol;
Vector_t Pincol;
long IDincol;
int Binincol;
double DTincol;
double Qincol;
long LastSecincol;
Vector_t Bfincol;
Vector_t Efincol;
typedef struct { // struct for description of particle in material
int label; // the status of the particle (0 = in material / -1 = move back to bunch
unsigned localID; // not so unique identifier of the particle
Vector_t Rincol; // position
Vector_t Pincol; // momentum
long IDincol; // unique identifier of the particle inherited from the bunch
int Binincol; // bin number
double DTincol; // time step size
double Qincol; // charge
Vector_t Bfincol; // magnetic field
Vector_t Efincol; // electric field
} PART;
#endif
......@@ -89,7 +87,7 @@ public:
std::string getName() { return FN_m;}
size_t getParticlesInMat() { return locPartsInMat_m;}
unsigned getRediffused() { return rediffusedStat_m;}
unsigned int getNumEntered() {return bunchToMatStat_m;}
inline void doPhysics(PartBunchBase<double, 3> *bunch);
......@@ -127,41 +125,45 @@ private:
void calcStat(double Eng);
double T_m; // own time, maybe larger than in the bunch object
double dT_m; // dt from bunch
gsl_rng *rGen_m;
gsl_rng *rGen_m; // random number generator
std::string material_m; // type of material e.g. aluminum
std::string FN_m; // name of element
ElementBase::ElementType collshape_m; // the type of element (DEGRADER, CCOLLIMATOR or FLEXIBLECOLLIMATOR)
std::string collshapeStr_m; // the type of element as string
std::string material_m;
std::string FN_m;
ElementBase::ElementType collshape_m;
std::string collshapeStr_m;
// material parameters
double Z_m; // the atomic number
double A_m; // the atomic mass
double rho_m; // the volumetric mass density
double X0_m; // the radiation length
double I_m; // the mean excitation energy
double Z_m;
double A_m;
double A2_c;
double A3_c;
double A4_c;
double A5_c;
double rho_m;
double X0_m;
double I_m;
double n_m;
double A2_c; // coefficients to fit model to measurement data
double A3_c; // see e.g. page 16-20 in H. H. Andersen, J. F. Ziegler,
double A4_c; // "Hydrogen Stopping Powers and Ranges in All Elements",
double A5_c; // Pergamon Press, 1977
// number of particles that enter the material in current step (count for single step)
unsigned bunchToMatStat_m;
// number of particles that are stopped by the material in current step
unsigned stoppedPartStat_m;
// number of particles that leave the material in current step
unsigned rediffusedStat_m;
// number of local particles that are in the material
size_t locPartsInMat_m;
// some statistics
double Eavg_m;
double Emax_m;
double Emin_m;
double Eavg_m; // average kinetic energy
double Emax_m; // maximum kinetic energy
double Emin_m; // minimum kinetic energy
std::vector<PART> locParts_m;
std::vector<PART> locParts_m; // local particles that are in material
std::unique_ptr<LossDataSink> lossDs_m;
......@@ -206,7 +208,7 @@ void CollimatorPhysics::EnergyLoss(double &Eng, bool &pdead, const double &delta
// vi: set et ts=4 sw=4 sts=4:
// Local Variables:
// mode:c
// mode:c++
// c-basic-offset: 4
// indent-tabs-mode:nil
// End:
\ No newline at end of file
......@@ -25,6 +25,7 @@ public:
virtual std::string getName() = 0;
virtual size_t getParticlesInMat() = 0;
virtual unsigned getRediffused() = 0;
virtual unsigned int getNumEntered() = 0;
void setFlagAllParticlesIn(bool p);
bool getFlagAllParticlesIn() const;
void updateElement(ElementBase *newref);
......
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