LCOV - code coverage report
Current view: top level - src/auxkernels - PorousFlowElementLength.C (source / functions) Hit Total Coverage
Test: idaholab/moose porous_flow: #31405 (292dce) with base fef103 Lines: 22 23 95.7 %
Date: 2025-09-04 07:55:56 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 "PorousFlowElementLength.h"
      11             : 
      12             : registerMooseObject("PorousFlowApp", PorousFlowElementLength);
      13             : 
      14             : InputParameters
      15         455 : PorousFlowElementLength::validParams()
      16             : {
      17         455 :   InputParameters params = AuxKernel::validParams();
      18             : 
      19         910 :   params.addCoupledVar("direction",
      20             :                        "Direction (3-component vector) along which to compute the length.  This "
      21             :                        "may be 3 real numbers, or 3 variables.");
      22             : 
      23         455 :   params.addClassDescription(
      24             :       "AuxKernel to compute the 'length' of elements along a given direction.  A plane is "
      25             :       "constructed through the element's centroid, with normal equal to the direction given.  The "
      26             :       "average of the distance of the nodal positions to this plane is the 'length' returned.  The "
      27             :       "Variable for this AuxKernel must be an elemental Variable");
      28             : 
      29         455 :   return params;
      30           0 : }
      31             : 
      32         246 : PorousFlowElementLength::PorousFlowElementLength(const InputParameters & parameters)
      33             :   : AuxKernel(parameters),
      34         246 :     _num_direction(coupledComponents("direction")),
      35         246 :     _direction_x(coupledValue("direction", 0)),
      36             :     // if _num_direction!=3,an informative error message is produced below
      37         490 :     _direction_y(coupledValue("direction", std::min(_num_direction - 1, (unsigned)1))),
      38         492 :     _direction_z(coupledValue("direction", std::min(_num_direction - 1, (unsigned)2)))
      39             : {
      40         246 :   if (isNodal())
      41           2 :     paramError("variable", "The variable must be an elemental variable");
      42         244 :   if (_num_direction != 3)
      43           2 :     paramError("direction", "Three values or variables must be provided");
      44         242 : }
      45             : 
      46             : Real
      47        1440 : PorousFlowElementLength::computeValue()
      48             : {
      49             :   const auto direction =
      50        1440 :       RealVectorValue(_direction_x[_qp], _direction_y[_qp], _direction_z[_qp]).unit();
      51        1440 :   const auto centroid = _current_elem->vertex_average();
      52             :   Real length = 0.0;
      53       11680 :   for (const auto & node : _current_elem->node_ref_range())
      54       10240 :     length += std::abs((node - centroid) * direction);
      55        1440 :   length /= _current_elem->n_nodes();
      56        1440 :   return length;
      57             : }

Generated by: LCOV version 1.14