diff --git a/src/BasicActions/DumpEMFields.cpp b/src/BasicActions/DumpEMFields.cpp index 377d826e7e9c6da10746c601182293ac10909db7..b114c1f476927a0bf1c32458570620327416eb5d 100644 --- a/src/BasicActions/DumpEMFields.cpp +++ b/src/BasicActions/DumpEMFields.cpp @@ -158,13 +158,13 @@ void DumpEMFields::buildGrid() { origin[0] = Attributes::getReal(itsAttr[X_START]); spacing[0] = Attributes::getReal(itsAttr[DX]); double nx = Attributes::getReal(itsAttr[X_STEPS]); - checkInt(nx, "X_STEPS"); + Util::checkInt(nx, "X_STEPS"); gridSize[0] = nx; origin[1] = Attributes::getReal(itsAttr[Y_START]); spacing[1] = Attributes::getReal(itsAttr[DY]); double ny = Attributes::getReal(itsAttr[Y_STEPS]); - checkInt(ny, "Y_STEPS"); + Util::checkInt(ny, "Y_STEPS"); gridSize[1] = ny; break; @@ -173,13 +173,13 @@ void DumpEMFields::buildGrid() { origin[0] = Attributes::getReal(itsAttr[R_START]); spacing[0] = Attributes::getReal(itsAttr[DR]); double nr = Attributes::getReal(itsAttr[R_STEPS]); - checkInt(nr, "R_STEPS"); + Util::checkInt(nr, "R_STEPS"); gridSize[0] = nr; origin[1] = Attributes::getReal(itsAttr[PHI_START]); spacing[1] = Attributes::getReal(itsAttr[DPHI]); double nphi = Attributes::getReal(itsAttr[PHI_STEPS]); - checkInt(nphi, "PHI_STEPS"); + Util::checkInt(nphi, "PHI_STEPS"); gridSize[1] = nphi; break; @@ -189,13 +189,13 @@ void DumpEMFields::buildGrid() { origin[2] = Attributes::getReal(itsAttr[Z_START]); spacing[2] = Attributes::getReal(itsAttr[DZ]); double nz = Attributes::getReal(itsAttr[Z_STEPS]); - checkInt(nz, "Z_STEPS"); + Util::checkInt(nz, "Z_STEPS"); gridSize[2] = nz; origin[3] = Attributes::getReal(itsAttr[T_START]); spacing[3] = Attributes::getReal(itsAttr[DT]); double nt = Attributes::getReal(itsAttr[T_STEPS]); - checkInt(nt, "T_STEPS"); + Util::checkInt(nt, "T_STEPS"); gridSize[3] = nt; if (grid_m != nullptr) { @@ -214,19 +214,6 @@ void DumpEMFields::writeFields(Component* field) { } } -void DumpEMFields::checkInt(double real, std::string name, double tolerance) { - real += tolerance; // prevent rounding error - if (std::abs(std::floor(real) - real) > 2*tolerance) { - throw OpalException("DumpEMFields::checkInt", - "Value for " + name + - " should be an integer but a real value was found"); - } - if (std::floor(real) < 0.5) { - throw OpalException("DumpEMFields::checkInt", - "Value for " + name + " should be 1 or more"); - } -} - void DumpEMFields::writeHeader(std::ofstream& fout) const { fout << grid_m->end().toInteger() << "\n"; switch (coordinates_m) { diff --git a/src/BasicActions/DumpEMFields.h b/src/BasicActions/DumpEMFields.h index 89071d21b909d13ecd18c311c9e505da93040505..50afe476609c7f67525ef37238b8f102179bf0ee 100644 --- a/src/BasicActions/DumpEMFields.h +++ b/src/BasicActions/DumpEMFields.h @@ -133,7 +133,6 @@ private: virtual void writeFieldThis(Component* field); virtual void buildGrid(); void parseCoordinateSystem(); - static void checkInt(double value, std::string name, double tolerance = 1e-9); void writeHeader(std::ofstream& fout) const; void writeFieldLine(Component* field, const Vector_t& point, diff --git a/src/BasicActions/DumpFields.cpp b/src/BasicActions/DumpFields.cpp index 58f18435fb55f553f288ca620c8ce9dd8793bfb2..3103a69c54a020d0e1a9996502e70dbae14fd3e2 100644 --- a/src/BasicActions/DumpFields.cpp +++ b/src/BasicActions/DumpFields.cpp @@ -114,9 +114,9 @@ void DumpFields::buildGrid() { double dz = Attributes::getReal(itsAttr[DZ]); double nz = Attributes::getReal(itsAttr[Z_STEPS]); - checkInt(nx, "X_STEPS"); - checkInt(ny, "Y_STEPS"); - checkInt(nz, "Z_STEPS"); + Util::checkInt(nx, "X_STEPS"); + Util::checkInt(ny, "Y_STEPS"); + Util::checkInt(nz, "Z_STEPS"); delete grid_m; grid_m = new interpolation::ThreeDGrid(dx, dy, dz, @@ -133,18 +133,6 @@ void DumpFields::writeFields(Component* field) { } } -void DumpFields::checkInt(double real, std::string name, double tolerance) { - if (std::abs(std::floor(real) - real) > tolerance) { - throw OpalException("DumpFields::checkInt", - "Value for " + name + - " should be an integer but a real value was found"); - } - if (std::floor(real) < 0.5) { - throw OpalException("DumpFields::checkInt", - "Value for " + name + " should be 1 or more"); - } -} - void DumpFields::writeFieldThis(Component* field) { if (grid_m == nullptr) { throw OpalException("DumpFields::writeFieldThis", diff --git a/src/BasicActions/DumpFields.h b/src/BasicActions/DumpFields.h index 75837b1a3926cecf8a44fd9513d06edaba742a87..098cf8cfc704e986d852631333c4d6f54d8f775c 100644 --- a/src/BasicActions/DumpFields.h +++ b/src/BasicActions/DumpFields.h @@ -116,7 +116,6 @@ public: private: virtual void writeFieldThis(Component* field); virtual void buildGrid(); - static void checkInt(double value, std::string name, double tolerance = 1e-9); interpolation::ThreeDGrid* grid_m = nullptr; diff --git a/src/Classic/Utilities/Util.cpp b/src/Classic/Utilities/Util.cpp index a9811fe7b3294ec32c19276cfea6b9b8df940df4..a3db487292f50ca76da8c5308e5643a39726399b 100644 --- a/src/Classic/Utilities/Util.cpp +++ b/src/Classic/Utilities/Util.cpp @@ -16,8 +16,9 @@ // along with OPAL. If not, see <https://www.gnu.org/licenses/>. // #include "Utilities/Util.h" -#include "Physics/Physics.h" + #include "OPALrevision.h" +#include "Utilities/OpalException.h" #include <boost/filesystem.hpp> #include <boost/regex.hpp> @@ -201,6 +202,19 @@ namespace Util { return path.string(); } + void checkInt(double real, std::string name, double tolerance) { + real += tolerance; // prevent rounding error + if (std::abs(std::floor(real) - real) > 2*tolerance) { + throw OpalException("Util::checkInt", + "Value for " + name + + " should be an integer but a real value was found"); + } + if (std::floor(real) < 0.5) { + throw OpalException("Util::checkInt", + "Value for " + name + " should be 1 or more"); + } + } + KahanAccumulation::KahanAccumulation(): sum(0.0), correction(0.0) diff --git a/src/Classic/Utilities/Util.h b/src/Classic/Utilities/Util.h index 394cd0fa696083e8df083aa6bf848185c350b3e8..5edf649f77659648f289cedbfe7e58bef014b6d5 100644 --- a/src/Classic/Utilities/Util.h +++ b/src/Classic/Utilities/Util.h @@ -20,7 +20,6 @@ #include "Algorithms/Vektor.h" #include "Algorithms/Quaternion.h" - #include "Physics/Physics.h" #include <algorithm> @@ -219,6 +218,8 @@ namespace Util { std::string combineFilePath(std::initializer_list<std::string>); + void checkInt(double real, std::string name, double tolerance = 1e-9); + template<class IteratorIn, class IteratorOut> void toString(IteratorIn first, IteratorIn last, IteratorOut out);