Skip to content

Commit cc7ddd0

Browse files
author
Roberto Di Remigio
committed
Reduce verbosity of Green's functions instantiation in tests
1 parent c1ccdb9 commit cc7ddd0

35 files changed

+240
-149
lines changed

src/bi_operators/CollocationIntegrator.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct CollocationIntegrator
7373
Eigen::MatrixXd singleLayer(const Vacuum<DerivativeTraits, CollocationIntegrator> & gf, const std::vector<Element> & e) const {
7474
return integrator::singleLayer(e,
7575
pcm::bind(integrator::SI, this->factor, 1.0, pcm::_1),
76-
pcm::bind(&Vacuum<DerivativeTraits, CollocationIntegrator>::kernelS, gf, pcm::_1, pcm::_2));
76+
gf.exportKernelS());
7777
}
7878
/*! \tparam DerivativeTraits how the derivatives of the Greens's function are calculated
7979
* \param[in] gf Green's function
@@ -83,7 +83,7 @@ struct CollocationIntegrator
8383
Eigen::MatrixXd doubleLayer(const Vacuum<DerivativeTraits, CollocationIntegrator> & gf, const std::vector<Element> & e) const {
8484
return integrator::doubleLayer(e,
8585
pcm::bind(integrator::DI, this->factor, pcm::_1),
86-
pcm::bind(&Vacuum<DerivativeTraits, CollocationIntegrator>::kernelD, gf, pcm::_1, pcm::_2, pcm::_3));
86+
gf.exportKernelD());
8787
}
8888
/**@}*/
8989

@@ -96,7 +96,7 @@ struct CollocationIntegrator
9696
Eigen::MatrixXd singleLayer(const UniformDielectric<DerivativeTraits, CollocationIntegrator> & gf, const std::vector<Element> & e) const {
9797
return integrator::singleLayer(e,
9898
pcm::bind(integrator::SI, this->factor, gf.epsilon(), pcm::_1),
99-
pcm::bind(&UniformDielectric<DerivativeTraits, CollocationIntegrator>::kernelS, gf, pcm::_1, pcm::_2));
99+
gf.exportKernelS());
100100
}
101101
/*! \tparam DerivativeTraits how the derivatives of the Greens's function are calculated
102102
* \param[in] gf Green's function
@@ -106,7 +106,7 @@ struct CollocationIntegrator
106106
Eigen::MatrixXd doubleLayer(const UniformDielectric<DerivativeTraits, CollocationIntegrator> & gf, const std::vector<Element> & e) const {
107107
return integrator::doubleLayer(e,
108108
pcm::bind(integrator::DI, this->factor, pcm::_1),
109-
pcm::bind(&UniformDielectric<DerivativeTraits, CollocationIntegrator>::kernelD, gf, pcm::_1, pcm::_2, pcm::_3));
109+
gf.exportKernelD());
110110
}
111111
/**@}*/
112112

src/bi_operators/IntegratorTypes.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
/*
33
* PCMSolver, an API for the Polarizable Continuum Model
44
* Copyright (C) 2013-2015 Roberto Di Remigio, Luca Frediani and contributors
5-
*
5+
*
66
* This file is part of PCMSolver.
7-
*
7+
*
88
* PCMSolver is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU Lesser General Public License as published by
1010
* the Free Software Foundation, either version 3 of the License, or
1111
* (at your option) any later version.
12-
*
12+
*
1313
* PCMSolver is distributed in the hope that it will be useful,
1414
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1515
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616
* GNU Lesser General Public License for more details.
17-
*
17+
*
1818
* You should have received a copy of the GNU Lesser General Public License
1919
* along with PCMSolver. If not, see <http://www.gnu.org/licenses/>.
20-
*
20+
*
2121
* For information on the complete list of contributors to the
2222
* PCMSolver API, see: <http://pcmsolver.readthedocs.org/>
2323
*/

