Skip to content

Commit 9afbcef

Browse files
committed
Rename a function. Angular momentum summation for image potential starts from 1 and not from 0
1 parent ae6381f commit 9afbcef

File tree

1 file changed

+30
-37
lines changed

1 file changed

+30
-37
lines changed

src/green/SphericalDiffuse.hpp

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ class SphericalDiffuse : public GreensFunction<Numerical, IntegratorPolicy, Prof
101101
const Eigen::Vector3d & p1, const Eigen::Vector3d & p2) const
102102
{
103103
double eps_r2 = 0.0;
104-
// Shift p2 by origin_
105-
std::tie(eps_r2, std::ignore) = this->profile_((p2 - this->origin_).norm());
104+
std::tie(eps_r2, std::ignore) = this->epsilon(p2);
106105

107106
return (eps_r2 * this->derivativeProbe(direction, p1, p2));
108107
}
@@ -130,40 +129,30 @@ class SphericalDiffuse : public GreensFunction<Numerical, IntegratorPolicy, Prof
130129
* \param[in] probe location of the probe charge
131130
*/
132131
double coefficientCoulomb(const Eigen::Vector3d & source, const Eigen::Vector3d & probe) const {
133-
double r1 = (source - this->origin_).norm();
134-
double r2 = (probe - this->origin_).norm();
135-
136132
// Obtain coefficient for the separation of the Coulomb singularity
137-
return this->coefficient(r1, r2);
133+
return this->coefficient_impl(source, probe);
138134
}
139135
/*! \brief Returns singular part of the Green's function
140136
* \param[in] source location of the source charge
141137
* \param[in] probe location of the probe charge
142138
*/
143139
double Coulomb(const Eigen::Vector3d & source, const Eigen::Vector3d & probe) const {
144-
Eigen::Vector3d source_shifted = source - this->origin_;
145-
Eigen::Vector3d probe_shifted = probe - this->origin_;
146-
double r1 = source_shifted.norm();
147-
double r2 = probe_shifted.norm();
148-
double r12 = (source_shifted - probe_shifted).norm();
140+
double r12 = (source - probe).norm();
149141

150142
// Obtain coefficient for the separation of the Coulomb singularity
151-
return (1.0 / (this->coefficient(r1, r2) * r12));
143+
return (1.0 / (this->coefficient_impl(source, probe) * r12));
152144
}
153145
/*! \brief Returns non-singular part of the Green's function (image potential)
154146
* \param[in] source location of the source charge
155147
* \param[in] probe location of the probe charge
156148
*/
157149
double imagePotential(const Eigen::Vector3d & source, const Eigen::Vector3d & probe) const {
158-
Eigen::Vector3d source_shifted = source - this->origin_;
159-
Eigen::Vector3d probe_shifted = probe - this->origin_;
160-
161150
// Obtain coefficient for the separation of the Coulomb singularity
162-
double Cr12 = this->coefficient(source_shifted.norm(), probe_shifted.norm());
151+
double Cr12 = this->coefficient_impl(source, probe);
163152

164153
double gr12 = 0.0;
165-
for (int L = 0; L <= maxLGreen_; ++L) {
166-
gr12 += this->functionSummation(L, source_shifted, probe_shifted, Cr12);
154+
for (int L = 1; L <= maxLGreen_; ++L) {
155+
gr12 += this->imagePotentialComponent_impl(L, source, probe, Cr12);
167156
}
168157

169158
return gr12;
@@ -215,7 +204,7 @@ class SphericalDiffuse : public GreensFunction<Numerical, IntegratorPolicy, Prof
215204
}
216205
/*! Handle to the dielectric profile evaluation */
217206
std::tuple<double, double> epsilon(const Eigen::Vector3d & point) const {
218-
return this->profile_((point - this->origin_).norm());
207+
return this->profile_((point + this->origin_).norm());
219208
}
220209
EIGEN_MAKE_ALIGNED_OPERATOR_NEW /* See http://eigen.tuxfamily.org/dox/group__TopicStructHavingEigenMembers.html */
221210
private:
@@ -229,16 +218,14 @@ class SphericalDiffuse : public GreensFunction<Numerical, IntegratorPolicy, Prof
229218
virtual Numerical operator()(Numerical * sp, Numerical * pp) const
230219
{
231220
// Transfer raw arrays to Eigen vectors using the Map type
232-
Eigen::Map<Eigen::Matrix<double, 3, 1> > p1(sp), p2(pp);
233-
Eigen::Vector3d source = p1 - this->origin_;
234-
Eigen::Vector3d probe = p2 - this->origin_;
221+
Eigen::Map<Eigen::Matrix<double, 3, 1> > source(sp), probe(pp);
235222

236223
// Obtain coefficient for the separation of the Coulomb singularity
237-
double Cr12 = this->coefficient(source.norm(), probe.norm());
224+
double Cr12 = this->coefficient_impl(source, probe);
238225

239226
double gr12 = 0.0;
240-
for (int L = 0; L <= maxLGreen_; ++L) {
241-
gr12 += this->functionSummation(L, source, probe, Cr12);
227+
for (int L = 1; L <= maxLGreen_; ++L) {
228+
gr12 += this->imagePotentialComponent_impl(L, source, probe, Cr12);
242229
}
243230
double r12 = (source - probe).norm();
244231

@@ -333,16 +320,18 @@ class SphericalDiffuse : public GreensFunction<Numerical, IntegratorPolicy, Prof
333320
std::vector<RadialFunction> omega_;
334321
/*! \brief Returns L-th component of the radial part of the Green's function
335322
* \param[in] L angular momentum
336-
* \param[in] sp source point, shifted by origin_
337-
* \param[in] pp probe point, shifted by origin_
323+
* \param[in] sp source point
324+
* \param[in] pp probe point
338325
* \param[in] Cr12 Coulomb singularity separation coefficient
339-
* \note This function expects that the source and probe points have been correctly shifted
340-
* to account for the position of the origin of the dielectric sphere.
326+
* \note This function shifts the given source and probe points by the location of the
327+
* dielectric sphere.
341328
*/
342-
double functionSummation(int L, const Eigen::Vector3d & sp, const Eigen::Vector3d & pp, double Cr12) const {
343-
double r1 = sp.norm();
344-
double r2 = pp.norm();
345-
double cos_gamma = sp.dot(pp) / (r1 * r2);
329+
double imagePotentialComponent_impl(int L, const Eigen::Vector3d & sp, const Eigen::Vector3d & pp, double Cr12) const {
330+
Eigen::Vector3d sp_shift = sp + this->origin_;
331+
Eigen::Vector3d pp_shift = pp + this->origin_;
332+
double r1 = sp_shift.norm();
333+
double r2 = pp_shift.norm();
334+
double cos_gamma = sp_shift.dot(pp_shift) / (r1 * r2);
346335
// Evaluate Legendre polynomial of order L
347336
// First of all clean-up cos_gamma, Legendre polynomials
348337
// are only defined for -1 <= x <= 1
@@ -366,7 +355,7 @@ class SphericalDiffuse : public GreensFunction<Numerical, IntegratorPolicy, Prof
366355
double d_omega2 = linearInterpolation(r2, omega_[L][0], omega_[L][2]);
367356

368357
double eps_r2 = 0.0;
369-
std::tie(eps_r2, std::ignore) = this->profile_(r2);
358+
std::tie(eps_r2, std::ignore) = this->profile_(pp_shift.norm());
370359

371360
double denominator = (d_zeta2 - d_omega2) * std::pow(r2, 2) * eps_r2;
372361

@@ -395,10 +384,14 @@ class SphericalDiffuse : public GreensFunction<Numerical, IntegratorPolicy, Prof
395384
*/
396385
RadialFunction omegaC_;
397386
/*! \brief Returns coefficient for the separation of the Coulomb singularity
398-
* \param[in] r1 first point
399-
* \param[in] r2 second point
387+
* \param[in] sp first point
388+
* \param[in] pp second point
389+
* \note This function shifts the given source and probe points by the location of the
390+
* dielectric sphere.
400391
*/
401-
double coefficient(double r1, double r2) const {
392+
double coefficient_impl(const Eigen::Vector3d & sp, const Eigen::Vector3d & pp) const {
393+
double r1 = (sp + this->origin_).norm();
394+
double r2 = (pp + this->origin_).norm();
402395
/* Value of zetaC_ at point with index 1 */
403396
double zeta1 = linearInterpolation(r1, zetaC_[0], zetaC_[1]);
404397
/* Value of zetaC_ at point with index 2 */

0 commit comments

Comments
 (0)