votca 2026-dev
Loading...
Searching...
No Matches
gaussiankernel.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2026 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20#pragma once
21#ifndef VOTCA_XTP_GAUSSIANKERNEL_H
22#define VOTCA_XTP_GAUSSIANKERNEL_H
23
24// Standard includes
25#include <cmath>
26
27// Local VOTCA includes
28#include "eigen.h"
29
30namespace votca {
31namespace xtp {
32
52 double B0 = 0.0;
53 double B1 = 0.0;
54 double B2 = 0.0;
55
56 GaussianKernel(double r, double S) {
57 if (S <= 0.0) {
58 B0 = 1.0 / r;
59 B1 = B0 * B0 * B0;
60 B2 = 3.0 * B1 * B0 * B0;
61 return;
62 }
63 const double x = r / S;
64 constexpr double two_over_sqrtpi = 1.1283791670955126;
65 if (x < 0.05) {
66 // series in x (to x^8): avoids the cancellation of the closed form at
67 // short range
68 const double x2 = x * x;
69 const double s1 = two_over_sqrtpi / S;
70 B0 = s1 *
71 (1.0 + x2 * (-1.0 / 3.0 +
72 x2 * (1.0 / 10.0 + x2 * (-1.0 / 42.0 + x2 / 216.0))));
73 const double s3 = s1 / (S * S);
74 B1 = s3 * (2.0 / 3.0 +
75 x2 * (-2.0 / 5.0 +
76 x2 * (1.0 / 7.0 + x2 * (-1.0 / 27.0 + x2 / 132.0))));
77 const double s5 = s3 / (S * S);
78 B2 = s5 * (4.0 / 5.0 +
79 x2 * (-4.0 / 7.0 +
80 x2 * (2.0 / 9.0 + x2 * (-2.0 / 33.0 + x2 / 78.0))));
81 return;
82 }
83 const double g = std::exp(-x * x);
84 B0 = std::erf(x) / r;
85 const double r2 = r * r;
86 B1 = (B0 - two_over_sqrtpi * g / S) / r2;
87 B2 = (3.0 * B1 - 2.0 * two_over_sqrtpi * g / (S * S * S)) / r2;
88 }
89
92 Eigen::Matrix3d DipoleTensor(const Eigen::Vector3d& r) const {
93 Eigen::Matrix3d T = -B2 * r * r.transpose();
94 T.diagonal().array() += B1;
95 return T;
96 }
97};
98
99} // namespace xtp
100} // namespace votca
101
102#endif // VOTCA_XTP_GAUSSIANKERNEL_H
Provides a means for comparing floating point numbers.
Definition basebead.h:33
GaussianKernel(double r, double S)
Eigen::Matrix3d DipoleTensor(const Eigen::Vector3d &r) const