Line data Source code
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 11 : #include "ElementsIntersectedByPlane.h" 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 26 33 : findElementsIntersectedByPlane(const libMesh::Plane & plane, 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 24453 : for (const auto & elem : mesh.element_ptr_range()) 32 : { 33 12210 : bool intersected = false; 34 : 35 : // Check whether the first node of this element is below or above the plane 36 12210 : const Node & node0 = elem->node_ref(0); 37 12210 : 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 92620 : for (unsigned int i = 1; i < elem->n_nodes(); ++i) 41 : { 42 80410 : const Node & node = elem->node_ref(i); 43 : 44 80410 : bool node_above_plane = plane.above_surface(node); 45 80410 : if (node0_above_plane != node_above_plane) 46 8558 : intersected = true; 47 : } 48 : 49 12210 : if (intersected) 50 2310 : intersected_elems.push_back(elem); 51 33 : } 52 33 : } 53 : 54 : void 55 33 : elementsIntersectedByPlane(const Point & p0, 56 : const Point & normal, 57 : const MeshBase & mesh, 58 : std::vector<const Elem *> & intersected_elems) 59 : { 60 : // Make sure our list is clear 61 33 : intersected_elems.clear(); 62 : 63 : // Create plane from point and normal: 64 33 : libMesh::Plane plane(p0, normal); 65 : 66 : // Find 'em! 67 33 : findElementsIntersectedByPlane(plane, mesh, intersected_elems); 68 33 : } 69 : 70 : void 71 0 : elementsIntersectedByPlane(const Point & p0, 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 0 : intersected_elems.clear(); 79 : 80 : // Create plane from three points: 81 0 : libMesh::Plane plane(p0, p1, p2); 82 : 83 : // Find 'em! 84 0 : findElementsIntersectedByPlane(plane, mesh, intersected_elems); 85 0 : } 86 : }