chombo-discharge
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
LookupTable1D< T, N, I > Class Template Reference

Class for interpolation of f = f(x) data in one independent variable x. More...

#include <CD_LookupTable1D.H>

Inheritance diagram for LookupTable1D< T, N, I >:
Inheritance graph
[legend]

Public Member Functions

 LookupTable1D () noexcept
 Default constructor. Creates a table without any entries.
 
virtual ~LookupTable1D () noexcept=default
 Destructor (does nothing).
 
void reset () noexcept
 Reset everything.
 
template<size_t M, typename... Ts>
LookupTable1D< T, M, I > slice (const Ts &... a_columns) const noexcept
 Slice this table, keeping only the user-specified columns. More...
 
template<typename... Ts>
void addData (const Ts &... x) noexcept
 Add entry. More...
 
void addData (const std::array< T, N+1 > &x) noexcept
 Add entry. More...
 
void swap (const size_t a_columnOne, const size_t a_columnTwo) noexcept
 Utility function for swapping columns. More...
 
template<size_t K>
void scale (const T &a_scale) noexcept
 Utility function which scales one of the columns (either dependent or independent variable)
 
void truncate (const T &a_min, const T &a_max, const size_t a_column) noexcept
 Utility function for truncating raw data along one of the variables (either dependent or independent). More...
 
void setRangeStrategyLo (const LookupTable::OutOfRangeStrategy &a_strategy) noexcept
 Set the out-of-range strategy on the low end. More...
 
void setRangeStrategyHi (const LookupTable::OutOfRangeStrategy &a_strategy) noexcept
 Set the out-of-range strategy on the high end. More...
 
void prepareTable (const size_t &a_independentVariable, const size_t &a_numPoints, const LookupTable::Spacing &a_spacing)
 Turn the raw data into uniform data for fast lookup. More...
 
template<size_t K>
interpolate (const T &a_x) const
 Interpolation function for specific dependent variable K. More...
 
std::array< T, N+1 > interpolate (const T &x) const
 Interpolate whole table. More...
 
std::vector< std::array< T, N+1 > > & getRawData () noexcept
 Access function for raw data. More...
 
std::vector< std::array< T, N+1 > > & getStructuredData () noexcept
 Access function for structured data. More...
 
const std::vector< std::array< T, N+1 > > & getRawData () const noexcept
 Access function for raw data. More...
 
const std::vector< std::array< T, N+1 > > & getStructuredData () const noexcept
 Access function for structured data. More...
 
void writeRawData (const std::string &a_file) const noexcept
 Dump raw table data to file. More...
 
void writeStructuredData (const std::string &a_file) const noexcept
 Dump structured table data to file. More...
 
void outputRawData (std::ostream &a_ostream=std::cout) const noexcept
 Dump raw table data to output stream. More...
 
void outputStructuredData (std::ostream &a_ostream=std::cout) const noexcept
 Dump structured table data to file. More...
 

Protected Member Functions

void outputData (std::ostream &a_ostream, const std::vector< std::array< T, N+1 >> &a_data) const noexcept
 Utility function for outputting data. More...
 
void writeToFile (const std::string &a_file, const std::vector< std::array< T, N+1 >> &a_data) const noexcept
 Utility function for outputting data to a file. More...
 
size_t getIndexLo (const T &a_x) const
 Get the lower index that brackets the input variable between two data points in the structured grid. More...
 

Protected Attributes

bool m_isGood
 Check if data can be interpolated.
 
LookupTable::OutOfRangeStrategy m_rangeStrategyLo
 Out-of-range strategy on low end.
 
LookupTable::OutOfRangeStrategy m_rangeStrategyHi
 Out-of-range strategy on high end.
 
std::tuple< LookupTable::Spacing, size_t, T, T, T > m_grid
 Underlying 1D grid. This is populated when calling prepareTable.
 
std::vector< std::array< T, N+1 > > m_rawData
 Raw data.
 
std::vector< std::array< T, N+1 > > m_structuredData
 Structured data. This is populated when calling prepareTable.
 

Detailed Description

template<typename T = Real, size_t N = 1, typename I = std::enable_if_t<std::is_floating_point<T>::value>>
class LookupTable1D< T, N, I >

Class for interpolation of f = f(x) data in one independent variable x.

N is the number of additional dependent variables. T must be a floating point type (e.g., float, double)

Member Function Documentation

◆ addData() [1/2]

template<typename T , size_t N, typename I >
void LookupTable1D< T, N, I >::addData ( const std::array< T, N+1 > &  x)
inlinenoexcept

Add entry.

Parameters
[in]xEntry to add.

◆ addData() [2/2]

template<typename T , size_t N, typename I >
template<typename... Ts>
void LookupTable1D< T, N, I >::addData ( const Ts &...  x)
inlinenoexcept

Add entry.

Parameters
[in]xEntry to add. For example addData(1,1,1,1). Number of elements in x must be N+1

◆ getIndexLo()

template<typename T , size_t N, typename I >
size_t LookupTable1D< T, N, I >::getIndexLo ( const T &  a_x) const
inlineprotected

Get the lower index that brackets the input variable between two data points in the structured grid.

Parameters
[in]a_xIndependent variable.

◆ getRawData() [1/2]

template<typename T , size_t N, typename I >
const std::vector< std::array< T, N+1 > > & LookupTable1D< T, N, I >::getRawData
inlinenoexcept

Access function for raw data.

Returns
Returns m_rawData

◆ getRawData() [2/2]

