https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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");
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
49std::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->set_subdomain_name(_new_block_id, _new_block_name, true);
97
98 mesh->unset_is_prepared();
99 return dynamic_pointer_cast<MeshBase>(mesh);
100}
registerMooseObject("MooseApp", BoundaryLayerSubdomainGenerator)
MeshGenerator for defining a subdomain on the layer next to one or more boundaries.
const SubdomainName _new_block_name
Block name to assign to the boundary layer region.
BoundaryLayerSubdomainGenerator(const InputParameters &parameters)
const bool _include_nodesets
Whether to consider nodesets in the boundary proximity check.
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
subdomain_id_type _new_block_id
Block ID to assign to the boundary layer region.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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...
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.
MeshGenerators are objects that can modify or add to an existing mesh.
static InputParameters validParams()
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition MooseBase.h:406
MeshBase & mesh
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.
SubdomainID getNextFreeSubdomainID(MeshBase &input_mesh)
Checks input mesh and returns max(block ID) + 1, which represents a block ID that is not currently in...