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