https://mooseframework.inl.gov
ParsedElementDeletionGenerator.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 
11 
13 
16 {
19 
20  params.addClassDescription(
21  "Removes elements such that the parsed expression is evaluated as strictly positive. "
22  "The parameters of the parsed expression can be the X,Y,Z coordinates of the "
23  "element vertex average (must be 'x','y','z' in the expression), the element volume "
24  "(must be 'volume' in the expression) and the element id ('id' in the expression).");
25  params.addRequiredParam<ParsedFunctionExpression>(
26  "expression", "Expression to evaluate to decide whether an element should be deleted");
27  params.addParam<std::vector<std::string>>(
28  "constant_names", {}, "Vector of constants used in the parsed function");
29  params.addParam<std::vector<std::string>>(
30  "constant_expressions",
31  {},
32  "Vector of values for the constants in constant_names (can be an FParser expression)");
33  return params;
34 }
35 
37  : ElementDeletionGeneratorBase(parameters), FunctionParserUtils<false>(parameters)
38 {
39  // Create parsed function
40  _function = std::make_shared<SymFunction>();
42  getParam<ParsedFunctionExpression>("expression"),
43  "x,y,z,volume,id",
44  getParam<std::vector<std::string>>("constant_names"),
45  getParam<std::vector<std::string>>("constant_expressions"),
46  comm());
47 
48  _func_params.resize(5);
49 }
50 
51 bool
53 {
54  const auto vertex_average = elem->vertex_average();
55  for (const auto i : make_range(3))
56  _func_params[i] = vertex_average(i);
57  _func_params[3] = elem->volume();
58  _func_params[4] = elem->id();
59 
60  return evaluate(_function, "expression") > 0;
61 }
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
virtual bool shouldDelete(const Elem *elem) override
Method that returns a Boolean indicating whether an element should be removed from the mesh...
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseBase.h:384
This class deletes elements from the mesh data structure after it has been generated or read but befo...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const Parallel::Communicator & comm() const
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...
ParsedElementDeletionGenerator(const InputParameters &parameters)
registerMooseObject("MooseApp", ParsedElementDeletionGenerator)
void parsedFunctionSetup(SymFunctionPtr &function, const std::string &expression, const std::string &variables, const std::vector< std::string > &constant_names, const std::vector< std::string > &constant_expressions, const libMesh::Parallel::Communicator &comm) const
Performs setup steps on a SymFunction.
Deletes elements based on the evaluation of a parsed expression, involving the coordinates of their v...
std::vector< GenericReal< is_ad > > _func_params
Array to stage the parameters passed to the functions when calling Eval.
IntRange< T > make_range(T beg, T end)
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...
static InputParameters validParams()
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...