LCOV - code coverage report
Current view: top level - src/vectorpostprocessors - VectorPostprocessorInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 95 112 84.8 %
Date: 2025-07-17 01:28:37 Functions: 20 26 76.9 %
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 "VectorPostprocessorInterface.h"
      11             : #include "FEProblemBase.h"
      12             : #include "ReporterData.h"
      13             : #include "VectorPostprocessor.h"
      14             : #include "MooseTypes.h"
      15             : #include "UserObject.h"
      16             : 
      17             : InputParameters
      18       57690 : VectorPostprocessorInterface::validParams()
      19             : {
      20       57690 :   return emptyInputParameters();
      21             : }
      22             : 
      23      634830 : VectorPostprocessorInterface::VectorPostprocessorInterface(const MooseObject * moose_object,
      24      634830 :                                                            bool broadcast_by_default)
      25      634830 :   : _broadcast_by_default(broadcast_by_default),
      26      634830 :     _vpi_moose_object(*moose_object),
      27      634830 :     _vpi_feproblem(*_vpi_moose_object.parameters().getCheckedPointerParam<FEProblemBase *>(
      28             :         "_fe_problem_base")),
      29      634830 :     _vpi_tid(_vpi_moose_object.parameters().have_parameter<THREAD_ID>("_tid")
      30      634830 :                  ? _vpi_moose_object.parameters().get<THREAD_ID>("_tid")
      31      634830 :                  : 0)
      32             : {
      33      634830 : }
      34             : 
      35             : const VectorPostprocessorValue &
      36        1338 : VectorPostprocessorInterface::getVectorPostprocessorValue(const std::string & param_name,
      37             :                                                           const std::string & vector_name) const
      38             : {
      39        1338 :   possiblyCheckHasVectorPostprocessor(param_name, vector_name);
      40        1330 :   return getVectorPostprocessorValueByName(getVectorPostprocessorName(param_name), vector_name);
      41             : }
      42             : 
      43             : const VectorPostprocessorValue &
      44        1831 : VectorPostprocessorInterface::getVectorPostprocessorValueByName(
      45             :     const VectorPostprocessorName & name, const std::string & vector_name) const
      46             : {
      47        1831 :   return getVectorPostprocessorByNameHelper(name, vector_name, _broadcast_by_default, 0);
      48             : }
      49             : 
      50             : const VectorPostprocessorValue &
      51          34 : VectorPostprocessorInterface::getVectorPostprocessorValueOld(const std::string & param_name,
      52             :                                                              const std::string & vector_name) const
      53             : {
      54          34 :   possiblyCheckHasVectorPostprocessor(param_name, vector_name);
      55          34 :   return getVectorPostprocessorValueOldByName(getVectorPostprocessorName(param_name), vector_name);
      56             : }
      57             : 
      58             : const VectorPostprocessorValue &
      59          34 : VectorPostprocessorInterface::getVectorPostprocessorValueOldByName(
      60             :     const VectorPostprocessorName & name, const std::string & vector_name) const
      61             : {
      62          34 :   return getVectorPostprocessorByNameHelper(name, vector_name, _broadcast_by_default, 1);
      63             : }
      64             : 
      65             : const VectorPostprocessorValue &
      66         249 : VectorPostprocessorInterface::getVectorPostprocessorValue(const std::string & param_name,
      67             :                                                           const std::string & vector_name,
      68             :                                                           bool needs_broadcast) const
      69             : {
      70         249 :   possiblyCheckHasVectorPostprocessor(param_name, vector_name);
      71         249 :   return getVectorPostprocessorValueByName(
      72         249 :       getVectorPostprocessorName(param_name), vector_name, needs_broadcast);
      73             : }
      74             : 
      75             : const VectorPostprocessorValue &
      76         249 : VectorPostprocessorInterface::getVectorPostprocessorValueByName(
      77             :     const VectorPostprocessorName & name,
      78             :     const std::string & vector_name,
      79             :     bool needs_broadcast) const
      80             : {
      81         249 :   return getVectorPostprocessorByNameHelper(
      82         498 :       name, vector_name, needs_broadcast || _broadcast_by_default, 0);
      83             : }
      84             : 
      85             : const VectorPostprocessorValue &
      86           0 : VectorPostprocessorInterface::getVectorPostprocessorValueOld(const std::string & param_name,
      87             :                                                              const std::string & vector_name,
      88             :                                                              bool needs_broadcast) const
      89             : {
      90           0 :   possiblyCheckHasVectorPostprocessor(param_name, vector_name);
      91           0 :   return getVectorPostprocessorValueOldByName(
      92           0 :       getVectorPostprocessorName(param_name), vector_name, needs_broadcast);
      93             : }
      94             : 
      95             : const VectorPostprocessorValue &
      96           0 : VectorPostprocessorInterface::getVectorPostprocessorValueOldByName(
      97             :     const VectorPostprocessorName & name,
      98             :     const std::string & vector_name,
      99             :     bool needs_broadcast) const
     100             : {
     101           0 :   return getVectorPostprocessorByNameHelper(
     102           0 :       name, vector_name, needs_broadcast || _broadcast_by_default, 1);
     103             : }
     104             : 
     105             : const ScatterVectorPostprocessorValue &
     106          94 : VectorPostprocessorInterface::getScatterVectorPostprocessorValue(
     107             :     const std::string & param_name, const std::string & vector_name) const
     108             : {
     109          94 :   possiblyCheckHasVectorPostprocessor(param_name, vector_name);
     110          94 :   return getScatterVectorPostprocessorValueByName(getVectorPostprocessorName(param_name),
     111          94 :                                                   vector_name);
     112             : }
     113             : 
     114             : const ScatterVectorPostprocessorValue &
     115          94 : VectorPostprocessorInterface::getScatterVectorPostprocessorValueByName(
     116             :     const VectorPostprocessorName & name, const std::string & vector_name) const
     117             : {
     118          94 :   return getVectorPostprocessorContextByNameHelper(name, vector_name).getScatterValue();
     119             : }
     120             : 
     121             : const ScatterVectorPostprocessorValue &
     122           0 : VectorPostprocessorInterface::getScatterVectorPostprocessorValueOld(
     123             :     const std::string & param_name, const std::string & vector_name) const
     124             : {
     125           0 :   possiblyCheckHasVectorPostprocessor(param_name, vector_name);
     126           0 :   return getScatterVectorPostprocessorValueOldByName(getVectorPostprocessorName(param_name),
     127           0 :                                                      vector_name);
     128             : }
     129             : 
     130             : const ScatterVectorPostprocessorValue &
     131           0 : VectorPostprocessorInterface::getScatterVectorPostprocessorValueOldByName(
     132             :     const VectorPostprocessorName & name, const std::string & vector_name) const
     133             : {
     134           0 :   return getVectorPostprocessorContextByNameHelper(name, vector_name).getScatterValueOld();
     135             : }
     136             : 
     137             : bool
     138         273 : VectorPostprocessorInterface::hasVectorPostprocessor(const std::string & param_name,
     139             :                                                      const std::string & vector_name) const
     140             : {
     141         273 :   if (!vectorPostprocessorsAdded())
     142           4 :     _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessor() until all VectorPostprocessors "
     143             :                               "have been constructed.");
     144             : 
     145         269 :   return hasVectorPostprocessorByName(getVectorPostprocessorName(param_name), vector_name);
     146             : }
     147             : 
     148             : bool
     149         542 : VectorPostprocessorInterface::hasVectorPostprocessorByName(const VectorPostprocessorName & name,
     150             :                                                            const std::string & vector_name) const
     151             : {
     152         542 :   if (!vectorPostprocessorsAdded())
     153           4 :     _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessorByName() until all "
     154             :                               "VectorPostprocessors have been constructed.");
     155             : 
     156        1076 :   const bool has_vpp = _vpi_feproblem.getReporterData().hasReporterValue<VectorPostprocessorValue>(
     157        1076 :       VectorPostprocessorReporterName(name, vector_name));
     158             : 
     159             :   if (has_vpp)
     160             :     mooseAssert(_vpi_feproblem.hasUserObject(name) && dynamic_cast<const VectorPostprocessor *>(
     161             :                                                           &_vpi_feproblem.getUserObjectBase(name)),
     162             :                 "Has reporter VectorPostprocessor Reporter value but not VectorPostprocessor UO");
     163             : 
     164         538 :   return has_vpp;
     165             : }
     166             : 
     167             : bool
     168         277 : VectorPostprocessorInterface::hasVectorPostprocessor(const std::string & param_name) const
     169             : {
     170         277 :   if (!vectorPostprocessorsAdded())
     171           4 :     _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessor() until all "
     172             :                               "VectorPostprocessors have been constructed.");
     173             : 
     174         273 :   return hasVectorPostprocessorByName(getVectorPostprocessorName(param_name));
     175             : }
     176             : 
     177             : bool
     178        8671 : VectorPostprocessorInterface::hasVectorPostprocessorByName(
     179             :     const VectorPostprocessorName & name) const
     180             : {
     181        8671 :   if (!vectorPostprocessorsAdded())
     182           4 :     _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessorByName() until all "
     183             :                               "VectorPostprocessors have been constructed.");
     184             : 
     185       17314 :   return _vpi_feproblem.hasUserObject(name) &&
     186       17314 :          dynamic_cast<const VectorPostprocessor *>(&_vpi_feproblem.getUserObjectBase(name));
     187             : }
     188             : 
     189             : bool
     190           0 : VectorPostprocessorInterface::isVectorPostprocessorDistributed(const std::string & param_name) const
     191             : {
     192           0 :   return isVectorPostprocessorDistributedByName(getVectorPostprocessorName(param_name));
     193             : }
     194             : 
     195             : bool
     196           0 : VectorPostprocessorInterface::isVectorPostprocessorDistributedByName(
     197             :     const VectorPostprocessorName & name) const
     198             : {
     199           0 :   return _vpi_feproblem.getVectorPostprocessorObjectByName(name).isDistributed();
     200             : }
     201             : 
     202             : const VectorPostprocessorName &
     203        2257 : VectorPostprocessorInterface::getVectorPostprocessorName(const std::string & param_name) const
     204             : {
     205        2257 :   const auto & params = _vpi_moose_object.parameters();
     206             : 
     207        2257 :   if (!params.isParamValid(param_name))
     208           4 :     _vpi_moose_object.mooseError(
     209             :         "When getting a VectorPostprocessor, failed to get a parameter with the name \"",
     210             :         param_name,
     211             :         "\".",
     212             :         "\n\nKnown parameters:\n",
     213           4 :         _vpi_moose_object.parameters());
     214             : 
     215        2253 :   if (!params.isType<VectorPostprocessorName>(param_name))
     216           4 :     _vpi_moose_object.mooseError(
     217             :         "Supplied parameter with name \"",
     218             :         param_name,
     219             :         "\" of type \"",
     220           4 :         params.type(param_name),
     221             :         "\" is not an expected type for getting a VectorPostprocessor.\n\n",
     222             :         "The allowed type is \"VectorPostprocessorName\".");
     223             : 
     224        2249 :   return params.get<VectorPostprocessorName>(param_name);
     225             : }
     226             : 
     227             : void
     228        1715 : VectorPostprocessorInterface::possiblyCheckHasVectorPostprocessor(
     229             :     const std::string & param_name, const std::string & vector_name) const
     230             : {
     231             :   // Can't do checking if vpps have not been added
     232        1715 :   if (!vectorPostprocessorsAdded())
     233        1442 :     return;
     234             : 
     235         273 :   if (!hasVectorPostprocessor(param_name))
     236           4 :     _vpi_moose_object.paramError(param_name,
     237             :                                  "A VectorPostprocessor with the name \"",
     238             :                                  getVectorPostprocessorName(param_name),
     239             :                                  "\" was not found.");
     240         269 :   if (!hasVectorPostprocessor(param_name, vector_name))
     241           4 :     _vpi_moose_object.paramError(param_name,
     242             :                                  "The VectorPostprocessor \"",
     243             :                                  getVectorPostprocessorName(param_name),
     244             :                                  "\" does not have a vector named \"",
     245             :                                  vector_name,
     246             :                                  "\".");
     247             : }
     248             : 
     249             : void
     250        2208 : VectorPostprocessorInterface::possiblyCheckHasVectorPostprocessorByName(
     251             :     const VectorPostprocessorName & name, const std::string & vector_name) const
     252             : {
     253             :   // Can't do checking if vpps have not been added
     254        2208 :   if (!vectorPostprocessorsAdded())
     255        1935 :     return;
     256             : 
     257         273 :   if (!hasVectorPostprocessorByName(name))
     258           4 :     _vpi_moose_object.mooseError(
     259             :         "A VectorPostprocessor with the name \"", name, "\" was not found.");
     260         269 :   if (!hasVectorPostprocessorByName(name, vector_name))
     261           4 :     _vpi_moose_object.mooseError("The VectorPostprocessor \"",
     262             :                                  name,
     263             :                                  "\" does not have a vector named \"",
     264             :                                  vector_name,
     265             :                                  "\".");
     266             : }
     267             : 
     268             : const VectorPostprocessorValue &
     269        2114 : VectorPostprocessorInterface::getVectorPostprocessorByNameHelper(
     270             :     const VectorPostprocessorName & name,
     271             :     const std::string & vector_name,
     272             :     bool broadcast,
     273             :     std::size_t t_index) const
     274             : {
     275        2114 :   possiblyCheckHasVectorPostprocessorByName(name, vector_name);
     276        2106 :   addVectorPostprocessorDependencyHelper(name);
     277             : 
     278        2106 :   const ReporterMode mode = broadcast ? REPORTER_MODE_REPLICATED : REPORTER_MODE_ROOT;
     279        4212 :   return _vpi_feproblem.getReporterData().getReporterValue<VectorPostprocessorValue>(
     280        6318 :       VectorPostprocessorReporterName(name, vector_name), _vpi_moose_object, mode, t_index);
     281        2106 : }
     282             : 
     283             : const VectorPostprocessorContext<VectorPostprocessorValue> &
     284          94 : VectorPostprocessorInterface::getVectorPostprocessorContextByNameHelper(
     285             :     const VectorPostprocessorName & name, const std::string & vector_name) const
     286             : {
     287          94 :   possiblyCheckHasVectorPostprocessorByName(name, vector_name);
     288          94 :   addVectorPostprocessorDependencyHelper(name);
     289             : 
     290             :   // The complete name of the store Reporter value
     291          94 :   const VectorPostprocessorReporterName r_name(name, vector_name);
     292             : 
     293             :   // Indicate the scatter value is desired, so the the VectorPostprocessorContext will do scatter
     294          94 :   _vpi_feproblem.getReporterData().getReporterValue<VectorPostprocessorValue>(
     295             :       r_name, _vpi_moose_object, REPORTER_MODE_VPP_SCATTER, 0);
     296             : 
     297             :   // Retrieve the VectorPostprocessorContext which contains the scattered value to be referenced
     298          94 :   const auto & context = _vpi_feproblem.getReporterData().getReporterContextBase(r_name);
     299          94 :   auto vpp_context_ptr =
     300          94 :       dynamic_cast<const VectorPostprocessorContext<VectorPostprocessorValue> *>(&context);
     301             :   mooseAssert(vpp_context_ptr, "Failed to get the VectorPostprocessorContext");
     302          94 :   return *vpp_context_ptr;
     303          94 : }
     304             : 
     305             : bool
     306       13686 : VectorPostprocessorInterface::vectorPostprocessorsAdded() const
     307             : {
     308       13686 :   return _vpi_feproblem.getMooseApp().actionWarehouse().isTaskComplete("add_vector_postprocessor");
     309             : }

Generated by: LCOV version 1.14