n2p2 - A neural network potential package
nnp::EwaldTruncKolafaFixR Class Reference

#include <EwaldTruncKolafaFixR.h>

Inheritance diagram for nnp::EwaldTruncKolafaFixR:
Collaboration diagram for nnp::EwaldTruncKolafaFixR:

Public Member Functions

void calculateParameters (EwaldGlobalSettings const &settings, EwaldStructureData const &sData, EwaldParameters &params) override
 
bool publishedNewCutoffs () override
 
bool isEstimateReliable (EwaldGlobalSettings const &settings, EwaldParameters const &params) const override
 
- Public Member Functions inherited from nnp::IEwaldTrunc
virtual void calculateParameters (EwaldGlobalSettings const &settings, EwaldStructureData const &sData, EwaldParameters &params)=0
 
virtual bool publishedNewCutoffs ()=0
 
virtual bool isEstimateReliable (EwaldGlobalSettings const &settings, EwaldParameters const &params) const =0
 
virtual ~IEwaldTrunc ()=default
 

Private Member Functions

double calculateEta (double const rCut, double const prec) const
 
double calculateKCut (double const eta, double const prec) const
 
void calculateC (double const qMax)
 

Private Attributes

double volume = 0.0
 
double fourPiEps = 1.0
 
std::size_t numAtoms = 0
 
bool newCutoffs = true
 
bool newCutoffsWerePublished = false
 
double C = 0.0
 

Detailed Description

Definition at line 13 of file EwaldTruncKolafaFixR.h.

Member Function Documentation

◆ calculateParameters()

void nnp::EwaldTruncKolafaFixR::calculateParameters ( EwaldGlobalSettings const &  settings,
EwaldStructureData const &  sData,
EwaldParameters params 
)
overridevirtual

Implements nnp::IEwaldTrunc.

Definition at line 12 of file EwaldTruncKolafaFixR.cpp.

15 {
16 size_t N = sData.getNumAtoms();
17 double V = sData.getVolume();
18
19 newCutoffs = (V != volume || N != numAtoms);
20 if (!newCutoffs) return;
22
23 volume = V;
24 fourPiEps = settings.fourPiEps;
25 numAtoms = N;
26 double rCut = params.rCut;
27 if (rCut == 0.0)
28 throw std::runtime_error("ERROR: Real space cutoff of Ewald "
29 "summation cannot be zero.");
30
31 calculateC(settings.maxCharge);
32 params.eta = calculateEta(rCut, settings.precision);
33 params.kCut = calculateKCut(params.eta, settings.precision);
34 return;
35 }
void calculateC(double const qMax)
double calculateEta(double const rCut, double const prec) const
double calculateKCut(double const eta, double const prec) const

References calculateC(), calculateEta(), calculateKCut(), nnp::EwaldParameters::eta, fourPiEps, nnp::EwaldGlobalSettings::fourPiEps, nnp::EwaldStructureData::getNumAtoms(), nnp::EwaldStructureData::getVolume(), nnp::EwaldParameters::kCut, nnp::EwaldGlobalSettings::maxCharge, newCutoffs, newCutoffsWerePublished, numAtoms, nnp::EwaldGlobalSettings::precision, nnp::EwaldParameters::rCut, and volume.

Here is the call graph for this function:

◆ publishedNewCutoffs()

bool nnp::EwaldTruncKolafaFixR::publishedNewCutoffs ( )
overridevirtual

Implements nnp::IEwaldTrunc.

Definition at line 36 of file EwaldTruncKolafaFixR.cpp.

37 {
38 bool answer = newCutoffsWerePublished;
40 return answer;
41 }

References newCutoffsWerePublished.

◆ isEstimateReliable()

bool nnp::EwaldTruncKolafaFixR::isEstimateReliable ( EwaldGlobalSettings const &  settings,
EwaldParameters const &  params 
) const
overridevirtual

Implements nnp::IEwaldTrunc.

