www.mooseframework.org
MeshSideSet.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 "MeshSideSet.h"
11 #include "MooseMesh.h"
12 
13 #include "libmesh/mesh_modification.h"
14 #include "libmesh/elem.h"
15 
16 registerMooseObject("MooseApp", MeshSideSet);
17 
18 template <>
21 {
23  params.addClassDescription("Add lower dimensional elements along the faces contained in a side "
24  "set to set up mixed dimensional problems");
25  params.addRequiredParam<std::vector<BoundaryName>>("boundaries",
26  "The name of the boundary to mesh");
28  "block_id", "Subdomain id to set for the new elements along the boundary");
29  params.addParam<SubdomainName>(
30  "block_name", "Subdomain name to set for the new elements along the boundary (optional)");
31  return params;
32 }
33 
35  : MeshModifier(parameters), _block_id(parameters.get<SubdomainID>("block_id"))
36 {
37 }
38 
39 void
41 {
42  // this modifier is not designed for working with distributed mesh
43  _mesh_ptr->errorIfDistributedMesh("MeshSideSet");
44 
45  // Reference the the libMesh::MeshBase
46  auto & mesh = _mesh_ptr->getMesh();
47  auto & boundary_info = mesh.get_boundary_info();
48 
49  // get IDs of all boundaries with which a new block is created
50  std::set<BoundaryID> mesh_boundary_ids;
51  if (isParamValid("boundaries"))
52  {
53  auto & boundary_names = getParam<std::vector<BoundaryName>>("boundaries");
54  for (auto & boundary_name : boundary_names)
55  mesh_boundary_ids.insert(_mesh_ptr->getBoundaryID(boundary_name));
56  }
57  else
58  mesh_boundary_ids = boundary_info.get_boundary_ids();
59 
61  for (auto it = _mesh_ptr->bndElemsBegin(); it != _mesh_ptr->bndElemsEnd(); ++it)
62  if (mesh_boundary_ids.count((*it)->_bnd_id) > 0)
63  {
64  Elem * elem = (*it)->_elem;
65  auto s = (*it)->_side;
66 
67  // build element from the side
68  std::unique_ptr<Elem> side(elem->build_side_ptr(s, false));
69  side->processor_id() = elem->processor_id();
70 
71  // Add the side set subdomain
72  Elem * new_elem = mesh.add_elem(side.release());
73  new_elem->subdomain_id() = _block_id;
74  }
75 
76  // Assign block name, if provided
77  if (isParamValid("block_name"))
78  mesh.subdomain_name(_block_id) = getParam<SubdomainName>("block_name");
79 }
virtual bnd_elem_iterator bndElemsEnd()
Definition: MooseMesh.C:884
registerMooseObject("MooseApp", MeshSideSet)
MeshSideSet(const InputParameters &parameters)
Definition: MeshSideSet.C:34
MeshModifiers are objects that can modify or add to an existing mesh.
Definition: MeshModifier.h:25
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual bnd_elem_iterator bndElemsBegin()
Return iterators to the beginning/end of the boundary elements list.
Definition: MooseMesh.C:876
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:68
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:2685
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
Definition: MeshSideSet.C:40
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2567
subdomain_id_type SubdomainID
void buildBndElemList()
Definition: MooseMesh.C:667
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...
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...
Add lower dimensional elements along the faces contained in a side set.
Definition: MeshSideSet.h:22
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:89
const SubdomainID _block_id
Block ID to assign to the region.
Definition: MeshSideSet.h:31
InputParameters validParams< MeshModifier >()
Definition: MeshModifier.C:15
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition: MooseMesh.C:1007
InputParameters validParams< MeshSideSet >()
Definition: MeshSideSet.C:20