Commit 20f41c7bc704231cd0f831da263ff15e19c7bc01
1 parent
7bdb1a97
initial version
Showing
2 changed files
with
143 additions
and
0 deletions
pyext/GIntegral.i
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GIntegral.hpp - Integration class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) 2010-2011 by Jurgen Knodlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file GIntegral.hpp | |
| 23 | + * @brief Integration class Python interface definition | |
| 24 | + * @author J. Knodlseder | |
| 25 | + */ | |
| 26 | +%{ | |
| 27 | +/* Put headers and other declarations here that are needed for compilation */ | |
| 28 | +#include "GIntegral.hpp" | |
| 29 | +#include "GTools.hpp" | |
| 30 | +%} | |
| 31 | + | |
| 32 | + | |
| 33 | +/***********************************************************************//** | |
| 34 | + * @class GIntegral | |
| 35 | + * | |
| 36 | + * @brief Integration class Python interface defintion. | |
| 37 | + * | |
| 38 | + * This class allows to perform integration using various methods. The | |
| 39 | + * integrand is implemented by a derived class of GIntegrand. | |
| 40 | + ***************************************************************************/ | |
| 41 | +class GIntegral { | |
| 42 | +public: | |
| 43 | + | |
| 44 | + // Constructors and destructors | |
| 45 | + explicit GIntegral(void); | |
| 46 | + explicit GIntegral(GIntegrand* integrand); | |
| 47 | + GIntegral(const GIntegral& integral); | |
| 48 | + virtual ~GIntegral(void); | |
| 49 | + | |
| 50 | + // Methods | |
| 51 | + void clear(void); | |
| 52 | + GIntegral* clone(void) const; | |
| 53 | + void max_iter(const int& max_iter) { m_max_iter=max_iter; } | |
| 54 | + void eps(const double& eps) { m_eps=eps; } | |
| 55 | + void silent(const bool& silent) { m_silent=silent; } | |
| 56 | + const int& iter(void) const { return m_iter; } | |
| 57 | + const int& max_iter(void) const { return m_max_iter; } | |
| 58 | + const double& eps(void) const { return m_eps; } | |
| 59 | + const bool& silent(void) const { return m_silent; } | |
| 60 | + void integrand(GIntegrand* integrand) { m_integrand=integrand; } | |
| 61 | + const GIntegrand* integrand(void) const { return m_integrand; } | |
| 62 | + double romb(double a, double b, int k = 5); | |
| 63 | + double trapzd(double a, double b, int n = 1, double result = 0.0); | |
| 64 | +}; | |
| 65 | + | |
| 66 | + | |
| 67 | +/***********************************************************************//** | |
| 68 | + * @brief GIntegral class extension | |
| 69 | + ***************************************************************************/ | |
| 70 | +%extend GIntegral { | |
| 71 | + char *__str__() { | |
| 72 | + return tochar(self->print()); | |
| 73 | + } | |
| 74 | + GIntegral copy() { | |
| 75 | + return (*self); | |
| 76 | + } | |
| 77 | +}; | ... | ... |
pyext/GIntegrand.i
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GIntegrand.hpp - Integrand function abstract base class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) 2010 by Jurgen Knodlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file GIntegrand.hpp | |
| 23 | + * @brief Integrand abstract virtual base class Python interface definition. | |
| 24 | + * @author J. Knodlseder | |
| 25 | + */ | |
| 26 | +%{ | |
| 27 | +/* Put headers and other declarations here that are needed for compilation */ | |
| 28 | +#include "GIntegrand.hpp" | |
| 29 | +#include "GTools.hpp" | |
| 30 | +%} | |
| 31 | + | |
| 32 | + | |
| 33 | +/***********************************************************************//** | |
| 34 | + * @class GIntegrand | |
| 35 | + * | |
| 36 | + * @brief Integrand class Python interface defintion. | |
| 37 | + * | |
| 38 | + * This class implements the abstract interface for the integration kernel | |
| 39 | + * function. It has no members. The only pure virtual method that has to | |
| 40 | + * be implemented by the derived class is the eval() method that provides | |
| 41 | + * function evaluation at a given value x, e.g. y=eval(x). | |
| 42 | + ***************************************************************************/ | |
| 43 | +class GIntegrand { | |
| 44 | +public: | |
| 45 | + | |
| 46 | + // Constructors and destructors | |
| 47 | + GIntegrand(void); | |
| 48 | + GIntegrand(const GIntegrand& arg); | |
| 49 | + virtual ~GIntegrand(void); | |
| 50 | + | |
| 51 | + // Methods | |
| 52 | + virtual double eval(double x) = 0; | |
| 53 | + | |
| 54 | +protected: | |
| 55 | + // Protected methods | |
| 56 | + void init_members(void); | |
| 57 | + void copy_members(const GIntegrand& arg); | |
| 58 | + void free_members(void); | |
| 59 | +}; | |
| 60 | + | |
| 61 | + | |
| 62 | +/***********************************************************************//** | |
| 63 | + * @brief GIntegrand class extension | |
| 64 | + ***************************************************************************/ | |
| 65 | +//%extend GIntegrand { | |
| 66 | +//}; | ... | ... |