www.mooseframework.org
Terminator.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "libmesh/libmesh_config.h"
11 
12 #ifdef LIBMESH_HAVE_FPARSER
13 
14 #include "Terminator.h"
15 #include "MooseApp.h"
16 #include "Executioner.h"
17 
18 registerMooseObject("MooseApp", Terminator);
19 
20 template <>
23 {
25  params.addRequiredCustomTypeParam<std::string>(
26  "expression",
27  "FunctionExpression",
28  "FParser expression to process Postprocessor values into a boolean value. "
29  "Termination of the simulation occurs when this returns true.");
30  return params;
31 }
32 
34  : GeneralUserObject(parameters),
35  _pp_names(),
36  _pp_values(),
37  _expression(getParam<std::string>("expression")),
38  _fp()
39 {
40  // build the expression object
41  if (_fp.ParseAndDeduceVariables(_expression, _pp_names) >= 0)
42  mooseError(std::string("Invalid function\n" + _expression + "\nin Terminator.\n") +
43  _fp.ErrorMsg());
44 
45  _pp_num = _pp_names.size();
46  _pp_values.resize(_pp_num);
47 
48  // get all necessary postprocessors
49  for (unsigned int i = 0; i < _pp_num; ++i)
51 
52  _params = new Real[_pp_num];
53 }
54 
56 
57 void
59 {
60  // copy current Postprocessor values into the FParser parameter buffer
61  for (unsigned int i = 0; i < _pp_num; ++i)
62  _params[i] = *(_pp_values[i]);
63 
64  // request termination of the run in case the expression evaluates to true
65  if (_fp.Eval(_params) != 0)
67 }
68 #endif
virtual const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name)
Terminator(const InputParameters &parameters)
Definition: Terminator.C:33
registerMooseObject("MooseApp", Terminator)
InputParameters validParams< Terminator >()
Definition: Terminator.C:22
std::vector< std::string > _pp_names
Postprocessor names.
Definition: Terminator.h:57
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
InputParameters validParams< GeneralUserObject >()
std::string _expression
Definition: Terminator.h:65
std::vector< const PostprocessorValue * > _pp_values
Postprocessor values.
Definition: Terminator.h:63
virtual void terminateSolve()
Allow objects to request clean termination of the solve.
Definition: Problem.h:40
This Userobject requests termination of the current solve based on the values of Postprocessors (and ...
Definition: Terminator.h:44
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:141
Real * _params
Fparser parameter buffer.
Definition: Terminator.h:71
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...
virtual void execute() override
Execute method.
Definition: Terminator.C:58
virtual ~Terminator()
The Terminator DEFINITELY needs a destructor!
Definition: Terminator.C:55
FunctionParserBase< Real > _fp
Fparser object.
Definition: Terminator.h:68
unsigned int _pp_num
Definition: Terminator.h:60