LCOV - code coverage report
Current view: top level - include/utils - TrilinearInterpolation.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 1 1 100.0 %
Date: 2025-07-17 01:28:37 Functions: 1 2 50.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 <vector>
      13             : #include "Moose.h"
      14             : 
      15             : using libMesh::Real;
      16             : 
      17             : /**
      18             :  * This class interpolates a function of three values (f(x,y,z)).  It takes 4
      19             :  * vectors for x, y, z, and function values, f(x,y,z).  The vector of function
      20             :  * values should be done in the following manner:
      21             :  * Function values of constant x and y are written, corresponding with values
      22             :  * in vector, z.
      23             :  * Function values for the constant x, next y-value, corresponding with values
      24             :  * in vector, z.
      25             :  * After last y-value, function values for the next x, first y-value,
      26             :  * corresponding with values in vector, z.
      27             :  *
      28             :  * An example:
      29             :  * f(1,4,7) = 10, f(1,4,8) = 11, f(1,4,9) = 12
      30             :  * f(1,5,7) = 13, f(1,5,8) = 14, f(1,5,9) = 15
      31             :  * f(1,6,7) = 16, f(1,6,8) = 17, f(1,6,9) = 18
      32             :  * f(2,4,7) = 20, f(2,4,8) = 21, f(2,4,9) = 22
      33             :  * f(2,5,7) = 23, f(2,5,8) = 24, f(2,5,9) = 25
      34             :  * f(2,6,7) = 26, f(2,6,8) = 27, f(2,6,9) = 28
      35             :  * f(3,4,7) = 30, f(3,4,8) = 31, f(3,4,9) = 32
      36             :  * f(3,5,7) = 33, f(3,5,8) = 34, f(3,5,9) = 35
      37             :  * f(3,6,7) = 36, f(3,6,8) = 37, f(3,6,9) = 38
      38             :  *
      39             :  * x = {1, 2, 3};
      40             :  * y = {4, 5, 6};
      41             :  * z = {7, 8, 9};
      42             :  * fxyz = {
      43             :  *  // fxyz for x = 1
      44             :  *  10, 11, 12,
      45             :  *  13, 14, 15,
      46             :  *  16, 17, 18,
      47             :  *  // fxyz for x = 2
      48             :  *  20, 21, 22,
      49             :  *  23, 24, 25,
      50             :  *  26, 27, 28,
      51             :  *  // fxyz for x = 3
      52             :  *  30, 31, 32,
      53             :  *  33, 34, 35,
      54             :  *  36, 37, 38
      55             :  *  };
      56             :  *
      57             :  */
      58             : class TrilinearInterpolation
      59             : {
      60             : public:
      61             :   /**
      62             :    * Constructor initializes data for interpolation
      63             :    * @param x vector for x-coordinates
      64             :    * @param y vector for y-coordinates
      65             :    * @param z vector for z-coordinates
      66             :    * @param data vector for function values formatted in the same manner as the example
      67             :    */
      68             :   TrilinearInterpolation(const std::vector<Real> & x,
      69             :                          const std::vector<Real> & y,
      70             :                          const std::vector<Real> & z,
      71             :                          const std::vector<Real> & data);
      72             : 
      73           5 :   virtual ~TrilinearInterpolation() = default;
      74             : 
      75             :   /**
      76             :    * Interpolates for the desired (x,y,z) coordinate and returns the value
      77             :    * based on the function values vector.
      78             :    * @param x desired x-coordinate
      79             :    * @param y desired y-coordinate
      80             :    * @param z desired z-coordinate
      81             :    * @return interpolated value at coordinate (x,y,z)
      82             :    */
      83             :   Real sample(Real x, Real y, Real z) const;
      84             : 
      85             : protected:
      86             :   /// vector of x-values
      87             :   std::vector<Real> _x_axis;
      88             : 
      89             :   /// vector of y-values
      90             :   std::vector<Real> _y_axis;
      91             : 
      92             :   /// vector of z-values
      93             :   std::vector<Real> _z_axis;
      94             : 
      95             :   /// vector of function values, f(x,y,z)
      96             :   std::vector<Real> _fxyz;
      97             : 
      98             :   /**
      99             :    * Finds the indices of the cube that point (x,y,z) is in.
     100             :    * @param[in] v vector to find lower and upper limits for the cube
     101             :    * @param[in] x desired coordinate
     102             :    * @param[out] lower lower limit for cube
     103             :    * @param[out] upper upper limit for cube
     104             :    * @param[out] d ratio of (x - lower) / (upper - lower)
     105             :    */
     106             :   void
     107             :   getCornerIndices(const std::vector<Real> & v, Real x, int & lower, int & upper, Real & d) const;
     108             : 
     109             :   /**
     110             :    * Searches the function value vector for the value at a given corner
     111             :    * coordinate from the getCornerIndices function.
     112             :    * @param x index for x-coordinate of corner
     113             :    * @param y index for y-coordinate of corner
     114             :    * @param z index for z-coordinate of corner
     115             :    * @return function value for the (x,y,z) coordinate
     116             :    */
     117             :   Real getCornerValues(int x, int y, int z) const;
     118             : };

Generated by: LCOV version 1.14