LCOV - code coverage report
Current view: top level - include/utils - BilinearInterpolation.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 1 1 100.0 %
Date: 2025-07-17 01:28:37 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             : // MOOSE includes
      13             : #include "ColumnMajorMatrix.h"
      14             : #include "BidimensionalInterpolation.h"
      15             : 
      16             : // C++ includes
      17             : #include <vector>
      18             : 
      19             : /**
      20             :  * This class applies the Least Squares algorithm to a set of points
      21             :  * to provide a smooth curve for sampling values.
      22             :  * BilinearInterpolation is designed to linearly interpolate a
      23             :  * function of two values e.g. z(x,y).  Supply Bilinearlinear with a
      24             :  * vector of x and a vector of y and a ColumnMajorMatrix of function
      25             :  * values, z, that correspond to the values in the vectors x and
      26             :  * y...and also a sample point (s1 and s2), and
      27             :  * BilinearInterpolation will return the value of the function at the
      28             :  * sample point.  A simple example:
      29             :  *
      30             :  * x = [1 2], y = [1 2],
      31             :  *
      32             :  * z = [1 2]
      33             :  *     [3 4]
      34             :  *
      35             :  * with s1 = 1.5 and s2 = 1.5 returns a value of 2.5.
      36             :  */
      37             : class BilinearInterpolation : public BidimensionalInterpolation
      38             : {
      39             : public:
      40             :   /**
      41             :    *  Constructor, Takes two vectors of points for which to apply the
      42             :    * fit.  One should be of the independent variable while the other
      43             :    * should be of the dependent variable.  These values should
      44             :    * correspond to one and other in the same position.
      45             :    */
      46             :   BilinearInterpolation(const std::vector<Real> & xaxis,
      47             :                         const std::vector<Real> & yaxis,
      48             :                         const ColumnMajorMatrix & zsurface);
      49             : 
      50         314 :   virtual ~BilinearInterpolation() = default;
      51             : 
      52             :   /**
      53             :    * This function will take an independent variable input and will
      54             :    * return the dependent variable based on the generated fit.
      55             :    */
      56             :   Real sample(const Real s1, const Real s2) const override;
      57             :   ADReal sample(const ADReal & s1, const ADReal & s2) const override;
      58             :   ChainedReal sample(const ChainedReal & s1, const ChainedReal & s2) const override;
      59             : 
      60             :   /**
      61             :    * Samples first derivative at point (s1, s2)
      62             :    */
      63             :   Real sampleDerivative(const Real s1, const Real s2, unsigned int deriv_var) const override;
      64             :   ADReal
      65             :   sampleDerivative(const ADReal & s1, const ADReal & s2, unsigned int deriv_var) const override;
      66             :   ChainedReal sampleDerivative(const ChainedReal & s1,
      67             :                                const ChainedReal & s2,
      68             :                                unsigned int deriv_var) const override;
      69             : 
      70             :   using BidimensionalInterpolation::sampleValueAndDerivatives;
      71             :   void sampleValueAndDerivatives(
      72             :       Real s1, Real s2, Real & y, Real & dy_ds1, Real & dy_ds2) const override;
      73             : 
      74             :   void getNeighborIndices(const std::vector<Real> & inArr,
      75             :                           Real x,
      76             :                           unsigned int & lowerX,
      77             :                           unsigned int & upperX) const;
      78             : 
      79             : private:
      80             :   /// sampleInternal only used by BilinearInterpolation, hence made private
      81             :   template <typename T>
      82             :   T sampleInternal(const T & s1, const T & s2) const;
      83             : 
      84             :   template <typename T>
      85             :   T sampleDerivativeInternal(const T s1, const T s2, const unsigned int deriv_var) const;
      86             : 
      87             :   ColumnMajorMatrix _z_surface;
      88             :   static int _file_number;
      89             : };

Generated by: LCOV version 1.14