LCOV - code coverage report
Current view: top level - include/reporters - ParallelSolutionStorage.h (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: f45d79 Lines: 4 4 100.0 %
Date: 2025-07-25 05:00:46 Functions: 3 3 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             : #pragma once
      11             : 
      12             : #include "GeneralReporter.h"
      13             : 
      14             : /**
      15             :  * A Reporter which stores serialized solution fields for given variables in a distributed fashion.
      16             :  * The solutions can be inserted from subapps using the SerializedSolutionTransfer.
      17             :  */
      18             : class ParallelSolutionStorage : public GeneralReporter
      19             : {
      20             : public:
      21             :   static InputParameters validParams();
      22             :   ParallelSolutionStorage(const InputParameters & parameters);
      23             :   virtual void initialSetup() override;
      24         350 :   virtual void initialize() override {}
      25         350 :   virtual void execute() override {}
      26         350 :   virtual void finalize() override {}
      27             : 
      28             :   /**
      29             :    * Add a new solution entry to the container.
      30             :    * @param vname The name of the variable
      31             :    * @param global_i The global index of the field
      32             :    * @param solution The vector that needs to be added
      33             :    */
      34             :   void
      35             :   addEntry(const VariableName & vname, unsigned int global_i, const DenseVector<Real> & solution);
      36             :   /**
      37             :    * Get the stored solution vectors for a given variable
      38             :    * @param variable The name of the given variable
      39             :    */
      40             :   ///@{
      41             :   std::unordered_map<unsigned int, std::vector<DenseVector<Real>>> &
      42             :   getStorage(const VariableName & variable);
      43             : 
      44             :   const std::unordered_map<unsigned int, std::vector<DenseVector<Real>>> &
      45             :   getStorage(const VariableName & variable) const;
      46             :   ///@}
      47             : 
      48             :   /// Get the whole solution container
      49             :   std::map<VariableName, std::unordered_map<unsigned int, std::vector<DenseVector<Real>>>> &
      50             :   getStorage() const
      51             :   {
      52         130 :     return _distributed_solutions;
      53             :   }
      54             : 
      55             :   /**
      56             :    * Determine if we have the solution vector with a given global sample index for a given
      57             :    * variable.
      58             :    * @param global_sample_i The global sample index of the solution field
      59             :    * @param variable The name of the variable whose data is requested
      60             :    */
      61             :   bool hasGlobalSample(unsigned int global_sample_i, const VariableName & variable) const;
      62             : 
      63             :   /**
      64             :    * Get the serialized solution field which is associated with a given
      65             :    * global sample index and variable
      66             :    * @param global_sample_i The global sampler index
      67             :    * @param variable The variable name
      68             :    */
      69             :   const std::vector<DenseVector<Real>> & getGlobalSample(unsigned int global_sample_i,
      70             :                                                          const VariableName & variable) const;
      71             : 
      72             :   /**
      73             :    * Return the number of total stored solutions for a given variable
      74             :    * @param vname The name of the variable
      75             :    */
      76             :   unsigned int totalNumberOfStoredSolutions(const VariableName & vname) const;
      77             : 
      78             :   /// Get the variable names which we can receive
      79             :   const std::vector<VariableName> & variableNames() const { return _variable_names; }
      80             : 
      81             : protected:
      82             :   /**
      83             :    * The container of the solutions. It indexes based on: the variable name > global sample index >
      84             :    * timestep index (for time-dependent simulations). This object stores a reference because we
      85             :    * would like this to be restartable.
      86             :    */
      87             :   std::map<VariableName, std::unordered_map<unsigned int, std::vector<DenseVector<Real>>>> &
      88             :       _distributed_solutions;
      89             : 
      90             : private:
      91             :   /// The names of the variables whose serialized solution this object is supposed to receive.
      92             :   const std::vector<VariableName> & _variable_names;
      93             : };
      94             : 
      95             : void to_json(
      96             :     nlohmann::json & json,
      97             :     const std::map<VariableName, std::unordered_map<unsigned int, std::vector<DenseVector<Real>>>> &
      98             :         solution_storage);

Generated by: LCOV version 1.14