LCOV - code coverage report
Current view: top level - src/vectorpostprocessors - CombinedVectorPostprocessor.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 45 47 95.7 %
Date: 2026-05-29 20:35:17 Functions: 4 4 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 "CombinedVectorPostprocessor.h"
      11             : #include "VectorPostprocessorInterface.h"
      12             : #include "VectorPostprocessor.h"
      13             : 
      14             : registerMooseObject("MooseApp", CombinedVectorPostprocessor);
      15             : 
      16             : InputParameters
      17        3109 : CombinedVectorPostprocessor::validParams()
      18             : {
      19        3109 :   InputParameters params = GeneralVectorPostprocessor::validParams();
      20             : 
      21       12436 :   params.addRequiredParam<std::vector<VectorPostprocessorName>>(
      22             :       "vectorpostprocessors", "The vectorpostprocessors whose vector values are to be combined");
      23       12436 :   params.addParam<std::vector<std::vector<std::string>>>(
      24             :       "vectors", "Vectors to combine from each vectorpostprocessor");
      25        9327 :   params.addParam<Real>("vector_filler_value",
      26        6218 :                         0,
      27             :                         "Which value to use to fill the smaller vectors (any smaller than the "
      28             :                         "largest vector) if the vectors are not the same size");
      29        6218 :   params.addClassDescription(
      30             :       "Outputs the values of an arbitrary user-specified set of "
      31             :       "vectorpostprocessors as a combined vector in the order specified by the user");
      32             : 
      33             :   // If the vectorpostprocessors are already broadcasted, this VPP should not need to
      34             :   // broadcast on its own
      35        3109 :   params.set<bool>("_auto_broadcast") = false;
      36             : 
      37        3109 :   return params;
      38           0 : }
      39             : 
      40          24 : CombinedVectorPostprocessor::CombinedVectorPostprocessor(const InputParameters & parameters)
      41          48 :   : GeneralVectorPostprocessor(parameters), _filler_value(getParam<Real>("vector_filler_value"))
      42             : {
      43             :   // Get all the names of the vectors to combine them
      44          72 :   const auto & vpps_names = getParam<std::vector<VectorPostprocessorName>>("vectorpostprocessors");
      45          24 :   std::vector<std::vector<std::string>> vpp_vectors(vpps_names.size());
      46          48 :   bool vecs_from_param = isParamValid("vectors");
      47          24 :   if (!vecs_from_param)
      48          36 :     for (const auto i : index_range(vpps_names))
      49             :     {
      50          24 :       const auto & vpp_name = vpps_names[i];
      51          24 :       const auto & vpp = _vpp_fe_problem.getVectorPostprocessorObjectByName(vpp_name);
      52          84 :       for (const auto & vec_name : vpp.getVectorNames())
      53          60 :         vpp_vectors[i].push_back(vec_name);
      54             :     }
      55             :   else
      56             :   {
      57          24 :     vpp_vectors = getParam<std::vector<std::vector<std::string>>>("vectors");
      58          12 :     if (vpp_vectors.size() != vpps_names.size())
      59           0 :       paramError(
      60             :           "vectors",
      61             :           "Outer vector size should be the same size as the 'vectorpostprocessors' parameter");
      62             :   }
      63             : 
      64             :   // Declare vectors
      65          72 :   for (const auto i : index_range(vpp_vectors))
      66         144 :     for (const auto j : index_range(vpp_vectors[i]))
      67          96 :       _vpp_vecs.push_back(&this->declareVector(vpps_names[i] + "_" + vpp_vectors[i][j]));
      68             : 
      69             :   // Grab a reference to all the values
      70          72 :   for (const auto i : index_range(vpps_names))
      71         144 :     for (const auto & vec_name : vpp_vectors[i])
      72             :       // This will error if the vectors don't exist in the VPP
      73         192 :       _vectorpostprocessor_values.push_back(
      74          96 :           &getVectorPostprocessorValueByName(vpps_names[i], vec_name));
      75          24 : }
      76             : 
      77             : void
      78          22 : CombinedVectorPostprocessor::initialize()
      79             : {
      80         110 :   for (auto & vec : _vpp_vecs)
      81          88 :     vec->clear();
      82          22 : }
      83             : 
      84             : void
      85          22 : CombinedVectorPostprocessor::execute()
      86             : {
      87          22 :   std::size_t max_size = 0;
      88             :   // The vectors are already ordered
      89         110 :   for (const auto i : index_range(_vectorpostprocessor_values))
      90             :   {
      91          88 :     *(_vpp_vecs[i]) = *(_vectorpostprocessor_values[i]);
      92          88 :     max_size = std::max(max_size, _vectorpostprocessor_values[i]->size());
      93             :   }
      94             : 
      95             :   // Resize to the max size
      96         110 :   for (const auto i : index_range(_vectorpostprocessor_values))
      97          88 :     _vpp_vecs[i]->resize(max_size);
      98             : 
      99             :   // Fill with the filler value
     100         110 :   for (const auto i : index_range(_vectorpostprocessor_values))
     101         154 :     for (const auto j : make_range(_vectorpostprocessor_values[i]->size(), max_size))
     102          66 :       (*(_vpp_vecs[i]))[j] = _filler_value;
     103          22 : }

Generated by: LCOV version 1.14