src/bi_operators/NumericalIntegrator.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct NumericalIntegrator
6363
*/
6464
template <typename DerivativeTraits>
6565
Eigen::MatrixXd singleLayer(const Vacuum<DerivativeTraits, NumericalIntegrator> & gf, const std::vector<Element> & e) const {
66-
integrator::KernelS kernelS = pcm::bind(&Vacuum<DerivativeTraits, NumericalIntegrator>::kernelS, gf, pcm::_1, pcm::_2);
66+
integrator::KernelS kernelS = gf.exportKernelS();
6767
integrator::Diagonal diagS = pcm::bind(&integrator::integrateS<32, 16>, kernelS, pcm::_1);
6868
return integrator::singleLayer(e, diagS, kernelS);
6969
}
@@ -73,7 +73,7 @@ struct NumericalIntegrator
7373
*/
7474
template <typename DerivativeTraits>
7575
Eigen::MatrixXd doubleLayer(const Vacuum<DerivativeTraits, NumericalIntegrator> & gf, const std::vector<Element> & e) const {
76-
integrator::KernelD kernelD = pcm::bind(&Vacuum<DerivativeTraits, NumericalIntegrator>::kernelD, gf, pcm::_1, pcm::_2, pcm::_3);
76+
integrator::KernelD kernelD = gf.exportKernelD();
7777
integrator::Diagonal diagD = pcm::bind(&integrator::integrateD<32, 16>, kernelD, pcm::_1);
7878
return integrator::doubleLayer(e, diagD, kernelD);
7979
}
@@ -86,7 +86,7 @@ struct NumericalIntegrator
8686
*/
8787
template <typename DerivativeTraits>
8888
Eigen::MatrixXd singleLayer(const UniformDielectric<DerivativeTraits, NumericalIntegrator> & gf, const std::vector<Element> & e) const {
89-
integrator::KernelS kernelS = pcm::bind(&UniformDielectric<DerivativeTraits, NumericalIntegrator>::kernelS, gf, pcm::_1, pcm::_2);
89+
integrator::KernelS kernelS = gf.exportKernelS();
9090
integrator::Diagonal diagS = pcm::bind(&integrator::integrateS<32, 16>, kernelS, pcm::_1);
9191
return integrator::singleLayer(e, diagS, kernelS);
9292
}
@@ -96,7 +96,7 @@ struct NumericalIntegrator
9696
*/
9797
template <typename DerivativeTraits>
9898
Eigen::MatrixXd doubleLayer(const UniformDielectric<DerivativeTraits, NumericalIntegrator> & gf, const std::vector<Element> & e) const {
99-
integrator::KernelD kernelD = pcm::bind(&UniformDielectric<DerivativeTraits, NumericalIntegrator>::kernelD, gf, pcm::_1, pcm::_2, pcm::_3);
99+
integrator::KernelD kernelD = gf.exportKernelD();
100100
integrator::Diagonal diagD = pcm::bind(&integrator::integrateD<32, 16>, kernelD, pcm::_1);
101101
return integrator::doubleLayer(e, diagD, kernelD);
102102
}
@@ -109,7 +109,7 @@ struct NumericalIntegrator
109109
*/
110110
template <typename DerivativeTraits>
111111
Eigen::MatrixXd singleLayer(const IonicLiquid<DerivativeTraits, NumericalIntegrator> & gf, const std::vector<Element> & e) const {
112-
integrator::KernelS kernelS = pcm::bind(&IonicLiquid<DerivativeTraits, NumericalIntegrator>::kernelS, gf, pcm::_1, pcm::_2);
112+
integrator::KernelS kernelS = gf.exportKernelS();
113113
integrator::Diagonal diagS = pcm::bind(&integrator::integrateS<32, 16>, kernelS, pcm::_1);
114114
return integrator::singleLayer(e, diagS, kernelS);
115115
}
@@ -119,7 +119,7 @@ struct NumericalIntegrator
119119
*/
120120
template <typename DerivativeTraits>
121121
Eigen::MatrixXd doubleLayer(const IonicLiquid<DerivativeTraits, NumericalIntegrator> & gf, const std::vector<Element> & e) const {
122-
integrator::KernelD kernelD = pcm::bind(&IonicLiquid<DerivativeTraits, NumericalIntegrator>::kernelD, gf, pcm::_1, pcm::_2, pcm::_3);
122+
integrator::KernelD kernelD = gf.exportKernelD();
123123
integrator::Diagonal diagD = pcm::bind(&integrator::integrateD<32, 16>, kernelD, pcm::_1);
124124
return integrator::doubleLayer(e, diagD, kernelD);
125125
}
@@ -132,7 +132,7 @@ struct NumericalIntegrator
132132
*/
133133
template <typename DerivativeTraits>
134134
Eigen::MatrixXd singleLayer(const AnisotropicLiquid<DerivativeTraits, NumericalIntegrator> & gf, const std::vector<Element> & e) const {
135-
integrator::KernelS kernelS = pcm::bind(&AnisotropicLiquid<DerivativeTraits, NumericalIntegrator>::kernelS, gf, pcm::_1, pcm::_2);
135+
integrator::KernelS kernelS = gf.exportKernelS();
136136
integrator::Diagonal diagS = pcm::bind(&integrator::integrateS<32, 16>, kernelS, pcm::_1);
137137
return integrator::singleLayer(e, diagS, kernelS);
138138
}
@@ -142,7 +142,7 @@ struct NumericalIntegrator
142142
*/
143143
template <typename DerivativeTraits>
144144
Eigen::MatrixXd doubleLayer(const AnisotropicLiquid<DerivativeTraits, NumericalIntegrator> & gf, const std::vector<Element> & e) const {
145-
integrator::KernelD kernelD = pcm::bind(&AnisotropicLiquid<DerivativeTraits, NumericalIntegrator>::kernelD, gf, pcm::_1, pcm::_2, pcm::_3);
145+
integrator::KernelD kernelD = gf.exportKernelD();
146146
integrator::Diagonal diagD = pcm::bind(&integrator::integrateD<32, 16>, kernelD, pcm::_1);
147147
return integrator::doubleLayer(e, diagD, kernelD);
148148
}

