16#include "libmesh/mesh_serializer.h"
17#include "libmesh/elem.h"
27 MooseEnum location(
"INSIDE OUTSIDE",
"INSIDE");
30 params.
addRequiredParam<MeshGeneratorName>(
"input",
"The mesh we want to modify.");
31 params.
addRequiredParam<MeshGeneratorName>(
"manifold",
"The mesh defining a closed manifold.");
32 params.
addRequiredParam<subdomain_id_type>(
"block_id",
"Subdomain id to assign.");
33 params.
addParam<SubdomainName>(
"block_name",
"Optional subdomain name to assign.");
35 "location", location,
"Control whether the manifold interior or exterior is tagged.");
36 params.
addParam<std::vector<SubdomainName>>(
"restricted_subdomains",
37 "Only reset subdomain ID for given subdomains.");
41 "surface_tolerance>0",
42 "Absolute geometric tolerance used for manifold validation and near-surface classification. "
43 "Choose this relative to the STL length scale and expected coordinate noise.");
45 "Changes the subdomain ID of elements whose vertex-average point lies inside or outside a "
46 "closed manifold defined by surface mesh.");
52 _input(getMesh(
"input")),
53 _manifold(getMesh(
"manifold")),
54 _location(parameters.get<
MooseEnum>(
"location")),
55 _block_id(parameters.get<subdomain_id_type>(
"block_id")),
56 _has_restriction(isParamValid(
"restricted_subdomains")),
57 _surface_tolerance(getParam<Real>(
"surface_tolerance"))
59#if LIBMESH_DOF_ID_BYTES != 8
61 "moose", 32898,
"ManifoldSubdomainGenerator currently only works with 64-bit DoF IDs");
65std::unique_ptr<MeshBase>
68 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
69 std::unique_ptr<MeshBase> manifold_mesh = std::move(
_manifold);
72 if (
mesh->mesh_dimension() != 3)
73 paramError(
"input",
"Only 3D meshes are supported.");
76 if (!manifold_mesh->is_prepared())
77 manifold_mesh->prepare_for_use();
81 if (*(manifold_mesh->elem_dimensions().begin()) != 2 ||
82 *(manifold_mesh->elem_dimensions().rbegin()) != 2)
83 paramError(
"manifold",
"Only 2D meshes are supported.");
85 std::set<SubdomainID> restricted_ids;
89 const auto & names = getParam<std::vector<SubdomainName>>(
"restricted_subdomains");
90 for (
const auto &
name : names)
93 paramError(
"restricted_subdomains",
"The block '",
name,
"' was not found in the mesh");
102 " already exists on the input mesh. Elements outside the closed manifold that are "
103 "already assigned to this block will remain unchanged.");
111 for (
const auto & elem :
mesh->active_element_ptr_range())
118 const bool contains = manifold.
contains(elem->vertex_average());
125 mesh->set_subdomain_name(
_block_id, getParam<SubdomainName>(
"block_name"),
true);
128 mesh->unset_has_cached_elem_data();
129 return dynamic_pointer_cast<MeshBase>(
mesh);
registerMooseObject("MooseApp", ManifoldSubdomainGenerator)
MeshGenerator for defining a subdomain based on whether element vertex averages lie within a closed m...
std::unique_ptr< MeshBase > generate() override
Apply STL-based subdomain tagging using element vertex averages as the query points.
const bool _has_restriction
Whether retagging is limited to a subset of existing subdomains.
const subdomain_id_type _block_id
Target subdomain identifier to assign.
static InputParameters validParams()
Declare the input parameters for STL-based subdomain assignment.
ManifoldSubdomainGenerator(const InputParameters ¶meters)
Construct the mesh generator from user input.
const MooseEnum _location
Whether to tag the interior or exterior of the STL manifold.
std::unique_ptr< MeshBase > & _manifold
Surface mesh that defines the closed manifold.
const Real _surface_tolerance
Absolute tolerance used by the manifold classifier; choose relative to geometry scale/noise.
std::unique_ptr< MeshBase > & _input
Input mesh to modify in place.
MeshGenerators are objects that can modify or add to an existing mesh.
static InputParameters validParams()
void mooseDocumentedError(const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
const std::string & name() const
Get the name of the class.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
void mooseInfo(Args &&... args) const
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Utility for querying point containment against a closed triangulated surface mesh.
bool contains(const Point &point) const
bool hasSubdomainName(const MeshBase &input_mesh, const SubdomainName &name)
Whether a particular subdomain name exists in the mesh.
bool hasSubdomainID(const MeshBase &input_mesh, const SubdomainID &id)
Whether a particular subdomain ID exists in the mesh.
SubdomainID getSubdomainID(const SubdomainName &subdomain_name, const MeshBase &mesh)
Gets the subdomain ID associated with the given SubdomainName.