Definition at line 42 of file EwaldTruncKolafaFixR.cpp.

45 {
46 return params.eta >= settings.maxQSigma;
47 }

References nnp::EwaldParameters::eta, and nnp::EwaldGlobalSettings::maxQSigma.

◆ calculateEta()

double nnp::EwaldTruncKolafaFixR::calculateEta ( double const  rCut,
double const  prec 
) const
private

Definition at line 49 of file EwaldTruncKolafaFixR.cpp.

51 {
52 double x = sqrt(rCut/2) * prec / C;
53 if (x >= 1.0)
54 throw runtime_error("ERROR: Bad Ewald precision settings, try a "
55 "smaller value.");
56 return rCut / sqrt(-2 * log(x));
57 }

References C.

Referenced by calculateParameters().

Here is the caller graph for this function:

◆ calculateKCut()

double nnp::EwaldTruncKolafaFixR::calculateKCut ( double const  eta,
double const  prec 
) const
private

Definition at line 59 of file EwaldTruncKolafaFixR.cpp.

61 {
62 double constexpr acceptError = 1.e-10;
63 double relXError = 1.0;
64 double relYError = 1.0;
65 double y = eta * prec / (sqrt(2) * C);
66
67 double kCut = 1.0/eta;
68 double kCutOld;
69 while (relXError > acceptError || relYError > acceptError)
70 {
71 kCutOld = kCut;
72 kCut -= 2 * kCut / (1 + 2*pow(kCut * eta,2.0))
73 * (-1 + sqrt(kCut) * exp(pow(kCut * eta,2.0)/2) * y);
74 // If kCut becomes negative, start with smaller value.
75 if (kCut <= 0)
76 {
77 kCut = kCutOld / 2;
78 continue;
79 }
80
81 relXError = abs((kCut - kCutOld) / kCut);
82 relYError = abs((1/sqrt(kCut)
83 * exp(-pow(kCut * eta,2.0) / 2) - y) / y);
84 }
85 return kCut;
86 }

References C.

Referenced by calculateParameters().

Here is the caller graph for this function:

◆ calculateC()

void nnp::EwaldTruncKolafaFixR::calculateC ( double const  qMax)
private

Definition at line 88 of file EwaldTruncKolafaFixR.cpp.

89 {
90 C = 2 * pow(qMax,2.0) * sqrt(numAtoms/volume) / fourPiEps;
91 }

References C, fourPiEps, numAtoms, and volume.

Referenced by calculateParameters().

Here is the caller graph for this function:

Member Data Documentation

◆ volume

double nnp::EwaldTruncKolafaFixR::volume = 0.0
private

Definition at line 25 of file EwaldTruncKolafaFixR.h.

Referenced by calculateC(), and calculateParameters().

◆ fourPiEps

double nnp::EwaldTruncKolafaFixR::fourPiEps = 1.0
private

Definition at line 26 of file EwaldTruncKolafaFixR.h.

Referenced by calculateC(), and calculateParameters().

◆ numAtoms

std::size_t nnp::EwaldTruncKolafaFixR::numAtoms = 0
private

Definition at line 27 of file EwaldTruncKolafaFixR.h.

Referenced by calculateC(), and calculateParameters().

◆ newCutoffs

bool nnp::EwaldTruncKolafaFixR::newCutoffs = true
private

Definition at line 28 of file EwaldTruncKolafaFixR.h.

Referenced by calculateParameters().

◆ newCutoffsWerePublished

bool nnp::EwaldTruncKolafaFixR::newCutoffsWerePublished = false
private

Definition at line 29 of file EwaldTruncKolafaFixR.h.

Referenced by calculateParameters(), and publishedNewCutoffs().

◆ C

double nnp::EwaldTruncKolafaFixR::C = 0.0
private

Definition at line 31 of file EwaldTruncKolafaFixR.h.

Referenced by calculateC(), calculateEta(), and calculateKCut().


The documentation for this class was generated from the following files: