www.mooseframework.org
ParsedSubdomainMeshModifier.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 
15 // MOOSE includes
17 #include "Conversion.h"
18 #include "MooseMesh.h"
19 
20 #include "libmesh/fparser_ad.hh"
21 
22 template <>
25 {
28  params.addRequiredParam<std::string>("combinatorial_geometry",
29  "Function expression encoding a combinatorial geometry");
30  params.addRequiredParam<SubdomainID>("block_id",
31  "Subdomain id to set for inside of the combinatorial");
32  params.addParam<SubdomainName>("block_name",
33  "Subdomain name to set for inside of the combinatorial");
34  params.addParam<std::vector<SubdomainID>>("excluded_subdomain_ids",
35  "A set of subdomain ids that will not changed even if "
36  "they are inside/outside the combinatorial geometry");
37  params.addParam<std::vector<std::string>>(
38  "constant_names", "Vector of constants used in the parsed function (use this for kB etc.)");
39  params.addParam<std::vector<std::string>>(
40  "constant_expressions",
41  "Vector of values for the constants in constant_names (can be an FParser expression)");
42  params.addClassDescription("MeshModifier that uses a parsed expression (combinatorial_geometry) "
43  "to determine if an element (aka its centroid) is inside the "
44  "combinatorial geometry and "
45  "assigns a new block id.");
46  return params;
47 }
48 
50  : MeshModifier(parameters),
51  FunctionParserUtils(parameters),
52  _function(parameters.get<std::string>("combinatorial_geometry")),
53  _block_id(parameters.get<SubdomainID>("block_id")),
54  _excluded_ids(parameters.get<std::vector<SubdomainID>>("excluded_subdomain_ids"))
55 {
56  // base function object
58 
59  // set FParser internal feature flags
61 
62  // add the constant expressions
64  getParam<std::vector<std::string>>("constant_names"),
65  getParam<std::vector<std::string>>("constant_expressions"));
66 
67  // parse function
68  if (_func_F->Parse(_function, "x,y,z") >= 0)
69  mooseError("Invalid function\n",
70  _function,
71  "\nin ParsedSubdomainMeshModifier ",
72  name(),
73  ".\n",
74  _func_F->ErrorMsg());
75 
76  _func_params.resize(3);
77 }
78 
79 void
81 {
82  // Check that we have access to the mesh
83  if (!_mesh_ptr)
84  mooseError(
85  "_mesh_ptr must be initialized before calling ParsedSubdomainMeshModifier::modify()");
86 
87  // Loop over the elements
88  for (const auto & elem : _mesh_ptr->getMesh().active_element_ptr_range())
89  {
90  _func_params[0] = elem->centroid()(0);
91  _func_params[1] = elem->centroid()(1);
92  _func_params[2] = elem->centroid()(2);
93  bool contains = evaluate(_func_F);
94 
95  if (contains &&
96  std::find(_excluded_ids.begin(), _excluded_ids.end(), elem->subdomain_id()) ==
97  _excluded_ids.end())
98  elem->subdomain_id() = _block_id;
99  }
100 
101  // Assign block name, if provided
102  if (isParamValid("block_name"))
103  _mesh_ptr->getMesh().subdomain_name(_block_id) = getParam<SubdomainName>("block_name");
104 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
Real evaluate(ADFunctionPtr &)
Evaluate FParser object and check EvalError.
void addFParserConstants(ADFunctionPtr &parser, const std::vector< std::string > &constant_names, const std::vector< std::string > &constant_expressions)
add constants (which can be complex expressions) to the parser object
FunctionParserADBase< Real > ADFunction
Shorthand for an autodiff function parser object.
const SubdomainID _block_id
Block ID to assign to the region.
subdomain_id_type SubdomainID
Definition: MooseTypes.h:77
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
MeshModifiers are objects that can modify or add to an existing mesh.
Definition: MeshModifier.h:31
ADFunctionPtr _func_F
function parser object describing the combinatorial geometry
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::shared_ptr< ADFunction > ADFunctionPtr
Shorthand for an smart pointer to an autodiff function parser object.
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...
MooseMesh * _mesh_ptr
Pointer to the mesh.
Definition: MeshModifier.h:74
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2408
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:67
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseObject.h:122
const std::vector< SubdomainID > _excluded_ids
A list of excluded subdomain ids that will not be changed even if they are in the combinatorial geome...
InputParameters validParams< FunctionParserUtils >()
std::vector< Real > _func_params
Array to stage the parameters passed to the functions when calling Eval.
ParsedSubdomainMeshModifier(const InputParameters &parameters)
Class constructor.
void setParserFeatureFlags(ADFunctionPtr &)
apply input paramters to internal feature flags of the parser object
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
InputParameters validParams< ParsedSubdomainMeshModifier >()
const std::string _function
function expression
InputParameters validParams< MeshModifier >()
Definition: MeshModifier.C:20