LCOV - code coverage report
Current view: top level - include/utils - MultiDimensionalInterpolation.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 1 2 50.0 %
Date: 2025-07-17 01:28:37 Functions: 1 9 11.1 %
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             : #include "ADReal.h"
      15             : #include "MultiIndex.h"
      16             : #include <vector>
      17             : #include <string>
      18             : 
      19             : /**
      20             :  * This class interpolates multi-dimensional data sets
      21             :  */
      22             : template <typename T>
      23             : class MultiDimensionalInterpolationTempl
      24             : {
      25             : public:
      26             :   /**
      27             :    * Constructor, Takes a double vector containing the interpolation base points, and a
      28             :    * MultiIndex object. The double vector base_points and the MultiIndex object data must
      29             :    */
      30             :   MultiDimensionalInterpolationTempl(const std::vector<std::vector<Real>> & base_points,
      31             :                                      const MultiIndex<Real> & data);
      32             :   MultiDimensionalInterpolationTempl();
      33             : 
      34           5 :   virtual ~MultiDimensionalInterpolationTempl() = default;
      35             : 
      36             :   /// returns the dimensionality of this interpolation object
      37           0 :   unsigned int dim() const { return _original_dim; }
      38             : 
      39             :   /// sets data but also fixes degenerate dimensions in data
      40             :   void setData(const std::vector<std::vector<Real>> & base_points, const MultiIndex<Real> & data);
      41             : 
      42             :   /**
      43             :    * linearSearch finds the indices i_k of the base point such that
      44             :    * base_point[d][i_k] <= values[d] < base_point[d][i_k + 1]
      45             :    * Note that argument is non-const to handle smaller/larger than tabulation range
      46             :    * For tabulations < 100 entries, linearSearch is expected to be better than bisection search
      47             :    */
      48             :   void linearSearch(std::vector<T> & values, MultiIndex<Real>::size_type & indices) const;
      49             : 
      50             :   /**
      51             :    * This function will take an independent variable input and will return the dependent variable
      52             :    * based on multi-linear interpolation. Multi-linear interpolation uses all 2^d values in the
      53             :    * base points surrounding x.
      54             :    */
      55             :   T multiLinearInterpolation(const std::vector<T> & x) const;
      56             : 
      57             : protected:
      58             :   /// checks consistency of the data
      59             :   void errorCheck();
      60             : 
      61             :   /**
      62             :    * linear search helper for a single std::vector; note that argument is non-const to
      63             :    * handle smaller/larger than tabulation range
      64             :    */
      65             :   unsigned int linearSearchHelper(T & x, const std::vector<Real> & vector) const;
      66             : 
      67             :   /// original dimension is to allow checks on user inputs for cases where arrays are sliced
      68             :   unsigned int _original_dim;
      69             : 
      70             :   /// this variable keeps track on which dimension is degenerate and was removed
      71             :   std::vector<bool> _degenerate_index;
      72             : 
      73             :   /**
      74             :    * if all dimensions have size one then there is only one value to return
      75             :    * this corner case should be supported so the calling routine does not need
      76             :    * to check for it
      77             :    */
      78             :   bool _degenerate_interpolation = false;
      79             : 
      80             : private:
      81             :   std::vector<std::vector<Real>> _base_points;
      82             :   MultiIndex<Real> _data;
      83             :   bool _setup_complete = false;
      84             : };
      85             : 
      86             : typedef MultiDimensionalInterpolationTempl<Real> MultiDimensionalInterpolation;
      87             : typedef MultiDimensionalInterpolationTempl<ADReal> DualMultiDimensionalInterpolation;
      88             : typedef DualMultiDimensionalInterpolation ADMultiDimensionalInterpolation;

Generated by: LCOV version 1.14