LCOV - code coverage report
Current view: top level - src/vectorpostprocessors - ElementValueSampler.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 36 37 97.3 %
Date: 2025-07-17 01:28:37 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 "ElementValueSampler.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "MooseVariableFE.h"
      14             : 
      15             : // C++ includes
      16             : #include <numeric>
      17             : 
      18             : registerMooseObject("MooseApp", ElementValueSampler);
      19             : 
      20             : InputParameters
      21       14840 : ElementValueSampler::validParams()
      22             : {
      23       14840 :   InputParameters params = ElementVariableVectorPostprocessor::validParams();
      24             : 
      25       14840 :   params.addClassDescription("Samples values of variables on elements.");
      26             : 
      27       14840 :   params += SamplerBase::validParams();
      28             : 
      29       14840 :   return params;
      30           0 : }
      31             : 
      32         299 : ElementValueSampler::ElementValueSampler(const InputParameters & parameters)
      33         299 :   : ElementVariableVectorPostprocessor(parameters), SamplerBase(parameters, this, _communicator)
      34             : {
      35             :   // ensure that variables are 'elemental'
      36         619 :   for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
      37             :   {
      38         332 :     if (_coupled_moose_vars[i]->isNodal())
      39           4 :       paramError("variable",
      40             :                  "The variable '",
      41           4 :                  _coupled_moose_vars[i]->name(),
      42             :                  "' is a nodal variable. Nodal variables can be sampled using a "
      43             :                  "'NodalValueSampler'.");
      44         328 :     SamplerBase::checkForStandardFieldVariableType(_coupled_moose_vars[i]);
      45             :   }
      46         287 :   std::vector<std::string> var_names(_coupled_moose_vars.size());
      47         287 :   _values.resize(_coupled_moose_vars.size());
      48             : 
      49         607 :   for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
      50         320 :     var_names[i] = _coupled_moose_vars[i]->name();
      51             : 
      52             :   // Initialize the data structures in SamplerBase
      53         287 :   SamplerBase::setupVariables(var_names);
      54         287 : }
      55             : 
      56             : void
      57         414 : ElementValueSampler::initialize()
      58             : {
      59         414 :   SamplerBase::initialize();
      60         414 : }
      61             : 
      62             : void
      63       71408 : ElementValueSampler::execute()
      64             : {
      65       71408 :   unsigned int i_fe = 0, i_fv = 0;
      66      142942 :   for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
      67       71534 :     if (_coupled_moose_vars[i]->isFV())
      68        2326 :       _values[i] = _coupled_standard_fv_moose_vars[i_fv++]->getElementalValue(_current_elem);
      69             :     else
      70       69208 :       _values[i] = _coupled_standard_moose_vars[i_fe++]->getElementalValue(_current_elem);
      71             : 
      72       71408 :   SamplerBase::addSample(_current_elem->vertex_average(), _current_elem->id(), _values);
      73       71408 : }
      74             : 
      75             : void
      76         379 : ElementValueSampler::finalize()
      77             : {
      78         379 :   SamplerBase::finalize();
      79         379 : }
      80             : 
      81             : void
      82          35 : ElementValueSampler::threadJoin(const UserObject & y)
      83             : {
      84          35 :   const auto & vpp = static_cast<const ElementValueSampler &>(y);
      85             : 
      86          35 :   SamplerBase::threadJoin(vpp);
      87          35 : }

Generated by: LCOV version 1.14