https://mooseframework.inl.gov
TerminateChainControl.C
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 #include "TerminateChainControl.h"
11 #include "FEProblemBase.h"
12 
14 
17 {
19 
20  params.addClassDescription(
21  "Terminates the simulation when a boolean chain control data has a certain value.");
22 
23  params.addRequiredParam<std::string>(
24  "input", "Boolean control data indicating if the simulation should be terminated");
25  params.addParam<bool>("terminate_on_true",
26  true,
27  "If set to 'true', termination occurs if the input has a value of 'true'; "
28  "else termination occurs if the input has a value of 'false'");
29  params.addParam<bool>("throw_error",
30  false,
31  "Flag to throw an error on termination; else just signal the problem to "
32  "terminate the solve.");
33  params.addRequiredParam<std::string>("termination_message",
34  "Message to use if termination occurs");
35  return params;
36 }
37 
39  : ChainControl(parameters),
40 
41  _terminate_on_true(getParam<bool>("terminate_on_true")),
42  _throw_error(getParam<bool>("throw_error")),
43  _termination_message(getParam<std::string>("termination_message")),
44  _input(getChainControlData<bool>("input"))
45 {
46 }
47 
48 void
50 {
52  terminate();
53 
54  if (!_terminate_on_true && !_input)
55  terminate();
56 }
57 
58 void
60 {
61  if (_throw_error)
63  else
64  {
65  _console << _termination_message << std::endl;
67  }
68 }
const bool _terminate_on_true
Whether to terminate on true or false.
registerMooseObject("MooseApp", TerminateChainControl)
const bool _throw_error
Flag to throw an error if the terminate condition is met.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
const std::string & _termination_message
Message to use if termination occurs.
virtual void terminateSolve()
Allow objects to request clean termination of the solve.
Definition: Problem.h:37
static InputParameters validParams()
Definition: ChainControl.C:14
TerminateChainControl(const InputParameters &parameters)
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this object.
Definition: Control.h:74
virtual void execute() override
Execute the control.
static InputParameters validParams()
const bool & _input
The control data that indicates if the simulation should be terminated.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
Terminates the simulation when a boolean chain control data has a certain value.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
void terminate()
Performs termination.
Control that additionally provides the capability to produce/consume data values, to allow control op...
Definition: ChainControl.h:21