7 #ifndef READUCT_TASK_H_
8 #define READUCT_TASK_H_
14 #include <yaml-cpp/yaml.h>
31 using SystemsMap = std::map<std::string, std::shared_ptr<Core::Calculator>>;
33 static std::shared_ptr<Core::Calculator> copyCalculator(SystemsMap& systems,
const std::string&
name,
34 const std::string& taskName) {
35 const auto findIter = systems.find(name);
36 if (findIter == systems.end()) {
37 throw std::runtime_error(
"System name '" + name +
"' is missing in " + taskName);
39 auto calc = findIter->second->clone();
40 calc->results() = findIter->second->results();
50 Task(std::vector<std::string>
input, std::vector<std::string>
output, std::shared_ptr<Core::Log> logger =
nullptr)
51 : _input(std::move(input)), _output(std::move(output)), _logger(std::move(logger)) {
53 _logger = std::make_shared<Core::Log>();
57 throw std::runtime_error(
"No input systems specified!");
61 virtual ~
Task() =
default;
67 virtual std::string
name()
const = 0;
80 observers = {})
const = 0;
85 const std::vector<std::string>&
input()
const {
92 const std::vector<std::string>&
output()
const {
99 if (_input.size() > 1) {
101 <<
" Warning: More than one input system was specified. Only taking first and ignoring all others.\n";
108 if (_output.size() > 1) {
110 <<
" Warning: More than one output system was specified. Only taking first and ignoring all others.\n";
115 bool stopOnError =
true;
116 if (taskSettings.valueExists(
"allow_unconverged")) {
117 _logger->warning <<
" The option 'allow_unconverged' is deprecated.\n"
118 <<
" It has been replaced with 'stop_on_error',\n"
119 <<
" which is now available for all tasks and is defaulted to 'true'.\n\n";
120 stopOnError = !taskSettings.extract(
"allow_unconverged",
false);
122 return taskSettings.extract(
"stop_on_error", stopOnError);
125 static std::string falseTaskSettingsErrorMessage(
const std::string& name) {
126 return " You gave Task settings for the " + name +
",\n" +
" but the only possible setting for this task, are the\n" +
127 " 'stop_on_error' option to control whether ReaDuct fails\n" +
128 " with a failed calculation or simply returns false\n" +
129 " and the 'silent_stdout_calculator' option to control whether\n"
130 " the standard output of the calculator should be printed.\n"
131 " You might want to specify the settings you put into the task settings\n" +
132 " in the systems section.";
136 const std::vector<std::string> _input;
137 const std::vector<std::string> _output;
138 std::shared_ptr<Core::Log> _logger;
144 #endif // READUCT_TASK_H_
void warningIfMultipleOutputsGiven() const
Warn if more than one output system was specified.
Definition: Task.h:107
const std::vector< std::string > & input() const
Getter for the expected names of the input systems.
Definition: Task.h:85
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:50
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:98
const std::vector< std::string > & output() const
Getter for the names of the output systems generated by this task.
Definition: Task.h:92
The base class for all tasks in Readuct.
Definition: Task.h:29