Commit 9880ff48 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

replaced string arguments by reference

parent f126815d
...@@ -31,7 +31,7 @@ int main(int argc, char** argv) ...@@ -31,7 +31,7 @@ int main(int argc, char** argv)
AdaptInfo adaptInfo("adapt"); AdaptInfo adaptInfo("adapt");
double* invTau = probInstat.getInvTau(); auto* invTau = probInstat.getInvTau();
auto opTimeLhs = makeOperator(tag::test_trial{}, std::ref(*invTau)); auto opTimeLhs = makeOperator(tag::test_trial{}, std::ref(*invTau));
prob.addMatrixOperator(opTimeLhs, 0, 0); prob.addMatrixOperator(opTimeLhs, 0, 0);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
namespace AMDiS namespace AMDiS
{ {
Dune::MPIHelper& init(int& argc, char**& argv, std::string initFileName) Dune::MPIHelper& init(int& argc, char**& argv, std::string const& initFileName)
{ {
// Maybe initialize MPI // Maybe initialize MPI
Dune::MPIHelper& mpiHelper = Dune::MPIHelper::instance(argc, argv); Dune::MPIHelper& mpiHelper = Dune::MPIHelper::instance(argc, argv);
...@@ -14,10 +14,8 @@ namespace AMDiS ...@@ -14,10 +14,8 @@ namespace AMDiS
Parameters::clearData(); Parameters::clearData();
if (initFileName == "") { if (initFileName == "") {
if (argc > 1) test_exit(argc > 1, "No init file specified!\n");
Parameters::init(argv[1]); Parameters::init(argv[1]);
else
error_exit("No init file specified!\n");
} else { } else {
Parameters::init(initFileName); Parameters::init(initFileName);
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
namespace AMDiS namespace AMDiS
{ {
Dune::MPIHelper& init(int& argc, char**& argv, std::string initFileName = ""); Dune::MPIHelper& init(int& argc, char**& argv, std::string const& initFileName = "");
void finalize(); void finalize();
......
...@@ -15,12 +15,12 @@ namespace AMDiS ...@@ -15,12 +15,12 @@ namespace AMDiS
{ {
public: public:
/// Constructor /// Constructor
AdaptBase(std::string name, AdaptBase(std::string const& name,
ProblemIterationInterface* problemIteration, ProblemIterationInterface* problemIteration,
AdaptInfo& adaptInfo, AdaptInfo& adaptInfo,
ProblemTimeInterface* problemTime = nullptr, ProblemTimeInterface* problemTime = nullptr,
AdaptInfo* initialAdaptInfo = nullptr) AdaptInfo* initialAdaptInfo = nullptr)
: name_(std::move(name)) : name_(name)
, problemIteration_(problemIteration) , problemIteration_(problemIteration)
, adaptInfo_(adaptInfo) , adaptInfo_(adaptInfo)
, problemTime_(problemTime) , problemTime_(problemTime)
...@@ -37,7 +37,7 @@ namespace AMDiS ...@@ -37,7 +37,7 @@ namespace AMDiS
virtual int adapt() = 0; virtual int adapt() = 0;
/// Returns \ref name /// Returns \ref name
std::string getName() const std::string const& getName() const
{ {
return name_; return name_;
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
namespace AMDiS namespace AMDiS
{ {
AdaptInfo::ScalContent::ScalContent(std::string prefix) AdaptInfo::ScalContent::ScalContent(std::string const& prefix)
{ {
Parameters::get(prefix + "->tolerance", spaceTolerance); Parameters::get(prefix + "->tolerance", spaceTolerance);
Parameters::get(prefix + "->time tolerance", timeTolerance); Parameters::get(prefix + "->time tolerance", timeTolerance);
...@@ -25,22 +25,22 @@ namespace AMDiS ...@@ -25,22 +25,22 @@ namespace AMDiS
} }
AdaptInfo::AdaptInfo(std::string name) AdaptInfo::AdaptInfo(std::string const& name)
: name_(std::move(name)) : name_(name)
{ {
// init(); // init();
Parameters::get(name_ + "->start time", startTime); Parameters::get(name + "->start time", startTime);
time = startTime; time = startTime;
Parameters::get(name_ + "->timestep", timestep); Parameters::get(name + "->timestep", timestep);
Parameters::get(name_ + "->end time", endTime); Parameters::get(name + "->end time", endTime);
Parameters::get(name_ + "->max iteration", maxSpaceIteration); Parameters::get(name + "->max iteration", maxSpaceIteration);
Parameters::get(name_ + "->max timestep iteration", maxTimestepIteration); Parameters::get(name + "->max timestep iteration", maxTimestepIteration);
Parameters::get(name_ + "->max time iteration", maxTimeIteration); Parameters::get(name + "->max time iteration", maxTimeIteration);
Parameters::get(name_ + "->min timestep", minTimestep); Parameters::get(name + "->min timestep", minTimestep);
Parameters::get(name_ + "->max timestep", maxTimestep); Parameters::get(name + "->max timestep", maxTimestep);
Parameters::get(name_ + "->number of timesteps", nTimesteps); Parameters::get(name + "->number of timesteps", nTimesteps);
Parameters::get(name_ + "->time tolerance", globalTimeTolerance); Parameters::get(name + "->time tolerance", globalTimeTolerance);
} }
......
...@@ -37,7 +37,7 @@ namespace AMDiS ...@@ -37,7 +37,7 @@ namespace AMDiS
{ {
public: public:
/// Constructor. /// Constructor.
explicit ScalContent(std::string prefix); explicit ScalContent(std::string const& prefix);
/// Sum of all error estimates /// Sum of all error estimates
double est_sum = 0.0; double est_sum = 0.0;
...@@ -75,7 +75,7 @@ namespace AMDiS ...@@ -75,7 +75,7 @@ namespace AMDiS
public: public:
/// Constructor. /// Constructor.
explicit AdaptInfo(std::string name); explicit AdaptInfo(std::string const& name);
/// Destructor. /// Destructor.
virtual ~AdaptInfo() = default; virtual ~AdaptInfo() = default;
...@@ -468,7 +468,7 @@ namespace AMDiS ...@@ -468,7 +468,7 @@ namespace AMDiS
} }
/// Gets \ref &time /// Gets \ref &time
double* getTimePtr() double const* getTimePtr() const
{ {
return &time; return &time;
} }
...@@ -538,7 +538,7 @@ namespace AMDiS ...@@ -538,7 +538,7 @@ namespace AMDiS
} }
/// Gets \ref &timestep /// Gets \ref &timestep
double* getTimestepPtr() double const* getTimestepPtr() const
{ {
return &timestep; return &timestep;
} }
......
...@@ -10,12 +10,12 @@ ...@@ -10,12 +10,12 @@
namespace AMDiS namespace AMDiS
{ {
AdaptInstationary::AdaptInstationary(std::string name, AdaptInstationary::AdaptInstationary(std::string const& name,
ProblemIterationInterface& problemIteration, ProblemIterationInterface& problemIteration,
AdaptInfo& adaptInfo, AdaptInfo& adaptInfo,
ProblemTimeInterface& problemTime, ProblemTimeInterface& problemTime,
AdaptInfo& initialAdaptInfo) AdaptInfo& initialAdaptInfo)
: AdaptBase(std::move(name), &problemIteration, adaptInfo, &problemTime, &initialAdaptInfo) : AdaptBase(name, &problemIteration, adaptInfo, &problemTime, &initialAdaptInfo)
{ {
Parameters::get(name_ + "->strategy", strategy_); Parameters::get(name_ + "->strategy", strategy_);
Parameters::get(name_ + "->time delta 1", timeDelta1_); Parameters::get(name_ + "->time delta 1", timeDelta1_);
......
...@@ -25,7 +25,7 @@ namespace AMDiS ...@@ -25,7 +25,7 @@ namespace AMDiS
public: public:
/// Creates a AdaptInstationary object with the given name for the time /// Creates a AdaptInstationary object with the given name for the time
/// dependent problem problemInstat. /// dependent problem problemInstat.
AdaptInstationary(std::string name, AdaptInstationary(std::string const& name,
ProblemIterationInterface& problemStat, ProblemIterationInterface& problemStat,
AdaptInfo& info, AdaptInfo& info,
ProblemTimeInterface& problemInstat, ProblemTimeInterface& problemInstat,
......
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
namespace AMDiS { namespace AMDiS {
AdaptStationary::AdaptStationary(std::string name, AdaptStationary::AdaptStationary(std::string const& name,
ProblemIterationInterface& problemIteration, ProblemIterationInterface& problemIteration,
AdaptInfo& adaptInfo) AdaptInfo& adaptInfo)
: AdaptBase(std::move(name), &problemIteration, adaptInfo) : AdaptBase(name, &problemIteration, adaptInfo)
{} {}
......
...@@ -30,7 +30,7 @@ namespace AMDiS ...@@ -30,7 +30,7 @@ namespace AMDiS
{ {
public: public:
/// Creates a AdaptStationary object with given name. /// Creates a AdaptStationary object with given name.
AdaptStationary(std::string name, AdaptStationary(std::string const& name,
ProblemIterationInterface& problemIteration, ProblemIterationInterface& problemIteration,
AdaptInfo& adaptInfo); AdaptInfo& adaptInfo);
......
...@@ -60,7 +60,7 @@ namespace AMDiS ...@@ -60,7 +60,7 @@ namespace AMDiS
public: public:
/// Constructor. /// Constructor.
FileWriter(std::string baseName, FileWriter(std::string const& baseName,
Vector const& dofvector) Vector const& dofvector)
: FileWriterInterface(baseName) : FileWriterInterface(baseName)
, dofvector_(dofvector) , dofvector_(dofvector)
......
...@@ -20,14 +20,14 @@ namespace AMDiS ...@@ -20,14 +20,14 @@ namespace AMDiS
// } // }
// } // }
void Initfile::init(std::string in) void Initfile::init(std::string const& in)
{ {
singlett().read(in); singlett().read(in);
singlett().getInternalParameters(); singlett().getInternalParameters();
} }
void Initfile::read(std::string fn, bool /*force*/) void Initfile::read(std::string const& fn, bool /*force*/)
{ {
InitfileParser::readInitfile(fn, pt_); InitfileParser::readInitfile(fn, pt_);
} }
...@@ -35,20 +35,12 @@ void Initfile::read(std::string fn, bool /*force*/) ...@@ -35,20 +35,12 @@ void Initfile::read(std::string fn, bool /*force*/)
void Initfile::getInternalParameters() void Initfile::getInternalParameters()
{ {
int val = 0; get("level of information", msgInfo_);
get("level of information", val); get("parameter information", paramInfo_);
msgInfo = val; get("break on missing tag", breakOnMissingTag_);
val = 1; if (msgInfo_ == 0)
get("parameter information", val); paramInfo_ = 0;
paramInfo = val;
val = 0;
get("break on missing tag", val);
breakOnMissingTag = val;
if (msgInfo == 0)
paramInfo = 0;
} }
......
...@@ -13,7 +13,7 @@ namespace AMDiS ...@@ -13,7 +13,7 @@ namespace AMDiS
{ {
public: public:
/// initialize singleton object and global parameters /// initialize singleton object and global parameters
static void init(std::string in); static void init(std::string const& in);
/// \brief Get parameter-values from parameter-tree /// \brief Get parameter-values from parameter-tree
/** /**
...@@ -23,7 +23,7 @@ namespace AMDiS ...@@ -23,7 +23,7 @@ namespace AMDiS
* Does not thrown an exception if something goes wrong! * Does not thrown an exception if something goes wrong!
**/ **/
template <class T> template <class T>
static Dune::Std::optional<T> get(std::string key) static Dune::Std::optional<T> get(std::string const& key)
{ {
try { try {
return pt().get<T>(key); return pt().get<T>(key);
...@@ -42,7 +42,7 @@ namespace AMDiS ...@@ -42,7 +42,7 @@ namespace AMDiS
* \param value: The default value and result. * \param value: The default value and result.
**/ **/
template <class T> template <class T>
static void get(std::string key, T& value) static void get(std::string const& key, T& value)
{ {
value = pt().get(key, value); value = pt().get(key, value);
} }
...@@ -50,7 +50,7 @@ namespace AMDiS ...@@ -50,7 +50,7 @@ namespace AMDiS
/// Returns specified info level /// Returns specified info level
static int getMsgInfo() static int getMsgInfo()
{ {
return singlett().msgInfo; return singlett().msgInfo_;
} }
/// print all data in singleton to std::cout /// print all data in singleton to std::cout
...@@ -75,15 +75,15 @@ namespace AMDiS ...@@ -75,15 +75,15 @@ namespace AMDiS
} }
/// Fill an parametr-tree from a file with filename fn /// Fill an parametr-tree from a file with filename fn
void read(std::string fn, bool force = false); void read(std::string const& fn, bool force = false);
void write(std::string fn); void write(std::string const& fn);
/// read standard values for output and information of parameter-values /// read standard values for output and information of parameter-values
void getInternalParameters(); void getInternalParameters();
int msgInfo = 0; int msgInfo_ = 0;
int paramInfo = 1; int paramInfo_ = 1;
int breakOnMissingTag = 0; bool breakOnMissingTag_ = false;
/// ParameterTree to read/store parameter values /// ParameterTree to read/store parameter values
Dune::ParameterTree pt_; Dune::ParameterTree pt_;
......
...@@ -6,10 +6,9 @@ ...@@ -6,10 +6,9 @@
namespace AMDiS { namespace AMDiS {
void InitfileParser::readInitfile(std::string fn, Dune::ParameterTree& pt, bool overwrite) void InitfileParser::readInitfile(std::string const& fn, Dune::ParameterTree& pt, bool overwrite)
{ {
test_exit(filesystem::exists(fn), test_exit(filesystem::exists(fn), "Init-file '{}' cannot be opened for reading", fn);
"init-file '{}' cannot be opened for reading", fn);
// read file if its not parsed already // read file if its not parsed already
auto ins = includeList().insert(fn); auto ins = includeList().insert(fn);
...@@ -37,8 +36,7 @@ void InitfileParser::readInitfile(std::istream& in, Dune::ParameterTree& pt, boo ...@@ -37,8 +36,7 @@ void InitfileParser::readInitfile(std::istream& in, Dune::ParameterTree& pt, boo
{ {
// parse line and extract map: tag->value // parse line and extract map: tag->value
std::size_t pos = sw.find(':'); std::size_t pos = sw.find(':');
if (pos == std::string::npos) test_exit(pos != std::string::npos, "Cannot find the delimiter ':' in line '{}'", sw);
throw std::runtime_error("cannot find the delimiter ':' in line '" + sw + "'");
std::string name = sw.substr(0, pos); std::string name = sw.substr(0, pos);
std::string value = sw.substr(pos + 1, sw.length() - (pos + 1)); std::string value = sw.substr(pos + 1, sw.length() - (pos + 1));
...@@ -73,11 +71,10 @@ void InitfileParser::readInitfile(std::istream& in, Dune::ParameterTree& pt, boo ...@@ -73,11 +71,10 @@ void InitfileParser::readInitfile(std::istream& in, Dune::ParameterTree& pt, boo
epos = sw.find_first_of(delimiter, pos); epos = sw.find_first_of(delimiter, pos);
fn = sw.substr(pos, epos - pos); fn = sw.substr(pos, epos - pos);
if (sw[epos]!=c) test_exit(sw[epos]==c, "Filename in #include not terminated by {}.", std::to_string(c));
throw std::runtime_error("filename in #include not terminated by " + std::to_string(c));
break; break;
default: default:
throw std::runtime_error("no filename given for #include"); error_exit("No filename given for #include");
} }
readInitfile(fn, pt, overwrite); readInitfile(fn, pt, overwrite);
...@@ -89,7 +86,7 @@ void InitfileParser::readInitfile(std::istream& in, Dune::ParameterTree& pt, boo ...@@ -89,7 +86,7 @@ void InitfileParser::readInitfile(std::istream& in, Dune::ParameterTree& pt, boo
} }
std::string InitfileParser::replaceVariable(Dune::ParameterTree const& pt, std::string input) std::string InitfileParser::replaceVariable(Dune::ParameterTree const& pt, std::string const& input)
{ {
std::string whitespaces = " \t\r\f"; std::string whitespaces = " \t\r\f";
std::string allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; std::string allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
...@@ -112,8 +109,8 @@ std::string InitfileParser::replaceVariable(Dune::ParameterTree const& pt, std:: ...@@ -112,8 +109,8 @@ std::string InitfileParser::replaceVariable(Dune::ParameterTree const& pt, std::
// if varname is found in parameter list then replace variable by value // if varname is found in parameter list then replace variable by value
// otherwise throw tagNotFound exception // otherwise throw tagNotFound exception
if (!pt.hasKey(varName)) test_exit(pt.hasKey(varName),
throw std::runtime_error("required tag '" + varName + "' for variable substitution not found"); "Required tag '{}' for variable substitution not found", varName);
std::string varParam = pt[varName]; std::string varParam = pt[varName];
...@@ -127,7 +124,7 @@ std::string InitfileParser::replaceVariable(Dune::ParameterTree const& pt, std:: ...@@ -127,7 +124,7 @@ std::string InitfileParser::replaceVariable(Dune::ParameterTree const& pt, std::
} }
std::string InitfileParser::replaceExpression(Dune::ParameterTree const& pt, std::string input) std::string InitfileParser::replaceExpression(Dune::ParameterTree const& pt, std::string const& input)
{ {
#if 0 #if 0
std::string whitespaces = " \t\r\f"; std::string whitespaces = " \t\r\f";
......
...@@ -30,7 +30,7 @@ namespace AMDiS ...@@ -30,7 +30,7 @@ namespace AMDiS
static void readInitfile(std::istream& in, Dune::ParameterTree& pt, bool overwrite); static void readInitfile(std::istream& in, Dune::ParameterTree& pt, bool overwrite);
/// Read initfile from input stream into parameter-tree /// Read initfile from input stream into parameter-tree
static void readInitfile(std::string fn, Dune::ParameterTree& pt, bool overwrite = true); static void readInitfile(std::string const& fn, Dune::ParameterTree& pt, bool overwrite = true);
private: private:
/// Provide a list of already read files. This is necessary to not double include the same file. /// Provide a list of already read files. This is necessary to not double include the same file.
...@@ -45,13 +45,13 @@ namespace AMDiS ...@@ -45,13 +45,13 @@ namespace AMDiS
* Replaces variables of the form ${variablename} or $variablename in the `input` * Replaces variables of the form ${variablename} or $variablename in the `input`
* by a corresponding value already stored in the parameter tree `pt`. * by a corresponding value already stored in the parameter tree `pt`.
*/ */
static std::string replaceVariable(Dune::ParameterTree const& pt, std::string input); static std::string replaceVariable(Dune::ParameterTree const& pt, std::string const& input);
/// \brief Evaluate an expression. NOTE: currently not implemented /// \brief Evaluate an expression. NOTE: currently not implemented
/** /**
* Evaluates expressions of the form $(expression) in the `input` * Evaluates expressions of the form $(expression) in the `input`
**/ **/
static std::string replaceExpression(Dune::ParameterTree const& pt, std::string input); static std::string replaceExpression(Dune::ParameterTree const& pt, std::string const& input);
}; };
} // end namespace AMDiS } // end namespace AMDiS
...@@ -33,7 +33,7 @@ namespace AMDiS { ...@@ -33,7 +33,7 @@ namespace AMDiS {
Marker() {} Marker() {}
/// Constructor. /// Constructor.
Marker(std::string name, std::string component, Estimates const& est, Marker(std::string const& name, std::string const& component, Estimates const& est,
std::shared_ptr<Grid> const& grid) std::shared_ptr<Grid> const& grid)
: name_(name) : name_(name)
, component_(component) , component_(component)
...@@ -41,10 +41,10 @@ namespace AMDiS { ...@@ -41,10 +41,10 @@ namespace AMDiS {
, est_(est) , est_(est)
, maximumMarking_(false) , maximumMarking_(false)
{ {
Parameters::get(name_ + "->p", p_); Parameters::get(name + "->p", p_);
Parameters::get(name_ + "->info", info_); Parameters::get(name + "->info", info_);
Parameters::get(name_ + "->max refinement level", maxRefineLevel_); Parameters::get(name + "->max refinement level", maxRefineLevel_);
Parameters::get(name_ + "->min refinement level", minRefineLevel_); Parameters::get(name + "->min refinement level", minRefineLevel_);
} }
/// destructor /// destructor
...@@ -106,13 +106,13 @@ namespace AMDiS { ...@@ -106,13 +106,13 @@ namespace AMDiS {
} }
/// Returns \ref name of the Marker /// Returns \ref name of the Marker
std::string getName() const std::string const& getName() const
{ {
return name_; return name_;
} }
/// Creates a scalar marker depending on the strategy set in parameters. /// Creates a scalar marker depending on the strategy set in parameters.
static std::shared_ptr<Marker<Traits> > createMarker(std::string name, std::string component, Estimates const& est, std::shared_ptr<Grid> const& grid);