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

Generated by: LCOV version 1.14