LCOV - code coverage report
Current view: top level - include/reporters - SnapshotContainerBase.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: 2 2 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 "libmesh/petsc_vector.h"
      14             : #include "libmesh/petsc_matrix.h"
      15             : #include "NonlinearSystemBase.h"
      16             : 
      17             : /**
      18             :  * Base class for storing and managing numerical data like solutions, residuals, and Jacobians.
      19             :  * The vectors are kept distributed with respect to the communicator of the application.
      20             :  * The whole snapshot vector is stored. The saving frequency can be defined using the `execute_on`
      21             :  * parameter.
      22             :  */
      23             : class SnapshotContainerBase : public GeneralReporter
      24             : {
      25             : public:
      26             :   static InputParameters validParams();
      27             :   SnapshotContainerBase(const InputParameters & parameters);
      28             : 
      29             :   /**
      30             :    * Storage for the snapshots.
      31             :    *
      32             :    * The underlying storage is unique_ptrs, but the public API
      33             :    * (read-only access) exposes just references.
      34             :    */
      35         970 :   class Snapshots : public UniqueStorage<NumericVector<Number>>
      36             :   {
      37             :   public:
      38             :     friend class SnapshotContainerBase;
      39             :   };
      40             : 
      41             :   virtual void initialSetup() override;
      42        1480 :   virtual void initialize() override {}
      43             :   virtual void execute() override;
      44        1480 :   virtual void finalize() override {}
      45             : 
      46             :   /**
      47             :    * Return the whole snapshot container
      48             :    * @return const std::vector<std::unique_ptr<NumericVector<Number>>>&
      49             :    */
      50        1800 :   const Snapshots & getSnapshots() const { return _accumulated_data; }
      51             : 
      52             :   /**
      53             :    * Return one of the stored snapshot vectors
      54             :    * @param local_i The index of the locally stored numeric data container
      55             :    */
      56             :   const NumericVector<Number> & getSnapshot(unsigned int local_i) const;
      57             : 
      58             : protected:
      59             :   /**
      60             :    * Clone the current snapshot vector.
      61             :    * @return std::unique_ptr<NumericVector<Number>>
      62             :    */
      63             :   virtual std::unique_ptr<NumericVector<Number>> collectSnapshot() = 0;
      64             : 
      65             :   /// Dynamic container for snapshot vectors. We store pointers to make sure that the change in size
      66             :   /// comes with little overhead. This is a reference because we need it to be restartable for
      67             :   /// stochastic runs in batch mode.
      68             :   Snapshots & _accumulated_data;
      69             : 
      70             :   /// The nonlinear system's number whose solution shall be collected
      71             :   const unsigned int _nonlinear_system_number;
      72             : };
      73             : 
      74             : void dataStore(std::ostream & stream, SnapshotContainerBase::Snapshots & v, void * context);
      75             : void dataLoad(std::istream & stream, SnapshotContainerBase::Snapshots & v, void * context);

Generated by: LCOV version 1.14