mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-06-20 00:06:55 +01:00
GSL integrator added - LatAnalyze now depends on GSL
This commit is contained in:
69
lib/GslQagsIntegrator.cpp
Normal file
69
lib/GslQagsIntegrator.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* GslQagsIntegrator.cpp, part of LatAnalyze 3
|
||||
*
|
||||
* Copyright (C) 2013 - 2014 Antonin Portelli
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <LatAnalyze/GslQagsIntegrator.hpp>
|
||||
#include <LatAnalyze/includes.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace Latan;
|
||||
|
||||
/******************************************************************************
|
||||
* GslQagIntegrator implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
GslQagsIntegrator::GslQagsIntegrator(const unsigned int limit,
|
||||
const double precision)
|
||||
: limit_(limit)
|
||||
, precision_(precision)
|
||||
{
|
||||
workspace_ = gsl_integration_workspace_alloc(limit);
|
||||
}
|
||||
|
||||
// destructor //////////////////////////////////////////////////////////////////
|
||||
GslQagsIntegrator::~GslQagsIntegrator(void)
|
||||
{
|
||||
gsl_integration_workspace_free(workspace_);
|
||||
}
|
||||
|
||||
// integral calculation ////////////////////////////////////////////////////////
|
||||
double GslQagsIntegrator::operator()(const DoubleFunction &f, const double xMin,
|
||||
const double xMax)
|
||||
{
|
||||
double (*fWrap)(double, void *) = [](double x, void *fPt)
|
||||
{
|
||||
return (*static_cast<DoubleFunction *>(fPt))(&x);
|
||||
};
|
||||
|
||||
gsl_function gslF;
|
||||
double result;
|
||||
|
||||
gslF.function = fWrap;
|
||||
gslF.params = reinterpret_cast<void *>(&const_cast<DoubleFunction &>(f));
|
||||
|
||||
gsl_integration_qags(&gslF, xMin, xMax, 0.0, precision_, limit_, workspace_,
|
||||
&result, &error_);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// get last error //////////////////////////////////////////////////////////////
|
||||
double GslQagsIntegrator::getLastError(void) const
|
||||
{
|
||||
return error_;
|
||||
}
|
58
lib/GslQagsIntegrator.hpp
Normal file
58
lib/GslQagsIntegrator.hpp
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* GslQagsIntegrator.hpp, part of LatAnalyze 3
|
||||
*
|
||||
* Copyright (C) 2013 - 2014 Antonin Portelli
|
||||
*
|
||||
* 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_GslQagsIntegrator_hpp_
|
||||
#define Latan_GslQagsIntegrator_hpp_
|
||||
|
||||
#include <LatAnalyze/Global.hpp>
|
||||
#include <LatAnalyze/Function.hpp>
|
||||
#include <LatAnalyze/Integrator.hpp>
|
||||
#include <gsl/gsl_integration.h>
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* GSL general quadrature adaptive integration with singularities *
|
||||
******************************************************************************/
|
||||
|
||||
class GslQagsIntegrator: public Integrator
|
||||
{
|
||||
public:
|
||||
static const unsigned int defaultLimit = 1000;
|
||||
static constexpr double defaultPrec = 1.0e-7;
|
||||
public:
|
||||
// constructor
|
||||
GslQagsIntegrator(const unsigned int limit = defaultLimit,
|
||||
const double precision = defaultPrec);
|
||||
// destructor
|
||||
virtual ~GslQagsIntegrator(void);
|
||||
// integral calculation
|
||||
virtual double operator()(const DoubleFunction &f, const double xMin,
|
||||
const double xMax);
|
||||
// get last error
|
||||
double getLastError(void) const;
|
||||
private:
|
||||
unsigned int limit_;
|
||||
double precision_, error_;
|
||||
gsl_integration_workspace *workspace_;
|
||||
};
|
||||
|
||||
END_NAMESPACE
|
||||
|
||||
#endif // Latan_GslQagsIntegrator_hpp_
|
46
lib/Integrator.hpp
Normal file
46
lib/Integrator.hpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Integrator.hpp, part of LatAnalyze 3
|
||||
*
|
||||
* Copyright (C) 2013 - 2014 Antonin Portelli
|
||||
*
|
||||
* 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_Integrator_hpp_
|
||||
#define Latan_Integrator_hpp_
|
||||
|
||||
#include <LatAnalyze/Global.hpp>
|
||||
#include <LatAnalyze/Function.hpp>
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* abstract integrator class *
|
||||
******************************************************************************/
|
||||
|
||||
class Integrator
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
Integrator(void) = default;
|
||||
// destructor
|
||||
virtual ~Integrator(void) = default;
|
||||
// integral calculation
|
||||
virtual double operator()(const DoubleFunction &f, const double xMin,
|
||||
const double xMax) = 0;
|
||||
};
|
||||
|
||||
END_NAMESPACE
|
||||
|
||||
#endif // Latan_Integrator_hpp_
|
@ -32,11 +32,12 @@ libLatAnalyze_la_SOURCES =\
|
||||
CompiledFunction.cpp \
|
||||
CompiledModel.cpp \
|
||||
Exceptions.cpp \
|
||||
Function.cpp \
|
||||
Global.cpp \
|
||||
includes.hpp \
|
||||
File.cpp \
|
||||
FitInterface.cpp \
|
||||
Function.cpp \
|
||||
Global.cpp \
|
||||
GslQagsIntegrator.cpp \
|
||||
includes.hpp \
|
||||
Mat.cpp \
|
||||
Math.cpp \
|
||||
MathInterpreter.cpp \
|
||||
@ -62,8 +63,10 @@ libLatAnalyze_la_HEADERS =\
|
||||
Exceptions.hpp \
|
||||
FitInterface.hpp \
|
||||
Function.hpp \
|
||||
Global.hpp \
|
||||
File.hpp \
|
||||
Global.hpp \
|
||||
GslQagsIntegrator.hpp \
|
||||
Integrator.hpp \
|
||||
IoObject.hpp \
|
||||
Mat.hpp \
|
||||
Math.hpp \
|
||||
|
Reference in New Issue
Block a user