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