www.mooseframework.org
ElementsIntersectedByPlane.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 // Moose includes
17 
18 #include "libmesh/plane.h"
19 #include "libmesh/point.h"
20 #include "libmesh/mesh.h"
21 #include "libmesh/elem.h"
22 
23 #include <algorithm>
24 
25 namespace Moose
26 {
27 
28 void
29 findElementsIntersectedByPlane(const Plane & plane,
30  const MeshBase & mesh,
31  std::vector<const Elem *> & intersected_elems)
32 {
33  // Loop over all elements to find elements intersected by the plane
34  for (const auto & elem : mesh.element_ptr_range())
35  {
36  bool intersected = false;
37 
38  // Check whether the first node of this element is below or above the plane
39  const Node & node0 = elem->node_ref(0);
40  bool node0_above_plane = plane.above_surface(node0);
41 
42  // Loop over the rest of the nodes and check if any node is on the other side of the plane
43  for (unsigned int i = 1; i < elem->n_nodes(); ++i)
44  {
45  const Node & node = elem->node_ref(i);
46 
47  bool node_above_plane = plane.above_surface(node);
48  if (node0_above_plane != node_above_plane)
49  intersected = true;
50  }
51 
52  if (intersected)
53  intersected_elems.push_back(elem);
54  }
55 }
56 
57 void
58 elementsIntersectedByPlane(const Point & p0,
59  const Point & normal,
60  const MeshBase & mesh,
61  std::vector<const Elem *> & intersected_elems)
62 {
63  // Make sure our list is clear
64  intersected_elems.clear();
65 
66  // Create plane from point and normal:
67  Plane plane(p0, normal);
68 
69  // Find 'em!
70  findElementsIntersectedByPlane(plane, mesh, intersected_elems);
71 }
72 
73 void
74 elementsIntersectedByPlane(const Point & p0,
75  const Point & p1,
76  const Point & p2,
77  const MeshBase & mesh,
78  std::vector<const Elem *> & intersected_elems)
79 {
80  // Make sure our list is clear
81  intersected_elems.clear();
82 
83  // Create plane from three points:
84  Plane plane(p0, p1, p2);
85 
86  // Find 'em!
87  findElementsIntersectedByPlane(plane, mesh, intersected_elems);
88 }
89 }
void elementsIntersectedByPlane(const Point &p0, const Point &normal, const MeshBase &mesh, std::vector< const Elem * > &intersected_elems)
Find all of the elements intersected by a plane.
Definition: Moose.h:84
void findElementsIntersectedByPlane(const Plane &plane, const MeshBase &mesh, std::vector< const Elem * > &intersected_elems)