https://mooseframework.inl.gov
TriangleManifold.h
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 
10 #pragma once
11 
12 #include "MooseTypes.h"
13 
14 #include "libmesh/bounding_box.h"
15 #include "libmesh/face_tri3.h"
16 #include "libmesh/mesh_tet_interface.h"
17 
18 #include <iosfwd>
19 #include <memory>
20 #include <cstdint>
21 #include <string>
22 #include <unordered_map>
23 #include <vector>
24 
45 {
46 public:
56  TriangleManifold(MeshBase & mesh, const Real surface_tolerance);
57 
61  bool contains(const Point & point) const;
62 
66  const libMesh::BoundingBox & boundingBox() const { return _bounding_box; };
67 
71  std::size_t numTriangles() const { return _mesh.n_active_elem(); }
72 
73 private:
81  enum class RayIntersection
82  {
83  Miss,
84  Hit,
85  Ambiguous
86  };
87 
89  void finalize();
90 
92  void buildCandidateGrid();
93 
95  bool pointInsideBoundingBox(const Point & point) const;
96 
98  bool pointOnSurface(const Point & point) const;
99 
101  RayIntersection rayIntersectsTriangle(const Point & point, const libMesh::Elem & tri) const;
102 
104  bool containsBySolidAngle(const Point & point) const;
105 
107  std::vector<dof_id_type> rayCandidates(const Point & point) const;
108 
110  std::size_t _num_y_cells = 1;
111 
113  std::size_t _num_z_cells = 1;
114 
116  Real _y_min = 0.0;
117 
119  Real _z_min = 0.0;
120 
123 
126 
128  std::unordered_map<dof_id_type, std::vector<dof_id_type>> _ray_grid;
129 
130  MeshBase & _mesh;
131 
134 
137 
139  const std::unique_ptr<libMesh::PointLocatorBase> _point_locator;
140 };
bool containsBySolidAngle(const Point &point) const
Robust fallback containment query based on accumulated solid angle.
const std::unique_ptr< libMesh::PointLocatorBase > _point_locator
Pre-built point locator for fast proximity-to-surface detection.
Real _z_min
Minimum global z coordinate used to map query points into yz-grid bins.
Real _z_cell_size
Width of one yz-grid cell in the z direction.
Real _y_cell_size
Width of one yz-grid cell in the y direction.
RayIntersection
Result of intersecting the positive x-direction ray with a triangle.
bool pointOnSurface(const Point &point) const
Detect whether a query point lies on or extremely near the manifold surface.
MeshBase & mesh
Real _y_min
Minimum global y coordinate used to map query points into yz-grid bins.
const Real _surface_tolerance
Absolute tolerance used throughout validation and geometric classification.
std::size_t _num_z_cells
Number of yz-grid bins in the z direction.
const libMesh::BoundingBox _bounding_box
Global bounding box of the transformed manifold.
std::unordered_map< dof_id_type, std::vector< dof_id_type > > _ray_grid
Lookup from packed yz-grid cell index to triangles that could intersect the +x query ray...
void buildCandidateGrid()
Build the yz-plane lookup grid used to accelerate +x ray queries.
bool pointInsideBoundingBox(const Point &point) const
Cheap global bounding-box rejection for containment queries.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const libMesh::BoundingBox & boundingBox() const
std::size_t numTriangles() const
TriangleManifold(MeshBase &mesh, const Real surface_tolerance)
Build a manifold classifier from a prepared surface mesh.
std::vector< dof_id_type > rayCandidates(const Point &point) const
Get the subset of triangles whose yz extents may intersect the query ray.
Utility for querying point containment against a closed triangulated surface mesh.
RayIntersection rayIntersectsTriangle(const Point &point, const libMesh::Elem &tri) const
Intersect a positive x-direction ray with a single triangle.
bool contains(const Point &point) const
void finalize()
Complete post-parse validation and acceleration-structure setup.
std::size_t _num_y_cells
Number of yz-grid bins in the y direction.