24 "Constructs a KDTree and boundary elements from a pre-existing surface mesh. " 25 "The surface mesh is specified in the Mesh block.");
29 "The name of the surface mesh saved via the MeshGenerator's `save_mesh_as` parameter.");
35 "Maximum number of points allowed in a leaf node of the KDTree. " 36 "Smaller values yield deeper trees with faster queries but slower build times; " 37 "larger values result in shallower trees with faster builds but slower queries. " 38 "Benchmarking is recommended to find an optimal tradeoff for your use case.");
42 "check_watertightness",
44 "Check if the mesh is watertight. If false, the mesh may not be suitable for In-Out tests.");
50 "Whether to build a kd-tree or not. If false, the kd-tree will not be built, " 51 "and the mesh will be used directly for queries.");
58 _leaf_max_size(getParam<
int>(
"leaf_max_size")),
59 _bnd_mesh_name(getParam<
std::string>(
"surface_mesh")),
60 _check_watertightness(getParam<bool>(
"check_watertightness")),
61 _build_kd_tree(getParam<bool>(
"build_kd_tree")),
62 _dim_embedding_mesh(_fe_problem.
mesh().dimension() )
73 const auto expected_dim_embedding_mesh =
_mesh->mesh_dimension() + 1;
75 if (!
_mesh->is_replicated())
77 "The mesh is distributed. Please use a serial mesh for SBMSurfaceMeshBuilder, which is " 78 "important for our In-Out test later.");
83 ") does not match the expected mesh dimension (",
84 expected_dim_embedding_mesh,
87 const std::size_t num_elems =
_mesh->n_elem();
93 for (
auto elem_it =
_mesh->active_elements_begin(); elem_it !=
_mesh->active_elements_end();
96 const Elem * elem = *elem_it;
98 const auto centroid = elem->vertex_average();
102 if (elem->type() ==
EDGE2)
104 else if (elem->type() ==
TRI3)
107 mooseError(
"Unsupported element type in SBMSurfaceMeshBuilder::initialSetup()");
119 mooseInfo(
"The mesh is not watertight. It may not be suitable for In-Out tests.");
121 mooseInfo(
"The mesh is watertight. It is suitable for In-Out tests.");
129 _mesh->active_element_ptr_range().begin(),
_mesh->active_element_ptr_range().end()));
135 mooseAssert(
_kd_tree,
"KDTree not built; callers must guard with hasKDTree() first.");
139 const std::vector<std::unique_ptr<SBMBndElementBase>> &
145 const std::vector<Point> &
void mooseInfo(Args &&... args) const
std::vector< Point > _centroids
The centroids of the elements in the boundary mesh are stored in a vector of Points. The sequence is the same as in _boundary_elements.
virtual void initialSetup() override
static InputParameters validParams()
SBMSurfaceMeshBuilder(const InputParameters ¶meters)
bool checkWatertightness() const
Checks whether the boundary mesh is "closed" – i.e.
registerMooseObject("ShiftedBoundaryMethodApp", SBMSurfaceMeshBuilder)
const std::string _bnd_mesh_name
The name of a mesh saved via MeshGenerator save_mesh_as parameter.
bool checkWatertightnessFromRawElems(const std::vector< const Elem *> &bd_elements)
KDTree & getKDTree() const
Returns a mutable reference because KDTree::neighborSearch is non-const (nanoflann's knnSearch thread...
std::vector< std::unique_ptr< SBMBndElementBase > > _boundary_elements
The boundary elements are stored in a vector of unique pointers to SBMBndElementBase.
const std::vector< Point > & getCentroids() const
Get the centroids of the boundary elements.
const std::vector< std::unique_ptr< SBMBndElementBase > > & getBoundaryElements() const
Get the SBM boundary elements.
const int _leaf_max_size
Configures KDTree leaf node size for performance tuning.
const unsigned int _dim_embedding_mesh
The dimension of the embedding mesh (2D or 3D).
const bool _build_kd_tree
whether we want to build a kd-tree or not
std::unique_ptr< MeshBase > _mesh
Holds the mesh to ensure boundary element pointers remain valid.
void mooseError(Args &&... args) const
MeshGeneratorSystem & getMeshGeneratorSystem()
std::unique_ptr< KDTree > _kd_tree
The KDTree is constructed using the centroids of the elements in the boundary mesh.
const bool _check_watertightness
The flag to check the watertightness of the mesh.
void ErrorVector unsigned int
static InputParameters validParams()