MRMD 0.4.0
Multi Resolution Molecular Dynamics
Loading...
Searching...
No Matches
CoulombDSF.hpp
Go to the documentation of this file.
1// Copyright 2024 Sebastian Eibl
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include "data/Atoms.hpp"
18#include "datatypes.hpp"
19#include "util/math.hpp"
20
21namespace mrmd
22{
23namespace action
24{
25namespace impl
26{
27
40{
41private:
42 real_t alpha_;
43 real_t rc_ = 0_r;
44 real_t rcSqr_ = 0_r;
45 real_t forceShift_ = 0_r;
46 real_t energyShift_ = 0_r;
47
48public:
53 KOKKOS_INLINE_FUNCTION
54 real_t computeForce(const real_t& distSqr, const real_t q1, const real_t q2) const
55 {
56 auto r = std::sqrt(distSqr);
57 real_t prefac = 138.935458_r * q1 * q2;
58 real_t expX2;
59 auto erfc = util::approxErfc(alpha_ * r, expX2);
60 auto force = prefac * (erfc / r + 2_r * alpha_ * inv_sqrtpi * expX2 + r * forceShift_);
61 return force / distSqr;
62 }
63
68 KOKKOS_INLINE_FUNCTION
69 real_t computeEnergy(const real_t& distSqr, const real_t q1, const real_t q2) const
70 {
71 auto r = std::sqrt(distSqr);
72 real_t prefac = 138.935458_r * q1 * q2;
73 auto erfc = util::approxErfc(alpha_ * r);
74 return prefac * (erfc / r - energyShift_ - forceShift_ * (r - rc_));
75 }
76
77 CoulombDSF(const real_t& rc, const real_t& alpha) : alpha_(alpha), rc_(rc), rcSqr_(rc * rc)
78 {
79 real_t erfc = std::erfc(alpha_ * rc);
80 real_t exp = std::exp(-alpha_ * alpha_ * rcSqr_);
81 forceShift_ = -(erfc / rcSqr_ + 2_r * inv_sqrtpi * alpha_ * exp / rc);
82 energyShift_ = erfc / rc;
83 }
84};
85} // namespace impl
86
87} // namespace action
88} // namespace mrmd
Implements the Coulomb potential with the Damped Shifted Force (DSF) method.
Definition CoulombDSF.hpp:40
KOKKOS_INLINE_FUNCTION real_t computeForce(const real_t &distSqr, const real_t q1, const real_t q2) const
DOI: 10.1140/epjst/e2016-60151-6 eq 16.
Definition CoulombDSF.hpp:54
KOKKOS_INLINE_FUNCTION real_t computeEnergy(const real_t &distSqr, const real_t q1, const real_t q2) const
DOI: 10.1140/epjst/e2016-60151-6 eq 15.
Definition CoulombDSF.hpp:69
CoulombDSF(const real_t &rc, const real_t &alpha)
Definition CoulombDSF.hpp:77
KOKKOS_INLINE_FUNCTION real_t approxErfc(const real_t &x, real_t &expX2)
"Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Table" Milton Abramowitz ...
Definition math.hpp:58
Definition BerendsenBarostat.cpp:18
constexpr auto inv_sqrtpi
Definition constants.hpp:27
double real_t
Definition datatypes.hpp:99