| 1 | /****************************************************************************** |
| 2 | |
| 3 | This source file is part of the Avogadro project. |
| 4 | |
| 5 | Copyright (C) 2010 Eric C. Brown |
| 6 | |
| 7 | This source code is released under the GPL v3 or later (the "License"). |
| 8 | |
| 9 | You should have received a copy of the GNU General Public License along with |
| 10 | this program; if not, write to the Free Software Foundation, Inc., 51 Franklin |
| 11 | Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 12 | |
| 13 | Unless required by applicable law or agreed to in writing, software |
| 14 | distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | See the License for the specific language governing permissions and |
| 17 | limitations under the License. |
| 18 | |
| 19 | ******************************************************************************/ |
| 20 | |
| 21 | /* Based on */ |
| 22 | |
| 23 | /* Adaptive multidimensional integration of a vector of integrands. |
| 24 | * |
| 25 | * Copyright (c) 2005-2009 Steven G. Johnson |
| 26 | * |
| 27 | * Portions (see comments) based on HIntLib (also distributed under |
| 28 | * the GNU GPL, v2 or later), copyright (c) 2002-2005 Rudolf Schuerer. |
| 29 | * (http://www.cosy.sbg.ac.at/~rschuer/hintlib/) |
| 30 | * |
| 31 | * Portions (see comments) based on GNU GSL (also distributed under |
| 32 | * the GNU GPL, v2 or later), copyright (c) 1996-2000 Brian Gough. |
| 33 | * (http://www.gnu.org/software/gsl/) |
| 34 | * |
| 35 | * This program is free software; you can redistribute it and/or modify |
| 36 | * it under the terms of the GNU General Public License as published by |
| 37 | * the Free Software Foundation; either version 2 of the License, or |
| 38 | * (at your option) any later version. |
| 39 | * |
| 40 | * This program is distributed in the hope that it will be useful, |
| 41 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 42 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 43 | * GNU General Public License for more details. |
| 44 | * |
| 45 | * You should have received a copy of the GNU General Public License |
| 46 | * along with this program; if not, write to the Free Software |
| 47 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 48 | * |
| 49 | */ |
| 50 | |
| 51 | #ifndef QTAIMCUBATURE_H |
| 52 | #define QTAIMCUBATURE_H |
| 53 | |
| 54 | #include <QPair> |
| 55 | |
| 56 | // #ifdef __cplusplus |
| 57 | // extern "C" |
| 58 | //{ |
| 59 | // #endif /* __cplusplus */ |
| 60 | |
| 61 | /* USAGE: Call adapt_integrate with your function as described below. |
| 62 | |
| 63 | To compile a test program, compile cubature.c with |
| 64 | -DTEST_INTEGRATOR as described at the end. */ |
| 65 | |
| 66 | /* a vector integrand - evaluates the function at the given point x |
| 67 | (an array of length ndim) and returns the result in fval (an array |
| 68 | of length fdim). The void* parameter is there in case you have |
| 69 | to pass any additional data through to your function (it corresponds |
| 70 | to the fdata parameter you pass to adapt_integrate). */ |
| 71 | using integrand = void (*)(unsigned int, const double*, void*, unsigned int, |
| 72 | double*); |
| 73 | |
| 74 | /* a vector integrand of a vector of npt points: x[i*ndim + j] is the |
| 75 | j-th coordinate of the i-th point, and the k-th function evaluation |
| 76 | for the i-th point is returned in fval[k*npt + i]. */ |
| 77 | using integrand_v = void (*)(unsigned int, unsigned int, const double*, void*, |
| 78 | unsigned int, double*); |
| 79 | |
| 80 | /* Integrate the function f from xmin[dim] to xmax[dim], with at most |
| 81 | maxEval function evaluations (0 for no limit), until the given |
| 82 | absolute or relative error is achieved. val returns the integral, |
| 83 | and err returns the estimate for the absolute error in val; both |
| 84 | of these are arrays of length fdim, the dimension of the vector |
| 85 | integrand f(x). The return value of the function is 0 on success |
| 86 | and non-zero if there was an error. */ |
| 87 | int adapt_integrate(unsigned int fdim, integrand f, void* fdata, |
| 88 | unsigned int dim, const double* xmin, const double* xmax, |
| 89 | unsigned int maxEval, double reqAbsError, |
| 90 | double reqRelError, double* val, double* err); |
| 91 | |
| 92 | /* as adapt_integrate, but vectorized integrand */ |
| 93 | int adapt_integrate_v(unsigned int fdim, integrand_v f, void* fdata, |
| 94 | unsigned int dim, const double* xmin, const double* xmax, |
| 95 | unsigned int maxEval, double reqAbsError, |
| 96 | double reqRelError, double* val, double* err); |
| 97 | |
| 98 | // #ifdef __cplusplus |
| 99 | // } /* extern "C" */ |
| 100 | // #endif /* __cplusplus */ |
| 101 | |
| 102 | #include "qtaimwavefunction.h" |
| 103 | |
| 104 | namespace Avogadro::QtPlugins { |
| 105 | |
| 106 | class QTAIMCubature |
| 107 | { |
| 108 | public: |
| 109 | enum |
| 110 | { |
| 111 | ElectronDensity = 0, |
| 112 | ElectronDensityLaplacian = 1 |
| 113 | }; |
| 114 | |
| 115 | explicit QTAIMCubature(QTAIMWavefunction& wfn); |
| 116 | ~QTAIMCubature(); |
| 117 | |
| 118 | QList<QPair<qreal, qreal>> integrate(qint64 mode, QList<qint64> basins); |
| 119 | |
| 120 | void setMode(qint64 mode); |
| 121 | |
| 122 | private: |
| 123 | QTAIMWavefunction* m_wfn; |
| 124 | qint64 m_mode; |
| 125 | QList<qint64> m_basins; |
| 126 | |
| 127 | QString m_temporaryFileName; |
| 128 | QString temporaryFileName(); |
| 129 | |
| 130 | QList<QVector3D> m_ncpList; |
| 131 | }; |
| 132 | |
| 133 | } // namespace Avogadro::QtPlugins |
| 134 | |
| 135 | #endif /* QTAIMCUBATURE_H */ |