template<typename T , size_t N, typename I >
std::vector< std::array< T, N+1 > > & LookupTable1D< T, N, I >::getRawData
inlinenoexcept

Access function for raw data.

Returns
Returns m_rawData

◆ getStructuredData() [1/2]

template<typename T , size_t N, typename I >
const std::vector< std::array< T, N+1 > > & LookupTable1D< T, N, I >::getStructuredData
inlinenoexcept

Access function for structured data.

Returns
Returns m_structuredData

◆ getStructuredData() [2/2]

template<typename T , size_t N, typename I >
std::vector< std::array< T, N+1 > > & LookupTable1D< T, N, I >::getStructuredData
inlinenoexcept

Access function for structured data.

Returns
Returns m_structuredData

◆ interpolate() [1/2]

template<typename T , size_t N, typename I >
template<size_t K>
T LookupTable1D< T, N, I >::interpolate ( const T &  a_x) const
inline

Interpolation function for specific dependent variable K.

Parameters
[in]a_xIndependent variable x

◆ interpolate() [2/2]

template<typename T , size_t N, typename I >
std::array< T, N+1 > LookupTable1D< T, N, I >::interpolate ( const T &  x) const
inline

Interpolate whole table.

Parameters
[in]a_xIndependent variable x

◆ outputData()

template<typename T , size_t N, typename I >
void LookupTable1D< T, N, I >::outputData ( std::ostream &  a_ostream,
const std::vector< std::array< T, N+1 >> &  a_data 
) const
inlineprotectednoexcept

Utility function for outputting data.

Parameters
[in]a_ostreamOutput stream
[in]a_dataData to be sent to output stream

◆ outputRawData()

template<typename T , size_t N, typename I >
void LookupTable1D< T, N, I >::outputRawData ( std::ostream &  a_ostream = std::cout) const
inlinenoexcept

Dump raw table data to output stream.

Parameters
[in]a_ostreamOutput stream

◆ outputStructuredData()

template<typename T , size_t N, typename I >
void LookupTable1D< T, N, I >::outputStructuredData ( std::ostream &  a_ostream = std::cout) const
inlinenoexcept

Dump structured table data to file.

Parameters
[in]a_ostreamOutput stream

◆ prepareTable()

template<typename T , size_t N, typename I >
void LookupTable1D< T, N, I >::prepareTable ( const size_t &  a_independentVariable,
const size_t &  a_numPoints,
const LookupTable::Spacing a_spacing 
)
inline

Turn the raw data into uniform data for fast lookup.

Parameters
[in]a_independentVariableThe independent variable (i.e., column in the input data).
[in]a_numPointsNumber of points in the input table.
[in]a_spacingTable spacing

◆ setRangeStrategyHi()

template<typename T , size_t N, typename I >
void LookupTable1D< T, N, I >::setRangeStrategyHi ( const LookupTable::OutOfRangeStrategy a_strategy)
inlinenoexcept

Set the out-of-range strategy on the high end.

Parameters
[in]a_strategyOut-of-range strategy on the high end

◆ setRangeStrategyLo()

template<typename T , size_t N, typename I >
void LookupTable1D< T, N, I >::setRangeStrategyLo ( const LookupTable::OutOfRangeStrategy a_strategy)
inlinenoexcept

Set the out-of-range strategy on the low end.

Parameters
[in]a_strategyOut-of-range strategy on low end

◆ slice()

template<typename T , size_t N, typename I >
template<size_t M, typename... Ts>
LookupTable1D< T, M, I > LookupTable1D< T, N, I >::slice ( const Ts &...  a_columns) const
noexcept

Slice this table, keeping only the user-specified columns.

This returns a new table with a reduced number of columns.

Parameters
[in]

◆ swap()

template<typename T , size_t N, typename I >
void LookupTable1D< T, N, I >::swap ( const size_t  a_columnOne,
const size_t  a_columnTwo 
)
inlinenoexcept

Utility function for swapping columns.

This is done on the raw data – if the user wants to swap columns in the resampled/structured data then he needs to call this function first and then resample the table through prepareTable

Parameters
[in]a_columnOneColumn to swap.
[in]a_columnTwoColumn to swap.

◆ truncate()

template<typename T , size_t N, typename I >
void LookupTable1D< T, N, I >::truncate ( const T &  a_min,
const T &  a_max,
const size_t  a_column 
)
inlinenoexcept

Utility function for truncating raw data along one of the variables (either dependent or independent).

This will discard (from the raw data) all data that fall outside the input interval. This is done on the raw data – the user will need to call prepareTable if the result should propagate into the resampled/structured data.

Parameters
[in]a_minMinimum value represented.
[in]a_maxMaximum value represented.

◆ writeRawData()

template<typename T , size_t N, typename I >
void LookupTable1D< T, N, I >::writeRawData ( const std::string &  a_file) const
inlinenoexcept

Dump raw table data to file.

Parameters
[in]a_fileFile name

◆ writeStructuredData()

template<typename T , size_t N, typename I >
void LookupTable1D< T, N, I >::writeStructuredData ( const std::string &  a_file) const
inlinenoexcept

Dump structured table data to file.

Parameters
[in]a_fileFile name

◆ writeToFile()

template<typename T , size_t N, typename I >
void LookupTable1D< T, N, I >::writeToFile ( const std::string &  a_file,
const std::vector< std::array< T, N+1 >> &  a_data 
) const
inlineprotectednoexcept

Utility function for outputting data to a file.

Parameters
[in]a_fileFile name
[in]a_dataData to be sent to output stream

The documentation for this class was generated from the following files: