GeneralMath Class Reference

#include <GeneralMath.h>

Static Public Member Functions

static bool CalculateConcentration (const SEScalarMass &mass, const SEScalarVolume &volume, SEScalarMassPerVolume &concentration, Logger *logger=nullptr)
 Calculates the concentration of a substance given mass and volume. concentration = mass / volume. More...
 
static bool CalculateMass (const SEScalarVolume &volume, const SEScalarMassPerVolume &concentration, SEScalarMass &mass, Logger *logger=nullptr)
 Calculates the mass of a substance given concentration and volume. mass = concentration * volume. More...
 
static bool CalculateHenrysLawConcentration (const SESubstance &substance, const SEScalarPressure &partialPressure, SEScalarMassPerVolume &concentration, Logger *logger=nullptr)
 Calculates the mass of a substance given concentration and volume. mass = concentration * volume. More...
 
static bool CalculatePartialPressureInGas (const SEScalar0To1 &volumeFraction, const SEScalarPressure &pressure, SEScalarPressure &partialPressure, Logger *logger=nullptr)
 Calculates the partial pressure of a substance in gas based on the volumeFraction * pressure. More...
 
static bool CalculatePartialPressureInLiquid (const SESubstance &substance, const SEScalarMassPerVolume &concentration, SEScalarPressure &partialPressure, Logger *logger=nullptr)
 Calculates the partial pressure of a substance in liquid using (density and solubility coefficient) and the concentration. More...
 
static void CalculateOsmolarity (const SEScalarAmountPerVolume &sodiumMolarity, const SEScalarAmountPerVolume &potassiumMolarity, const SEScalarAmountPerVolume &glucoseMolarity, const SEScalarAmountPerVolume &ureaMolarity, SEScalarOsmolarity &fluidOsmolarity)
 [32] More...
 
static void CalculateOsmolality (const SEScalarAmountPerVolume &sodiumMolarity, const SEScalarAmountPerVolume &potassiumMolarity, const SEScalarAmountPerVolume &glucoseMolarity, const SEScalarAmountPerVolume &ureaMolarity, const SEScalar &specificGravity, SEScalarOsmolality &fluidOsmolality)
 [32] More...
 
static bool CalculateSpecificGravity (const SEScalarMass &mass, const SEScalarVolume &volume, SEScalar &specificGravity, Logger *logger=nullptr)
 
static void Combinations (std::vector< size_t > maxValues, std::vector< std::vector< size_t > > &permutations)
 
static bool LinearInterpolator (std::vector< double > &v, size_t newSize)
 
static void LinearInterpolator1 (std::vector< double > &v, size_t newSize)
 A 1D linear interpolator which keeps the min/max value from input. More...
 
static double LinearInterpolator (double initial, double target, double percent)
 Performs a 1D linear interpolation between two points given the percent between start/finish. More...
 
static double LinearInterpolator (double x1, double x2, double y1, double y2, double xPrime)
 Performs linear interpolation between two points. More...
 
static double PiecewiseLinearInterpolator (const std::vector< std::pair< double, double > > &points, double x)
 
static void SplineInterpolater (std::vector< double > &v, size_t newSize)
 
static double ParbolicInterpolator (double min, double max, double factor)
 
static double Damper (double targetValue, double previousValue, double dampenFraction_perSec, double timeStep_s)
 
static double PercentDifference (double expected, double calculated)
 
static double PercentTolerance (double expected, double calculated, double epsilon=1e-20)
 
static double ExponentialDecayFunction (double dbase, double dmin, double dmax, double dx)
 Returns y value for the specified logarithmic function given a normalized x value (0.0 to 1.0). More...
 
static double ExponentialGrowthFunction (double dbase, double dmin, double dmax, double dx)
 Returns y value for the specified logarithmic function given a normalized x value (0.0 to 1.0). More...
 
static double LogisticFunction (double a, double x50, double k, double x)
 A logistic function. More...
 
