https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Executor.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "Executioner.h"
13#include "ExecutorInterface.h"
14
15#include <string>
16
17class Problem;
18class Executor;
19
27{
28public:
35 struct Result
36 {
37 Result() : converged(true), _name("NO_NAME") {}
38 Result(const std::string & name) : converged(true), _name(name) {}
39 Result(const MooseObject * obj) : converged(true), _name(obj->name()) {}
40
46 bool converged = true;
47
49 std::string reason;
50
56 std::map<std::string, Result> subs;
57
62 std::string
63 str(bool success_msg = false, const std::string & indent = "", const std::string & subname = "")
64 {
65 std::string s = indent + label(success_msg, subname) + "\n";
66 for (auto & entry : subs)
67 s += entry.second.str(success_msg, indent + " ", entry.first);
68 return s;
69 }
70
75 void pass(const std::string & msg, bool overwrite = false)
76 {
77 mooseAssert(converged || overwrite,
78 "cannot override nonconverged executioner result with a passing one");
79 ((void)(overwrite)); // avoid unused error due to assert
80 reason = msg;
81 converged = true;
82 }
83
86 void fail(const std::string & msg)
87 {
88 reason = msg;
89 converged = false;
90 }
91
97 bool record(const std::string & name, const Result & r)
98 {
99 subs[name] = r;
100 return r.convergedAll();
101 }
102
108 bool convergedAll() const
109 {
110 if (!converged)
111 return false;
112 for (auto & entry : subs)
113 if (!entry.second.convergedAll())
114 return false;
115 return true;
116 }
117
118 private:
119 std::string label(bool success_msg, const std::string & subname = "")
120 {
121 std::string state_str =
122 success_msg || !converged ? (std::string("(") + (converged ? "pass" : "FAIL") + ")") : "";
123 return subname + (subname.empty() ? "" : ":") + _name + state_str +
124 ((success_msg || !converged) && !reason.empty() ? ": " + reason : "");
125 }
126 std::string _name;
127 };
128
130
131 virtual ~Executor() {}
132
134
137 Result exec();
138
139 virtual void execute() override final {}
140
147 {
148 _result = Result(this);
149 return _result;
150 }
151
153 virtual bool lastSolveConverged() const override { return _result.convergedAll(); }
154
155protected:
160 virtual Result run() = 0;
161
170
171private:
175};
Executioners are objects that do the actual work of solving your problem.
Definition Executioner.h:37
Interface class for classes which interact with Postprocessors.
The Executor class directs the execution flow of simulations.
Definition Executor.h:27
virtual void execute() override final
Pure virtual execute function MUST be overridden by children classes.
Definition Executor.h:139
virtual ~Executor()
Definition Executor.h:131
Result _result
Stores the result representing the outcome from the run function.
Definition Executor.h:174
Result & newResult()
Executors need to return a Result object describing how execution went - rather than constructing Res...
Definition Executor.h:146
virtual bool lastSolveConverged() const override
Whether the executor and all its sub-executors passed / converged.
Definition Executor.h:153
static InputParameters validParams()
Definition Executor.C:17
ExecFlagType _end_flag
The execute-on flag to associate with the end of this executor's execution.
Definition Executor.h:169
ExecFlagType _begin_flag
The execute-on flag to associate with the beginning of this executor's execution.
Definition Executor.h:165
Result exec()
This is the main function for executors - this is how executors should invoke child/sub executors - b...
Definition Executor.C:42
virtual Result run()=0
This function contains the primary execution implementation for a executor.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
Class for containing MooseEnum item information.
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
Class that hold the whole problem being solved.
Definition Problem.h:20
This object tracks the success/failure state of the executor system as execution proceeds in a simula...
Definition Executor.h:36
Result(const MooseObject *obj)
Definition Executor.h:39
std::string str(bool success_msg=false, const std::string &indent="", const std::string &subname="")
Prints a full recursive output of this result object - including all descendant's results.
Definition Executor.h:63
std::string _name
Definition Executor.h:126
bool record(const std::string &name, const Result &r)
Records results from sub/internal executors in a executor's result.
Definition Executor.h:97
std::string reason
Optional message detailing why an executor passed or failed (i.e. failed to converge).
Definition Executor.h:49
void fail(const std::string &msg)
Marks the result as failing/unconverged with the given msg text describing detail about how things ra...
Definition Executor.h:86
void pass(const std::string &msg, bool overwrite=false)
Marks the result as passing/converged with the given msg text describing detail about how things ran.
Definition Executor.h:75
std::string label(bool success_msg, const std::string &subname="")
Definition Executor.h:119
std::map< std::string, Result > subs
Maps a name/label of a executor's internal/sub executors to the result object returned by running eac...
Definition Executor.h:56
bool convergedAll() const
Returns false if any single executor in the current hierarchy of results (i.e.
Definition Executor.h:108
Result(const std::string &name)
Definition Executor.h:38
bool converged
whether or not a executor ran its code successfully - only reports results from the executor itself.
Definition Executor.h:46