LCOV - code coverage report
Current view: top level - src/vectorpostprocessors - PointVariableSamplerBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 50 51 98.0 %
Date: 2025-08-08 20:01:16 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       44335 : PointVariableSamplerBase::validParams()
      20             : {
      21       44335 :   InputParameters params = GeneralVectorPostprocessor::validParams();
      22             : 
      23       44335 :   params += SamplerBase::validParams();
      24             : 
      25       44335 :   params.addRequiredCoupledVar(
      26             :       "variable", "The names of the variables that this VectorPostprocessor operates on");
      27      133005 :   params.addParam<PostprocessorName>(
      28       88670 :       "scaling", 1.0, "The postprocessor that the variables are multiplied with");
      29      133005 :   params.addParam<bool>(
      30             :       "warn_discontinuous_face_values",
      31       88670 :       true,
      32             :       "Whether to return a warning if a discontinuous variable is sampled on a face");
      33             : 
      34       44335 :   return params;
      35           0 : }
      36             : 
      37         771 : 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         771 :                                  Moose::VarFieldType::VAR_FIELD_STANDARD)
      45             : {
      46         771 :   addMooseVariableDependency(&mooseVariableField());
      47             : 
      48         771 :   std::vector<std::string> var_names(_coupled_moose_vars.size());
      49             : 
      50        1902 :   for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
      51             :   {
      52        1131 :     var_names[i] = _coupled_moose_vars[i]->name();
      53        1131 :     SamplerBase::checkForStandardFieldVariableType(_coupled_moose_vars[i]);
      54             :   }
      55             : 
      56             :   // Initialize the data structures in SamplerBase
      57         771 :   SamplerBase::setupVariables(var_names);
      58         771 : }
      59             : 
      60             : void
      61        4191 : PointVariableSamplerBase::initialize()
      62             : {
      63        4191 :   PointSamplerBase::initialize();
      64             : 
      65             :   // Check for elemental variables, which are ill-defined on faces for this object
      66        8981 :   for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
      67             :   {
      68             :     const auto continuity =
      69        4790 :         _assembly.getFE(_coupled_moose_vars[i]->feType(), _mesh.dimension())->get_continuity();
      70        4790 :     if (continuity != libMesh::C_ZERO && continuity != libMesh::C_ONE)
      71         435 :       _discontinuous_at_faces = true;
      72             :   }
      73        4191 : }
      74             : 
      75             : void
      76        4191 : PointVariableSamplerBase::execute()
      77             : {
      78        4191 :   BoundingBox bbox = _mesh.getInflatedProcessorBoundingBox();
      79             : 
      80             :   /// So we don't have to create and destroy this
      81        4191 :   std::vector<Point> point_vec(1);
      82             : 
      83       66590 :   for (MooseIndex(_points) i = 0; i < _points.size(); ++i)
      84             :   {
      85       62399 :     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       62399 :     if (bbox.contains_point(p) || _discontinuous_at_faces)
      91             :     {
      92       47624 :       auto & values = _point_values[i];
      93             : 
      94       47624 :       if (values.empty())
      95       47624 :         values.resize(_coupled_moose_vars.size());
      96             : 
      97             :       // First find the element the hit lands in
      98       47624 :       const Elem * elem = getLocalElemContainingPoint(p);
      99             : 
     100       47624 :       if (elem)
     101             :       {
     102             :         // We have to pass a vector of points into reinitElemPhys
     103       45551 :         point_vec[0] = p;
     104             : 
     105       45551 :         _subproblem.setCurrentSubdomainID(elem, 0);
     106       45551 :         _subproblem.reinitElemPhys(elem, point_vec, 0); // Zero is for tid
     107             : 
     108       95807 :         for (MooseIndex(_coupled_moose_vars) j = 0; j < _coupled_moose_vars.size(); ++j)
     109      100512 :           values[j] = (dynamic_cast<MooseVariableField<Real> *>(_coupled_moose_vars[j]))->sln()[0] *
     110       50256 :                       _pp_value; // The zero is for the "qp"
     111             : 
     112       45551 :         _found_points[i] = true;
     113             :       }
     114             :     }
     115             :   }
     116        4191 : }
     117             : 
     118             : void
     119          97 : PointVariableSamplerBase::setPointsVector(const std::vector<Point> & points)
     120             : {
     121          97 :   _points = points;
     122          97 : }
     123             : 
     124             : void
     125          97 : PointVariableSamplerBase::transferPointsVector(std::vector<Point> && points)
     126             : {
     127          97 :   _points = std::move(points);
     128          97 : }

Generated by: LCOV version 1.14