www.mooseframework.org
Terminator.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 #include "Terminator.h"
15 #include "MooseApp.h"
16 #include "Executioner.h"
17 
18 template <>
21 {
23  params.addRequiredCustomTypeParam<std::string>(
24  "expression",
25  "FunctionExpression",
26  "FParser expression to process Postprocessor values into a boolean value. "
27  "Termination of the simulation occurs when this returns true.");
28  return params;
29 }
30 
32  : GeneralUserObject(parameters),
33  _pp_names(),
34  _pp_values(),
35  _expression(getParam<std::string>("expression")),
36  _fp()
37 {
38  // build the expression object
39  if (_fp.ParseAndDeduceVariables(_expression, _pp_names) >= 0)
40  mooseError(std::string("Invalid function\n" + _expression + "\nin Terminator.\n") +
41  _fp.ErrorMsg());
42 
43  _pp_num = _pp_names.size();
44  _pp_values.resize(_pp_num);
45 
46  // get all necessary postprocessors
47  for (unsigned int i = 0; i < _pp_num; ++i)
49 
50  _params = new Real[_pp_num];
51 }
52 
54 
55 void
57 {
58  // copy current Postprocessor values into the FParser parameter buffer
59  for (unsigned int i = 0; i < _pp_num; ++i)
60  _params[i] = *(_pp_values[i]);
61 
62  // request termination of the run in case the expression evaluates to true
63  if (_fp.Eval(_params) != 0)
65 }
virtual const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name)
Terminator(const InputParameters &parameters)
Definition: Terminator.C:31
InputParameters validParams< Terminator >()
Definition: Terminator.C:20
std::vector< std::string > _pp_names
Postprocessor names.
Definition: Terminator.h:58
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters validParams< GeneralUserObject >()
std::string _expression
Definition: Terminator.h:66
std::vector< const PostprocessorValue * > _pp_values
Postprocessor values.
Definition: Terminator.h:64
virtual void terminateSolve()
Allow objects to request clean termination of the solve.
Definition: Problem.h:45
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:149
Real * _params
Fparser parameter buffer.
Definition: Terminator.h:72
void addRequiredCustomTypeParam(const std::string &name, const std::string &custom_type, const std::string &doc_string)
These methods add an option parameter and with a customer type to the InputParameters object...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
virtual void execute() override
Execute method.
Definition: Terminator.C:56
virtual ~Terminator()
The Terminator DEFINITELY needs a destructor!
Definition: Terminator.C:53
FunctionParserBase< Real > _fp
Fparser object.
Definition: Terminator.h:69
unsigned int _pp_num
Definition: Terminator.h:61