src/bi_operators/PurisimaIntegrator.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct PurisimaIntegrator
7777
Eigen::MatrixXd singleLayer(const Vacuum<DerivativeTraits, PurisimaIntegrator> & gf, const std::vector<Element> & e) const {
7878
return integrator::singleLayer(e,
7979
pcm::bind(integrator::SI, this->factor, 1.0, pcm::_1),
80-
pcm::bind(&Vacuum<DerivativeTraits, PurisimaIntegrator>::kernelS, gf, pcm::_1, pcm::_2));
80+
gf.exportKernelS());
8181
}
8282
/*! \tparam DerivativeTraits how the derivatives of the Greens's function are calculated
8383
* \param[in] gf Green's function
@@ -86,7 +86,7 @@ struct PurisimaIntegrator
8686
template <typename DerivativeTraits>
8787
Eigen::MatrixXd doubleLayer(const Vacuum<DerivativeTraits, PurisimaIntegrator> & gf, const std::vector<Element> & e) const {
8888
// Obtain off-diagonal first
89-
Eigen::MatrixXd D = offDiagonalD(e, pcm::bind(&Vacuum<DerivativeTraits, PurisimaIntegrator>::kernelD, gf, pcm::_1, pcm::_2, pcm::_3));
89+
Eigen::MatrixXd D = offDiagonalD(e, gf.exportKernelD());
9090
// Fill diagonal based on Purisima's formula
9191
Eigen::VectorXd D_diag = diagonalD(e, D);
9292
D.diagonal() = D_diag;
@@ -103,7 +103,7 @@ struct PurisimaIntegrator
103103
Eigen::MatrixXd singleLayer(const UniformDielectric<DerivativeTraits, PurisimaIntegrator> & gf, const std::vector<Element> & e) const {
104104
return integrator::singleLayer(e,
105105
pcm::bind(integrator::SI, this->factor, gf.epsilon(), pcm::_1),
106-
pcm::bind(&UniformDielectric<DerivativeTraits, PurisimaIntegrator>::kernelS, gf, pcm::_1, pcm::_2));
106+
gf.exportKernelS());
107107
}
108108
/*! \tparam DerivativeTraits how the derivatives of the Greens's function are calculated
109109
* \param[in] gf Green's function
@@ -112,7 +112,7 @@ struct PurisimaIntegrator
112112
template <typename DerivativeTraits>
113113
Eigen::MatrixXd doubleLayer(const UniformDielectric<DerivativeTraits, PurisimaIntegrator> & gf, const std::vector<Element> & e) const {
114114
// Obtain off-diagonal first
115-
Eigen::MatrixXd D = offDiagonalD(e, pcm::bind(&UniformDielectric<DerivativeTraits, PurisimaIntegrator>::kernelD, gf, pcm::_1, pcm::_2, pcm::_3));
115+
Eigen::MatrixXd D = offDiagonalD(e, gf.exportKernelD());
116116
// Fill diagonal based on Purisima's formula
117117
Eigen::VectorXd D_diag = diagonalD(e, D);
118118
D.diagonal() = D_diag;

src/green/AnisotropicLiquid.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636

3737
class Element;
3838

39+
#include "DerivativeTypes.hpp"
40+
#include "DerivativeUtils.hpp"
41+
#include "bi_operators/IntegratorForward.hpp"
3942
#include "dielectric_profile/Anisotropic.hpp"
4043
#include "GreensFunction.hpp"
4144

@@ -48,8 +51,8 @@ class Element;
4851
* \tparam IntegratorPolicy policy for the calculation of the matrix represenation of S and D
4952
*/
5053

