DiFfRG
Loading...
Searching...
No Matches
DiFfRG::ExternalDataInterpolator Class Reference

This class takes in a .csv file with x-dependent data and interpolates it to a given x on request. More...

#include <external_data_interpolator.hh>

Public Member Functions

 ExternalDataInterpolator (std::vector< std::string > input_files, std::vector< std::function< double(double)> > post_processors, char separator=',', bool has_header=false, uint x_column=0, uint order=1)
 Construct a new External Data Interpolator object.
 
 ExternalDataInterpolator (std::vector< std::string > input_files, char separator=',', bool has_header=false, uint x_column=0, uint order=1)
 Construct a new External Data Interpolator object.
 
 ExternalDataInterpolator ()
 Construct an empty External Data Interpolator object.
 
double value (double x, uint i) const
 Interpolate the data to a given x.
 
double derivative (double x, uint i) const
 Interpolate the derivative of the data to a given x.
 

Private Member Functions

void setup (const std::vector< std::string > &input_files, const std::vector< std::function< double(double)> > &post_processors, char separator=',', bool has_header=false, uint x_column=0, uint order=1)
 Set up the interpolator.
 
bool check_consistency (double tolerance) const
 Check whether the interpolator is consistent with the original data. The interpolator checks if it can reproduce the original data with a given relative precision.
 

Private Attributes

std::string input_file
 
std::vector< std::vector< double > > file_data
 
std::vector< boost::math::interpolators::barycentric_rational< double > > interpolators
 
double max_x
 
double min_x
 

Detailed Description

This class takes in a .csv file with x-dependent data and interpolates it to a given x on request.

Data can be read from several files which are identically formatted and will then be concatenated. The choice which column represents the independent x variable can be made by the user when creating the object. After read-in, the data can be post-processed before interpolation. After the object is constructed, this class allows to access both the interpolant and its derivative.

Note, that interpolations beyond the range of the data will return the value at the closest boundary.

Internally, the boost barycentric rational interpolator is used.

Constructor & Destructor Documentation

◆ ExternalDataInterpolator() [1/3]

DiFfRG::ExternalDataInterpolator::ExternalDataInterpolator ( std::vector< std::string > input_files,
std::vector< std::function< double(double)> > post_processors,
char separator = ',',
bool has_header = false,
uint x_column = 0,
uint order = 1 )

Construct a new External Data Interpolator object.

Parameters
input_filesThe .csv file(s) to read the data from.
post_processorsThe post processors to apply to the data.
separatorThe separator used in the .csv file.
has_headerWhether the .csv file has a header.
x_columnThe column in the .csv file(s) that contains the x values. This counts all columns, including the ones from previous files.

◆ ExternalDataInterpolator() [2/3]

DiFfRG::ExternalDataInterpolator::ExternalDataInterpolator ( std::vector< std::string > input_files,
char separator = ',',
bool has_header = false,
uint x_column = 0,
uint order = 1 )

Construct a new External Data Interpolator object.

Parameters
input_filesThe .csv file(s) to read the data from.
separatorThe separator used in the .csv file.
has_headerWhether the .csv file has a header.
x_columnThe column in the .csv file(s) that contains the x values. This counts all columns, including the ones from previous files.

◆ ExternalDataInterpolator() [3/3]

DiFfRG::ExternalDataInterpolator::ExternalDataInterpolator ( )

Construct an empty External Data Interpolator object.

Member Function Documentation

◆ check_consistency()

bool DiFfRG::ExternalDataInterpolator::check_consistency ( double tolerance) const
private

Check whether the interpolator is consistent with the original data. The interpolator checks if it can reproduce the original data with a given relative precision.

Parameters
toleranceThe relative precision to use.
Returns
true If the interpolator is consistent with the original data.

◆ derivative()

double DiFfRG::ExternalDataInterpolator::derivative ( double x,
uint i ) const

Interpolate the derivative of the data to a given x.

Parameters
xThe x to interpolate to.
iThe index of the data to interpolate.
Returns
double The interpolated derivative.

◆ setup()

void DiFfRG::ExternalDataInterpolator::setup ( const std::vector< std::string > & input_files,
const std::vector< std::function< double(double)> > & post_processors,
char separator = ',',
bool has_header = false,
uint x_column = 0,
uint order = 1 )
private

Set up the interpolator.

Parameters
input_filesThe .csv file(s) to read the data from.
post_processorsThe post processors to apply to the data.
separatorThe separator used in the .csv file.
has_headerWhether the .csv file has a header.
x_columnThe column in the .csv file(s) that contains the x values. This counts all columns, including the ones from previous files.

◆ value()

double DiFfRG::ExternalDataInterpolator::value ( double x,
uint i ) const

Interpolate the data to a given x.

Parameters
xThe x to interpolate to.
iThe index of the data to interpolate.
Returns
double The interpolated data.

Member Data Documentation

◆ file_data

std::vector<std::vector<double> > DiFfRG::ExternalDataInterpolator::file_data
private

◆ input_file

std::string DiFfRG::ExternalDataInterpolator::input_file
private

◆ interpolators

std::vector<boost::math::interpolators::barycentric_rational<double> > DiFfRG::ExternalDataInterpolator::interpolators
private

◆ max_x

double DiFfRG::ExternalDataInterpolator::max_x
private

◆ min_x

double DiFfRG::ExternalDataInterpolator::min_x
private

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