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