LCOV - code coverage report
Current view: top level - include/reporters - PolynomialChaosReporter.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             : #include "SurrogateModelInterface.h"
      14             : 
      15             : #include "PolynomialChaos.h"
      16             : #include "nlohmann/json.h"
      17             : 
      18             : class PolynomialChaosReporter : public GeneralReporter, public SurrogateModelInterface
      19             : {
      20             : public:
      21             :   static InputParameters validParams();
      22             :   PolynomialChaosReporter(const InputParameters & parameters);
      23             : 
      24         272 :   virtual void initialize() override {}
      25             :   virtual void execute() override;
      26         272 :   virtual void finalize() override {}
      27             : 
      28             : private:
      29             :   /// Helper function for computing local sensitivity from a polynomial chaos model
      30             :   static std::vector<Real> computeLocalSensitivity(const PolynomialChaos & pc,
      31             :                                                    const std::vector<Real> & data);
      32             : 
      33             :   /// Points for local sensitivity calculation
      34             :   const std::vector<std::vector<Real>> & _loc_point;
      35             :   /// Samplers for local sensitivity calculation
      36             :   std::vector<Sampler *> _loc_sampler;
      37             : 
      38             :   /// Polynomial chaos models
      39             :   std::vector<const PolynomialChaos *> _pc;
      40             : 
      41             :   /// Local sensitivity from specified points
      42             :   std::vector<std::vector<std::vector<Real>> *> _loc_point_sense;
      43             :   /// Local sensitivity from sampled points
      44             :   std::vector<std::vector<std::vector<Real>> *> _loc_sampler_sense;
      45             : };
      46             : 
      47             : void to_json(nlohmann::json & json, const PolynomialChaos * const & pc);
      48             : 
      49             : /**
      50             :  * PCStatisticsContext is almost identical to ReporterStatisticsContext with
      51             :  * InType == Outype. Unfortunately, we cannot derive from ReporterStatisticsContext
      52             :  * since that class relies on the construction of a Calculator object, something
      53             :  * that is unnecessary for calculating statistics with polynomial chaos.
      54             :  */
      55             : template <typename OutType>
      56             : class PCStatisticsContext : public ReporterGeneralContext<std::pair<OutType, std::vector<OutType>>>
      57             : {
      58             : public:
      59             :   PCStatisticsContext(const libMesh::ParallelObject & other,
      60             :                       const MooseObject & producer,
      61             :                       ReporterState<std::pair<OutType, std::vector<OutType>>> & state,
      62             :                       const PolynomialChaos & pc,
      63             :                       const MooseEnumItem & stat);
      64             : 
      65             :   virtual void finalize() override;
      66             :   virtual void storeInfo(nlohmann::json & json) const override;
      67             : 
      68             : private:
      69             :   /// Polynomial chaos surrogate object
      70             :   const PolynomialChaos & _pc;
      71             :   /// The stat to compute
      72             :   const MooseEnumItem _stat;
      73             : };
      74             : 
      75             : /**
      76             :  * PCSobolContext is almost identical to SobolReporterContext with
      77             :  * InType == Outype. Unfortunately, we cannot derive from SobolReporterContext
      78             :  * since that class relies on the construction of a Calculator object, something
      79             :  * that is unnecessary for calculating statistics with polynomial chaos.
      80             :  */
      81             : template <typename OutType>
      82             : class PCSobolContext : public ReporterGeneralContext<
      83             :                            std::pair<std::vector<OutType>, std::vector<std::vector<OutType>>>>
      84             : {
      85             : public:
      86             :   PCSobolContext(
      87             :       const libMesh::ParallelObject & other,
      88             :       const MooseObject & producer,
      89             :       ReporterState<std::pair<std::vector<OutType>, std::vector<std::vector<OutType>>>> & state,
      90             :       const PolynomialChaos & pc);
      91             : 
      92             :   virtual void finalize() override;
      93          70 :   virtual std::string type() const override
      94             :   {
      95         140 :     return "SobolIndices<" + MooseUtils::prettyCppType<OutType>() + ">";
      96             :   }
      97             : 
      98             : protected:
      99             :   virtual void store(nlohmann::json & json) const override;
     100             : 
     101             : private:
     102             :   /// Polynomial chaos surrogate object
     103             :   const PolynomialChaos & _pc;
     104             : };

Generated by: LCOV version 1.14