7 #ifndef READUCT_TASK_H_
8 #define READUCT_TASK_H_
13 #include <yaml-cpp/yaml.h>
30 using SystemsMap = std::map<std::string, std::shared_ptr<Core::Calculator>>;
32 static std::shared_ptr<Core::Calculator> copyCalculator(SystemsMap& systems,
const std::string&
name,
33 const std::string& taskName) {
34 const auto findIter = systems.find(name);
35 if (findIter == systems.end()) {
36 throw std::runtime_error(
"System name '" + name +
"' is missing in " + taskName);
38 return findIter->second->clone();
47 Task(std::vector<std::string>
input, std::vector<std::string>
output, std::shared_ptr<Core::Log> logger =
nullptr)
48 : _input(std::move(input)), _output(std::move(output)), _logger(std::move(logger)) {
50 _logger = std::make_shared<Core::Log>();
54 throw std::runtime_error(
"No input systems specified!");
58 virtual ~
Task() =
default;
64 virtual std::string
name()
const = 0;
77 observers = {})
const = 0;
82 const std::vector<std::string>&
input()
const {
89 const std::vector<std::string>&
output()
const {
96 if (_input.size() > 1) {
98 <<
" Warning: More than one input system was specified. Only taking first and ignoring all others.\n";
105 if (_output.size() > 1) {
107 <<
" Warning: More than one output system was specified. Only taking first and ignoring all others.\n";
112 bool stopOnError =
true;
113 if (taskSettings.valueExists(
"allow_unconverged")) {
114 _logger->warning <<
" The option 'allow_unconverged' is deprecated.\n"
115 <<
" It has been replaced with 'stop_on_error',\n"
116 <<
" which is now available for all tasks and is defaulted to 'true'.\n\n";
117 stopOnError = !taskSettings.extract(
"allow_unconverged",
false);
119 return taskSettings.extract(
"stop_on_error", stopOnError);
122 static std::string falseTaskSettingsErrorMessage(
const std::string& name) {
123 return " You gave Task settings for the " + name +
",\n" +
" but the only possible setting for this task, are the\n" +
124 " 'stop_on_error' option to control whether ReaDuct fails\n" +
125 " with a failed calculation or simply returns false\n" +
126 " and the 'silent_stdout_calculator' option to control whether\n"
127 " the standard output of the calculator should be printed.\n"
128 " You might want to specify the settings you put into the task settings\n" +
129 " in the systems section.";
133 const std::vector<std::string> _input;
134 const std::vector<std::string> _output;
135 std::shared_ptr<Core::Log> _logger;
141 #endif // READUCT_TASK_H_
void warningIfMultipleOutputsGiven() const
Warn if more than one output system was specified.
Definition: Task.h:104
const std::vector< std::string > & input() const
Getter for the expected names of the input systems.
Definition: Task.h:82
Task(std::vector< std::string > input, std::vector< std::string > output, std::shared_ptr< Core::Log > logger=nullptr)
Construct a new Task.
Definition: Task.h:47
virtual std::string name() const =0
Getter for the tasks name.
virtual bool run(SystemsMap &systems, Utils::UniversalSettings::ValueCollection taskSettings, bool test=false, std::vector< std::function< void(const int &, const Utils::AtomCollection &, const Utils::Results &, const std::string &)>> observers={}) const =0
Executes the actual task represented by this class.
void warningIfMultipleInputsGiven() const
Warn if more than one input system was specified.
Definition: Task.h:95
const std::vector< std::string > & output() const
Getter for the names of the output systems generated by this task.
Definition: Task.h:89
The base class for all tasks in Readuct.
Definition: Task.h:28