static double RootMeanSquaredError (std::vector< double > observed, std::vector< double > predicted, bool normalize=false, double outlierStandardDeviation=-1.0)
 

Member Function Documentation

◆ CalculateConcentration()

PUSH_EIGEN_WARNINGS POP_EIGEN_WARNINGS bool GeneralMath::CalculateConcentration ( const SEScalarMass mass,
const SEScalarVolume volume,
SEScalarMassPerVolume concentration,
Logger logger = nullptr 
)
static

Calculates the concentration of a substance given mass and volume. concentration = mass / volume.

◆ CalculateHenrysLawConcentration()

bool GeneralMath::CalculateHenrysLawConcentration ( const SESubstance substance,
const SEScalarPressure partialPressure,
SEScalarMassPerVolume concentration,
Logger logger = nullptr 
)
static

Calculates the mass of a substance given concentration and volume. mass = concentration * volume.

◆ CalculateMass()

bool GeneralMath::CalculateMass ( const SEScalarVolume volume,
const SEScalarMassPerVolume concentration,
SEScalarMass mass,
Logger logger = nullptr 
)
static

Calculates the mass of a substance given concentration and volume. mass = concentration * volume.

◆ CalculateOsmolality()

void GeneralMath::CalculateOsmolality ( const SEScalarAmountPerVolume sodiumMolarity,
const SEScalarAmountPerVolume potassiumMolarity,
const SEScalarAmountPerVolume glucoseMolarity,
const SEScalarAmountPerVolume ureaMolarity,
const SEScalar specificGravity,
SEScalarOsmolality fluidOsmolality 
)
static

◆ CalculateOsmolarity()

void GeneralMath::CalculateOsmolarity ( const SEScalarAmountPerVolume sodiumMolarity,
const SEScalarAmountPerVolume potassiumMolarity,
const SEScalarAmountPerVolume glucoseMolarity,
const SEScalarAmountPerVolume ureaMolarity,
SEScalarOsmolarity fluidOsmolarity 
)
static

◆ CalculatePartialPressureInGas()

bool GeneralMath::CalculatePartialPressureInGas ( const SEScalar0To1 volumeFraction,
const SEScalarPressure pressure,
SEScalarPressure partialPressure,
Logger logger = nullptr 
)
static

Calculates the partial pressure of a substance in gas based on the volumeFraction * pressure.

◆ CalculatePartialPressureInLiquid()

bool GeneralMath::CalculatePartialPressureInLiquid ( const SESubstance substance,
const SEScalarMassPerVolume concentration,
SEScalarPressure partialPressure,
Logger logger = nullptr 
)
static

Calculates the partial pressure of a substance in liquid using (density and solubility coefficient) and the concentration.

◆ CalculateSpecificGravity()

bool GeneralMath::CalculateSpecificGravity ( const SEScalarMass mass,
const SEScalarVolume volume,
SEScalar specificGravity,
Logger logger = nullptr 
)
static

◆ Combinations()

void GeneralMath::Combinations ( std::vector< size_t >  maxValues,
std::vector< std::vector< size_t > > &  permutations 
)
static

◆ Damper()

double GeneralMath::Damper ( double  targetValue,
double  previousValue,
double  dampenFraction_perSec,
double  timeStep_s 
)
static

◆ ExponentialDecayFunction()

double GeneralMath::ExponentialDecayFunction ( double  dbase,
double  dmin,
double  dmax,
double  dx 
)
static

Returns y value for the specified logarithmic function given a normalized x value (0.0 to 1.0).

y = dbase ^ [(Log10(dmin/dmax) * x) + Log10(dmax)]

Parameters
dbasebase value
dminminimum
dmaxmaximum
xnormalized x, 0.0 to 1.0
Returns
y

Exponential function used to model changes based on severity. Requires a base value for the function, a maximum y value (x = 0), and minimum y value (x = 1). Return the y value that maps to x.

