LCOV - code coverage report
Current view: top level - include/utils - LinearInterpolation.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 6 6 100.0 %
Date: 2025-07-17 01:28:37 Functions: 3 3 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             : #include "Moose.h"
      13             : #include "MooseTypes.h"
      14             : 
      15             : #include <vector>
      16             : #include <string>
      17             : 
      18             : /**
      19             :  * This class interpolates values given a set of data pairs and an abscissa.
      20             :  */
      21             : class LinearInterpolation
      22             : {
      23             : public:
      24             :   /* Constructor, Takes two vectors of points for which to apply the fit.  One should be of the
      25             :    * independent variable while the other should be of the dependent variable.  These values should
      26             :    * correspond to one and other in the same position.
      27             :    */
      28             :   LinearInterpolation(const std::vector<Real> & X,
      29             :                       const std::vector<Real> & Y,
      30             :                       const bool extrap = false);
      31             :   LinearInterpolation() : _x(std::vector<Real>()), _y(std::vector<Real>()), _extrap(false) {}
      32             : 
      33        6176 :   virtual ~LinearInterpolation() = default;
      34             : 
      35             :   /**
      36             :    * Set the x and y values.
      37             :    */
      38         100 :   void setData(const std::vector<Real> & X, const std::vector<Real> & Y)
      39             :   {
      40         100 :     _x = X;
      41         100 :     _y = Y;
      42         100 :     errorCheck();
      43         100 :   }
      44             : 
      45             :   void errorCheck();
      46             : 
      47             :   /**
      48             :    * This function will take an independent variable input and will return the dependent variable
      49             :    * based on the generated fit
      50             :    */
      51             :   template <typename T>
      52             :   T sample(const T & x) const;
      53             : 
      54             :   /**
      55             :    * This function will take an independent variable input and will return the derivative of the
      56             :    * dependent variable
      57             :    * with respect to the independent variable based on the generated fit
      58             :    */
      59             :   template <typename T>
      60             :   T sampleDerivative(const T & x) const;
      61             : 
      62             :   /**
      63             :    * This function returns the size of the array holding the points, i.e. the number of sample
      64             :    * points
      65             :    */
      66             :   unsigned int getSampleSize() const;
      67             : 
      68             :   /**
      69             :    * This function returns the integral of the function over the whole domain
      70             :    */
      71             :   Real integrate();
      72             : 
      73             :   /**
      74             :    * Returns the integral of the function over a specified domain
      75             :    *
      76             :    * @param[in] x1  First point in integral domain
      77             :    * @param[in] x2  Second point in integral domain
      78             :    */
      79             :   Real integratePartial(Real x1, Real x2) const;
      80             : 
      81             :   Real domain(int i) const;
      82             :   Real range(int i) const;
      83             : 
      84             : private:
      85             :   std::vector<Real> _x;
      86             :   std::vector<Real> _y;
      87             : 
      88             :   bool _extrap;
      89             : };
      90             : 
      91             : // for backwards compatibility
      92             : typedef LinearInterpolation ADLinearInterpolation;
      93             : 
      94             : // temporary fixes to avoid breaking bison
      95             : template <typename T>
      96             : class LinearInterpolationTempl : public LinearInterpolation
      97             : {
      98             : public:
      99             :   using LinearInterpolation::LinearInterpolation;
     100             : };

Generated by: LCOV version 1.14