1
0
Fork 0
mirror of https://github.com/gwm17/catima.git synced 2024-11-26 20:18:51 -05:00
catima/integrator.h

72 lines
1.9 KiB
C
Raw Normal View History

2017-07-25 12:19:11 -04:00
/*
* Author: Andrej Prochazka
* Copyright(C) 2017
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INTEGRATOR_H
#define INTEGRATOR_H
2017-12-14 09:07:54 -05:00
#include "catima/build_config.h"
2017-07-25 12:19:11 -04:00
#include <functional>
2017-12-14 09:07:54 -05:00
#include <array>
2018-10-21 16:08:16 -04:00
//#ifdef USE_THREADS
//#include <mutex>
//#endif
2020-08-04 11:35:33 -04:00
#include "catima/glq_integrator.h"
#include "catima/gkq_integrator.h"
2018-10-21 16:08:16 -04:00
#ifdef GSL_INTEGRATION
#include "gsl/gsl_integration.h"
2017-07-25 12:19:11 -04:00
#endif
2020-08-04 11:35:33 -04:00
using integrators::GaussLegendreIntegration;
using integrators::GaussKronrodIntegration;
2017-07-25 12:19:11 -04:00
namespace catima{
2018-10-21 16:08:16 -04:00
#ifdef GSL_INTEGRATION
2017-07-25 12:19:11 -04:00
/// helper class to integrate functions using the GSL library
class IntegratorGSL{
public:
2017-12-14 09:07:54 -05:00
IntegratorGSL(bool adapt=true);
2017-07-25 12:19:11 -04:00
~IntegratorGSL();
2017-12-14 09:07:54 -05:00
double integrate(std::function<double(double)> f, double min, double max, double precision=0.001);
2017-07-25 12:19:11 -04:00
private:
2017-12-14 09:07:54 -05:00
gsl_integration_workspace *w;
bool adaptive;
2017-07-25 12:19:11 -04:00
double error;
double result;
double min;
double max;
#ifdef USE_THREADS
std::mutex integration_mutex;
#endif
};
2018-10-21 16:08:16 -04:00
#endif
2017-07-25 12:19:11 -04:00
2017-12-14 09:07:54 -05:00
#ifdef GSL_INTEGRATION
using integrator_type = IntegratorGSL;
#else
using integrator_type = GaussLegendreIntegration<8>;
#endif
2020-08-05 19:28:19 -04:00
using integrator_adaptive_type = GaussKronrodIntegration<15>;
2017-12-14 09:07:54 -05:00
extern integrator_type integrator;
2020-08-04 11:35:33 -04:00
extern integrator_adaptive_type integrator_adaptive;
2017-07-25 12:19:11 -04:00
}
#endif