LCOV - code coverage report
Current view: top level - src/vectorpostprocessors - PointVariableSamplerBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: d5e406 Lines: 50 51 98.0 %
Date: 2026-07-08 21:15:44 Functions: 6 6 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 "PointVariableSamplerBase.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "MooseMesh.h"
      14             : #include "Assembly.h"
      15             : 
      16             : #include "libmesh/mesh_tools.h"
      17             : 
      18             : InputParameters
      19       10989 : PointVariableSamplerBase::validParams()
      20             : {
      21       10989 :   InputParameters params = GeneralVectorPostprocessor::validParams();
      22             : 
      23       10989 :   params += SamplerBase::validParams();
      24             : 
      25       43956 :   params.addRequiredCoupledVar(
      26             :       "variable", "The names of the variables that this VectorPostprocessor operates on");
      27       32967 :   params.addParam<PostprocessorName>(
      28       21978 :       "scaling", 1.0, "The postprocessor that the variables are multiplied with");
      29       21978 :   params.addParam<bool>(
      30             :       "warn_discontinuous_face_values",
      31       21978 :       true,
      32             :       "Whether to return a warning if a discontinuous variable is sampled on a face");
      33             : 
      34       10989 :   return params;
      35           0 : }
      36             : 
      37         905 : PointVariableSamplerBase::PointVariableSamplerBase(const InputParameters & parameters)
      38             :   : PointSamplerBase(parameters),
      39             :     CoupleableMooseVariableDependencyIntermediateInterface(this, false),
      40             :     MooseVariableInterface<Real>(this,
      41             :                                  false,
      42             :                                  "variable",
      43             :                                  Moose::VarKindType::VAR_ANY,
      44        1810 :                                  Moose::VarFieldType::VAR_FIELD_STANDARD)
      45             : {
      46         905 :   addMooseVariableDependency(&mooseVariableField());
      47             : 
      48         905 :   std::vector<std::string> var_names(_coupled_moose_vars.size());
      49             : 
      50        2191 :   for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
      51             :   {
      52        1286 :     var_names[i] = _coupled_moose_vars[i]->name();
      53        3858 :     SamplerBase::checkForStandardFieldVariableType(_coupled_moose_vars[i]);
      54             :   }
      55             : 
      56             :   // Initialize the data structures in SamplerBase
      57         905 :   SamplerBase::setupVariables(var_names);
      58         905 : }
      59             : 
      60             : void
      61        4008 : PointVariableSamplerBase::initialize()
      62             : {
      63        4008 :   PointSamplerBase::initialize();
      64             : 
      65             :   // Check for elemental variables, which are ill-defined on faces for this object
      66        8608 :   for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
      67             :   {
      68             :     const auto continuity =
      69        4600 :         _assembly.getFE(_coupled_moose_vars[i]->feType(), _mesh.dimension())->get_continuity();
      70        4600 :     if (continuity != libMesh::C_ZERO && continuity != libMesh::C_ONE)
      71         595 :       _discontinuous_at_faces = true;
      72             :   }
      73        4008 : }
      74             : 
      75             : void
      76        4008 : PointVariableSamplerBase::execute()
      77             : {
      78        4008 :   BoundingBox bbox = _mesh.getInflatedProcessorBoundingBox();
      79             : 
      80             :   /// So we don't have to create and destroy this
      81        4008 :   std::vector<Point> point_vec(1);
      82             : 
      83       76705 :   for (MooseIndex(_points) i = 0; i < _points.size(); ++i)
      84             :   {
      85       72697 :     Point & p = _points[i];
      86             : 
      87             :     // Do a bounding box check so we're not doing unnecessary PointLocator lookups
      88             :     // In the discontinuous case all ranks must proceed to get a global consensus
      89             :     // on who owns face points in getLocalElemContainingPoint()
      90       72697 :     if (bbox.contains_point(p) || _discontinuous_at_faces)
      91             :     {
      92       58176 :       auto & values = _point_values[i];
      93             : 
      94       58176 :       if (values.empty())
      95       58176 :         values.resize(_coupled_moose_vars.size());
      96             : 
      97             :       // First find the element the hit lands in
      98       58176 :       const Elem * elem = getLocalElemContainingPoint(p);
      99             : 
     100       58176 :       if (elem)
     101             :       {
     102             :         // We have to pass a vector of points into reinitElemPhys
     103       51471 :         point_vec[0] = p;
     104             : 
     105       51471 :         _subproblem.setCurrentSubdomainID(elem, 0);
     106       51471 :         _subproblem.reinitElemPhys(elem, point_vec, 0); // Zero is for tid
     107             : 
     108      107695 :         for (MooseIndex(_coupled_moose_vars) j = 0; j < _coupled_moose_vars.size(); ++j)
     109      112448 :           values[j] = (dynamic_cast<MooseVariableField<Real> *>(_coupled_moose_vars[j]))->sln()[0] *
     110       56224 :                       _pp_value; // The zero is for the "qp"
     111             : 
     112       51471 :         _found_points[i] = true;
     113             :       }
     114             :     }
     115             :   }
     116        4008 : }
     117             : 
     118             : void
     119          89 : PointVariableSamplerBase::setPointsVector(const std::vector<Point> & points)
     120             : {
     121          89 :   _points = points;
     122          89 : }
     123             : 
     124             : void
     125          89 : PointVariableSamplerBase::transferPointsVector(std::vector<Point> && points)
     126             : {
     127          89 :   _points = std::move(points);
     128          89 : }

Generated by: LCOV version 1.14