Loading [MathJax]/extensions/tex2jax.js
www.mooseframework.org
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
MeshSideSetGenerator.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 "MeshSideSetGenerator.h"
11 #include "BndElement.h"
12 #include "CastUniquePointer.h"
13 
14 #include "libmesh/mesh_modification.h"
15 #include "libmesh/distributed_mesh.h"
16 #include "libmesh/elem.h"
17 
18 #include <typeinfo>
19 
21 
23 
26 {
28 
29  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
30  params.addClassDescription("Add lower dimensional elements along the faces contained in a side "
31  "set to set up mixed dimensional problems");
32  params.addRequiredParam<std::vector<BoundaryName>>("boundaries",
33  "The name of the boundary to mesh");
34  params.addRequiredParam<subdomain_id_type>(
35  "block_id", "Subdomain id to set for the new elements along the boundary");
36  params.addParam<SubdomainName>(
37  "block_name", "Subdomain name to set for the new elements along the boundary (optional)");
38 
39  return params;
40 }
41 
43  : MeshGenerator(parameters),
44  _input(getMesh("input")),
45  _block_id(parameters.get<subdomain_id_type>("block_id"))
46 {
47  if (typeid(_input).name() == typeid(std::unique_ptr<DistributedMesh>).name())
48  mooseError("MeshSideSetGenerator only works with ReplicatedMesh");
49 }
50 
51 std::unique_ptr<MeshBase>
53 {
54  std::unique_ptr<MeshBase> mesh = std::move(_input);
55 
56  auto & boundary_info = mesh->get_boundary_info();
57 
58  // get IDs of all boundaries with which a new block is created
59  std::set<boundary_id_type> mesh_boundary_ids;
60  if (isParamValid("boundaries"))
61  {
62  auto & boundary_names = getParam<std::vector<BoundaryName>>("boundaries");
63  for (auto & boundary_name : boundary_names)
64  mesh_boundary_ids.insert(boundary_info.get_id_by_name(boundary_name));
65  }
66  else
67  mesh_boundary_ids = boundary_info.get_boundary_ids();
68 
69  // Equivalent to MooseMesh::buildBndElemList()
70  auto bc_tuples = boundary_info.build_active_side_list();
71  int n = bc_tuples.size();
72  std::vector<std::unique_ptr<BndElement>> bnd_elems;
73  std::map<boundary_id_type, std::set<dof_id_type>> bnd_elem_ids;
74  bnd_elems.reserve(n);
75  for (const auto & t : bc_tuples)
76  {
77  auto elem_id = std::get<0>(t);
78  auto side_id = std::get<1>(t);
79  auto bc_id = std::get<2>(t);
80 
81  std::unique_ptr<BndElement> bndElem =
82  libmesh_make_unique<BndElement>(mesh->elem_ptr(elem_id), side_id, bc_id);
83  bnd_elems.push_back(std::move(bndElem));
84  bnd_elem_ids[bc_id].insert(elem_id);
85  }
86 
87  for (auto it = bnd_elems.begin(); it != bnd_elems.end(); ++it)
88  if (mesh_boundary_ids.count((*it)->_bnd_id) > 0)
89  {
90  Elem * elem = (*it)->_elem;
91  auto s = (*it)->_side;
92 
93  // build element from the side
94  std::unique_ptr<Elem> side(elem->build_side_ptr(s, false));
95  side->processor_id() = elem->processor_id();
96 
97  // Add the side set subdomain
98  Elem * new_elem = mesh->add_elem(side.release());
99  new_elem->subdomain_id() = _block_id;
100  }
101 
102  // Assign block name, if provided
103  if (isParamValid("block_name"))
104  mesh->subdomain_name(_block_id) = getParam<SubdomainName>("block_name");
105 
106  return dynamic_pointer_cast<MeshBase>(mesh);
107 }
MooseObject::mooseError
void mooseError(Args &&... args) const
Definition: MooseObject.h:141
MooseObject::isParamValid
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:100
MeshSideSetGenerator.h
defineLegacyParams
defineLegacyParams(MeshSideSetGenerator)
MeshGenerator
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32
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
MeshSideSetGenerator::generate
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
Definition: MeshSideSetGenerator.C:52
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
registerMooseObject
registerMooseObject("MooseApp", MeshSideSetGenerator)
MeshSideSetGenerator::_block_id
const subdomain_id_type _block_id
Block ID to assign to the region.
Definition: MeshSideSetGenerator.h:36
MeshSideSetGenerator::MeshSideSetGenerator
MeshSideSetGenerator(const InputParameters &parameters)
Definition: MeshSideSetGenerator.C:42
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
MeshSideSetGenerator
Add lower dimensional elements along the faces contained in a side set.
Definition: MeshSideSetGenerator.h:23
MeshSideSetGenerator::validParams
static InputParameters validParams()
Definition: MeshSideSetGenerator.C:25
MeshGenerator::validParams
static InputParameters validParams()
Constructor.
Definition: MeshGenerator.C:17
MeshSideSetGenerator::_input
std::unique_ptr< MeshBase > & _input
Definition: MeshSideSetGenerator.h:33
CastUniquePointer.h
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
BndElement.h
MooseObject::name
virtual const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:70
n
PetscInt n
Definition: PetscDMMoose.C:1504