Ember
Loading...
Searching...
No Matches
Namespaces | Macros | Typedefs | Functions | Variables
mathUtils.h File Reference
#include <vector>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include "debugUtils.h"
#include "cantera/base/ct_defs.h"
#include <eigen3/Eigen/Dense>
Include dependency graph for mathUtils.h:
This graph shows which files directly or indirectly include this file:

Namespaces

namespace  mathUtils
 A collection of general-purpose mathematical functions for working with vectors.
 

Macros

#define _USE_MATH_DEFINES
 
#define NOMINMAX
 

Typedefs

typedef Eigen::ArrayXXd dmatrix
 
typedef Eigen::ArrayXd dvec
 
typedef Eigen::ArrayXd::Index index_t
 
typedef Eigen::Stride< Eigen::Dynamic, Eigen::Dynamic > StrideXX
 
typedef Eigen::Stride< 1, Eigen::Dynamic > Stride1X
 
typedef Eigen::Map< dmatrix, Eigen::Aligned, StrideXXMatrixMap
 
typedef Eigen::Map< dvec, Eigen::Unaligned, Stride1XVecMap
 
typedef std::vector< double > dvector
 

Functions

void remap (dmatrix &M, MatrixMap &A, index_t nRows, index_t nCols, index_t start)
 
void remap (dmatrix &M, VecMap &A, index_t nVals, index_t start)
 
double mathUtils::maxval (const dvector &v)
 Returns the value of the maximum element of a vector.
 
double mathUtils::minval (const dvector &v)
 Returns the value of the minimum element of a vector.
 
double mathUtils::range (const dvector &v)
 Returns the range (maximum - minimum) of a vector.
 
double mathUtils::sum (const dvector &v)
 Returns the sum of all the elements in a vector.
 
double mathUtils::mean (const dvector &v)
 Returns the arithemetic mean of the elements in a vector.
 
double mathUtils::maxval (const dvector &v, size_t iStart, size_t iEnd)
 Returns the value of the maximum element of the sub-vector of v with indices on the closed interval [iStart, iEnd]
 
double mathUtils::minval (const dvector &v, size_t iStart, size_t iEnd)
 Returns the value of the minimum element of the sub-vector of v with indices on the closed interval [iStart, iEnd]
 
double mathUtils::range (const dvector &v, size_t iStart, size_t iEnd)
 Returns the range (maximum - minimum) of the sub-vector of v with indices on the closed interval [iStart, iEnd]
 
double mathUtils::sum (const dvector &v, size_t iStart, size_t iEnd)
 Returns the sum of all the elements in the sub-vector of v with indices on the closed interval [iStart, iEnd]
 
double mathUtils::mean (const dvector &v, size_t iStart, size_t iEnd)
 Returns the arithemetic mean of the sub-vector of v with indices on the closed interval [iStart, iEnd]
 
size_t mathUtils::minloc (const dvector &v)
 Returns the index of the minimum element of v.
 
size_t mathUtils::maxloc (const dvector &v)
 Returns the index of the maximum element of v.
 
template<typename Derived >
bool mathUtils::notnan (const Eigen::EigenBase< Derived > &v)
 Returns true if v does not contain any NaNs.
 
template<typename T >
bool mathUtils::notnan (const vector< T > &v)
 Returns true if v does not contain any NaNs.
 
bool mathUtils::notnan (const double &v)
 Returns true if v is not NaN.
 
bool mathUtils::notnan (const sdVector &v)
 Returns true if v does not contain any NaNs.
 
size_t mathUtils::nanloc (const dvector &v)
 Returns the index of first NaN component of v.
 
bool mathUtils::almostEqual (double a, double b, double rtol=1e-10, double atol=1e-18)
 Returns true if a and b are equal to within the specified relative (rtol) and absolute (atol) tolerances.
 
dvector mathUtils::abs (const dvector &v)
 Returns a vector containing the absolute values of the elements of v.
 
template<class T >
int mathUtils::findFirst (const T &v)
 Returns the index of the first element of v which is true.
 
template<class T >
int mathUtils::findLast (const T &v)
 Returns the index of the last element of v which is true.
 
vector< int > mathUtils::find (vector< bool > &v)
 Returns a vector containing the indices of the elements of v which are true.
 
template<class T >
void mathUtils::smooth (T &v)
 Applies a simple smoothing function to v which effectively filters out high-frequency components.
 
dvector mathUtils::linspace (const double x1, const double x2, const int n)
 Returns a vector of n elements linearly spaced along the closed interval [x1, x2]
 