Limitations:

  • dmin > 0
  • dmax > 0
  • 0.0 <= dx <= 1.0

If any of the input variables fall outside the above bounds, the function returns NaN

Input with a min value greater than max value will be exponential growth

◆ ExponentialGrowthFunction()

double GeneralMath::ExponentialGrowthFunction ( double  dbase,
double  dmin,
double  dmax,
double  dx 
)
static

Returns y value for the specified logarithmic function given a normalized x value (0.0 to 1.0).

y = dbase ^ [(Log10(dmax/dmin) * x) + Log10(dmin)]

Parameters
dbasebase value
dminminimum
dmaxmaximum
xnormalized x, 0.0 to 1.0
Returns
y

Exponential function used to model changes based on severity. Requires a base value for the function, a minimum y value (x = 0), and maximum y value (x = 1). Return the y value that maps to x.

Limitations:

  • dmin > 0
  • dmax > 0
  • 0.0 <= dx <= 1.0

If any of the input variables fall outside the above bounds, the function returns NaN

Input with a min value greater than max value will be exponential decay

◆ LinearInterpolator() [1/3]

double GeneralMath::LinearInterpolator ( double  initial,
double  target,
double  percent 
)
static

Performs a 1D linear interpolation between two points given the percent between start/finish.

Parameters
startinitial value
finishtarget value
percentpercent to interpolate between initial and target
Returns
the value between initial and target at the given percent

◆ LinearInterpolator() [2/3]

double GeneralMath::LinearInterpolator ( double  x1,
double  x2,
double  y1,
double  y2,
double  xPrime 
)
static

Performs linear interpolation between two points.

Parameters
x1value 1 on the x axis, must be smaller than x2
x2value 2 on the x axis, must be larger than x1
y1the y value corresponding to x1
y2the y value corresponding to x2
xPrimethe interpolation point
Returns
the y value corresponding to xPrime

Linear Interpolator finds the y value at xPrime, as long as xPrime is between x1 and x2. The slope and Y intercept of the line connecting (x1,y1) and (x2,y2) are then found so y = mx + b can be used to find yPrime by inputting xPrime.

◆ LinearInterpolator() [3/3]

bool GeneralMath::LinearInterpolator ( std::vector< double > &  v,
size_t  newSize 
)
static

◆ LinearInterpolator1()

void GeneralMath::LinearInterpolator1 ( std::vector< double > &  v,
size_t  newSize 
)
static

A 1D linear interpolator which keeps the min/max value from input.

Parameters
vinput 1D vector
newSizenumber of points in output vector

A 1D linear interpolator which sets the min/max values from the original input to the nearest neighbour points for maintaining the range the original input. Both input and output are assumed to be equally spaced.

◆ LogisticFunction()

double GeneralMath::LogisticFunction ( double  a,
double  x50,
double  k,
double  x 
)
static

A logistic function.

Parameters
aasymptote
x50x-value at sigmoid midpoint
kcurve steepness and direction parameter
xinput value
Returns
y

A logistic function.

◆ ParbolicInterpolator()

double GeneralMath::ParbolicInterpolator ( double  min,
double  max,
double  factor 
)
static

◆ PercentDifference()

double GeneralMath::PercentDifference ( double  expected,
double  calculated 
)
static

◆ PercentTolerance()

double GeneralMath::PercentTolerance ( double  expected,
double  calculated,
double  epsilon = 1e-20 
)
static

◆ PiecewiseLinearInterpolator()

double GeneralMath::PiecewiseLinearInterpolator ( const std::vector< std::pair< double, double > > &  points,
double  x 
)
static

◆ RootMeanSquaredError()

double GeneralMath::RootMeanSquaredError ( std::vector< double >  observed,
std::vector< double >  predicted,
bool  normalize = false,
double  outlierStandardDeviation = -1.0 
)
static

◆ SplineInterpolater()

void GeneralMath::SplineInterpolater ( std::vector< double > &  v,
size_t  newSize 
)
static

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.