15#include "libmesh/type_vector.h"
16#include "libmesh/point.h"
17#include "libmesh/elem.h"
18#include "libmesh/fe_base.h"
19#include "libmesh/quadrature_gauss.h"
29 "Removes elements lying \"near\" another mesh. The proximity is examined by the distance "
31 "the element's centroid to the faces of elements of the \"proximity_mesh\"");
32 params.
addParam<std::vector<SubdomainName>>(
35 "Subdomains from the input mesh that may have their elements deleted if they are close to "
36 "the proximity mesh");
38 "Mesh providing the deletion criterion");
42 "The distance from the centroid of elements in the 'input' mesh to elements in the "
43 "'proximity_mesh' under which they are marked for deletion");
45 options_order.assign(
"CONSTANT");
48 "Order of the face quadrature used to find the nearest face in the "
49 "'proximity_mesh'. Default is CONSTANT");
56 _blocks_included(getParam<
std::vector<SubdomainName>>(
"blocks_included")),
57 _proximity_mesh(getMesh(
"proximity_mesh")),
58 _distance(getParam<Real>(
"distance"))
62std::unique_ptr<MeshBase>
70 _pl->enable_out_of_mesh_mode();
75 std::vector<Point> all_side_qps;
76 const auto & order = getParam<MooseEnum>(
"side_order");
81 const auto dim = elem->dim();
82 for (
const auto side_i : make_range(elem->n_sides()))
85 if (elem->neighbor_ptr(side_i))
87 const std::unique_ptr<const Elem> face = elem->build_side_ptr(side_i);
88 std::unique_ptr<libMesh::FEBase> fe(
91 fe->attach_quadrature_rule(&qface);
92 const auto & qpoints = fe->get_xyz();
93 fe->reinit(elem, side_i);
94 all_side_qps.insert(all_side_qps.end(), qpoints.begin(), qpoints.end());
97 mooseAssert(!all_side_qps.empty(),
"Should have found side Qps");
98 _kd_tree = std::make_unique<KDTree>(all_side_qps, 1);
111 const auto delete_due_to_point = [
this](
const Point & pt) ->
bool
118 std::vector<Real> distance_sqr(2);
119 std::vector<std::size_t> return_indices(2);
120 _kd_tree->neighborSearch(pt, 1, return_indices, distance_sqr);
122 distance_sqr.empty() ? std::numeric_limits<Real>::max() : std::sqrt(distance_sqr[0]);
134 const auto centroid = elem->vertex_average();
135 if (delete_due_to_point(centroid))
139 for (
const auto & node : elem->node_ref_range())
140 if (delete_due_to_point(node))
registerMooseObject("MooseApp", DeleteElementsNearMeshGenerator)
Deletes elements close to another mesh.
std::unique_ptr< libMesh::PointLocatorBase > _pl
Point locator to weed out elements inside the proximity mesh.
static InputParameters validParams()
DeleteElementsNearMeshGenerator(const InputParameters ¶meters)
virtual bool shouldDelete(const Elem *elem) override
Method that returns a Boolean indicating whether an element should be removed from the mesh.
std::vector< SubdomainID > _blocks_included_ids
Subdomain IDs to include when deleting elements.
std::unique_ptr< MeshBase > & _proximity_mesh
Mesh used to define the proximity deletion criterion.
std::shared_ptr< KDTree > _kd_tree
KD Tree to find the nearest side Qp in the proximity mesh.
const Real _distance
Distance for deletion criterion.
virtual std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
const std::vector< SubdomainName > & _blocks_included
Subdomain names to include when deleting elements.
This class deletes elements from the mesh data structure after it has been generated or read but befo...
std::unique_ptr< MeshBase > & _input
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
static InputParameters validParams()
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
static MooseEnum getQuadratureOrderEnum()
Return the potential selections for the order of the quadrature, with an 'auto' default.
std::unique_ptr< FEGenericBase< Real > > build(const unsigned int dim, const FEType &fet)
std::vector< subdomain_id_type > getSubdomainIDs(const libMesh::MeshBase &mesh, const std::vector< SubdomainName > &subdomain_name)
Get the associated subdomainIDs for the subdomain names that are passed in.
Order stringToEnum< Order >(const std::string &s)
Real distance(const Point &p)