www.mooseframework.org
ParsedAddSideset.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
16 #include "ParsedAddSideset.h"
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<BoundaryName>("new_sideset_name", "The name of the new sideset");
31  params.addParam<std::vector<SubdomainID>>(
32  "included_subdomain_ids",
33  "A set of subdomain ids whose sides will be included in the new sidesets");
34  params.addParam<Point>(
35  "normal",
36  Point(),
37  "If provided specifies the normal vector on sides that are added to the new ");
38  params.addParam<std::vector<std::string>>(
39  "constant_names", "Vector of constants used in the parsed function (use this for kB etc.)");
40  params.addParam<std::vector<std::string>>(
41  "constant_expressions",
42  "Vector of values for the constants in constant_names (can be an FParser expression)");
43  params.addClassDescription("A MeshModifier that adds element's sides to a sideset if the "
44  "centroid satisfies the combinatorial_geometry expression, (and "
45  "optionally) "
46  "if one of the side's elements is in included_subdomain_ids and if it "
47  "features the correct normal.");
48  return params;
49 }
50 
52  : AddSideSetsBase(parameters),
53  FunctionParserUtils(parameters),
54  _function(parameters.get<std::string>("combinatorial_geometry")),
55  _sideset_name(getParam<BoundaryName>("new_sideset_name")),
56  _check_subdomains(isParamValid("included_subdomain_ids")),
57  _check_normal(parameters.isParamSetByUser("normal")),
58  _included_ids(_check_subdomains
59  ? parameters.get<std::vector<SubdomainID>>("included_subdomain_ids")
60  : std::vector<SubdomainID>()),
61  _normal(getParam<Point>("normal"))
62 {
63  // base function object
65 
66  // set FParser internal feature flags
68 
69  // add the constant expressions
71  getParam<std::vector<std::string>>("constant_names"),
72  getParam<std::vector<std::string>>("constant_expressions"));
73 
74  // parse function
75  if (_func_F->Parse(_function, "x,y,z") >= 0)
76  mooseError("Invalid function\n",
77  _function,
78  "\nin ParsedAddSideset ",
79  name(),
80  ".\n",
81  _func_F->ErrorMsg());
82 
83  _func_params.resize(3);
84 }
85 
86 void
88 {
89  // this mesh modifier works only on replicated meshes
90  _mesh_ptr->errorIfDistributedMesh("ParsedAddSideset");
91 
92  setup();
93 
94  MeshBase & mesh = _mesh_ptr->getMesh();
95 
96  // Get a reference to our BoundaryInfo object for later use
97  BoundaryInfo & boundary_info = mesh.get_boundary_info();
98 
99  // Get the BoundaryIDs from the mesh
100  std::vector<BoundaryID> boundary_ids = _mesh_ptr->getBoundaryIDs({_sideset_name}, true);
101  mooseAssert(boundary_ids.size() == 1, "Length of boundary_ids should be one");
102 
103  for (const auto & elem : mesh.active_element_ptr_range())
104  {
105  SubdomainID curr_subdomain = elem->subdomain_id();
106 
107  // check if the element is included
108  if (_check_subdomains &&
109  std::find(_included_ids.begin(), _included_ids.end(), curr_subdomain) ==
110  _included_ids.end())
111  continue;
112 
113  for (unsigned int side = 0; side < elem->n_sides(); ++side)
114  {
115  _fe_face->reinit(elem, side);
116  const std::vector<Point> & normals = _fe_face->get_normals();
117 
118  // check normal if requested
119  if (_check_normal && std::abs(1.0 - _normal * normals[0]) > _variance)
120  continue;
121 
122  // check expression
123  std::unique_ptr<Elem> curr_side = elem->side(side);
124  _func_params[0] = curr_side->centroid()(0);
125  _func_params[1] = curr_side->centroid()(1);
126  _func_params[2] = curr_side->centroid()(2);
127  if (evaluate(_func_F))
128  boundary_info.add_side(elem, side, boundary_ids[0]);
129  }
130  }
131  finalize();
132  boundary_info.sideset_name(boundary_ids[0]) = _sideset_name;
133  boundary_info.nodeset_name(boundary_ids[0]) = _sideset_name;
134 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
ADFunctionPtr _func_F
function parser object describing the combinatorial geometry
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
BoundaryName _sideset_name
name of the new sideset
FunctionParserADBase< Real > ADFunction
Shorthand for an autodiff function parser object.
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
subdomain_id_type SubdomainID
Definition: MooseTypes.h:77
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
Returns a vector of boundary IDs for the requested element on the requested side. ...
Definition: MooseMesh.C:1951
std::unique_ptr< FEBase > _fe_face
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters validParams< ParsedAddSideset >()
std::shared_ptr< ADFunction > ADFunctionPtr
Shorthand for an smart pointer to an autodiff function parser object.
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:2473
void finalize()
This method finalizes the object, setting names back in the boundary_info object and releasing memory...
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:2355
bool _check_subdomains
whether to check subdomain ids when adding sides or not
ParsedAddSideset(const InputParameters &parameters)
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseObject.h:122
std::vector< SubdomainID > _included_ids
A list of included subdomain ids that the side has to be part of.
InputParameters validParams< AddSideSetsBase >()
bool _check_normal
whether to check normals when adding sides or not
Point _normal
A normal vector that (if provided) is compared against side&#39;s normals.
InputParameters validParams< FunctionParserUtils >()
std::vector< Real > _func_params
Array to stage the parameters passed to the functions when calling Eval.
void setParserFeatureFlags(ADFunctionPtr &)
apply input paramters to internal feature flags of the parser object
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
std::string _function
function expression
void setup()
This method is used to construct the FE object so we can compute normals of faces.