51-
template <typename DerivativeTraits,
52-
typename IntegratorPolicy>
54+
template <typename DerivativeTraits = AD_directional,
55+
typename IntegratorPolicy = CollocationIntegrator>
5356
class AnisotropicLiquid __final : public GreensFunction<DerivativeTraits, IntegratorPolicy, Anisotropic,
5457
AnisotropicLiquid<DerivativeTraits, IntegratorPolicy> >
5558
{
@@ -125,6 +128,12 @@ class AnisotropicLiquid __final : public GreensFunction<DerivativeTraits, Integr
125128
Eigen::Vector3d scratch = this->profile_.epsilon() * (this->gradientProbe(p1, p2));
126129
return scratch.dot(direction);
127130
}
131+
virtual KernelS exportKernelS_impl() const __override {
132+
return pcm::bind(&AnisotropicLiquid<DerivativeTraits, IntegratorPolicy>::kernelS, *this, pcm::_1, pcm::_2);
133+
}
134+
virtual KernelD exportKernelD_impl() const __override {
135+
return pcm::bind(&AnisotropicLiquid<DerivativeTraits, IntegratorPolicy>::kernelD, *this, pcm::_1, pcm::_2, pcm::_3);
136+
}
128137
virtual std::ostream & printObject(std::ostream & os) __override
129138
{
130139
os << "Green's function type: anisotropic liquid" << std::endl;

src/green/IGreensFunction.hpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,27 @@ class Element;
4848
* them.
4949
*/
5050

51+
/*! \typedef KernelS
52+
* \brief functor handle to the kernelS method
53+
*/
54+
typedef pcm::function<double(const Eigen::Vector3d &, const Eigen::Vector3d &)> KernelS;
55+
56+
/*! \typedef KernelD
57+
* \brief functor handle to the kernelD method
58+
*/
59+
typedef pcm::function<double(const Eigen::Vector3d &, const Eigen::Vector3d &, const Eigen::Vector3d &)> KernelD;
60+
5161
class IGreensFunction
5262
{
53-
public:
63+
public:
5464
virtual ~IGreensFunction() {}
5565
/*! Returns value of the kernel of the \f$\mathcal{S}\f$ integral operator, i.e. the value of the
5666
* Greens's function for the pair of points p1, p2: \f$ G(\mathbf{p}_1, \mathbf{p}_2)\f$
5767
* \param[in] p1 first point
5868
* \param[in] p2 second point
5969
*/
6070
double kernelS(const Eigen::Vector3d & p1, const Eigen::Vector3d &p2) const {
61-
return kernelS_impl(p1, p2);
71+
return kernelS_impl(p1, p2);
6272
}
6373
/*! Returns value of the kernel of the \f$\mathcal{D}\f$ integral operator for the pair of points p1, p2:
6474
* \f$ [\boldsymbol{\varepsilon}\nabla_{\mathbf{p_2}}G(\mathbf{p}_1, \mathbf{p}_2)]\cdot \mathbf{n}_{\mathbf{p}_2}\f$
@@ -69,7 +79,14 @@ class IGreensFunction
6979
* \param[in] p2 second point
7080
*/
7181
double kernelD(const Eigen::Vector3d & direction, const Eigen::Vector3d & p1, const Eigen::Vector3d & p2) const {
72-
return kernelD_impl(direction, p1, p2);
82+
return kernelD_impl(direction, p1, p2);
83+
}
84+
85+
KernelS exportKernelS() const {
86+
return exportKernelS_impl();
87+
}
88+
KernelD exportKernelD() const {
89+
return exportKernelD_impl();
7390
}
7491

7592
/*! Whether the Green's function describes a uniform environment */
@@ -87,9 +104,9 @@ class IGreensFunction
87104
virtual Eigen::MatrixXd doubleLayer(const std::vector<Element> & e) const = 0;
88105

89106
friend std::ostream & operator<<(std::ostream & os, IGreensFunction & gf) {
90-
return gf.printObject(os);
107+
return gf.printObject(os);
91108
}
92-
protected:
109+
protected:
93110
/*! Returns value of the kernel of the \f$\mathcal{S}\f$ integral operator, i.e. the value of the
94111
* Greens's function for the pair of points p1, p2: \f$ G(\mathbf{p}_1, \mathbf{p}_2)\f$
95112
* \param[in] p1 first point
@@ -105,7 +122,9 @@ class IGreensFunction
105122
* \param[in] p2 second point
106123
*/
107124
virtual double kernelD_impl(const Eigen::Vector3d & direction,
108-
const Eigen::Vector3d & p1, const Eigen::Vector3d & p2) const = 0;
125+
const Eigen::Vector3d & p1, const Eigen::Vector3d & p2) const = 0;
126+
virtual KernelS exportKernelS_impl() const = 0;
127+
virtual KernelD exportKernelD_impl() const = 0;
109128
virtual std::ostream & printObject(std::ostream & os) = 0;
110129
};
111130

