2014-09-26 18:40:52 +01:00
|
|
|
/*
|
|
|
|
* Derivative.hpp, part of LatAnalyze 3
|
|
|
|
*
|
2015-06-11 14:04:54 +01:00
|
|
|
* Copyright (C) 2013 - 2015 Antonin Portelli
|
2014-09-26 18:40:52 +01:00
|
|
|
*
|
|
|
|
* LatAnalyze 3 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* LatAnalyze 3 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef Latan_Derivative_hpp_
|
|
|
|
#define Latan_Derivative_hpp_
|
|
|
|
|
|
|
|
#include <LatAnalyze/Global.hpp>
|
|
|
|
#include <LatAnalyze/Function.hpp>
|
|
|
|
|
2015-01-28 17:15:05 +00:00
|
|
|
BEGIN_LATAN_NAMESPACE
|
2014-09-26 18:40:52 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Derivative *
|
|
|
|
******************************************************************************/
|
2015-02-24 17:00:19 +00:00
|
|
|
class Derivative: public DoubleFunctionFactory
|
2014-09-26 18:40:52 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr double defaultStep = 1.0e-2;
|
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
Derivative(const DoubleFunction &f, const Index dir, const Index order,
|
2015-02-24 17:00:19 +00:00
|
|
|
const DVec &point, const double step = defaultStep);
|
2014-09-26 18:40:52 +01:00
|
|
|
// destructor
|
|
|
|
virtual ~Derivative(void) = default;
|
|
|
|
// access
|
2016-04-04 14:56:21 +01:00
|
|
|
Index getDir(void) const;
|
2014-09-26 18:40:52 +01:00
|
|
|
Index getNPoint(void) const;
|
|
|
|
Index getOrder(void) const;
|
|
|
|
double getStep(void) const;
|
2016-04-04 14:56:21 +01:00
|
|
|
void setDir(const Index dir);
|
2015-01-28 17:15:05 +00:00
|
|
|
void setFunction(const DoubleFunction &f);
|
2015-02-24 17:00:19 +00:00
|
|
|
void setOrderAndPoint(const Index order, const DVec &point);
|
2014-09-26 18:40:52 +01:00
|
|
|
void setStep(const double step);
|
|
|
|
// function call
|
2015-02-24 17:00:19 +00:00
|
|
|
double operator()(const double *x) const;
|
|
|
|
// function factory
|
|
|
|
virtual DoubleFunction makeFunction(const bool makeHardCopy = true) const;
|
2014-09-26 18:40:52 +01:00
|
|
|
protected:
|
|
|
|
// constructor
|
|
|
|
Derivative(const DoubleFunction &f, const Index dir,
|
|
|
|
const double step = defaultStep);
|
|
|
|
private:
|
|
|
|
void makeCoefficients(void);
|
|
|
|
private:
|
2015-02-24 17:00:19 +00:00
|
|
|
DoubleFunction f_;
|
2014-09-26 18:40:52 +01:00
|
|
|
Index dir_, order_;
|
|
|
|
double step_;
|
|
|
|
DVec point_, coefficient_;
|
|
|
|
std::shared_ptr<DVec> buffer_;
|
|
|
|
};
|
|
|
|
|
2015-02-24 17:00:19 +00:00
|
|
|
DoubleFunction derivative(const DoubleFunction &f, const Index dir,
|
|
|
|
const Index order, const DVec point,
|
|
|
|
const double step = Derivative::defaultStep);
|
|
|
|
|
|
|
|
class CentralDerivative: public Derivative
|
2014-09-26 18:40:52 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const Index defaultPrecOrder = 2;
|
|
|
|
public:
|
|
|
|
// constructor
|
2016-04-04 14:56:21 +01:00
|
|
|
CentralDerivative(const DoubleFunction &f = DoubleFunction(),
|
|
|
|
const Index dir = 0,
|
2014-09-26 18:40:52 +01:00
|
|
|
const Index order = 1,
|
|
|
|
const Index precOrder = defaultPrecOrder);
|
|
|
|
// destructor
|
|
|
|
virtual ~CentralDerivative(void) = default;
|
|
|
|
// access
|
|
|
|
Index getPrecOrder(void) const;
|
|
|
|
void setOrder(const Index order, const Index precOrder = defaultPrecOrder);
|
|
|
|
// function call
|
|
|
|
using Derivative::operator();
|
|
|
|
private:
|
|
|
|
// step tuning
|
|
|
|
void tuneStep(void);
|
|
|
|
private:
|
|
|
|
Index precOrder_;
|
|
|
|
};
|
|
|
|
|
2015-02-24 17:00:19 +00:00
|
|
|
DoubleFunction centralDerivative(const DoubleFunction &f, const Index dir = 0,
|
|
|
|
const Index order = 1,
|
|
|
|
const Index precOrder =
|
|
|
|
CentralDerivative::defaultPrecOrder);
|
|
|
|
|
2015-01-28 17:15:05 +00:00
|
|
|
END_LATAN_NAMESPACE
|
2014-09-26 18:40:52 +01:00
|
|
|
|
|
|
|
#endif // Latan_Derivative_hpp_
|