LCOV - code coverage report
Current view: top level - src/vectorpostprocessors - StochasticResults.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: f45d79 Lines: 33 34 97.1 %
Date: 2025-07-25 05:00:46 Functions: 7 7 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             : // Stocastic Tools Includes
      11             : #include "StochasticResults.h"
      12             : 
      13             : // MOOSE includes
      14             : #include "Sampler.h"
      15             : #include "SamplerPostprocessorTransfer.h"
      16             : 
      17             : registerMooseObject("StochasticToolsApp", StochasticResults);
      18             : 
      19        1664 : StochasticResultsData::StochasticResultsData(const VectorPostprocessorName & name,
      20        1664 :                                              VectorPostprocessorValue * vpp)
      21        1664 :   : name(name), vector(vpp)
      22             : {
      23        1664 : }
      24             : 
      25             : InputParameters
      26        3124 : StochasticResults::validParams()
      27             : {
      28        3124 :   InputParameters params = GeneralVectorPostprocessor::validParams();
      29        3124 :   params.addClassDescription(
      30             :       "Storage container for stochastic simulation results coming from a Postprocessor.");
      31             : 
      32        6248 :   params.addDeprecatedParam<std::vector<SamplerName>>(
      33             :       "samplers",
      34             :       "A list of sampler names of associated data.",
      35             :       "This parameter is no longer needed, please remove it from your input file.");
      36             : 
      37             :   // If 'parallel_type = REPLICATED' broadcast the vector automatically
      38        3124 :   params.set<bool>("_auto_broadcast") = true;
      39        3124 :   return params;
      40           0 : }
      41             : 
      42        1552 : StochasticResults::StochasticResults(const InputParameters & parameters)
      43        1552 :   : GeneralVectorPostprocessor(parameters)
      44             : {
      45        1552 : }
      46             : 
      47             : void
      48        2688 : StochasticResults::initialize()
      49             : {
      50             :   // Clear any existing data, unless the complete history is desired
      51        2688 :   if (!containsCompleteHistory())
      52        5392 :     for (auto & data : _sample_vectors)
      53        2752 :       data.vector->clear();
      54        2688 : }
      55             : 
      56             : void
      57        2688 : StochasticResults::finalize()
      58             : {
      59        2688 :   if (!isDistributed())
      60             :   {
      61        5428 :     for (auto & data : _sample_vectors)
      62        2770 :       _communicator.gather(0, data.current);
      63             :   }
      64             : 
      65        5488 :   for (auto & data : _sample_vectors)
      66             :   {
      67        2800 :     data.vector->insert(data.vector->end(), data.current.begin(), data.current.end());
      68             :     data.current.clear();
      69             :   }
      70        2688 : }
      71             : 
      72             : void
      73        2584 : StochasticResults::setCurrentLocalVectorPostprocessorValue(
      74             :     const std::string & vector_name, const VectorPostprocessorValue && current)
      75             : {
      76        2584 :   auto data_ptr = std::find_if(_sample_vectors.begin(),
      77             :                                _sample_vectors.end(),
      78             :                                [&vector_name](StochasticResultsData & data)
      79        2744 :                                { return data.name == vector_name; });
      80             : 
      81             :   mooseAssert(data_ptr != _sample_vectors.end(),
      82             :               "Unable to locate a vector with the supplied name of '" << vector_name << "'.");
      83        2584 :   data_ptr->current = current;
      84        2584 : }
      85             : 
      86             : void
      87        1664 : StochasticResults::initVector(const std::string & vector_name)
      88             : {
      89        1664 :   _sample_vectors.emplace_back(vector_name, &declareVector(vector_name));
      90        1664 : }

Generated by: LCOV version 1.14