https://mooseframework.inl.gov
ElementsIntersectedByPlane.C
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 // Moose includes
12 
13 #include "libmesh/plane.h"
14 #include "libmesh/point.h"
15 #include "libmesh/mesh.h"
16 #include "libmesh/elem.h"
17 
18 #include <algorithm>
19 
20 using namespace libMesh;
21 
22 namespace Moose
23 {
24 
25 void
27  const MeshBase & mesh,
28  std::vector<const Elem *> & intersected_elems)
29 {
30  // Loop over all elements to find elements intersected by the plane
31  for (const auto & elem : mesh.element_ptr_range())
32  {
33  bool intersected = false;
34 
35  // Check whether the first node of this element is below or above the plane
36  const Node & node0 = elem->node_ref(0);
37  bool node0_above_plane = plane.above_surface(node0);
38 
39  // Loop over the rest of the nodes and check if any node is on the other side of the plane
40  for (unsigned int i = 1; i < elem->n_nodes(); ++i)
41  {
42  const Node & node = elem->node_ref(i);
43 
44  bool node_above_plane = plane.above_surface(node);
45  if (node0_above_plane != node_above_plane)
46  intersected = true;
47  }
48 
49  if (intersected)
50  intersected_elems.push_back(elem);
51  }
52 }
53 
54 void
56  const Point & normal,
57  const MeshBase & mesh,
58  std::vector<const Elem *> & intersected_elems)
59 {
60  // Make sure our list is clear
61  intersected_elems.clear();
62 
63  // Create plane from point and normal:
64  libMesh::Plane plane(p0, normal);
65 
66  // Find 'em!
67  findElementsIntersectedByPlane(plane, mesh, intersected_elems);
68 }
69 
70 void
72  const Point & p1,
73  const Point & p2,
74  const MeshBase & mesh,
75  std::vector<const Elem *> & intersected_elems)
76 {
77  // Make sure our list is clear
78  intersected_elems.clear();
79 
80  // Create plane from three points:
81  libMesh::Plane plane(p0, p1, p2);
82 
83  // Find 'em!
84  findElementsIntersectedByPlane(plane, mesh, intersected_elems);
85 }
86 }
void elementsIntersectedByPlane(const libMesh::Point &p0, const libMesh::Point &normal, const libMesh::MeshBase &mesh, std::vector< const libMesh::Elem *> &intersected_elems)
Find all of the elements intersected by a plane.
MeshBase & mesh
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
virtual bool above_surface(const Point &p) const override
void findElementsIntersectedByPlane(const libMesh::Plane &plane, const MeshBase &mesh, std::vector< const Elem *> &intersected_elems)
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...