template<class T1 , class T2 >
vector< T1 > mathUtils::computeSplines (const T1 &xIn, const T2 &yIn)
 Internal function for calculating cubic splines for a sequence of data points.
 
template<class T >
mathUtils::interp1 (const T &xIn, const T &yIn, const T &xOut, bool extrap=true)
 Linear interpolation for a vector of desired outputs.
 
template<class T >
double mathUtils::interp1 (const T &xIn, const T &yIn, const double xOut, bool extrap=true)
 Linear interpolation for a single output point.
 
dvec mathUtils::splines (const dvec &xIn, const dvec &yIn, const dvec &xOut)
 Cubic spline interpolation for a vector of desired outputs.
 
double mathUtils::splines (const dvec &xIn, const dvec &yIn, const double xOut)
 Cubic spline interpolation for a single output point.
 
template<class T1 , class T2 >
double mathUtils::integrate (const T1 &x, const T2 &y)
 Numerical integration using the cubic spline fit for the given data.
 
template<class T1 , class T2 >
double mathUtils::trapz (const T1 &x, const T2 &y)
 Trapezoidal rule integration.
 
void mathUtils::vectorVectorToArray2D (const vector< dvector > &v, dmatrix &a)
 
void mathUtils::array2DToVectorVector (const dmatrix &a, vector< dvector > &v)
 
std::string mathUtils::stringify (double x)
 
std::string mathUtils::stringify (double x, int nDigits)
 
std::string mathUtils::stringify (int x)
 
int mathUtils::sign (const double x)
 
int mathUtils::sign (const int x)
 
template<class Tx , class Ty >
void mathUtils::uniqueSort (vector< Tx > &keys, vector< vector< Ty > > &values)
 Sort & remove duplicate entries from keys, and perform the same permutation on values Requires that keys.size() == values[i].size()
 
std::ostream & operator<< (std::ostream &os, const dvector &v)
 
std::ostream & operator<< (std::ostream &os, const vector< bool > &v)
 
std::ostream & operator<< (std::ostream &os, const vector< int > &v)
 
dvectoroperator+= (dvector &v1, const dvector &v2)
 
dvector operator+ (const dvector &v1, const dvector &v2)
 
dvectoroperator-= (dvector &v1, const dvector &v2)
 
dvector operator- (const dvector &v1, const dvector &v2)
 
dvectoroperator+= (dvector &v1, const double s)
 
dvector operator+ (const dvector &v1, const double s)
 
dvectoroperator-= (dvector &v1, const double s)
 
dvector operator- (const dvector &v1, const double s)
 
dvectoroperator*= (dvector &v1, const dvector &v2)
 
dvector operator* (const dvector &v1, const dvector &v2)
 
dvectoroperator*= (dvector &v1, const double s)
 
dvector operator* (const dvector &v1, const double s)
 
dvector operator* (const double s, const dvector &v1)
 
dvectoroperator/= (dvector &v1, const dvector &v2)
 
dvector operator/ (const dvector &v1, const dvector &v2)
 
dvectoroperator/= (dvector &v1, const double s)
 
dvector operator/ (const dvector &v1, const double s)
 
vector< bool > operator> (const dvector &v1, const dvector &v2)
 
vector< bool > operator< (const dvector &v1, const dvector &v2)
 
vector< bool > operator>= (const dvector &v1, const dvector &v2)
 
vector< bool > operator<= (const dvector &v1, const dvector &v2)
 
vector< bool > operator== (const dvector &v1, const dvector &v2)
 
vector< bool > operator!= (const dvector &v1, const dvector &v2)
 
vector< bool > operator> (const dvector &v1, const double &s)
 
vector< bool > operator< (const dvector &v1, const double &s)
 
vector< bool > operator>= (const dvector &v1, const double &s)
 
vector< bool > operator<= (const dvector &v1, const double &s)
 
vector< bool > operator== (const dvector &v1, const double &s)
 
vector< bool > operator!= (const dvector &v1, const double &s)
 
vector< bool > operator! (const vector< bool > &v)
 
vector< bool > operator&& (const vector< bool > &v1, const vector< bool > &v2)
 
vector< bool > operator|| (const vector< bool > &v1, const vector< bool > &v2)
 

Variables

const double NaN
 

Macro Definition Documentation

◆ _USE_MATH_DEFINES

#define _USE_MATH_DEFINES

◆ NOMINMAX

#define NOMINMAX

Typedef Documentation

◆ dmatrix

typedef Eigen::ArrayXXd dmatrix

◆ dvec

typedef Eigen::ArrayXd dvec

◆ index_t