src/green/IonicLiquid.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636

3737
class Element;
3838

39+
#include "DerivativeTypes.hpp"
3940
#include "DerivativeUtils.hpp"
41+
#include "bi_operators/IntegratorForward.hpp"
4042
#include "GreensFunction.hpp"
4143
#include "dielectric_profile/Yukawa.hpp"
4244

@@ -49,8 +51,8 @@ class Element;
4951
* \tparam IntegratorPolicy policy for the calculation of the matrix represenation of S and D
5052
*/
5153

52-
template <typename DerivativeTraits,
53-
typename IntegratorPolicy>
54+
template <typename DerivativeTraits = AD_directional,
55+
typename IntegratorPolicy = CollocationIntegrator>
5456
class IonicLiquid __final : public GreensFunction<DerivativeTraits, IntegratorPolicy, Yukawa,
5557
IonicLiquid<DerivativeTraits, IntegratorPolicy> >
5658
{
@@ -106,6 +108,12 @@ class IonicLiquid __final : public GreensFunction<DerivativeTraits, IntegratorPo
106108
{
107109
return this->profile_.epsilon * (this->derivativeProbe(direction, p1, p2));
108110
}
111+
virtual KernelS exportKernelS_impl() const __override {
112+
return pcm::bind(&IonicLiquid<DerivativeTraits, IntegratorPolicy>::kernelS, *this, pcm::_1, pcm::_2);
113+
}
114+
virtual KernelD exportKernelD_impl() const __override {
115+
return pcm::bind(&IonicLiquid<DerivativeTraits, IntegratorPolicy>::kernelD, *this, pcm::_1, pcm::_2, pcm::_3);
116+
}
109117
virtual std::ostream & printObject(std::ostream & os) __override
110118
{
111119
os << "Green's function type: ionic liquid" << std::endl;

src/green/SphericalDiffuse.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
// Boost.Math includes
4040
#include <boost/math/special_functions/legendre.hpp>
4141

42+
#include "DerivativeUtils.hpp"
43+
#include "bi_operators/IntegratorForward.hpp"
44+
#include "dielectric_profile/ProfileForward.hpp"
4245
#include "GreensFunction.hpp"
4346
#include "utils/MathUtils.hpp"
4447

@@ -64,8 +67,8 @@
6467
* at a pair of points, a translation of the sampling points is performed first.
6568
*/
6669

67-
template <typename IntegratorPolicy,
68-
typename ProfilePolicy>
70+
template <typename IntegratorPolicy = CollocationIntegrator,
71+
typename ProfilePolicy = OneLayerTanh>
6972
class SphericalDiffuse __final : public GreensFunction<Numerical, IntegratorPolicy, ProfilePolicy,
7073
SphericalDiffuse<IntegratorPolicy, ProfilePolicy> >
7174
{
@@ -248,6 +251,12 @@ class SphericalDiffuse __final : public GreensFunction<Numerical, IntegratorPoli
248251

249252
return (eps_r2 * this->derivativeProbe(direction, p1, p2));
250253
}
254+
virtual KernelS exportKernelS_impl() const __override {
255+
return pcm::bind(&SphericalDiffuse<IntegratorPolicy, ProfilePolicy>::kernelS, *this, pcm::_1, pcm::_2);
256+
}
257+
virtual KernelD exportKernelD_impl() const __override {
258+
return pcm::bind(&SphericalDiffuse<IntegratorPolicy, ProfilePolicy>::kernelD, *this, pcm::_1, pcm::_2, pcm::_3);
259+
}
251260
virtual std::ostream & printObject(std::ostream & os) __override
252261
{
253262
Eigen::IOFormat CleanFmt(Eigen::StreamPrecision, 0, ", ", "\n", "(", ")");

src/green/SphericalSharp.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434

3535
#include <Eigen/Core>
3636

37+
#include "DerivativeTypes.hpp"
3738
#include "DerivativeUtils.hpp"
39+
#include "bi_operators/IntegratorForward.hpp"
3840
#include "GreensFunction.hpp"
3941
#include "utils/legendre.h"
4042
#include "utils/MathUtils.hpp"
@@ -49,8 +51,8 @@
4951
* \tparam IntegratorPolicy policy for the calculation of the matrix represenation of S and D
5052
*/
5153

52-
template <typename DerivativeTraits,
53-
typename IntegratorPolicy>
54+
template <typename DerivativeTraits = AD_directional,
55+
typename IntegratorPolicy = CollocationIntegrator>
5456
class SphericalSharp __final : public GreensFunction<DerivativeTraits, IntegratorPolicy, Sharp,
5557
SphericalSharp<DerivativeTraits, IntegratorPolicy> >
5658
{
@@ -154,6 +156,12 @@ class SphericalSharp __final : public GreensFunction<DerivativeTraits, Integrato
154156
{
155157
return (this->profile_.epsilonSolvent * this->derivativeProbe(direction, p1, p2));
156158
}
159+
virtual KernelS exportKernelS_impl() const __override {
160+
return pcm::bind(&SphericalSharp<DerivativeTraits, IntegratorPolicy>::kernelS, *this, pcm::_1, pcm::_2);
161+
}
162+
virtual KernelD exportKernelD_impl() const __override {
163+
return pcm::bind(&SphericalSharp<DerivativeTraits, IntegratorPolicy>::kernelD, *this, pcm::_1, pcm::_2, pcm::_3);
164+
}
157165
DerivativeTraits imagePotential_impl(DerivativeTraits * sp, DerivativeTraits * pp) const
158166
{
159167
// Data from permittivity profile

0 commit comments

Comments
 (0)