Commit fedf63ac authored by Jan Oliver Oelerich's avatar Jan Oliver Oelerich

Some bugs fixed of the stemsalabim binary

parent 4ce4514c
......@@ -36,6 +36,14 @@ using namespace std;
using namespace stemsalabim;
Params::Params() {
_params.push_back(std::make_shared<ParamInterface>("random_seed", "simulation", "The random seed of the run"));
_params.push_back(std::make_shared<ParamInterface>("title", "simulation", "Title of the simulation"));
}
void Params::readParamsFromString(const string &prms) {
try {
......@@ -49,6 +57,11 @@ void Params::readParamsFromString(const string &prms) {
output::error("Parse error at %s:%d - %s", pex.getFile(), pex.getLine(), pex.getError());
}
// for(auto & prm: _params) {
// auto path = output::fmt("%s.%s", prm->group(), prm->name());
// _cfg.lookupValue(path, prm.val());
// }
//Setting &root = _cfg.getRoot();
_cfg.lookupValue("application.random_seed", _random_seed);
......@@ -248,9 +261,14 @@ void Params::broadcast(int rank) {
}
void Params::readParamsFromNCFile() {
readParamsFromNCFile(_param_file);
}
void Params::readParamsFromNCFile(const std::string & path) {
NCFile f(_param_file, false, true);
NCFile f(path, false, true);
auto g = f.group("params");
_init_from_ncfile = true;
......
#include <utility>
/*
* STEMsalabim: Magical STEM image simulations
*
......@@ -33,6 +35,40 @@
namespace stemsalabim {
class ParamInterface {
public:
ParamInterface(std::string name, std::string group, std::string description)
: _name(std::move(name))
, _group(std::move(group))
, _description(std::move(description)) {}
const std::string &name() const {
return _name;
}
const std::string &group() const {
return _group;
}
const std::string &description() const {
return _description;
}
private:
std::string _name{""};
std::string _group{""};
std::string _description{""};
};
template<typename T>
class Param : public ParamInterface {
public:
private:
T _val;
};
/*!
* A singleton class containing all simulation parameters, which are collected from command line
* arguments and the input parameter file. In addition, it generates (if required) a random seed
......@@ -54,7 +90,7 @@ namespace stemsalabim {
*/
void initFromCLI(int argc, const char **argv);
void setCell(const std::shared_ptr<atomic::Cell> & cell) {
void setCell(const std::shared_ptr<atomic::Cell> &cell) {
_cell = cell;
}
......@@ -84,6 +120,13 @@ namespace stemsalabim {
return _param_file;
};
/*!
* Set the param file path.
*/
void setParamsFileName(const std::string & path) {
_param_file = path;
};
/*!
* Read the simulation parameters from a string with the contents of the parameters file.
* The file is not read in by the Param class itself to ensure that MPI processes other than the
......@@ -94,6 +137,7 @@ namespace stemsalabim {
/*!
* Read the simulation parameters from another NC file.
*/
void readParamsFromNCFile(const std::string & path);
void readParamsFromNCFile();
/*!
......@@ -493,7 +537,7 @@ namespace stemsalabim {
std::string _param_file{""};
private:
Params() = default;
Params();
std::string _command_line_arguments{""};
......@@ -569,10 +613,12 @@ namespace stemsalabim {
std::shared_ptr<atomic::Cell> _cell;
std::vector<std::shared_ptr<ParamInterface>> _params;
public:
Params(Params const &) = delete;
void operator=(Params const &) = delete;
void operator=(Params const &) = delete;
};
}
......
......@@ -197,7 +197,8 @@ void Simulation::run() {
output::fmt("Finished calculation of transmission functions in %s.\n",
output::humantime(algorithms::getTimeSince(t1))));
_io->generateTemporaryResultFile();
if(mpi_env.isMpi())
_io->generateTemporaryResultFile();
if(mpi_env.isMaster()) {
multisliceMaster(st);
......
......@@ -37,6 +37,8 @@
#include "utilities/Wave.hpp"
#include "classes/Simulation.hpp"
#include "utilities/initialize.hpp"
#include "classes/Params.hpp"
using namespace std;
using namespace stemsalabim;
......@@ -106,8 +108,10 @@ int main(int argc, const char **argv) {
initialize_input_file(argc, argv);
p.readParamsFromNCFile();
p.setCell(IO::initCrystalFromNCFile(p.paramsFileName()));
p.setParamsFileName(p.outputFilename());
p.readParamsFromNCFile(p.outputFilename());
p.setCell(IO::initCrystalFromNCFile(p.outputFilename()));
if(mpi_env.isMpi())
p.broadcast(mpi::Environment::MASTER);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment