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 "PublicRestartable.h" 13 : #include "StochasticToolsApp.h" 14 : 15 : /** 16 : * An interface class which manages the model data save and load functionalities from moose objects 17 : * (such as surrogates, mappings, etc.) in the stochastic tools module. 18 : */ 19 170 : class RestartableModelInterface 20 : { 21 : public: 22 : static InputParameters validParams(); 23 : 24 : RestartableModelInterface(const MooseObject & object, 25 : const bool read_only, 26 : const std::string & meta_data_name); 27 : 28 : ///@{ 29 : /** 30 : * Declare model data for loading from file as well as restart 31 : */ 32 : // MOOSEDOCS_BEGIN 33 : template <typename T, typename... Args> 34 : T & declareModelData(const std::string & data_name, Args &&... args); 35 : // MOOSEDOCS_END 36 : ///@} 37 : 38 : ///@{ 39 : /** 40 : * Retrieve model data from the interface 41 : */ 42 : template <typename T, typename... Args> 43 : const T & getModelData(const std::string & data_name, Args &&... args) const; 44 : ///@} 45 : 46 : /// Accessor for the name of the model meta data 47 1917 : const std::string & modelMetaDataName() const { return _model_meta_data_name; } 48 : 49 : /// Get the associated filename 50 : const FileName & getModelDataFileName() const; 51 : 52 : /// Check if we need to load model data (if the filename parameter is used) 53 : bool hasModelData() const; 54 : 55 : private: 56 : /// Reference to the MooseObject that uses this interface 57 : const MooseObject & _model_object; 58 : 59 : /// The model meta data name. This is used to store the restartable data within the 60 : /// RestartableDataMap. 61 : const std::string _model_meta_data_name; 62 : 63 : /** 64 : * Member for interfacing with the framework's restartable system. We need this because 65 : * we would like to have the capability to handle the model data separately from the 66 : * other data members used for checkpointing. 67 : */ 68 : PublicRestartable _model_restartable; 69 : }; 70 : 71 : template <> 72 : void dataStore(std::ostream & stream, Eigen::LLT<RealEigenMatrix> & decomp, void * context); 73 : template <> 74 : void dataLoad(std::istream & stream, Eigen::LLT<RealEigenMatrix> & decomp, void * context); 75 : 76 : template <typename T, typename... Args> 77 : T & 78 : RestartableModelInterface::declareModelData(const std::string & data_name, Args &&... args) 79 : { 80 : return _model_restartable.declareRestartableData<T>(data_name, std::forward<Args>(args)...); 81 : } 82 : 83 : template <typename T, typename... Args> 84 : const T & 85 : RestartableModelInterface::getModelData(const std::string & data_name, Args &&... args) const 86 : { 87 : return _model_restartable.getRestartableData<T>(data_name, std::forward<Args>(args)...); 88 : }