14#include "libmesh/type_vector.h"
15#include "libmesh/point.h"
16#include "libmesh/elem.h"
17#include "libmesh/fe_base.h"
18#include "libmesh/quadrature_gauss.h"
28 "Removes elements lying \"near\" another mesh. The proximity is examined by the distance "
30 "the element's centroid to the faces of elements of the \"proximity_mesh\"");
32 "Mesh providing the deletion criterion");
36 "The distance from the centroid of elements in the 'input' mesh to elements in the "
37 "'proximity_mesh' under which they are marked for deletion");
39 options_order.assign(CONSTANT);
42 "Order of the face quadrature used to find the nearest face in the "
43 "'proximity_mesh'. Default is CONSTANT");
50 _proximity_mesh(getMesh(
"proximity_mesh")),
51 _distance(getParam<Real>(
"distance"))
55std::unique_ptr<MeshBase>
60 _pl->enable_out_of_mesh_mode();
65 std::vector<Point> all_side_qps;
66 const auto & order = getParam<MooseEnum>(
"side_order");
71 const auto dim = elem->dim();
72 for (
const auto side_i : make_range(elem->n_sides()))
75 if (elem->neighbor_ptr(side_i))
77 const std::unique_ptr<const Elem> face = elem->build_side_ptr(side_i);
78 std::unique_ptr<libMesh::FEBase> fe(
81 fe->attach_quadrature_rule(&qface);
82 const auto & qpoints = fe->get_xyz();
83 fe->reinit(elem, side_i);
84 all_side_qps.insert(all_side_qps.end(), qpoints.begin(), qpoints.end());
87 mooseAssert(!all_side_qps.empty(),
"Should have found side Qps");
88 _kd_tree = std::make_unique<KDTree>(all_side_qps, 1);
101 const auto delete_due_to_point = [
this](
const Point & pt) ->
bool
108 std::vector<Real> distance_sqr(2);
109 std::vector<std::size_t> return_indices(2);
110 _kd_tree->neighborSearch(pt, 1, return_indices, distance_sqr);
112 distance_sqr.empty() ? std::numeric_limits<Real>::max() : std::sqrt(distance_sqr[0]);
118 const auto centroid = elem->vertex_average();
119 if (delete_due_to_point(centroid))
123 for (
const auto & node : elem->node_ref_range())
124 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::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.
This class deletes elements from the mesh data structure after it has been generated or read but befo...
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)
Order stringToEnum< Order >(const std::string &s)
Real distance(const Point &p)