typedef Eigen::ArrayXd::Index index_t

◆ StrideXX

typedef Eigen::Stride<Eigen::Dynamic,Eigen::Dynamic> StrideXX

◆ Stride1X

typedef Eigen::Stride<1,Eigen::Dynamic> Stride1X

◆ MatrixMap

typedef Eigen::Map<dmatrix, Eigen::Aligned, StrideXX > MatrixMap

◆ VecMap

typedef Eigen::Map<dvec, Eigen::Unaligned, Stride1X> VecMap

◆ dvector

typedef std::vector<double> dvector

Function Documentation

◆ remap() [1/2]

void remap ( dmatrix M,
MatrixMap A,
index_t  nRows,
index_t  nCols,
index_t  start 
)
inline

◆ remap() [2/2]

void remap ( dmatrix M,
VecMap A,
index_t  nVals,
index_t  start 
)
inline

◆ operator<<() [1/3]

std::ostream & operator<< ( std::ostream &  os,
const dvector v 
)

◆ operator<<() [2/3]

std::ostream & operator<< ( std::ostream &  os,
const vector< bool > &  v 
)

◆ operator<<() [3/3]

std::ostream & operator<< ( std::ostream &  os,
const vector< int > &  v 
)

◆ operator+=() [1/2]

dvector & operator+= ( dvector v1,
const dvector v2 
)

◆ operator+() [1/2]

dvector operator+ ( const dvector v1,
const dvector v2 
)

◆ operator-=() [1/2]

dvector & operator-= ( dvector v1,
const dvector v2 
)

◆ operator-() [1/2]

dvector operator- ( const dvector v1,
const dvector v2 
)

◆ operator+=() [2/2]

dvector & operator+= ( dvector v1,
const double  s 
)

◆ operator+() [2/2]

dvector operator+ ( const dvector v1,
const double  s 
)

◆ operator-=() [2/2]

dvector & operator-= ( dvector v1,
const double  s 
)

◆ operator-() [2/2]

dvector operator- ( const dvector v1,
const double  s 
)

◆ operator*=() [1/2]

dvector & operator*= ( dvector v1,
const dvector v2 
)

◆ operator*() [1/3]

dvector operator* ( const dvector v1,
const dvector v2 
)

◆ operator*=() [2/2]

dvector & operator*= ( dvector v1,
const double  s 
)

◆ operator*() [2/3]

dvector operator* ( const dvector v1,
const double  s 
)

◆ operator*() [3/3]

dvector operator* ( const double  s,
const dvector v1 
)

◆ operator/=() [1/2]

dvector & operator/= ( dvector v1,
const dvector v2 
)

◆ operator/() [1/2]

dvector operator/ ( const dvector v1,
const dvector v2 
)

◆ operator/=() [2/2]

dvector & operator/= ( dvector v1,
const double  s 
)

◆ operator/() [2/2]

dvector operator/ ( const dvector v1,
const double  s 
)

◆ operator>() [1/2]

vector< bool > operator> ( const dvector v1,
const dvector v2 
)

◆ operator<() [1/2]

vector< bool > operator< ( const dvector v1,
const dvector v2 
)

◆ operator>=() [1/2]

vector< bool > operator>= ( const dvector v1,
const dvector v2 
)

◆ operator<=() [1/2]

vector< bool > operator<= ( const dvector v1,
const dvector v2 
)

◆ operator==() [1/2]

vector< bool > operator== ( const dvector v1,
const dvector v2 
)

◆ operator!=() [1/2]

vector< bool > operator!= ( const dvector v1,
const dvector v2 
)

◆ operator>() [2/2]

vector< bool > operator> ( const dvector v1,
const double &  s 
)

◆ operator<() [2/2]

vector< bool > operator< ( const dvector v1,
const double &  s 
)

◆ operator>=() [2/2]

vector< bool > operator>= ( const dvector v1,
const double &  s 
)

◆ operator<=() [2/2]

vector< bool > operator<= ( const dvector v1,
const double &  s 
)

◆ operator==() [2/2]

vector< bool > operator== ( const dvector v1,
const double &  s 
)

◆ operator!=() [2/2]

vector< bool > operator!= ( const dvector v1,
const double &  s 
)

◆ operator!()

vector< bool > operator! ( const vector< bool > &  v)

◆ operator&&()

vector< bool > operator&& ( const vector< bool > &  v1,
const vector< bool > &  v2 
)

◆ operator||()

vector< bool > operator|| ( const vector< bool > &  v1,
const vector< bool > &  v2 
)

Variable Documentation

◆ NaN

const double NaN
extern