Commit dbc2560a authored by Nabil Chouika's avatar Nabil Chouika
Browse files

NumA utils documentation partons/core/partons#4

parent 055454af
...@@ -16,26 +16,57 @@ namespace NumA { ...@@ -16,26 +16,57 @@ namespace NumA {
/** /**
* @class Differences * @class Differences
* *
* @brief * @brief Class defining absolute and relative differences for comparison of real numbers (double).
*/ */
class Differences { class Differences {
public: public:
/**
* Default constructor (differences equal to 0).
*/
Differences(); Differences();
/**
* Constructor.
* @param absoluteDifference Absolute difference.
* @param relativeDifference Relative difference.
*/
Differences(const double absoluteDifference, Differences(const double absoluteDifference,
const double relativeDifference); const double relativeDifference);
/**
* Default destructor.
*/
virtual ~Differences(); virtual ~Differences();
/**
*
* @return Pre-formatted string with the differences.
*/
std::string toString() const; std::string toString() const;
/**
*
* @return Absolute difference.
*/
double getAbsoluteDifference() const; double getAbsoluteDifference() const;
/**
*
* @return Relative difference.
*/
double getRelativeDifference() const; double getRelativeDifference() const;
/**
*
* @param absoluteDifference Absolute difference.
*/
void setAbsoluteDifference(double absoluteDifference); void setAbsoluteDifference(double absoluteDifference);
/**
*
* @param relativeDifference Relative difference.
*/
void setRelativeDifference(double relativeDifference); void setRelativeDifference(double relativeDifference);
private: private:
double m_absoluteDifference; double m_absoluteDifference; ///< Absolute difference.
double m_relativeDifference; double m_relativeDifference; ///< Relative difference.
}; };
} // namespace NumA } // namespace NumA
......
...@@ -13,24 +13,51 @@ namespace NumA { ...@@ -13,24 +13,51 @@ namespace NumA {
/** /**
* @class Errors * @class Errors
* *
* @brief * @brief Class for defining estimations of absolute and relative errors.
*/ */
class Errors { class Errors {
public: public:
/**
* Default constructor (errors equal to 0).
*/
Errors(); Errors();
/**
* Constructor.
* @param absolute Absolute error.
* @param relative Relative error.
*/
Errors(const double absolute, const double relative); Errors(const double absolute, const double relative);
/**
* Default destructor.
*/
virtual ~Errors(); virtual ~Errors();
// ##### GETTERS & SETTERS ##### // ##### GETTERS & SETTERS #####
/**
*
* @return Absolute error.
*/
double getAbsolute() const; double getAbsolute() const;
/**
*
* @param absolute Absolute error.
*/
void setAbsolute(double absolute); void setAbsolute(double absolute);
/**
*
* @return Relative error.
*/
double getRelative() const; double getRelative() const;
/**
*
* @param relative Relative error.
*/
void setRelative(double relative); void setRelative(double relative);
private: private:
double m_absolute; double m_absolute; ///< Absolute error.
double m_relative; double m_relative; ///< Relative error.
}; };
} /* namespace NumA */ } /* namespace NumA */
......
...@@ -17,21 +17,38 @@ namespace NumA { ...@@ -17,21 +17,38 @@ namespace NumA {
/** /**
* @class Interval * @class Interval
*
* @brief Class defining an interval (with given bounds and step).
*/ */
template<typename T> template<typename T>
class Interval { class Interval {
public: public:
/**
* Type of interval.
*/
enum StepMode { enum StepMode {
NORMAL = 0, LOG = 1 NORMAL = 0, ///< Linear interval.
LOG = 1 ///< Logarithmic interval.
}; };
/**
* Constructor.
* @param lowerBound Lower bound of the interval.
* @param upperBound Upper bound of the interval.
* @param step Value of the step.
* @param stepMode Type of interval.
*/
Interval(T lowerBound, T upperBound, T step = 1, Interval(T lowerBound, T upperBound, T step = 1,
Interval::StepMode stepMode = NORMAL) : Interval::StepMode stepMode = NORMAL) :
m_lowerBound(lowerBound), m_upperBound(upperBound), m_step(step), m_stepMode( m_lowerBound(lowerBound), m_upperBound(upperBound), m_step(step), m_stepMode(
stepMode) { stepMode) {
} }
/**
*
* @return Nodes of interval.
*/
std::vector<T> computeSteps() const { std::vector<T> computeSteps() const {
std::vector<T> steps; std::vector<T> steps;
...@@ -61,6 +78,14 @@ public: ...@@ -61,6 +78,14 @@ public:
return steps; return steps;
} }
/**
* Static function that computes the nodes of an interval for a chosen number of nodes.
* @param lowerBound Lower bound of the interval.
* @param upperBound Upper bound of the interval.
* @param num Number of nodes.
* @param stepMode Type of interval.
* @return Nodes.
*/
static std::vector<T> computeNodes(T lowerBound, T upperBound, size_t num = static std::vector<T> computeNodes(T lowerBound, T upperBound, size_t num =
10, Interval::StepMode stepMode = NORMAL) { 10, Interval::StepMode stepMode = NORMAL) {
T node = lowerBound; T node = lowerBound;
...@@ -89,36 +114,60 @@ public: ...@@ -89,36 +114,60 @@ public:
return nodes; return nodes;
} }
/**
*
* @return Lower bound of the interval.
*/
T getLowerBound() const { T getLowerBound() const {
return m_lowerBound; return m_lowerBound;
} }
/**
*
* @param lowerBound Lower bound of the interval.
*/
void setLowerBound(T lowerBound) { void setLowerBound(T lowerBound) {
this->m_lowerBound = lowerBound; this->m_lowerBound = lowerBound;
} }
/**
*
* @return Step.
*/
T getStep() const { T getStep() const {
return m_step; return m_step;
} }
/**
*
* @param step Value of the step.
*/
void setStep(T step) { void setStep(T step) {
this->m_step = step; this->m_step = step;
} }
/**
*
* @return Upper bound of the interval.
*/
T getUpperBound() const { T getUpperBound() const {
return m_upperBound; return m_upperBound;
} }
/**
*
* @param upperBound Upper bound of the interval.
*/
void setUpperBound(T upperBound) { void setUpperBound(T upperBound) {
this->m_upperBound = upperBound; this->m_upperBound = upperBound;
} }
private: private:
T m_lowerBound; T m_lowerBound; ///< Lower bound of the interval.
T m_upperBound; T m_upperBound; ///< Upper bound of the interval.
T m_step; T m_step; ///< Step.
Interval::StepMode m_stepMode; Interval::StepMode m_stepMode; ///< Type of interval.
}; };
} /* namespace NumA */ } /* namespace NumA */
......
...@@ -13,11 +13,21 @@ namespace NumA { ...@@ -13,11 +13,21 @@ namespace NumA {
/** /**
* @class MathUtils * @class MathUtils
* *
* @brief * @brief Miscellaneous utilities (mathematical functions, etc).
*/ */
class MathUtils { class MathUtils {
public: public:
/**
* Degree-radian conversion.
* @param degree Angle in degree.
* @return Angle in radian.
*/
static double convertDegreeToRadian(double degree); static double convertDegreeToRadian(double degree);
/**
* DiLograrithm function.
* @param x
* @return \f$ Li_2\left(x\right) \f$.
*/
static double DiLog(double x); static double DiLog(double x);
}; };
......
...@@ -15,29 +15,60 @@ namespace NumA { ...@@ -15,29 +15,60 @@ namespace NumA {
/** /**
* @class Tolerances * @class Tolerances
* *
* @brief Define absolute and relative tolerance for comparison of real numbers (double) and check they are positive. * @brief Define absolute and relative tolerances for comparison of real numbers (double) and check if they are positive.
*/ */
class Tolerances { class Tolerances {
public: public:
/**
* Default constructor (tolerances equal to 0).
*/
Tolerances(); Tolerances();
/**
* Constructor.
* @param absoluteTolerance Absolute tolerance.
* @param relativeTolerance Relative tolerance.
*/
Tolerances(double absoluteTolerance, double relativeTolerance); Tolerances(double absoluteTolerance, double relativeTolerance);
/**
* Default destructor.
*/
virtual ~Tolerances(); virtual ~Tolerances();
/**
*
* @return Pre-formatted string with the tolerances.
*/
std::string toString() const; std::string toString() const;
// ##### GETTERS & SETTERS ##### // ##### GETTERS & SETTERS #####
/**
*
* @return Absolute tolerance.
*/
double getAbsoluteTolerance() const; double getAbsoluteTolerance() const;
/**
*
* @return Relative tolerance.
*/
double getRelativeTolerance() const; double getRelativeTolerance() const;
/**
*
* @param absoluteTolerance Absolute tolerance.
*/
void setAbsoluteTolerance(double absoluteTolerance); void setAbsoluteTolerance(double absoluteTolerance);
/**
*
* @param relativeTolerance Relative tolerance.
*/
void setRelativeTolerance(double relativeTolerance); void setRelativeTolerance(double relativeTolerance);
private: private:
double m_absoluteTolerance; double m_absoluteTolerance; ///< Absolute tolerance.
double m_relativeTolerance; double m_relativeTolerance; ///< Relative tolerance.
void testPositivity(const double &tolerance) const; void testPositivity(const double &tolerance) const; ///< Positivity test.
}; };
} // namespace NumA } // namespace NumA
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment