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

Generated by: LCOV version 1.14