LCOV - code coverage report
Current view: top level - src/vectorpostprocessors - SideValueSampler.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 49 51 96.1 %
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 "SideValueSampler.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "MooseVariableFE.h"
      14             : 
      15             : #include "libmesh/quadrature.h"
      16             : 
      17             : registerMooseObject("MooseApp", SideValueSampler);
      18             : 
      19             : InputParameters
      20       14479 : SideValueSampler::validParams()
      21             : {
      22       14479 :   InputParameters params = SideVectorPostprocessor::validParams();
      23       14479 :   params += SamplerBase::validParams();
      24       14479 :   params.addClassDescription("Sample variable(s) along a sideset, internal or external.");
      25       14479 :   params.addRequiredCoupledVar(
      26             :       "variable", "The names of the variables that this VectorPostprocessor operates on");
      27             : 
      28       14479 :   return params;
      29           0 : }
      30             : 
      31         110 : SideValueSampler::SideValueSampler(const InputParameters & parameters)
      32             :   : SideVectorPostprocessor(parameters),
      33             :     SamplerBase(parameters, this, _communicator),
      34         110 :     _qp_sampling(true)
      35             : {
      36         110 :   std::vector<std::string> var_names(_coupled_moose_vars.size());
      37         110 :   _values.resize(_coupled_moose_vars.size());
      38             : 
      39         274 :   for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
      40             :   {
      41         164 :     var_names[i] = _coupled_moose_vars[i]->name();
      42         164 :     SamplerBase::checkForStandardFieldVariableType(_coupled_moose_vars[i]);
      43             :   }
      44             : 
      45         110 :   if (!_coupled_standard_fv_moose_vars.empty() || !_coupled_standard_linear_fv_moose_vars.empty())
      46             :   {
      47             :     const auto num_fv_vars =
      48          26 :         _coupled_standard_fv_moose_vars.size() + _coupled_standard_linear_fv_moose_vars.size();
      49          26 :     if (num_fv_vars != _coupled_moose_vars.size())
      50           0 :       paramError(
      51             :           "variable",
      52             :           "This object cannot accept mixed FE and FV variables, please make "
      53             :           "sure all the provided variables are either FE or FV by separating this vector "
      54             :           "postprocessor "
      55             :           "into two blocks, one for finite element and another for finite volume variables!");
      56             : 
      57          52 :     for (const auto var : _coupled_standard_fv_moose_vars)
      58          26 :       _fv_vars.push_back(dynamic_cast<const MooseVariableField<Real> *>(var));
      59          52 :     for (const auto var : _coupled_standard_linear_fv_moose_vars)
      60          26 :       _fv_vars.push_back(dynamic_cast<const MooseVariableField<Real> *>(var));
      61             : 
      62          26 :     _qp_sampling = false;
      63             :   }
      64             : 
      65             :   // Initialize the data structures in SamplerBase
      66         110 :   SamplerBase::setupVariables(var_names);
      67         110 : }
      68             : 
      69             : void
      70         102 : SideValueSampler::initialize()
      71             : {
      72         102 :   SamplerBase::initialize();
      73         102 : }
      74             : 
      75             : void
      76       29016 : SideValueSampler::execute()
      77             : {
      78       29016 :   if (_qp_sampling)
      79       57924 :     for (unsigned int _qp = 0; _qp < _qrule->n_points(); _qp++)
      80             :     {
      81       58248 :       for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
      82       29232 :         _values[i] = (dynamic_cast<MooseVariable *>(_coupled_moose_vars[i]))->sln()[_qp];
      83             : 
      84       29016 :       SamplerBase::addSample(_q_point[_qp], _current_elem->id(), _values);
      85             :     }
      86             :   else
      87             :   {
      88         108 :     getFaceInfos();
      89             : 
      90         108 :     const auto state = determineState();
      91             : 
      92         216 :     for (const auto & fi : _face_infos)
      93             :     {
      94         324 :       for (unsigned int i = 0; i < _fv_vars.size(); i++)
      95             :       {
      96             :         mooseAssert(_fv_vars[i]->hasFaceSide(*fi, true) || _fv_vars[i]->hasFaceSide(*fi, false),
      97             :                     "Variable " + _fv_vars[i]->name() +
      98             :                         " should be defined on one side of the face!");
      99             : 
     100         216 :         const auto * elem = _fv_vars[i]->hasFaceSide(*fi, true) ? fi->elemPtr() : fi->neighborPtr();
     101             : 
     102         216 :         const auto face_arg = Moose::FaceArg(
     103         216 :             {fi, Moose::FV::LimiterType::CentralDifference, true, false, elem, nullptr});
     104         216 :         _values[i] = MetaPhysicL::raw_value((*_fv_vars[i])(face_arg, state));
     105             :       }
     106             : 
     107         108 :       SamplerBase::addSample(fi->faceCentroid(), _current_elem->id(), _values);
     108             :     }
     109             :   }
     110       29016 : }
     111             : 
     112             : void
     113          96 : SideValueSampler::finalize()
     114             : {
     115          96 :   SamplerBase::finalize();
     116          96 : }
     117             : 
     118             : void
     119           6 : SideValueSampler::threadJoin(const UserObject & y)
     120             : {
     121           6 :   const auto & vpp = static_cast<const SideValueSampler &>(y);
     122             : 
     123           6 :   SamplerBase::threadJoin(vpp);
     124           6 : }

Generated by: LCOV version 1.14