Commit a1d2c53b authored by snuverink_j's avatar snuverink_j
Browse files

Merge branch '589-replace-all-c-assert-with-passert' into 'master'

Resolve "replace all C assert with PAssert"

Closes #589

See merge request !419
parents 7c1f8233 54c163ba
...@@ -36,10 +36,10 @@ ...@@ -36,10 +36,10 @@
#include "Particle/PairBuilder/HashPairBuilderPeriodic.h" #include "Particle/PairBuilder/HashPairBuilderPeriodic.h"
#include "Particle/PairBuilder/HashPairBuilderPeriodicParallel.h" #include "Particle/PairBuilder/HashPairBuilderPeriodicParallel.h"
#include "Particle/PairBuilder/PairConditions.h" #include "Particle/PairBuilder/PairConditions.h"
#include "Utility/PAssert.h"
#include "math.h" #include "math.h"
#include <random> #include <random>
#include <cassert>
#include "VTKFieldWriterParallel.hpp" #include "VTKFieldWriterParallel.hpp"
#include "ChargedParticleFactory.hpp" #include "ChargedParticleFactory.hpp"
...@@ -477,9 +477,9 @@ public: ...@@ -477,9 +477,9 @@ public:
#if defined (NDEBUG) #if defined (NDEBUG)
(void)h5err; (void)h5err;
#endif #endif
assert (h5err != H5_ERR); PAssert (h5err != H5_ERR);
H5f_m = H5OpenFile (fn.c_str(), H5_O_RDONLY, props); H5f_m = H5OpenFile (fn.c_str(), H5_O_RDONLY, props);
assert (H5f_m != (h5_file_t)H5_ERR); PAssert (H5f_m != (h5_file_t)H5_ERR);
H5CloseProp (props); H5CloseProp (props);
} }
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
// along with OPAL. If not, see <https://www.gnu.org/licenses/>. // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
// //
#include "Ippl.h" #include "Ippl.h"
#include <cassert>
#include <string> #include <string>
#include <vector> #include <vector>
#include <iostream> #include <iostream>
...@@ -35,6 +34,7 @@ ...@@ -35,6 +34,7 @@
#include "Particle/PairBuilder/HashPairBuilderPeriodic.h" #include "Particle/PairBuilder/HashPairBuilderPeriodic.h"
#include "Particle/PairBuilder/HashPairBuilderPeriodicParallel.h" #include "Particle/PairBuilder/HashPairBuilderPeriodicParallel.h"
#include "Particle/PairBuilder/PairConditions.h" #include "Particle/PairBuilder/PairConditions.h"
#include "Utility/PAssert.h"
#include "math.h" #include "math.h"
//#include "FixedAlgebra/FMatrix.h" //#include "FixedAlgebra/FMatrix.h"
...@@ -61,8 +61,8 @@ typedef Field<std::complex<double>, Dim, Mesh_t, Center_t> CxField_t; ...@@ -61,8 +61,8 @@ typedef Field<std::complex<double>, Dim, Mesh_t, Center_t> CxField_t;
typedef FFT<CCTransform, Dim, double> FFT_t; typedef FFT<CCTransform, Dim, double> FFT_t;
typedef IntCIC IntrplCIC_t; typedef IntCIC IntrplCIC_t;
typedef IntNGP IntrplNGP_t; //typedef IntNGP IntrplNGP_t;
typedef IntTSC IntrplTSC_t; //typedef IntTSC IntrplTSC_t;
typedef UniformCartesian<2, double> Mesh2d_t; typedef UniformCartesian<2, double> Mesh2d_t;
typedef CenteredFieldLayout<2, Mesh2d_t, Center_t> FieldLayout2d_t; typedef CenteredFieldLayout<2, Mesh2d_t, Center_t> FieldLayout2d_t;
...@@ -464,7 +464,7 @@ class ChargedParticles : public IpplParticleBase<PL> { ...@@ -464,7 +464,7 @@ class ChargedParticles : public IpplParticleBase<PL> {
h5_prop_t props = H5CreateFileProp (); h5_prop_t props = H5CreateFileProp ();
MPI_Comm comm = Ippl::getComm(); MPI_Comm comm = Ippl::getComm();
h5_err_t h5err = H5SetPropFileMPIOCollective (props, &comm); h5_err_t h5err = H5SetPropFileMPIOCollective (props, &comm);
assert (h5err != H5_ERR); PAssert (h5err != H5_ERR);
H5f_m = H5OpenFile(fn.c_str(), H5_O_WRONLY, props); H5f_m = H5OpenFile(fn.c_str(), H5_O_WRONLY, props);
} }
......
...@@ -27,9 +27,10 @@ ...@@ -27,9 +27,10 @@
#include "Algorithms/AmrPartBunch.h" #include "Algorithms/AmrPartBunch.h"
#include "Structure/FieldSolver.h" #include "Structure/FieldSolver.h"
#include "Solvers/PoissonSolver.h" #include "Solvers/PoissonSolver.h"
#include "Utility/PAssert.h"
#include "Amr/AmrYtWriter.h" #include "Amr/AmrYtWriter.h"
#include <AMReX_MultiFabUtil.H> #include <AMReX_MultiFabUtil.H>
#include <AMReX_ParmParse.H> // used in initialize function #include <AMReX_ParmParse.H> // used in initialize function
...@@ -721,7 +722,7 @@ void AmrBoxLib::doRegrid_m(int lbase, double time) { ...@@ -721,7 +722,7 @@ void AmrBoxLib::doRegrid_m(int lbase, double time) {
MakeNewGrids(lbase, time, new_finest, new_grids); MakeNewGrids(lbase, time, new_finest, new_grids);
BL_ASSERT(new_finest <= finest_level+1); PAssert(new_finest <= finest_level+1);
for (int lev = lbase+1; lev <= new_finest; ++lev) for (int lev = lbase+1; lev <= new_finest; ++lev)
{ {
......
...@@ -39,9 +39,9 @@ ...@@ -39,9 +39,9 @@
#include "BoxLibLayout.h" #include "BoxLibLayout.h"
#include "Message/Formatter.h" #include "Message/Formatter.h"
#include "Utility/PAssert.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include <cassert>
#include <cmath> #include <cmath>
template <class T, unsigned Dim> template <class T, unsigned Dim>
...@@ -473,7 +473,7 @@ void BoxLibLayout<T, Dim>::buildLevelMask(int lev, const int ncells) { ...@@ -473,7 +473,7 @@ void BoxLibLayout<T, Dim>::buildLevelMask(int lev, const int ncells) {
template <class T, unsigned Dim> template <class T, unsigned Dim>
void BoxLibLayout<T, Dim>::clearLevelMask(int lev) { void BoxLibLayout<T, Dim>::clearLevelMask(int lev) {
assert(lev < (int)masks_m.size()); PAssert(lev < (int)masks_m.size());
masks_m[lev].reset(nullptr); masks_m[lev].reset(nullptr);
} }
...@@ -548,9 +548,9 @@ bool BoxLibLayout<T, Dim>::Where(AmrParticleBase< BoxLibLayout<T,Dim> >& p, ...@@ -548,9 +548,9 @@ bool BoxLibLayout<T, Dim>::Where(AmrParticleBase< BoxLibLayout<T,Dim> >& p,
if (lev_max == -1) if (lev_max == -1)
lev_max = finestLevel(); lev_max = finestLevel();
BL_ASSERT(lev_max <= finestLevel()); PAssert(lev_max <= finestLevel());
BL_ASSERT(nGrow == 0 || (nGrow >= 0 && lev_min == lev_max)); PAssert(nGrow == 0 || (nGrow >= 0 && lev_min == lev_max));
std::vector< std::pair<int, AmrBox_t> > isects; std::vector< std::pair<int, AmrBox_t> > isects;
...@@ -558,7 +558,7 @@ bool BoxLibLayout<T, Dim>::Where(AmrParticleBase< BoxLibLayout<T,Dim> >& p, ...@@ -558,7 +558,7 @@ bool BoxLibLayout<T, Dim>::Where(AmrParticleBase< BoxLibLayout<T,Dim> >& p,
{ {
const AmrIntVect_t& iv = Index(p, ip, lev); const AmrIntVect_t& iv = Index(p, ip, lev);
const AmrGrid_t& ba = ParticleBoxArray(lev); const AmrGrid_t& ba = ParticleBoxArray(lev);
BL_ASSERT(ba.ixType().cellCentered()); PAssert(ba.ixType().cellCentered());
if (lev == (int)p.Level[ip]) { if (lev == (int)p.Level[ip]) {
// The fact that we are here means this particle does not belong to any finer grids. // The fact that we are here means this particle does not belong to any finer grids.
...@@ -605,7 +605,7 @@ bool BoxLibLayout<T, Dim>::EnforcePeriodicWhere (AmrParticleBase< BoxLibLayout<T ...@@ -605,7 +605,7 @@ bool BoxLibLayout<T, Dim>::EnforcePeriodicWhere (AmrParticleBase< BoxLibLayout<T
if (lev_max == -1) if (lev_max == -1)
lev_max = finestLevel(); lev_max = finestLevel();
BL_ASSERT(lev_max <= finestLevel()); PAssert(lev_max <= finestLevel());
// //
// Create a copy "dummy" particle to check for periodic outs. // Create a copy "dummy" particle to check for periodic outs.
// //
...@@ -678,7 +678,7 @@ bool BoxLibLayout<T, Dim>::PeriodicShift (SingleParticlePos_t R) const ...@@ -678,7 +678,7 @@ bool BoxLibLayout<T, Dim>::PeriodicShift (SingleParticlePos_t R) const
// //
R[i] += .125*geom.CellSize(i); R[i] += .125*geom.CellSize(i);
BL_ASSERT(R[i] >= geom.ProbLo(i)); PAssert(R[i] >= geom.ProbLo(i));
shifted = true; shifted = true;
} }
...@@ -700,7 +700,7 @@ bool BoxLibLayout<T, Dim>::PeriodicShift (SingleParticlePos_t R) const ...@@ -700,7 +700,7 @@ bool BoxLibLayout<T, Dim>::PeriodicShift (SingleParticlePos_t R) const
// //
R[i] -= .125*geom.CellSize(i); R[i] -= .125*geom.CellSize(i);
BL_ASSERT(R[i] <= geom.ProbHi(i)); PAssert(R[i] <= geom.ProbHi(i));
shifted = true; shifted = true;
} }
...@@ -810,8 +810,8 @@ void BoxLibLayout<T, Dim>::initBaseBox_m(int nGridPoints, ...@@ -810,8 +810,8 @@ void BoxLibLayout<T, Dim>::initBaseBox_m(int nGridPoints,
AmrDomain_t real_box; AmrDomain_t real_box;
for (int d = 0; d < AMREX_SPACEDIM; ++d) { for (int d = 0; d < AMREX_SPACEDIM; ++d) {
assert(lowerBound[d] < 0); PAssert(lowerBound[d] < 0);
assert(upperBound[d] > 0); PAssert(upperBound[d] > 0);
real_box.setLo(d, lowerBound[d] * (1.0 + dh)); real_box.setLo(d, lowerBound[d] * (1.0 + dh));
real_box.setHi(d, upperBound[d] * (1.0 + dh)); real_box.setHi(d, upperBound[d] * (1.0 + dh));
......
//
// Class PartBins
// Defines a structure to hold energy bins and their associated data
//
// Copyright (c) 2007-2020, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
#include "Algorithms/PartBins.h" #include "Algorithms/PartBins.h"
#include "Algorithms/PBunchDefs.h" #include "Algorithms/PBunchDefs.h"
#include "Physics/Physics.h" #include "Physics/Physics.h"
#include "Utility/Inform.h"
#include <cfloat> #include <cfloat>
#include <limits> #include <limits>
#include <vector> #include <vector>
#include <cmath> #include <cmath>
PartBins::PartBins(int bins, int sbins) : PartBins::PartBins(int bins, int sbins) :
gamma_m(1.0), gamma_m(1.0),
bins_m(bins), bins_m(bins),
...@@ -14,17 +32,16 @@ PartBins::PartBins(int bins, int sbins) : ...@@ -14,17 +32,16 @@ PartBins::PartBins(int bins, int sbins) :
xmin_m(0.0), xmin_m(0.0),
xmax_m(0.0), xmax_m(0.0),
hBin_m(0.0), hBin_m(0.0),
nemittedBins_m(0), nemittedBins_m(0) {
nemittedSBins_m(0) {
// number of particles in the bins on the local node // number of particles in the bins on the local node
nBin_m = std::unique_ptr<size_t[]>(new size_t[bins_m]); nBin_m = std::unique_ptr<size_t[]>(new size_t[bins_m]);
xbinmin_m = std::unique_ptr<double[]>(new double[bins_m]); xbinmin_m = std::unique_ptr<double[]>(new double[bins_m]);
xbinmax_m = std::unique_ptr<double[]>(new double[bins_m]); xbinmax_m = std::unique_ptr<double[]>(new double[bins_m]);
// flag whether the bin contain particles or not // flag whether the bin contain particles or not
binsEmitted_m = std::unique_ptr<bool[]>(new bool[bins_m]); binsEmitted_m = std::unique_ptr<bool[]>(new bool[bins_m]);
nDelBin_m = std::unique_ptr<size_t[]>(new size_t[bins_m]); nDelBin_m = std::unique_ptr<size_t[]>(new size_t[bins_m]);
for(int i = 0; i < bins_m; i++) { for(int i = 0; i < bins_m; i++) {
...@@ -57,46 +74,6 @@ size_t PartBins::getTotalNumPerBin(int b) { ...@@ -57,46 +74,6 @@ size_t PartBins::getTotalNumPerBin(int b) {
return s; return s;
} }
void PartBins::updateStatus(const int bunchCount, const size_t partInBin) {
// array index of binsEmitted_m[] starts from 0
// nemittedBins_m and bins_m index starts from 1
binsEmitted_m[bunchCount - 1] = true;
size_t NpartInBin = partInBin;
reduce(NpartInBin, NpartInBin, OpAddAssign());
nBin_m[bunchCount - 1] = NpartInBin;
nemittedBins_m++;
}
void PartBins::updateDeletedPartsInBin(size_t countLost[]) {
Inform msg("updateDeletedPartsInBin ");
const int lastEmittedBin = getLastemittedBin();
reduce(&(countLost[0]), &(countLost[0]) + lastEmittedBin, &(countLost[0]), OpAddAssign());
for(int ii = 0; ii < lastEmittedBin; ii++) {
if(countLost[ii] > 0) {
nDelBin_m[ii] = countLost[ii];
msg << "In Bin: " << ii << ", " << nDelBin_m[ii] << " particle(s) lost" << endl;
}
}
}
void PartBins::updatePartInBin(size_t countLost[]) {
Inform msg0("updatePartInBin ");
for(int ii = 0; ii < nemittedBins_m; ii++) {
msg0 << "In Bin: " << ii << ", " << nBin_m[ii] << " particles " << endl;
}
reduce(&(countLost[0]), &(countLost[0]) + nemittedBins_m, &(countLost[0]), OpAddAssign());
for(int ii = 0; ii < nemittedBins_m; ii++) {
if(countLost[ii] > 0) {
nBin_m[ii] -= countLost[ii];
msg0 << "In Bin: " << ii << ", " << countLost[ii] << " particle(s) lost" << endl;
}
}
}
void PartBins::updatePartInBin_cyc(size_t countLost[]) { void PartBins::updatePartInBin_cyc(size_t countLost[]) {
...@@ -106,16 +83,6 @@ void PartBins::updatePartInBin_cyc(size_t countLost[]) { ...@@ -106,16 +83,6 @@ void PartBins::updatePartInBin_cyc(size_t countLost[]) {
} }
} }
void PartBins::resetPartInBin(size_t newPartNum[]) {
reduce(&(newPartNum[0]), &(newPartNum[0]) + nemittedBins_m, &(newPartNum[0]), OpAddAssign());
for(int ii = 0; ii < nemittedBins_m; ii++) {
nBin_m[ii] = newPartNum[ii];
INFOMSG("After reset Bin: " << ii << ", particle(s): " << newPartNum[ii] << endl);
}
}
void PartBins::resetPartInBin_cyc(size_t newPartNum[], int maxbinIndex) { void PartBins::resetPartInBin_cyc(size_t newPartNum[], int maxbinIndex) {
reduce(maxbinIndex, maxbinIndex, OpMaxAssign()); reduce(maxbinIndex, maxbinIndex, OpMaxAssign());
nemittedBins_m = maxbinIndex + 1; nemittedBins_m = maxbinIndex + 1;
...@@ -127,7 +94,6 @@ void PartBins::resetPartInBin_cyc(size_t newPartNum[], int maxbinIndex) { ...@@ -127,7 +94,6 @@ void PartBins::resetPartInBin_cyc(size_t newPartNum[], int maxbinIndex) {
} }
PartBins::~PartBins() { PartBins::~PartBins() {
tmppart_m.clear(); tmppart_m.clear();
isEmitted_m.clear(); isEmitted_m.clear();
...@@ -171,10 +137,6 @@ void PartBins::sortArray() { ...@@ -171,10 +137,6 @@ void PartBins::sortArray() {
} }
void PartBins::sortArrayT() {
setActualemittedBin(0);
}
void PartBins::calcHBins() { void PartBins::calcHBins() {
for(unsigned int n = 0; n < tmppart_m.size(); n++) for(unsigned int n = 0; n < tmppart_m.size(); n++)
...@@ -182,27 +144,6 @@ void PartBins::calcHBins() { ...@@ -182,27 +144,6 @@ void PartBins::calcHBins() {
calcExtrema(); calcExtrema();
} }
size_t PartBins::getSum() {
size_t s = 0;
for(int n = 0; n < bins_m; n++)
s += nBin_m[n];
return s;
}
void PartBins::calcGlobalExtrema() {
xmin_m = std::numeric_limits<double>::max();
xmax_m = -xmin_m;
for(unsigned int n = 0; n < tmppart_m.size(); n++) {
if(tmppart_m[n][2] <= xmin_m)
xmin_m = tmppart_m[n][2];
if(tmppart_m[n][2] >= xmax_m)
xmax_m = tmppart_m[n][2];
}
double xdiff = 0.01 * (xmax_m - xmin_m);
xmin_m -= xdiff;
xmax_m += xdiff;
}
void PartBins::calcExtrema() { void PartBins::calcExtrema() {
for(unsigned int n = 0; n < tmppart_m.size(); n++) { for(unsigned int n = 0; n < tmppart_m.size(); n++) {
if(xbinmin_m[(int)tmppart_m[n][6]] >= tmppart_m[n][2]) if(xbinmin_m[(int)tmppart_m[n][6]] >= tmppart_m[n][2])
......
/** \file //
* \brief Defines a structure to hold energy bins and their // Class PartBins
* associated data // Defines a structure to hold energy bins and their associated data
* //
* // Copyright (c) 2007-2020, Paul Scherrer Institut, Villigen PSI, Switzerland
* // All rights reserved
* \author Andreas Adelmann //
* \date xx. November 2007 // This file is part of OPAL.
* //
* \warning None. // OPAL is free software: you can redistribute it and/or modify
* \attention // it under the terms of the GNU General Public License as published by
* \bug sure no bug in this code :=) // the Free Software Foundation, either version 3 of the License, or
* \todo // (at your option) any later version.
*/ //
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
#ifndef OPAL_Bins_HH #ifndef OPAL_Bins_HH
#define OPAL_Bins_HH #define OPAL_Bins_HH
#ifndef PartBinTest
#include "Algorithms/PBunchDefs.h"
#else
#include "ranlib.h"
#define Inform ostream
#endif
#include <gsl/gsl_rng.h>
#include <gsl/gsl_histogram.h> #include <gsl/gsl_histogram.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_randist.h>
#include <functional>
#include <memory>
#include <vector>
#include "Algorithms/PBunchDefs.h"
class Inform;
class PartBins { class PartBins {
...@@ -48,14 +48,6 @@ public: ...@@ -48,14 +48,6 @@ public:
virtual ~PartBins(); virtual ~PartBins();
/** \brief How many deleted particles are on one bin */
inline int getDelBinCont(int bin) {
int a = nDelBin_m[bin];
reduce(a, a, OpAddAssign());
return a;
}
/** \brief Add a particle to the temporary container */ /** \brief Add a particle to the temporary container */
void fill(std::vector<double> &p) { void fill(std::vector<double> &p) {
tmppart_m.push_back(p); tmppart_m.push_back(p);
...@@ -73,11 +65,6 @@ public: ...@@ -73,11 +65,6 @@ public:
/** set particles number in given bin */ /** set particles number in given bin */
void setPartNum(int bin, long long num) {nBin_m[bin] = num;} void setPartNum(int bin, long long num) {nBin_m[bin] = num;}
/** assume we emmit in monotinic increasing order */
void setBinEmitted(int bin) {binsEmitted_m[bin] = true;}
bool getBinEmitted(int bin) {return binsEmitted_m[bin];}
/** \brief Is true if we still have particles to emit */ /** \brief Is true if we still have particles to emit */
bool doEmission() {return getNp() > 0;} bool doEmission() {return getNp() > 0;}
...@@ -85,19 +72,6 @@ public: ...@@ -85,19 +72,6 @@ public:
return isEmitted_m[n]; //(isEmitted_m[n][0]==1) && (isEmitted_m[n][1] == bin); return isEmitted_m[n]; //(isEmitted_m[n][0]==1) && (isEmitted_m[n][1] == bin);
} }
void setEmitted(int n, int /*bin*/) {
isEmitted_m[n] = true;
}
void updatePartPos(int n, int /*bin*/, double z) {
tmppart_m[n][2] = z;
}
void updateExtramePos(int bin, double dz) {
xbinmax_m[bin] += dz;
xbinmin_m[bin] += dz;
}
/** assigns the proper position of particle n if it belongs to bin 'bin' */ /** assigns the proper position of particle n if it belongs to bin 'bin' */
bool getPart(size_t n, int bin, std::vector<double> &p); bool getPart(size_t n, int bin, std::vector<double> &p);
...@@ -106,29 +80,19 @@ public: ...@@ -106,29 +80,19 @@ public:
*/ */
void sortArray(); void sortArray();
private:
/** assigns the particles to the bins */ /** assigns the particles to the bins */
void calcHBins(); void calcHBins();
size_t getSum();
void calcGlobalExtrema();
void calcExtrema(); void calcExtrema();
void getExtrema(double &min, double &max) { /** assume we emit in monotonic increasing order */
min = xmin_m; void setBinEmitted(int bin) {binsEmitted_m[bin] = true;}
max = xmax_m;
}
/** update global bin parameters after inject a new bunch */ public:
void updateStatus(int bunchCount, size_t nPartInBin);
/** update particles number in bin after reset Bin ID of PartBunch */
void resetPartInBin(size_t newPartNum[]);
/** update local particles number in bin after reset Bin ID of PartBunch */ /** update local particles number in bin after reset Bin ID of PartBunch */
void resetPartInBin_cyc(size_t newPartNum[], int binID); void resetPartInBin_cyc(size_t newPartNum[], int binID);
/** update particles number in bin after particle deletion */
void updatePartInBin(size_t countLost[]);
/** update local particles number in bin after particle deletion */ /** update local particles number in bin after particle deletion */
void updatePartInBin_cyc(size_t countLost[]); void updatePartInBin_cyc(size_t countLost[]);
void updateDeletedPartsInBin(size_t countLost[]) ;
void setGamma(double gamma) { gamma_m = gamma;} void setGamma(double gamma) { gamma_m = gamma;}
double getGamma() {return gamma_m;} double getGamma() {return gamma_m;}
...@@ -159,13 +123,8 @@ protected: ...@@ -159,13 +123,8 @@ protected:
std::vector< std::vector<double> > tmppart_m; std::vector< std::vector<double> > tmppart_m;
std::vector< bool > isEmitted_m;