https://mooseframework.inl.gov
BoundaryLayerSubdomainGenerator.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 
11 #include "CastUniquePointer.h"
12 #include "MooseMeshUtils.h"
13 
14 #include "libmesh/elem.h"
15 
17 
20 {
22 
23  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
24  params.addClassDescription(
25  "Changes the subdomain ID of elements near the specified boundary(ies).");
26 
27  params.addRequiredParam<SubdomainName>(
28  "block_name", "Subdomain name to set for inside/outside the bounding box (optional)");
29  params.addParam<subdomain_id_type>("block_id",
30  "Subdomain id to set for inside/outside the bounding box");
31 
32  params.addParam<bool>("include_nodesets",
33  false,
34  "Whether to include nodesets in the boundaries. Nodesets are not sided so "
35  "elements on both sides of the nodesets will be included");
36  params.addRequiredParam<std::vector<BoundaryName>>("boundaries",
37  "Boundaries to add the layer next to");
38  return params;
39 }
40 
42  : MeshGenerator(parameters),
43  _input(getMesh("input")),
44  _new_block_name(getParam<SubdomainName>("block_name")),
45  _include_nodesets(getParam<bool>("include_nodesets"))
46 {
47 }
48 
49 std::unique_ptr<MeshBase>
51 {
52  std::unique_ptr<MeshBase> mesh = std::move(_input);
53 
54  // Get the next free block id
56 
57  // Get the ids for the boundaries
58  const auto boundary_ids = MooseMeshUtils::getBoundaryIDs(
59  *mesh, getParam<std::vector<BoundaryName>>("boundaries"), false);
60 
61  // Boundary info
62  const auto & boundary_info = mesh->get_boundary_info();
63 
64  // Loop over the elements
65  for (const auto & elem : mesh->element_ptr_range())
66  {
67  // Check all the sides for a boundary in the concerned list
68  bool next_to_a_boundary = false;
69  for (const auto side : elem->side_index_range())
70  for (const auto bid : boundary_ids)
71  if (boundary_info.has_boundary_id(elem, side, bid))
72  {
73  next_to_a_boundary = true;
74  goto out_loop_1;
75  }
76  out_loop_1:;
77 
78  // Check all the nodes in case the boundary is a nodeset
79  if (!next_to_a_boundary && _include_nodesets)
80  {
81  for (const auto node_index : elem->node_index_range())
82  for (const auto bid : boundary_ids)
83  if (boundary_info.has_boundary_id(elem->node_ptr(node_index), bid))
84  {
85  next_to_a_boundary = true;
86  goto out_loop_2;
87  }
88  out_loop_2:;
89  }
90 
91  if (next_to_a_boundary)
92  elem->subdomain_id() = _new_block_id;
93  }
94 
95  // Assign block name
96  mesh->subdomain_name(_new_block_id) = _new_block_name;
97 
98  mesh->set_isnt_prepared();
99  return dynamic_pointer_cast<MeshBase>(mesh);
100 }
const bool _include_nodesets
Whether to consider nodesets in the boundary proximity check.
subdomain_id_type _new_block_id
Block ID to assign to the boundary layer region.
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
MeshGenerator for defining a subdomain on the layer next to one or more boundaries.
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...
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
std::vector< BoundaryID > getBoundaryIDs(const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown, const std::set< BoundaryID > &mesh_boundary_ids)
Gets the boundary IDs with their names.
static InputParameters validParams()
Definition: MeshGenerator.C:23
const SubdomainName _new_block_name
Block name to assign to the boundary layer region.
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 optional parameter and a documentation string to the InputParameters object...
SubdomainID getNextFreeSubdomainID(MeshBase &input_mesh)
Checks input mesh and returns max(block ID) + 1, which represents a block ID that is not currently in...
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
registerMooseObject("MooseApp", BoundaryLayerSubdomainGenerator)
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32
BoundaryLayerSubdomainGenerator(const InputParameters &parameters)