LCOV - code coverage report
Current view: top level - src/meshgenerators - PlaneDeletionGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 19 22 86.4 %
Date: 2025-07-17 01:28:37 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          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             : #include "PlaneDeletionGenerator.h"
      11             : 
      12             : #include "libmesh/type_vector.h"
      13             : #include "libmesh/point.h"
      14             : #include "libmesh/elem.h"
      15             : 
      16             : registerMooseObject("MooseApp", PlaneDeletionGenerator);
      17             : 
      18             : InputParameters
      19       14305 : PlaneDeletionGenerator::validParams()
      20             : {
      21       14305 :   InputParameters params = ElementDeletionGeneratorBase::validParams();
      22             : 
      23       14305 :   params.addClassDescription(
      24             :       "Removes elements lying 'above' the plane (in the direction of the normal).");
      25             : 
      26       14305 :   params.addRequiredParam<Point>("point", "The point that defines the plane");
      27       14305 :   params.addRequiredParam<RealVectorValue>("normal", "The normal that defines the plane");
      28             : 
      29       14305 :   return params;
      30           0 : }
      31             : 
      32          20 : PlaneDeletionGenerator::PlaneDeletionGenerator(const InputParameters & parameters)
      33             :   : ElementDeletionGeneratorBase(parameters),
      34          20 :     _point(getParam<Point>("point")),
      35          40 :     _normal(getParam<RealVectorValue>("normal"))
      36             : {
      37          20 :   if (!_normal.norm())
      38           0 :     paramError("normal", "Normal vector must have a size!");
      39             : 
      40             :   // Make sure it's a unit vector
      41          20 :   _normal /= _normal.norm();
      42          20 : }
      43             : 
      44             : bool
      45       18528 : PlaneDeletionGenerator::shouldDelete(const Elem * elem)
      46             : {
      47       18528 :   auto centroid = elem->vertex_average();
      48             : 
      49       18528 :   auto vec_from_plane_point = centroid - _point;
      50             : 
      51       18528 :   auto norm = vec_from_plane_point.norm();
      52             : 
      53             :   // If we _perfectly_ hit a centroid... default to deleting the element
      54       18528 :   if (!norm)
      55           0 :     return true;
      56             : 
      57             :   // Unitize it
      58       18528 :   vec_from_plane_point /= norm;
      59             : 
      60       18528 :   return vec_from_plane_point * _normal > 0;
      61             : }

Generated by: LCOV version 1.14