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 std::shared_ptr<Core::Calculator>(findIter->second->clone().release());
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 const std::vector<std::string>&
input()
const {
84 const std::vector<std::string>&
output()
const {
91 if (_input.size() > 1) {
93 <<
" Warning: More than one input system was specified. Only taking first and ignoring all others.\n";
100 if (_output.size() > 1) {
102 <<
" Warning: More than one output system was specified. Only taking first and ignoring all others.\n";
107 bool stopOnError =
true;
108 if (taskSettings.valueExists(
"allow_unconverged")) {
109 _logger->warning <<
" The option 'allow_unconverged' is deprecated.\n"
110 <<
" It has been replaced with 'stop_on_error',\n"
111 <<
" which is now available for all tasks and is defaulted to 'true'.\n\n";
112 stopOnError = !taskSettings.extract(
"allow_unconverged",
false);
114 return taskSettings.extract(
"stop_on_error", stopOnError);
117 static std::string falseTaskSettingsErrorMessage(
const std::string& name) {
118 return " You gave Task settings for the " + name +
",\n" +
" but the only possible setting for this task, are the\n" +
119 " 'stop_on_error' option to control whether ReaDuct fails\n" +
120 " with a failed calculation or simply returns false\n" +
121 " and the 'silent_stdout_calculator' option to control whether\n"
122 " the standard output of the calculator should be printed.\n"
123 " You might want to specify the settings you put into the task settings\n" +
124 " in the systems section.";
128 const std::vector<std::string> _input;
129 const std::vector<std::string> _output;
130 std::shared_ptr<Core::Log> _logger;
136 #endif // READUCT_TASK_H_
void warningIfMultipleOutputsGiven() const
Warn if more than one output system was specified.
Definition: Task.h:99
const std::vector< std::string > & input() const
Getter for the expected names of the input systems.
Definition: Task.h:77
virtual bool run(SystemsMap &systems, Utils::UniversalSettings::ValueCollection taskSettings, bool test=false) const =0
Executes the actual task represented by this class.
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.
void warningIfMultipleInputsGiven() const
Warn if more than one input system was specified.
Definition: Task.h:90
const std::vector< std::string > & output() const
Getter for the names of the output systems generated by this task.
Definition: Task.h:84
The base class for all tasks in Readuct.
Definition: Task.h:28