LCOV - code coverage report
Current view: top level - src/auxkernels - UniformLayerAuxKernel.C (source / functions) Hit Total Coverage
Test: idaholab/mastodon: 55510a Lines: 30 31 96.8 %
Date: 2025-08-26 23:09:31 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Mastodon includes
       2             : #include "UniformLayerAuxKernel.h"
       3             : 
       4             : registerMooseObject("MastodonApp", UniformLayerAuxKernel);
       5             : 
       6             : InputParameters
       7         471 : UniformLayerAuxKernel::validParams()
       8             : {
       9         471 :   InputParameters params = AuxKernel::validParams();
      10         942 :   params.addRequiredParam<std::vector<Real>>(
      11             :       "interfaces",
      12             :       "A list of layer interface locations to apply across the "
      13             :       "domain in the specified direction.");
      14         942 :   params.addParam<std::vector<unsigned int>>(
      15             :       "layer_ids",
      16             :       {},
      17             :       "A list of layer identifiers to assign to each interface. "
      18             :       "If not provided integer values starting from 0 are "
      19             :       "utilized, if provided the length of this vector must be "
      20             :       "identical to the 'intefaces' vector.");
      21         471 :   params.addParam<RealVectorValue>(
      22         471 :       "direction", RealVectorValue(1, 0, 0), "The direction to apply layering.");
      23         471 :   params.addClassDescription("Computes an AuxVariable for representing a "
      24             :                              "layered structure in an arbitrary direction.");
      25         471 :   return params;
      26           0 : }
      27             : 
      28         249 : UniformLayerAuxKernel::UniformLayerAuxKernel(const InputParameters & parameters)
      29             :   : AuxKernel(parameters),
      30         249 :     _interfaces(getParam<std::vector<Real>>("interfaces")),
      31         996 :     _layer_ids(getParam<std::vector<unsigned int>>("layer_ids"))
      32             : {
      33             :   // Normalize the direction
      34         498 :   _direction = getParam<RealVectorValue>("direction");
      35         249 :   if (_direction.norm() == 0)
      36           1 :     mooseError("The supplied direction vector is not valid, it has a zero norm.");
      37         248 :   _direction /= _direction.norm();
      38             : 
      39             :   // If not provided populate the ids vector starting a zero
      40         248 :   if (_layer_ids.empty())
      41             :   {
      42         234 :     _layer_ids.resize(_interfaces.size());
      43         660 :     for (unsigned int id = 0; id < _interfaces.size(); ++id)
      44         426 :       _layer_ids[id] = id;
      45             :   }
      46             : 
      47         248 :   if (_layer_ids.size() != _interfaces.size())
      48           1 :     mooseError("The number of 'interfaces' must match the number of 'layer_ids'.");
      49         247 : }
      50             : 
      51             : Real
      52       46347 : UniformLayerAuxKernel::computeValue()
      53             : {
      54             :   // Compute projected distance (dot product of direction vector and the current
      55             :   // point)
      56       46347 :   if (_nodal)
      57         882 :     _distance = _direction * (*_current_node);
      58             :   else
      59       45465 :     _distance = _direction * _current_elem->vertex_average();
      60             : 
      61             :   // Locate the layer
      62             :   std::vector<Real>::const_iterator iter =
      63       46347 :       std::upper_bound(_interfaces.begin(), _interfaces.end(), _distance);
      64       46347 :   if (iter == _interfaces.end())
      65           1 :     mooseError("Failed to locate an interface within the domain.");
      66             : 
      67             :   // Return the "layer_id" at the same location as the interface that was
      68             :   // located.
      69       46346 :   return _layer_ids[std::distance(_interfaces.begin(), iter)];
      70             : }

Generated by: LCOV version 1.14