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

Generated by: LCOV version 1.14