LCOV - code coverage report
Current view: top level - src/meshgenerators - PlaneDeletionGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 19 22 86.4 %
Date: 2025-08-08 20:01:16 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       14309 : PlaneDeletionGenerator::validParams()
      20             : {
      21       14309 :   InputParameters params = ElementDeletionGeneratorBase::validParams();
      22             : 
      23       14309 :   params.addClassDescription(
      24             :       "Removes elements lying 'above' the plane (in the direction of the normal).");
      25             : 
      26       14309 :   params.addRequiredParam<Point>("point", "The point that defines the plane");
      27       14309 :   params.addRequiredParam<RealVectorValue>("normal", "The normal that defines the plane");
      28             : 
      29       14309 :   return params;
      30           0 : }
      31             : 
      32          22 : PlaneDeletionGenerator::PlaneDeletionGenerator(const InputParameters & parameters)
      33             :   : ElementDeletionGeneratorBase(parameters),
      34          22 :     _point(getParam<Point>("point")),
      35          44 :     _normal(getParam<RealVectorValue>("normal"))
      36             : {
      37          22 :   if (!_normal.norm())
      38           0 :     paramError("normal", "Normal vector must have a size!");
      39             : 
      40             :   // Make sure it's a unit vector
      41          22 :   _normal /= _normal.norm();
      42          22 : }
      43             : 
      44             : bool
      45       20384 : PlaneDeletionGenerator::shouldDelete(const Elem * elem)
      46             : {
      47       20384 :   auto centroid = elem->vertex_average();
      48             : 
      49       20384 :   auto vec_from_plane_point = centroid - _point;
      50             : 
      51       20384 :   auto norm = vec_from_plane_point.norm();
      52             : 
      53             :   // If we _perfectly_ hit a centroid... default to deleting the element
      54       20384 :   if (!norm)
      55           0 :     return true;
      56             : 
      57             :   // Unitize it
      58       20384 :   vec_from_plane_point /= norm;
      59             : 
      60       20384 :   return vec_from_plane_point * _normal > 0;
      61             : }

Generated by: LCOV version 1.14