#ifndef __JMATH__JMATHLIB3D__ #define __JMATH__JMATHLIB3D__ #include "JMath/JMathlib.hh" /** * \file * Functional algebra in 3D. * * \author mdejong */ namespace JMATH {} namespace JPP { using namespace JMATH; } namespace JMATH { /** * Make 3D function of x from 1D function. */ template struct JMake3X : public JMathlib< JMake3X >, public JF1_t { using JMathlib< JMake3X >::operator(); /** * Default constructor. */ JMake3X() {} /** * Constructor. * * \param f1 function */ JMake3X(const JF1_t& f1) : JF1_t(f1) {} /** * Constructor. * * \param args list of values */ template JMake3X(const Args& ...args) : JF1_t(args...) {} /** * Function value. * * \param x abscissa value * \param y abscissa value * \param z abscissa value * \return function value */ double getValue(const double x, const double y, const double z) const { return static_cast(*this).getValue(x); } /** * Get gradient. * * \param x abscissa value * \param y abscissa value * \param z abscissa value * \return gradient */ const JMake3X& getGradient(const double x, const double y, const double z) const { static JMake3X gradient; static_cast(gradient) = static_cast(*this).getGradient(x); return gradient; } }; /** * Make 3D function of y from 1D function. */ template struct JMake3Y : public JMathlib< JMake3Y >, public JF1_t { using JMathlib< JMake3Y >::operator(); /** * Default constructor. */ JMake3Y() {} /** * Constructor. * * \param f1 function */ JMake3Y(const JF1_t& f1) : JF1_t(f1) {} /** * Constructor. * * \param args list of values */ template JMake3Y(const Args& ...args) : JF1_t(args...) {} /** * Function value. * * \param x abscissa value * \param y abscissa value * \param z abscissa value * \return function value */ double getValue(const double x, const double y, const double z) const { return static_cast(*this).getValue(y); } /** * Get gradient. * * \param x abscissa value * \param y abscissa value * \param z abscissa value * \return gradient */ const JMake3Y& getGradient(const double x, const double y, const double z) const { static JMake3Y gradient; static_cast(gradient) = static_cast(*this).getGradient(y); return gradient; } }; /** * Make 3D function of z from 1D function. */ template struct JMake3Z : public JMathlib< JMake3Z >, public JF1_t { using JMathlib< JMake3Z >::operator(); /** * Default constructor. */ JMake3Z() {} /** * Constructor. * * \param f1 function */ JMake3Z(const JF1_t& f1) : JF1_t(f1) {} /** * Constructor. * * \param args list of values */ template JMake3Z(const Args& ...args) : JF1_t(args...) {} /** * Function value. * * \param x abscissa value * \param y abscissa value * \param z abscissa value * \return function value */ double getValue(const double x, const double y, const double z) const { return static_cast(*this).getValue(z); } /** * Get gradient. * * \param x abscissa value * \param y abscissa value * \param z abscissa value * \return gradient */ const JMake3Z& getGradient(const double x, const double y, const double z) const { static JMake3Z gradient; static_cast(gradient) = static_cast(*this).getGradient(z); return gradient; } }; template using JPolynome3X = JMake3X< JPolynome >; //!< 3D polynomial function of x. template using JPolynome3Y = JMake3Y< JPolynome >; //!< 3D polynomial function of y. template using JPolynome3Z = JMake3Z< JPolynome >; //!< 3D polynomial function of z. template using JGauss3X = JMake3X< JGauss >; //!< 3D Gauss function of x. template using JGauss3Y = JMake3Y< JGauss >; //!< 3D Gauss function of y. template using JGauss3Z = JMake3Z< JGauss >; //!< 3D Gauss function of z. template using JPow3X = JMake3X< JPow >; //!< 3D power of function of x. template using JPow3Y = JMake3Y< JPow >; //!< 3D power of function of y. template using JPow3Z = JMake3Z< JPow >; //!< 3D power of function of z. template using JXn3X = JMake3X< JXn >; //!< 3D fixed power of x. template using JXn3Y = JMake3Y< JXn >; //!< 3D fixed power of y. template using JXn3Z = JMake3Z< JXn >; //!< 3D fixed power of z. template using JSqrt3X = JMake3X< JSqrt >; //!< 3D square root of function of x. template using JSqrt3Y = JMake3Y< JSqrt >; //!< 3D square root of function of y. template using JSqrt3Z = JMake3Z< JSqrt >; //!< 3D square root of function of z. template using JSin3X = JMake3X< JSin >; //!< 3D sine of function of x. template using JSin3Y = JMake3Y< JSin >; //!< 3D sine of function of y. template using JSin3Z = JMake3Z< JSin >; //!< 3D sine of function of z. template using JCos3X = JMake3X< JCos >; //!< 3D cosine of function of x. template using JCos3Y = JMake3Y< JCos >; //!< 3D cosine of function of y. template using JCos3Z = JMake3Z< JCos >; //!< 3D cosine of function of z. template using JExp3X = JMake3X< JExp >; //!< 3D exponent of function of x. template using JExp3Y = JMake3Y< JExp >; //!< 3D exponent of function of y. template using JExp3Z = JMake3Z< JExp >; //!< 3D exponent of function of z. template using JLog3X = JMake3X< JLog >; //!< 3D logarithm of function of x. template using JLog3Y = JMake3Y< JLog >; //!< 3D logarithm of function of y. template using JLog3Z = JMake3Z< JLog >; //!< 3D logarithm of function of z. /** * 3D correlated Gauss function. */ template struct JGauss3D : public JMathlib< JGauss3D >, public JGauss { using JMathlib< JGauss3D >::operator(); /** * Default constructor. */ JGauss3D() {} /** * Constructor. * * \param mean mean * \param sigma sigma */ JGauss3D(const double mean, const double sigma) : JGauss(mean, sigma) {} /** * Function value. * * \param x abscissa value * \param y abscissa value * \param z abscissa value * \return function value */ double getValue(const double x, const double y, const double z) const { typedef JGauss JGauss_t; return (static_cast(*this).getValue(x) * static_cast(*this).getValue(y) * static_cast(*this).getValue(z)); } /** * Get gradient. * * \param x abscissa value * \param y abscissa value * \param z abscissa value * \return gradient */ const JGauss3D& getGradient(const double x, const double y, const double z) const { static JGauss3D gradient; typedef JGauss JGauss_t; static_cast(gradient) = JGauss_t(static_cast(*this).getGradient(x)).mul(static_cast(*this).getValue(y) * static_cast(*this).getValue(z)); static_cast(gradient) += JGauss_t(static_cast(*this).getGradient(y)).mul(static_cast(*this).getValue(x) * static_cast(*this).getValue(z)); static_cast(gradient) += JGauss_t(static_cast(*this).getGradient(z)).mul(static_cast(*this).getValue(x) * static_cast(*this).getValue(y)); return gradient; } }; } #endif