LCOV - code coverage report
Current view: top level - src/vectorpostprocessors - PositionsFunctorValueSampler.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 41 43 95.3 %
Date: 2025-08-08 20:01:16 Functions: 4 4 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 "PositionsFunctorValueSampler.h"
      11             : #include "Positions.h"
      12             : #include "FEProblemBase.h"
      13             : 
      14             : registerMooseObject("MooseApp", PositionsFunctorValueSampler);
      15             : 
      16             : InputParameters
      17       14291 : PositionsFunctorValueSampler::validParams()
      18             : {
      19       14291 :   InputParameters params = PointSamplerBase::validParams();
      20       14291 :   params.addClassDescription(
      21             :       "Sample one or more functors at points specified by a Positions object.");
      22       14291 :   params.addRequiredParam<PositionsName>(
      23             :       "positions",
      24             :       "Positions object specifying the points where you want to evaluate the functors");
      25       14291 :   params.addRequiredParam<std::vector<MooseFunctorName>>(
      26             :       "functors", "The functors we want to evaluate at the positions");
      27       14291 :   params.addRequiredParam<bool>("discontinuous", "Indicate whether the functors are discontinuous");
      28             : 
      29       14291 :   return params;
      30           0 : }
      31             : 
      32          13 : PositionsFunctorValueSampler::PositionsFunctorValueSampler(const InputParameters & parameters)
      33             :   : PointSamplerBase(parameters),
      34             :     NonADFunctorInterface(this),
      35          13 :     _positions(_fe_problem.getPositionsObject(getParam<PositionsName>("positions")))
      36             : {
      37          13 :   const auto & functor_names = getParam<std::vector<MooseFunctorName>>("functors");
      38          65 :   for (const auto & functor_name : functor_names)
      39          52 :     _functors.push_back(&getFunctor<Real>(functor_name));
      40             : 
      41             :   // Checks all elements around the face when discontinuous
      42          13 :   _discontinuous_at_faces = getParam<bool>("discontinuous");
      43             : 
      44             :   // Initialize the data structures in SamplerBase
      45          13 :   std::vector<std::string> functor_string_names;
      46          65 :   for (const auto & functor_name : functor_names)
      47          52 :     functor_string_names.push_back(functor_name);
      48          13 :   SamplerBase::setupVariables(functor_string_names);
      49          13 : }
      50             : 
      51             : void
      52          12 : PositionsFunctorValueSampler::initialize()
      53             : {
      54             :   // Pull new points
      55          12 :   _points = _positions.getPositions(_fe_problem.getCurrentExecuteOnFlag() == EXEC_INITIAL);
      56             : 
      57          12 :   PointSamplerBase::initialize();
      58          12 : }
      59             : 
      60             : void
      61          12 : PositionsFunctorValueSampler::execute()
      62             : {
      63          12 :   BoundingBox bbox = _mesh.getInflatedProcessorBoundingBox();
      64          12 :   const auto state = determineState();
      65             : 
      66             :   // Pull new points
      67          12 :   const auto old_size = _points.size();
      68          12 :   _points = _positions.getPositions(_fe_problem.getCurrentExecuteOnFlag() == EXEC_INITIAL);
      69          12 :   if (_points.size() != old_size)
      70           0 :     mooseError("The points array has grown since initialize() was called");
      71             : 
      72          48 :   for (const auto i : index_range(_points))
      73             :   {
      74          36 :     const Point & p = _points[i];
      75             : 
      76             :     // Do a bounding box check so we're not doing unnecessary PointLocator lookups
      77             :     // In the discontinuous case all ranks must proceed to get a global consensus
      78             :     // on who owns face points in getLocalElemContainingPoint()
      79          36 :     if (bbox.contains_point(p) || _discontinuous_at_faces)
      80             :     {
      81          36 :       auto & values = _point_values[i];
      82             : 
      83          36 :       if (values.empty())
      84          36 :         values.resize(_functors.size());
      85             : 
      86             :       // First find the element the hit lands in
      87          36 :       const Elem * elem = getLocalElemContainingPoint(p);
      88             : 
      89          36 :       if (elem)
      90             :       {
      91          27 :         Moose::ElemPointArg elem_point_arg = {elem, p, false};
      92         135 :         for (const auto j : index_range(_functors))
      93         108 :           values[j] = (*_functors[j])(elem_point_arg, state) * _pp_value;
      94             : 
      95          27 :         _found_points[i] = true;
      96             :       }
      97             :     }
      98             :   }
      99          12 : }

Generated by: LCOV version 1.14