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 "StochasticToolsApp.h" 13 : #include "MooseObject.h" 14 : #include "RestartableModelInterface.h" 15 : 16 : #include "libmesh/petsc_vector.h" 17 : #include "libmesh/petsc_matrix.h" 18 : 19 : /** 20 : * This is an abstract base class for objects that provide mapping between a full-order 21 : * and a latent space. 22 : */ 23 : class VariableMappingBase : public MooseObject, public RestartableModelInterface 24 : { 25 : public: 26 : static InputParameters validParams(); 27 : VariableMappingBase(const InputParameters & parameters); 28 : 29 340 : virtual ~VariableMappingBase() {} 30 : 31 : /** 32 : * Abstract function for building mapping for a given variable. 33 : * @param vname The name of the variable 34 : */ 35 : virtual void buildMapping(const VariableName & vname) = 0; 36 : 37 : /** 38 : * Map a full-order solution vector (in DenseVector format) for a given variable into a 39 : * reduced-order vector (in a standard vector format) 40 : * @param vname The name of the variable 41 : * @param full_order_vector The full-order vector 42 : * @param reduced_order_vector The reduced-order vector to fill 43 : */ 44 : virtual void map(const VariableName & vname, 45 : const DenseVector<Real> & full_order_vector, 46 : std::vector<Real> & reduced_order_vector) const = 0; 47 : 48 : /** 49 : * Map a full-order solution vector with a given global sample number for a given variable into a 50 : * reduced-order vector (in a standard vector format) 51 : * @param vname The name of the variable 52 : * @param global_sample_i The global sample index 53 : * @param reduced_order_vector The reduced-order vector to fill 54 : */ 55 : virtual void map(const VariableName & vname, 56 : const unsigned int global_sample_i, 57 : std::vector<Real> & reduced_order_vector) const = 0; 58 : 59 : /** 60 : * Map a reduced-order vector (from the latent space) back to a full-order solution vector 61 : * (in DenseVector format) for a given variable 62 : * @param vname The name of the variable 63 : * @param reduced_order_vector The reduced-order vector 64 : * @param full_order_vector The full order vector to fill 65 : */ 66 : virtual void inverse_map(const VariableName & vname, 67 : const std::vector<Real> & reduced_order_vector, 68 : DenseVector<Real> & full_order_vector) const = 0; 69 : 70 : /// Get the available variable names in this mapping 71 110 : virtual const std::vector<VariableName> & getVariableNames() { return _variable_names; } 72 : 73 : protected: 74 : /// Check if we have a mapping for the variable and if it is ready to be used 75 : void checkIfReadyToUse(const VariableName & libmesh_dbg_var(vname)) const; 76 : 77 : /// Storage for the names of the variables this mapping can handle 78 : const std::vector<VariableName> & _variable_names; 79 : 80 : /// Bool to decide if we already have the mapping built or not to make sure it is 81 : /// not computed multiple times unless the user requests it 82 : std::map<VariableName, bool> & _mapping_ready_to_use; 83 : };