Commit 80ed400a authored by snuverink_j's avatar snuverink_j
Browse files

Merge branch 'std__math' into 'master'

use c++11 std__math methods instead of own classes

See merge request !296
parents ee231a93 70434ca3
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
#include "Parser/Statement.h" #include "Parser/Statement.h"
#include "Utilities/Options.h" #include "Utilities/Options.h"
#include "Utilities/ParseError.h" #include "Utilities/ParseError.h"
#include "Utilities/Round.h"
#include <cmath>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
...@@ -100,7 +100,7 @@ void Object::parse(Statement &stat) { ...@@ -100,7 +100,7 @@ void Object::parse(Statement &stat) {
if(Attribute *attr = findAttribute(name)) { if(Attribute *attr = findAttribute(name)) {
if(stat.delimiter('[')) { if(stat.delimiter('[')) {
int index = int(Round(Expressions::parseRealConst(stat))); int index = int(std::round(Expressions::parseRealConst(stat)));
Expressions::parseDelimiter(stat, ']'); Expressions::parseDelimiter(stat, ']');
if(stat.delimiter('=')) { if(stat.delimiter('=')) {
......
...@@ -53,8 +53,6 @@ ...@@ -53,8 +53,6 @@
#include "Physics/Physics.h" #include "Physics/Physics.h"
#include "Utilities/NumToStr.h"
class Beamline; class Beamline;
class PartData; class PartData;
using Physics::c; using Physics::c;
...@@ -678,7 +676,7 @@ namespace { ...@@ -678,7 +676,7 @@ namespace {
zt = ::implicitIntStep(zt, f, gradf, ya * dsc, nx); zt = ::implicitIntStep(zt, f, gradf, ya * dsc, nx);
} catch(ConvergenceError &cnverr) { } catch(ConvergenceError &cnverr) {
if(++ci > cx) { if(++ci > cx) {
std::string msg = "Convergence not achieved within " + NumToStr<int>(cx) + " cuts of step-size!"; std::string msg = "Convergence not achieved within " + std::to_string(cx) + " cuts of step-size!";
throw ConvergenceError("ThickMapper::implicitInt4()", msg); throw ConvergenceError("ThickMapper::implicitInt4()", msg);
} }
//std::cerr << " cutting step size in half" << std::endl; //std::cerr << " cutting step size in half" << std::endl;
...@@ -722,7 +720,7 @@ namespace { ...@@ -722,7 +720,7 @@ namespace {
int ni = 0; int ni = 0;
while(bcount < PSdim) { while(bcount < PSdim) {
if(ni == nx) { if(ni == nx) {
std::string msg = "Convergence not achieved within " + NumToStr<int>(nx) + " iterations!"; std::string msg = "Convergence not achieved within " + std::to_string(nx) + " iterations!";
throw ConvergenceError("ThickMapper::implicitIntStep()", msg); throw ConvergenceError("ThickMapper::implicitIntStep()", msg);
} }
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/Options.h" #include "Utilities/Options.h"
#include "Utilities/ParseError.h" #include "Utilities/ParseError.h"
#include "Utilities/Round.h"
#include "Utilities/Util.h" #include "Utilities/Util.h"
#include <cmath> #include <cmath>
...@@ -404,7 +403,7 @@ void OpalElement::parse(Statement &stat) { ...@@ -404,7 +403,7 @@ void OpalElement::parse(Statement &stat) {
} }
if(stat.delimiter('[')) { if(stat.delimiter('[')) {
int index = int(Round(Expressions::parseRealConst(stat))); int index = int(std::round(Expressions::parseRealConst(stat)));
Expressions::parseDelimiter(stat, ']'); Expressions::parseDelimiter(stat, ']');
if(stat.delimiter('=')) { if(stat.delimiter('=')) {
......
...@@ -51,9 +51,6 @@ ...@@ -51,9 +51,6 @@
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/Options.h" #include "Utilities/Options.h"
#include "Utilities/ParseError.h" #include "Utilities/ParseError.h"
#include "Utilities/CLRangeError.h"
#include "Utilities/Round.h"
#include "Utilities/Truncate.h"
#include "ValueDefinitions/BoolConstant.h" #include "ValueDefinitions/BoolConstant.h"
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
...@@ -183,8 +180,8 @@ namespace Expressions { ...@@ -183,8 +180,8 @@ namespace Expressions {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
static const TFunction1<double, double> table1[] = { static const TFunction1<double, double> table1[] = {
{ "TRUNC", -1, Truncate }, { "TRUNC", -1, std::trunc },
{ "ROUND", -1, Round }, { "ROUND", -1, std::round },
{ "FLOOR", -1, std::floor }, { "FLOOR", -1, std::floor },
{ "CEIL", -1, std::ceil }, { "CEIL", -1, std::ceil },
{ "SIGN", -1, Sign }, { "SIGN", -1, Sign },
...@@ -448,7 +445,6 @@ namespace Expressions { ...@@ -448,7 +445,6 @@ namespace Expressions {
return new AList<bool>(array); return new AList<bool>(array);
} }
PtrToArray<double> parseRealArray(Statement &stat) { PtrToArray<double> parseRealArray(Statement &stat) {
PtrToArray<double> result; PtrToArray<double> result;
PtrToArray<double> second; PtrToArray<double> second;
...@@ -549,7 +545,7 @@ namespace Expressions { ...@@ -549,7 +545,7 @@ namespace Expressions {
std::string name = parseString(stat, "Expected <name> or '#'."); std::string name = parseString(stat, "Expected <name> or '#'.");
int occurrence = 1; int occurrence = 1;
if(stat.delimiter('[')) { if(stat.delimiter('[')) {
occurrence = int(Round(parseRealConst(stat))); occurrence = int(std::round(parseRealConst(stat)));
parseDelimiter(stat, ']'); parseDelimiter(stat, ']');
if(occurrence <= 0) { if(occurrence <= 0) {
...@@ -593,7 +589,7 @@ namespace Expressions { ...@@ -593,7 +589,7 @@ namespace Expressions {
int index = 0; int index = 0;
if(stat.delimiter('[')) { if(stat.delimiter('[')) {
index = int(Round(parseRealConst(stat))); index = int(std::round(parseRealConst(stat)));
parseDelimiter(stat, ']'); parseDelimiter(stat, ']');
if(index <= 0) { if(index <= 0) {
...@@ -1051,7 +1047,7 @@ namespace Expressions { ...@@ -1051,7 +1047,7 @@ namespace Expressions {
parseDelimiter(stat, '('); parseDelimiter(stat, '(');
// Read the array index set. // Read the array index set.
int frst = int(Round(parseRealConst(stat))); int frst = int(std::round(parseRealConst(stat)));
int last = 1; int last = 1;
int step = 1; int step = 1;
...@@ -1059,9 +1055,9 @@ namespace Expressions { ...@@ -1059,9 +1055,9 @@ namespace Expressions {
last = frst; last = frst;
frst = 1; frst = 1;
} else if(stat.delimiter(':')) { } else if(stat.delimiter(':')) {
last = int(Round(parseRealConst(stat))); last = int(std::round(parseRealConst(stat)));
if(stat.delimiter(':')) { if(stat.delimiter(':')) {
step = int(Round(parseRealConst(stat))); step = int(std::round(parseRealConst(stat)));
} }
parseDelimiter(stat, ','); parseDelimiter(stat, ',');
} else { } else {
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
#include "AbstractObjects/Expressions.h" #include "AbstractObjects/Expressions.h"
#include "Utilities/CLRangeError.h" #include "Utilities/CLRangeError.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/Round.h"
#include <cerrno> #include <cerrno>
#include <cmath>
#include <iosfwd> #include <iosfwd>
#include <vector> #include <vector>
...@@ -99,7 +99,7 @@ namespace Expressions { ...@@ -99,7 +99,7 @@ namespace Expressions {
template <class T> inline template <class T> inline
T Indexer<T>::evaluate() const { T Indexer<T>::evaluate() const {
std::vector<T> op1 = lft->evaluate(); std::vector<T> op1 = lft->evaluate();
int op2 = int(Round(rgt->evaluate())); int op2 = int(std::round(rgt->evaluate()));
if(op2 <= 0 || static_cast<unsigned>(op2) > op1.size()) { if(op2 <= 0 || static_cast<unsigned>(op2) > op1.size()) {
throw CLRangeError("Expressions::Indexer()", "Index out of range."); throw CLRangeError("Expressions::Indexer()", "Index out of range.");
......
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/Options.h" #include "Utilities/Options.h"
#include "Utilities/ParseError.h" #include "Utilities/ParseError.h"
#include "Utilities/Round.h" #include <iostream>
#include <vector> #include <string>
// Class ConstraintCmd // Class ConstraintCmd
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "Algebra/Vector.h" #include "Algebra/Vector.h"
#include "Attributes/Attributes.h" #include "Attributes/Attributes.h"
#include "Match/Match.h" #include "Match/Match.h"
#include "Utilities/Round.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <cfloat> #include <cfloat>
...@@ -80,7 +79,7 @@ void LMDif::execute() { ...@@ -80,7 +79,7 @@ void LMDif::execute() {
// Fetch command attributes. // Fetch command attributes.
double tol = max(DBL_EPSILON, Attributes::getReal(itsAttr[TOLERANCE])); double tol = max(DBL_EPSILON, Attributes::getReal(itsAttr[TOLERANCE]));
int nfcnmax = int(Round(Attributes::getReal(itsAttr[CALLS]))); int nfcnmax = int(std::round(Attributes::getReal(itsAttr[CALLS])));
// Initialize. // Initialize.
double fnorm = 0.0; double fnorm = 0.0;
......
...@@ -19,8 +19,7 @@ ...@@ -19,8 +19,7 @@
#include "Match/MatchOption.h" #include "Match/MatchOption.h"
#include "Attributes/Attributes.h" #include "Attributes/Attributes.h"
#include "Match/Match.h" #include "Match/Match.h"
#include "Utilities/Round.h" #include <cmath>
// Class MatchOption // Class MatchOption
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
...@@ -50,6 +49,6 @@ MatchOption *MatchOption::clone(const std::string &name) { ...@@ -50,6 +49,6 @@ MatchOption *MatchOption::clone(const std::string &name) {
void MatchOption::execute() { void MatchOption::execute() {
int level = int(Round(Attributes::getReal(itsAttr[0]))); int level = int(std::round(Attributes::getReal(itsAttr[0])));
Match::block->setPrintLevel(level); Match::block->setPrintLevel(level);
} }
\ No newline at end of file
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "Algebra/Vector.h" #include "Algebra/Vector.h"
#include "Attributes/Attributes.h" #include "Attributes/Attributes.h"
#include "Match/Match.h" #include "Match/Match.h"
#include "Utilities/Round.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <cfloat> #include <cfloat>
...@@ -79,7 +78,7 @@ void Migrad::execute() { ...@@ -79,7 +78,7 @@ void Migrad::execute() {
// fetch command attributes. // fetch command attributes.
double tol = max(Attributes::getReal(itsAttr[TOLERANCE]), DBL_EPSILON); double tol = max(Attributes::getReal(itsAttr[TOLERANCE]), DBL_EPSILON);
int nfcnmax = int(Round(Attributes::getReal(itsAttr[CALLS]))); int nfcnmax = int(std::round(Attributes::getReal(itsAttr[CALLS])));
// Working vectors. // Working vectors.
int n = Match::block->countVariables(); int n = Match::block->countVariables();
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "Attributes/Attributes.h" #include "Attributes/Attributes.h"
#include "Match/Match.h" #include "Match/Match.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/Round.h"
#include <cfloat> #include <cfloat>
#include <cmath> #include <cmath>
#include <numeric> #include <numeric>
...@@ -115,7 +114,7 @@ void Simplex::execute() { ...@@ -115,7 +114,7 @@ void Simplex::execute() {
state = CONVERGED; state = CONVERGED;
} else { } else {
// Fetch command attributes. // Fetch command attributes.
int nfcnmax = int(Round(Attributes::getReal(itsAttr[CALLS]))); int nfcnmax = int(std::round(Attributes::getReal(itsAttr[CALLS])));
// Set up the simplex. // Set up the simplex.
Fsim = Array1D<double>(n + 1); Fsim = Array1D<double>(n + 1);
......
...@@ -34,8 +34,8 @@ ...@@ -34,8 +34,8 @@
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/ParseError.h" #include "Utilities/ParseError.h"
#include "Utilities/Options.h" #include "Utilities/Options.h"
#include "Utilities/Round.h"
#include <cassert> #include <cassert>
#include <cmath>
#include <ctime> #include <ctime>
#include <exception> #include <exception>
#include <iostream> #include <iostream>
...@@ -286,7 +286,7 @@ void OpalParser::parseAssign(Statement &stat) const { ...@@ -286,7 +286,7 @@ void OpalParser::parseAssign(Statement &stat) const {
int index = 0; int index = 0;
if(stat.delimiter('[')) { if(stat.delimiter('[')) {
index = int(Round(parseRealConst(stat))); index = int(std::round(parseRealConst(stat)));
parseDelimiter(stat, ']'); parseDelimiter(stat, ']');
if(index <= 0) { if(index <= 0) {
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "Physics/Physics.h" #include "Physics/Physics.h"
#include "Structure/Beam.h" #include "Structure/Beam.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/Round.h"
#include <cmath> #include <cmath>
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
...@@ -99,7 +98,7 @@ void Dynamic::execute() { ...@@ -99,7 +98,7 @@ void Dynamic::execute() {
const PartData &reference = beam->getReference(); const PartData &reference = beam->getReference();
// Compute transfer map. // Compute transfer map.
int order = std::max(int(Round(Attributes::getReal(itsAttr[ORDER]))), 1); int order = std::max(int(std::round(Attributes::getReal(itsAttr[ORDER]))), 1);
FTps<double, 6>::setGlobalTruncOrder(order); FTps<double, 6>::setGlobalTruncOrder(order);
LieMapper mapper(*use->fetchLine(), reference, false, false, order); LieMapper mapper(*use->fetchLine(), reference, false, false, order);
mapper.execute(); mapper.execute();
......
...@@ -29,13 +29,11 @@ ...@@ -29,13 +29,11 @@
#include "Physics/Physics.h" #include "Physics/Physics.h"
#include "Structure/Beam.h" #include "Structure/Beam.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/Round.h" #include <cmath>
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
using std::complex;
// Class Static // Class Static
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
...@@ -100,7 +98,7 @@ void Static::execute() { ...@@ -100,7 +98,7 @@ void Static::execute() {
// Compute transfer map. // Compute transfer map.
// JMJ comment: minimum sensible order is 2 // JMJ comment: minimum sensible order is 2
int order = std::max(int(Round(Attributes::getReal(itsAttr[ORDER]))), 2); int order = std::max(int(std::round(Attributes::getReal(itsAttr[ORDER]))), 2);
LieMapper mapper(*use->fetchLine(), reference, false, false, order); LieMapper mapper(*use->fetchLine(), reference, false, false, order);
FTps<double, 6>::setGlobalTruncOrder(order); FTps<double, 6>::setGlobalTruncOrder(order);
std::cout << "mapper.execute(); start " << std::endl; std::cout << "mapper.execute(); start " << std::endl;
...@@ -129,11 +127,11 @@ void Static::execute() { ...@@ -129,11 +127,11 @@ void Static::execute() {
// Print normal form. // Print normal form.
// const DragtFinnNormalForm<3> normal(map); // const DragtFinnNormalForm<3> normal(map);
// const FVector<complex<double>,6> &lambda = normal.eigenValues(); // const FVector<std::complex<double>,6> &lambda = normal.eigenValues();
// 21-06-2000, remove const // 21-06-2000, remove const
DragtFinnNormalForm<3> normal(map); DragtFinnNormalForm<3> normal(map);
const FVector<complex<double>, 6> &lambda = normal.eigenValues(); const FVector<std::complex<double>, 6> &lambda = normal.eigenValues();
os << "\nEigenvalues of the linear map:\n"; os << "\nEigenvalues of the linear map:\n";
for(int i = 0; i < 4; i++) { for(int i = 0; i < 4; i++) {
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "Tables/Flatten.h" #include "Tables/Flatten.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/Options.h" #include "Utilities/Options.h"
#include "Utilities/Round.h" #include <cmath>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <string> #include <string>
...@@ -96,7 +96,7 @@ void Micado::execute() { ...@@ -96,7 +96,7 @@ void Micado::execute() {
// Get the data for correction. // Get the data for correction.
RangeRep range = Attributes::getRange(itsAttr[RANGE]); RangeRep range = Attributes::getRange(itsAttr[RANGE]);
int iterations = int(Round(Attributes::getReal(itsAttr[ITERATIONS]))); int iterations = int(std::round(Attributes::getReal(itsAttr[ITERATIONS])));
bool listm1 = Attributes::getBool(itsAttr[LISTM1]); bool listm1 = Attributes::getBool(itsAttr[LISTM1]);
bool listm2 = Attributes::getBool(itsAttr[LISTM2]); bool listm2 = Attributes::getBool(itsAttr[LISTM2]);
bool listc1 = Attributes::getBool(itsAttr[LISTC1]); bool listc1 = Attributes::getBool(itsAttr[LISTC1]);
...@@ -339,7 +339,7 @@ void Micado::solve(int plane, Matrix<double> &A, Vector<double> &B) { ...@@ -339,7 +339,7 @@ void Micado::solve(int plane, Matrix<double> &A, Vector<double> &B) {
// Begin of iteration loop. // Begin of iteration loop.
double tol = Attributes::getReal(itsAttr[TOL]); double tol = Attributes::getReal(itsAttr[TOL]);
int correctors = int(Round(Attributes::getReal(itsAttr[CORRECTORS]))); int correctors = int(std::round(Attributes::getReal(itsAttr[CORRECTORS])));
if(correctors > n || correctors == 0) correctors = n; if(correctors > n || correctors == 0) correctors = n;
int corr = 0; int corr = 0;
while(true) { while(true) {
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include "Structure/Beam.h" #include "Structure/Beam.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/Options.h" #include "Utilities/Options.h"
#include "Utilities/Round.h"
#include <cmath> #include <cmath>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include "Utilities/DomainError.h" #include "Utilities/DomainError.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/Options.h" #include "Utilities/Options.h"
#include "Utilities/Round.h"
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include "Utilities/DomainError.h" #include "Utilities/DomainError.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/Options.h" #include "Utilities/Options.h"
#include "Utilities/Round.h"
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include "Tables/Flatten.h" #include "Tables/Flatten.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/Options.h" #include "Utilities/Options.h"
#include "Utilities/Round.h"
#include <cmath> #include <cmath>
#include <iomanip> #include <iomanip>
...@@ -597,7 +596,7 @@ void Twiss::execute() { ...@@ -597,7 +596,7 @@ void Twiss::execute() {
revBeam = Attributes::getBool(itsAttr[REVBEAM]); revBeam = Attributes::getBool(itsAttr[REVBEAM]);
revTrack = Attributes::getBool(itsAttr[REVTRACK]); revTrack = Attributes::getBool(itsAttr[REVTRACK]);
revPath = ( revBeam && !revTrack ) || ( !revBeam && revTrack ); revPath = ( revBeam && !revTrack ) || ( !revBeam && revTrack );
order = int(Round(Attributes::getReal(itsAttr[ORDER]))); order = int(std::round(Attributes::getReal(itsAttr[ORDER])));
if(method == "THICK") { if(method == "THICK") {
//std::cerr << " method == \"THICK\"" << std::endl; //std::cerr << " method == \"THICK\"" << std::endl;
......
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
#include "Distribution/Distribution.h" #include "Distribution/Distribution.h"
#include "Track/Track.h" #include "Track/Track.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/Round.h"
#include "Utilities/Util.h" #include "Utilities/Util.h"
#include "Structure/Beam.h" #include "Structure/Beam.h"
#include "Structure/BoundaryGeometry.h" #include "Structure/BoundaryGeometry.h"
...@@ -57,6 +56,7 @@ ...@@ -57,6 +56,7 @@
#include <boost/regex.hpp> #include <boost/regex.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <cmath>
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
...@@ -203,7 +203,7 @@ void TrackRun::execute() { ...@@ -203,7 +203,7 @@ void TrackRun::execute() {
} }
if(method == "THIN" || method == "THICK") { if(method == "THIN" || method == "THICK") {
int turns = int(Round(Attributes::getReal(itsAttr[TURNS]))); int turns = int(std::round(Attributes::getReal(itsAttr[TURNS])));
// Track for the all but last turn. // Track for the all but last turn.
for(int turn = 1; turn < turns; ++turn) { for(int turn = 1; turn < turns; ++turn) {
...@@ -602,7 +602,7 @@ void TrackRun::setupCyclotronTracker(){ ...@@ -602,7 +602,7 @@ void TrackRun::setupCyclotronTracker(){