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 : // MOOSE includes 13 : #include "ColumnMajorMatrix.h" 14 : #include "MooseTypes.h" 15 : 16 : // C++ includes 17 : #include <vector> 18 : 19 : /** 20 : * This class interpolates tabulated data with a Bidimension function (either bicubic or bilinear). 21 : * In order to minimize the computational expense of each sample, the coefficients at each point in 22 : * the tabulated data are computed once in advance, and then accessed during the interpolation. 23 : * 24 : * Adapted from Numerical Recipes in C (section 3.6). The terminology used is 25 : * consistent with that used in Numerical Recipes, where moving over a column 26 : * corresponds to moving over the x1 coord. Likewise, moving over a row means 27 : * moving over the x2 coord. 28 : */ 29 : class BidimensionalInterpolation 30 : { 31 : public: 32 : BidimensionalInterpolation(const std::vector<Real> & x1, const std::vector<Real> & x2); 33 : 34 159 : virtual ~BidimensionalInterpolation() = default; 35 : 36 : /// Independent values in the x1 direction 37 : std::vector<Real> _x1; 38 : /// Independent values in the x2 direction 39 : std::vector<Real> _x2; 40 : 41 : /** 42 : * Samples value at point (x1, x2) 43 : */ 44 : virtual Real sample(const Real x1, const Real x2) const = 0; 45 : virtual ADReal sample(const ADReal & x1, const ADReal & x2) const = 0; 46 : virtual ChainedReal sample(const ChainedReal & x1, const ChainedReal & x2) const = 0; 47 : 48 : /** 49 : * Samples first derivative at point (x1, x2) 50 : */ 51 : virtual Real 52 0 : sampleDerivative(const Real /*x1*/, const Real /*x2*/, unsigned int /*deriv_var*/) const 53 : { 54 0 : mooseError("sampleDerivative for Real numbers is not implemented for this interpolation class"); 55 : } 56 : virtual ADReal 57 0 : sampleDerivative(const ADReal & /*x1*/, const ADReal & /*x2*/, unsigned int /*deriv_var*/) const 58 : { 59 0 : mooseError( 60 : "sampleDerivative for ADReal numbers is not implemented for this interpolation class"); 61 : } 62 0 : virtual ChainedReal sampleDerivative(const ChainedReal & /*x1*/, 63 : const ChainedReal & /*x2*/, 64 : unsigned int /*deriv_var*/) const 65 : { 66 0 : mooseError( 67 : "sampleDerivative for ChainedReal numbers is not implemented for this interpolation class"); 68 : } 69 : 70 : /** 71 : * Samples second derivative at point (x1, x2) 72 : */ 73 1 : virtual Real sample2ndDerivative(Real /*x1*/, Real /*x2*/, unsigned int /*deriv_var*/) const 74 : { 75 1 : mooseError("sample2ndDerivative is not implemented for this interpolation class"); 76 : } 77 : 78 : /** 79 : * Samples value and first derivatives at point (x1, x2) 80 : * Use this function for speed when computing both value and derivatives, 81 : * as it minimizes the amount of time spent locating the point in the 82 : * tabulated data 83 : */ 84 0 : virtual void sampleValueAndDerivatives( 85 : Real /*x1*/, Real /*x2*/, Real & /* y*/, Real & /* dy1*/, Real & /* dy2*/) const 86 : { 87 0 : mooseError("sampleValueAndDerivatives for Real numbers is not implemented for this " 88 : "interpolation class"); 89 : } 90 1 : virtual void sampleValueAndDerivatives(const ADReal & /*x1*/, 91 : const ADReal & /*x2*/, 92 : ADReal & /* y*/, 93 : ADReal & /* dy1*/, 94 : ADReal & /* dy2*/) const 95 : { 96 1 : mooseError("sampleValueAndDerivatives for ADReal numbers is not implemented for this " 97 : "interpolation class"); 98 : } 99 0 : virtual void sampleValueAndDerivatives(const ChainedReal & /*x1*/, 100 : const ChainedReal & /*x2*/, 101 : ChainedReal & /* y*/, 102 : ChainedReal & /* dy1*/, 103 : ChainedReal & /* dy2*/) const 104 : { 105 0 : mooseError("sampleValueAndDerivatives for ChainedReal numbers is not implemented for this " 106 : "interpolation class"); 107 : } 108 : };