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

replaced string arguments by reference

parent f126815d
......@@ -31,7 +31,7 @@ int main(int argc, char** argv)
AdaptInfo adaptInfo("adapt");
double* invTau = probInstat.getInvTau();
auto* invTau = probInstat.getInvTau();
auto opTimeLhs = makeOperator(tag::test_trial{}, std::ref(*invTau));
prob.addMatrixOperator(opTimeLhs, 0, 0);
......
......@@ -6,7 +6,7 @@
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
Dune::MPIHelper& mpiHelper = Dune::MPIHelper::instance(argc, argv);
......@@ -14,10 +14,8 @@ namespace AMDiS
Parameters::clearData();
if (initFileName == "") {
if (argc > 1)
Parameters::init(argv[1]);
else
error_exit("No init file specified!\n");
test_exit(argc > 1, "No init file specified!\n");
Parameters::init(argv[1]);
} else {
Parameters::init(initFileName);
}
......
......@@ -12,7 +12,7 @@
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();
......
......@@ -15,12 +15,12 @@ namespace AMDiS
{
public:
/// Constructor
AdaptBase(std::string name,
AdaptBase(std::string const& name,
ProblemIterationInterface* problemIteration,
AdaptInfo& adaptInfo,
ProblemTimeInterface* problemTime = nullptr,
AdaptInfo* initialAdaptInfo = nullptr)
: name_(std::move(name))
: name_(name)
, problemIteration_(problemIteration)
, adaptInfo_(adaptInfo)
, problemTime_(problemTime)
......@@ -37,7 +37,7 @@ namespace AMDiS
virtual int adapt() = 0;
/// Returns \ref name
std::string getName() const
std::string const& getName() const
{
return name_;
}
......
......@@ -9,7 +9,7 @@
namespace AMDiS
{
AdaptInfo::ScalContent::ScalContent(std::string prefix)
AdaptInfo::ScalContent::ScalContent(std::string const& prefix)
{
Parameters::get(prefix + "->tolerance", spaceTolerance);
Parameters::get(prefix + "->time tolerance", timeTolerance);
......@@ -25,22 +25,22 @@ namespace AMDiS
}
AdaptInfo::AdaptInfo(std::string name)
: name_(std::move(name))
AdaptInfo::AdaptInfo(std::string const& name)
: name_(name)
{
// init();
Parameters::get(name_ + "->start time", startTime);
Parameters::get(name + "->start time", startTime);
time = startTime;
Parameters::get(name_ + "->timestep", timestep);
Parameters::get(name_ + "->end time", endTime);
Parameters::get(name_ + "->max iteration", maxSpaceIteration);
Parameters::get(name_ + "->max timestep iteration", maxTimestepIteration);
Parameters::get(name_ + "->max time iteration", maxTimeIteration);
Parameters::get(name_ + "->min timestep", minTimestep);
Parameters::get(name_ + "->max timestep", maxTimestep);
Parameters::get(name_ + "->number of timesteps", nTimesteps);
Parameters::get(name_ + "->time tolerance", globalTimeTolerance);
Parameters::get(name + "->timestep", timestep);
Parameters::get(name + "->end time", endTime);
Parameters::get(name + "->max iteration", maxSpaceIteration);
Parameters::get(name + "->max timestep iteration", maxTimestepIteration);
Parameters::get(name + "->max time iteration", maxTimeIteration);
Parameters::get(name + "->min timestep", minTimestep);
Parameters::get(name + "->max timestep", maxTimestep);
Parameters::get(name + "->number of timesteps", nTimesteps);
Parameters::get(name + "->time tolerance", globalTimeTolerance);
}
......
......@@ -37,7 +37,7 @@ namespace AMDiS
{
public:
/// Constructor.
explicit ScalContent(std::string prefix);
explicit ScalContent(std::string const& prefix);
/// Sum of all error estimates
double est_sum = 0.0;
......@@ -75,7 +75,7 @@ namespace AMDiS
public:
/// Constructor.
explicit AdaptInfo(std::string name);
explicit AdaptInfo(std::string const& name);
/// Destructor.
virtual ~AdaptInfo() = default;
......@@ -468,7 +468,7 @@ namespace AMDiS
}
/// Gets \ref &time
double* getTimePtr()
double const* getTimePtr() const
{
return &time;
}
......@@ -538,7 +538,7 @@ namespace AMDiS
}
/// Gets \ref &timestep
double* getTimestepPtr()
double const* getTimestepPtr() const
{
return &timestep;
}
......
......@@ -10,12 +10,12 @@
namespace AMDiS
{
AdaptInstationary::AdaptInstationary(std::string name,
AdaptInstationary::AdaptInstationary(std::string const& name,
ProblemIterationInterface& problemIteration,
AdaptInfo& adaptInfo,
ProblemTimeInterface& problemTime,
AdaptInfo& initialAdaptInfo)
: AdaptBase(std::move(name), &problemIteration, adaptInfo, &problemTime, &initialAdaptInfo)
: AdaptBase(name, &problemIteration, adaptInfo, &problemTime, &initialAdaptInfo)
{
Parameters::get(name_ + "->strategy", strategy_);
Parameters::get(name_ + "->time delta 1", timeDelta1_);
......
......@@ -25,7 +25,7 @@ namespace AMDiS
public:
/// Creates a AdaptInstationary object with the given name for the time
/// dependent problem problemInstat.
AdaptInstationary(std::string name,
AdaptInstationary(std::string const& name,
ProblemIterationInterface& problemStat,
AdaptInfo& info,
ProblemTimeInterface& problemInstat,
......
......@@ -8,10 +8,10 @@
namespace AMDiS {
AdaptStationary::AdaptStationary(std::string name,
AdaptStationary::AdaptStationary(std::string const& name,
ProblemIterationInterface& problemIteration,
AdaptInfo& adaptInfo)
: AdaptBase(std::move(name), &problemIteration, adaptInfo)
: AdaptBase(name, &problemIteration, adaptInfo)
{}
......
......@@ -30,7 +30,7 @@ namespace AMDiS
{
public:
/// Creates a AdaptStationary object with given name.
AdaptStationary(std::string name,
AdaptStationary(std::string const& name,
ProblemIterationInterface& problemIteration,
AdaptInfo& adaptInfo);
......
......@@ -60,7 +60,7 @@ namespace AMDiS
public:
/// Constructor.
FileWriter(std::string baseName,
FileWriter(std::string const& baseName,
Vector const& dofvector)
: FileWriterInterface(baseName)
, dofvector_(dofvector)
......
......@@ -20,14 +20,14 @@ namespace AMDiS
// }
// }
void Initfile::init(std::string in)
void Initfile::init(std::string const& in)
{
singlett().read(in);
singlett().getInternalParameters();
}
void Initfile::read(std::string fn, bool /*force*/)
void Initfile::read(std::string const& fn, bool /*force*/)
{
InitfileParser::readInitfile(fn, pt_);
}
......@@ -35,20 +35,12 @@ void Initfile::read(std::string fn, bool /*force*/)
void Initfile::getInternalParameters()
{
int val = 0;
get("level of information", val);
msgInfo = val;
get("level of information", msgInfo_);
get("parameter information", paramInfo_);
get("break on missing tag", breakOnMissingTag_);
val = 1;
get("parameter information", val);
paramInfo = val;
val = 0;
get("break on missing tag", val);
breakOnMissingTag = val;
if (msgInfo == 0)
paramInfo = 0;
if (msgInfo_ == 0)
paramInfo_ = 0;
}
......
......@@ -13,7 +13,7 @@ namespace AMDiS
{
public:
/// 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
/**
......@@ -23,7 +23,7 @@ namespace AMDiS
* Does not thrown an exception if something goes wrong!
**/
template <class T>
static Dune::Std::optional<T> get(std::string key)
static Dune::Std::optional<T> get(std::string const& key)
{
try {
return pt().get<T>(key);
......@@ -42,7 +42,7 @@ namespace AMDiS
* \param value: The default value and result.
**/
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);
}
......@@ -50,7 +50,7 @@ namespace AMDiS
/// Returns specified info level
static int getMsgInfo()
{
return singlett().msgInfo;
return singlett().msgInfo_;
}
/// print all data in singleton to std::cout
......@@ -75,15 +75,15 @@ namespace AMDiS
}
/// Fill an parametr-tree from a file with filename fn
void read(std::string fn, bool force = false);
void write(std::string fn);
void read(std::string const& fn, bool force = false);
void write(std::string const& fn);
/// read standard values for output and information of parameter-values
void getInternalParameters();
int msgInfo = 0;
int paramInfo = 1;
int breakOnMissingTag = 0;
int msgInfo_ = 0;
int paramInfo_ = 1;
bool breakOnMissingTag_ = false;
/// ParameterTree to read/store parameter values
Dune::ParameterTree pt_;
......
......@@ -6,10 +6,9 @@
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),
"init-file '{}' cannot be opened for reading", fn);
test_exit(filesystem::exists(fn), "Init-file '{}' cannot be opened for reading", fn);
// read file if its not parsed already
auto ins = includeList().insert(fn);
......@@ -37,8 +36,7 @@ void InitfileParser::readInitfile(std::istream& in, Dune::ParameterTree& pt, boo
{
// parse line and extract map: tag->value
std::size_t pos = sw.find(':');
if (pos == std::string::npos)
throw std::runtime_error("cannot find the delimiter ':' in line '" + sw + "'");
test_exit(pos != std::string::npos, "Cannot find the delimiter ':' in line '{}'", sw);
std::string name = sw.substr(0, pos);
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
epos = sw.find_first_of(delimiter, pos);
fn = sw.substr(pos, epos - pos);
if (sw[epos]!=c)
throw std::runtime_error("filename in #include not terminated by " + std::to_string(c));
test_exit(sw[epos]==c, "Filename in #include not terminated by {}.", std::to_string(c));
break;
default:
throw std::runtime_error("no filename given for #include");
error_exit("No filename given for #include");
}
readInitfile(fn, pt, overwrite);
......@@ -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 allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
......@@ -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
// otherwise throw tagNotFound exception
if (!pt.hasKey(varName))
throw std::runtime_error("required tag '" + varName + "' for variable substitution not found");
test_exit(pt.hasKey(varName),
"Required tag '{}' for variable substitution not found", varName);
std::string varParam = pt[varName];
......@@ -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
std::string whitespaces = " \t\r\f";
......
......@@ -30,7 +30,7 @@ namespace AMDiS
static void readInitfile(std::istream& in, Dune::ParameterTree& pt, bool overwrite);
/// 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:
/// Provide a list of already read files. This is necessary to not double include the same file.
......@@ -45,13 +45,13 @@ namespace AMDiS
* Replaces variables of the form ${variablename} or $variablename in the `input`
* 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
/**
* 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
......@@ -33,7 +33,7 @@ namespace AMDiS {
Marker() {}
/// 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)
: name_(name)
, component_(component)
......@@ -41,10 +41,10 @@ namespace AMDiS {
, est_(est)
, maximumMarking_(false)
{
Parameters::get(name_ + "->p", p_);
Parameters::get(name_ + "->info", info_);
Parameters::get(name_ + "->max refinement level", maxRefineLevel_);
Parameters::get(name_ + "->min refinement level", minRefineLevel_);
Parameters::get(name + "->p", p_);
Parameters::get(name + "->info", info_);
Parameters::get(name + "->max refinement level", maxRefineLevel_);
Parameters::get(name + "->min refinement level", minRefineLevel_);
}
/// destructor
......@@ -106,13 +106,13 @@ namespace AMDiS {
}
/// Returns \ref name of the Marker
std::string getName() const
std::string const& getName() const
{
return name_;
}
/// 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);
static std::unique_ptr<Marker<Traits> > createMarker(std::string const& name, std::string const& component, Estimates const& est, std::shared_ptr<Grid> const& grid);
protected:
/// Name of the scalar marker.
......@@ -186,9 +186,9 @@ namespace AMDiS {
public:
/// Constructor.
GRMarker(std::string name, std::string component, Estimates const& est,
GRMarker(std::string const& name, std::string component, Estimates const& est,
std::shared_ptr<Grid> const& grid)
: Marker<Traits>(std::move(name), std::move(component), est, grid)
: Marker<Traits>(name, std::move(component), est, grid)
{}
/// Implementation of Marker::markElement().
......@@ -217,12 +217,12 @@ namespace AMDiS {
public:
/// Constructor.
MSMarker(std::string name, std::string component, Estimates const& est,
MSMarker(std::string const& name, std::string component, Estimates const& est,
std::shared_ptr<Grid> const& grid)
: Super{std::move(name), std::move(component), est, grid}
: Super{name, std::move(component), est, grid}
{
Parameters::get(this->name_ + "->MSGamma", msGamma_);
Parameters::get(this->name_ + "->MSGammaC", msGammaC_);
Parameters::get(name + "->MSGamma", msGamma_);
Parameters::get(name + "->MSGammaC", msGammaC_);
}
/// Implementation of Marker::initMarking().
......@@ -254,12 +254,12 @@ namespace AMDiS {
public:
/// Constructor.
ESMarker(std::string name, std::string component, Estimates const& est,
ESMarker(std::string const& name, std::string component, Estimates const& est,
std::shared_ptr<Grid> const& grid)
: Super{std::move(name), std::move(component), est, grid}
: Super{name, std::move(component), est, grid}
{
Parameters::get(this->name_ + "->ESTheta", esTheta_);
Parameters::get(this->name_ + "->ESThetaC", esThetaC_);
Parameters::get(name + "->ESTheta", esTheta_);
Parameters::get(name + "->ESThetaC", esThetaC_);
}
/// Implementation of Marker::initMarking().
......@@ -292,13 +292,13 @@ namespace AMDiS {
public:
/// Constructor.
GERSMarker(std::string name, std::string component, Estimates const& est,
GERSMarker(std::string const& name, std::string component, Estimates const& est,
std::shared_ptr<Grid> const& grid)
: Super{std::move(name), std::move(component), est, grid}
: Super{name, std::move(component), est, grid}
{
Parameters::get(this->name_ + "->GERSThetaStar", gersThetaStar_);
Parameters::get(this->name_ + "->GERSNu", gersNu_);
Parameters::get(this->name_ + "->GERSThetaC", gersThetaC_);
Parameters::get(name + "->GERSThetaStar", gersThetaStar_);
Parameters::get(name + "->GERSNu", gersNu_);
Parameters::get(name + "->GERSThetaC", gersThetaC_);
}
/// Implementation of Marker::markGrid().
......
......@@ -3,37 +3,37 @@
namespace AMDiS {
template <class Traits>
std::shared_ptr<Marker<Traits> > Marker<Traits>::createMarker(std::string name, std::string component, Estimates const& est, std::shared_ptr<Grid> const& grid)
std::unique_ptr<Marker<Traits> > Marker<Traits>::
createMarker(std::string const& name, std::string const& component,
Estimates const& est, std::shared_ptr<Grid> const& grid)
{
int strategy = 0;
Parameters::get(name + "->strategy", strategy);
std::shared_ptr<Marker<Traits> > marker;
switch (strategy) {
case 0: // no refinement/coarsening
break;
case 1:
msg("Creating global refinement (GR) marker");
marker = std::make_shared<GRMarker<Traits> >(name, component, est, grid);
return std::make_unique<GRMarker<Traits> >(name, component, est, grid);
break;
case 2:
msg("Creating maximum strategy (MS) marker");
marker = std::make_shared<MSMarker<Traits> >(name, component, est, grid);
return std::make_unique<MSMarker<Traits> >(name, component, est, grid);
break;
case 3:
msg("Creating equidistribution strategy (ES) marker");
marker = std::make_shared<ESMarker<Traits> >(name, component, est, grid);
return std::make_unique<ESMarker<Traits> >(name, component, est, grid);
break;
case 4:
msg("Creating guaranteed error reduction strategy (GERS) marker");
marker = std::make_shared<GERSMarker<Traits> >(name, component, est, grid);
return std::make_unique<GERSMarker<Traits> >(name, component, est, grid);
break;
default:
error_exit("invalid strategy");
}
return marker;
return {};
}
......
......@@ -70,7 +70,7 @@ namespace AMDiS
template <class Grid>
struct MeshCreator
{
static std::unique_ptr<Grid> create(std::string meshName)
static std::unique_ptr<Grid> create(std::string const& meshName)
{
error_exit("Creator not yet implemented for this mesh type.");
return {};
......@@ -83,7 +83,7 @@ namespace AMDiS
{
using Grid = Dune::AlbertaGrid<dim, dimworld>;
static std::unique_ptr<Grid> create(std::string meshName)
static std::unique_ptr<Grid> create(std::string const& meshName)
{
std::string macro_filename = "";
Parameters::get(meshName + "->macro file name", macro_filename);
......@@ -103,31 +103,30 @@ namespace AMDiS
{
using Grid = Dune::UGGrid<dim>;
static std::unique_ptr<Grid> create(std::string meshName)
static std::unique_ptr<Grid> create(std::string const& meshName)
{
std::string filename = "";
Parameters::get(meshName + "->macro file name", filename);
if (!filename.empty()) {
filesystem::path fn(filename);
auto ext = fn.extension();
test_exit(!filename.empty(),
"Construction of UGGrid without filename not yet implemented!");
filesystem::path fn(filename);
auto ext = fn.extension();
if (ext == ".msh") {
Dune::GmshReader<Grid> reader;
return std::unique_ptr<Grid>{reader.read(filename)};
}
#if HAVE_ALBERTA
if (ext == ".1d" || ext == ".2d" || ext == ".3d") {
Dune::GridFactory<Grid> factory;
Dune::AlbertaReader<Grid> reader;
reader.readGrid(filename, factory);
return std::unique_ptr<Grid>{factory.createGrid()};
}
#endif
if (ext == ".msh") {
Dune::GmshReader<Grid> reader;
return std::unique_ptr<Grid>{reader.read(filename)};
}
} else {
error_exit("Construction of UGGrid without filename not yet implemented!");
else if (ext == ".1d" || ext == ".2d" || ext == ".3d") {
Dune::GridFactory<Grid> factory;