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 "SamplerInterface.h" 15 : #include "SurrogateModelInterface.h" 16 : #include "RestartableModelInterface.h" 17 : 18 : class SurrogateModel : public MooseObject, 19 : public SamplerInterface, 20 : public SurrogateModelInterface, 21 : public RestartableModelInterface 22 : { 23 : public: 24 : static InputParameters validParams(); 25 : SurrogateModel(const InputParameters & parameters); 26 : 27 : static MooseEnum defaultPredictorTypes() { return MooseEnum("real"); } 28 2896 : static MooseEnum defaultResponseTypes() { return MooseEnum("real vector_real"); } 29 : 30 : /** 31 : * Evaluate surrogate model given a row of parameters. 32 : */ 33 0 : virtual Real evaluate(const std::vector<Real> & x) const 34 : { 35 0 : evaluateError(x, Real()); 36 : return 0.0; 37 : }; 38 : 39 : /// @{ 40 : /** 41 : * Various evaluate methods that can be overriden 42 : */ 43 0 : virtual void evaluate(const std::vector<Real> & x, std::vector<Real> & y) const 44 : { 45 0 : evaluateError(x, y); 46 : } 47 : ///@} 48 : 49 : /// @{ 50 : /** 51 : * Evaluate methods that also return predicted standard deviation (see GaussianProcess.h) 52 : */ 53 0 : virtual Real evaluate(const std::vector<Real> & x, Real & std) const 54 : { 55 0 : evaluateError(x, std, true); 56 : return 0.0; 57 : } 58 : virtual void 59 0 : evaluate(const std::vector<Real> & x, std::vector<Real> & y, std::vector<Real> & /*std*/) const 60 : { 61 0 : evaluateError(x, y, true); 62 : } 63 : ///@} 64 : 65 : private: 66 : template <typename P, typename R> 67 : void evaluateError(P x, R y, bool with_std = false) const; 68 : }; 69 : 70 : template <typename P, typename R> 71 : void 72 0 : SurrogateModel::evaluateError(P /*x*/, R /*y*/, bool with_std) const 73 : { 74 0 : std::stringstream ss; 75 0 : ss << "Evaluate method"; 76 0 : if (with_std) 77 0 : ss << " (including standard deviation computation)"; 78 0 : ss << " with predictor type " << MooseUtils::prettyCppType<P>(); 79 0 : ss << " and response type " << MooseUtils::prettyCppType<R>(); 80 0 : ss << " has not been implemented."; 81 0 : mooseError(ss.str()); 82 0 : }