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

#include <CutoffFunction.h>

Collaboration diagram for nnp::CutoffFunction:

Public Types

enum  CutoffType {
  CT_HARD , CT_COS , CT_TANHU , CT_TANH ,
  CT_EXP , CT_POLY1 , CT_POLY2 , CT_POLY3 ,
  CT_POLY4
}
 List of available cutoff function types. More...
 

Public Member Functions

 CutoffFunction ()
 Constructor, initializes to ´CT_HARD´. More...
 
void setCutoffType (CutoffType const cutoffType)
 Set cutoff type. More...
 
CutoffType getCutoffType () const
 Getter for cutoffType. More...
 
void setCutoffRadius (double const cutoffRadius)
 Set cutoff radius. More...
 
double getCutoffRadius () const
 Getter for rc. More...
 
void setCutoffParameter (double const alpha)
 Set parameter for polynomial cutoff function (CT_POLY). More...
 
double getCutoffParameter () const
 Getter for alpha. More...
 
double f (double r) const
 Cutoff function \(f_c\). More...
 
double df (double r) const
 Derivative of cutoff function \(\frac{d f_c}{d r}\). More...
 
void fdf (double r, double &fc, double &dfc) const
 Calculate cutoff function \(f_c\) and derivative \(\frac{d f_c}{d r}\). More...
 

Private Member Functions

double fHARD (double r) const
 
double dfHARD (double r) const
 
void fdfHARD (double r, double &fc, double &dfc) const
 
double fCOS (double r) const
 
double dfCOS (double r) const
 
void fdfCOS (double r, double &fc, double &dfc) const
 
double fTANHU (double r) const
 
double dfTANHU (double r) const
 
void fdfTANHU (double r, double &fc, double &dfc) const
 
double fTANH (double r) const
 
double dfTANH (double r) const
 
void fdfTANH (double r, double &fc, double &dfc) const
 
double fCORE (double r) const
 
double dfCORE (double r) const
 
void fdfCORE (double r, double &fc, double &dfc) const
 

Private Attributes

CutoffType cutoffType
 Cutoff function type. More...
 
double rc
 Outer cutoff radius \(r_c\). More...
 
double rcinv
 Inverse cutoff radius \(\frac{1}{r_c}\). More...
 
double rci
 Inner cutoff for cutoff function types which allow shifting. More...
 
double alpha
 Cutoff function parameter for CT_POLYn and CT_EXP \(\alpha\). More...
 
double iw
 Inverse width of cutoff function \(\frac{1}{r_c - r_{ci}}\). More...
 
CoreFunction core
 Core functions used by POLYN, if any. More...
 
double(CutoffFunction::* fPtr )(double r) const
 Function pointer to f. More...
 
double(CutoffFunction::* dfPtr )(double r) const
 Function pointer to df. More...
 
void(CutoffFunction::* fdfPtr )(double r, double &fc, double &dfc) const
 Function pointer to fdf. More...
 

Static Private Attributes

static double const PI = 4.0 * atan(1.0)
 
static double const PI_2 = 2.0 * atan(1.0)
 
static double const E = exp(1.0)
 
static double const TANH_PRE = pow((E + 1 / E) / (E - 1 / E), 3)
 

Detailed Description

Definition at line 25 of file CutoffFunction.h.

Member Enumeration Documentation

◆ CutoffType

List of available cutoff function types.

Most cutoff types allow the definition of an inner cutoff \( r_{ci} := \alpha \, r_c\). Then the cutoff is equal to \(1\) up to the inner cutoff:

\( f_c(r) = \begin{cases} 1, & \text{for } 0 \le r < r_{ci} \\ f(x), & \text{for } r_{ci} \le r < r_c \text{ where } x := \frac{r - r_{ci}}{r_c - r_{ci}} \\ 0 & \text{for } r \geq r_c \end{cases} \)

Enumerator
CT_HARD 

\(f(x) = 1\)

CT_COS 

\(f(x) = \frac{1}{2} \left[ \cos (\pi x) + 1\right] \)

CT_TANHU 

\(f_c(r) = \tanh^3 \left(1 - \frac{r}{r_c} \right) \)

CT_TANH 

\(f_c(r) = c \tanh^3 \left(1 - \frac{r}{r_c} \right),\, f(0) = 1 \)

CT_EXP 

\(f(x) = e^{1 - \frac{1}{1 - x^2}}\)

CT_POLY1 

\(f(x) = (2x - 3)x^2 + 1\)

CT_POLY2 

\(f(x) = ((15 - 6x)x - 10) x^3 + 1\)

CT_POLY3 

\(f(x) = (x(x(20x - 70) + 84) - 35)x^4 + 1\)

CT_POLY4 

\(f(x) = (x(x((315 - 70x)x - 540) + 420) - 126)x^5 + 1\)

Definition at line 42 of file CutoffFunction.h.

Constructor & Destructor Documentation

◆ CutoffFunction()

CutoffFunction::CutoffFunction ( )

Constructor, initializes to ´CT_HARD´.

Definition at line 30 of file CutoffFunction.cpp.

31 rc (0.0 ),
32 rcinv (0.0 ),
33 rci (0.0 ),
34 alpha (0.0 ),
35 iw (0.0 ),
36 fPtr (&CutoffFunction:: fHARD),
39{
40}
double rci
Inner cutoff for cutoff function types which allow shifting.
void fdfHARD(double r, double &fc, double &dfc) const
double rcinv
Inverse cutoff radius .
double iw
Inverse width of cutoff function .
double(CutoffFunction::* fPtr)(double r) const
Function pointer to f.
double(CutoffFunction::* dfPtr)(double r) const
Function pointer to df.
double rc
Outer cutoff radius .
CutoffType cutoffType
Cutoff function type.
double alpha
Cutoff function parameter for CT_POLYn and CT_EXP .
double dfHARD(double r) const
void(CutoffFunction::* fdfPtr)(double r, double &fc, double &dfc) const
Function pointer to fdf.

Member Function Documentation

◆ setCutoffType()

void CutoffFunction::setCutoffType ( CutoffType const  cutoffType)

Set cutoff type.

Parameters
[in]cutoffTypeType of cutoff used.

Definition at line 42 of file CutoffFunction.cpp.

43{
44 this->cutoffType = cutoffType;
45
46 if (cutoffType == CT_HARD)
47 {
51 }
52 else if (cutoffType == CT_COS)
53 {
57 }
58 else if (cutoffType == CT_TANHU)
59 {
63 }
64 else if (cutoffType == CT_TANH)
65 {
69 }
70 else if (cutoffType == CT_POLY1 ||
75 {
76 using CFT = CoreFunction::Type;
77 if (cutoffType == CT_POLY1) core.setType(CFT::POLY1);
78 else if (cutoffType == CT_POLY2) core.setType(CFT::POLY2);
79 else if (cutoffType == CT_POLY3) core.setType(CFT::POLY3);
80 else if (cutoffType == CT_POLY4) core.setType(CFT::POLY4);
81 else if (cutoffType == CT_EXP) core.setType(CFT::EXP);
82
86 }
87 else
88 {
89 throw invalid_argument("ERROR: Unknown cutoff type.\n");
90 }
91
92 return;
93}
void setType(Type const type)
Set function type.
Type
List of available function types.
Definition: CoreFunction.h:33
double fHARD(double r) const
double fCORE(double r) const
void fdfCOS(double r, double &fc, double &dfc) const
void fdfTANH(double r, double &fc, double &dfc) const
double fTANHU(double r) const
void fdfTANHU(double r, double &fc, double &dfc) const
void fdfCORE(double r, double &fc, double &dfc) const
double fTANH(double r) const
double dfCOS(double r) const
double fCOS(double r) const
double dfTANH(double r) const
double dfCORE(double r) const
double dfTANHU(double r) const
CoreFunction core
Core functions used by POLYN, if any.

References core, CT_COS, CT_EXP, CT_HARD, CT_POLY1, CT_POLY2, CT_POLY3, CT_POLY4, CT_TANH, CT_TANHU, cutoffType, dfCORE(), dfCOS(), dfHARD(), dfPtr, dfTANH(), dfTANHU(), fCORE(), fCOS(), fdfCORE(), fdfCOS(), fdfHARD(), fdfPtr, fdfTANH(), fdfTANHU(), fHARD(), fPtr, fTANH(), fTANHU(), and nnp::CoreFunction::setType().

Referenced by nnp::SymGrpExpAngn::addMember(), nnp::SymGrpExpAngnWeighted::addMember(), nnp::SymGrpExpAngw::addMember(), nnp::SymGrpExpRad::addMember(), nnp::SymGrpExpRadWeighted::addMember(), runTest(), and nnp::SymFncBaseCutoff::setCutoffFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCutoffType()

CutoffFunction::CutoffType nnp::CutoffFunction::getCutoffType ( ) const
inline

Getter for cutoffType.

Returns
CutoffType used.

Definition at line 183 of file CutoffFunction.h.

184{
185 return cutoffType;
186}

References cutoffType.

◆ setCutoffRadius()

◆ getCutoffRadius()

double nnp::CutoffFunction::getCutoffRadius ( ) const
inline

Getter for rc.

Returns
Cutoff radius used.

Definition at line 188 of file CutoffFunction.h.

189{
190 return rc;
191}

References rc.

◆ setCutoffParameter()

void CutoffFunction::setCutoffParameter ( double const  alpha)

Set parameter for polynomial cutoff function (CT_POLY).

Parameters
[in]alphaWidth parameter \(\alpha\).

Definition at line 102 of file CutoffFunction.cpp.

103{
104 if (alpha < 0.0 || alpha >= 1.0)
105 {
106 throw invalid_argument("ERROR: 0 <= alpha < 1.0 is required.\n");
107 }
108 this->alpha = alpha;
109 rci = rc * alpha;
110 iw = 1.0 / (rc - rci);
111 return;
112}

References alpha, iw, rc, and rci.

Referenced by nnp::SymGrpExpAngn::addMember(), nnp::SymGrpExpAngnWeighted::addMember(), nnp::SymGrpExpAngw::addMember(), nnp::SymGrpExpRad::addMember(), nnp::SymGrpExpRadWeighted::addMember(), nnp::SymFncBaseExpAng::changeLengthUnit(), nnp::SymFncExpAngnWeighted::changeLengthUnit(), nnp::SymFncExpRad::changeLengthUnit(), nnp::SymFncExpRadWeighted::changeLengthUnit(), main(), nnp::SymFncBaseCutoff::setCutoffFunction(), nnp::SymFncBaseExpAng::setParameters(), nnp::SymFncExpAngnWeighted::setParameters(), nnp::SymFncExpRad::setParameters(), and nnp::SymFncExpRadWeighted::setParameters().

Here is the caller graph for this function:

◆ getCutoffParameter()

double nnp::CutoffFunction::getCutoffParameter ( ) const
inline

Getter for alpha.

Returns
Cutoff parameter used.

Definition at line 193 of file CutoffFunction.h.

194{
195 return alpha;
196}

References alpha.

◆ f()

double nnp::CutoffFunction::f ( double  r) const
inline

Cutoff function \(f_c\).

Parameters
[in]rDistance.
Returns
Cutoff function value.

Definition at line 198 of file CutoffFunction.h.

199{
200 if (r >= rc) return 0.0;
201 return (this->*fPtr)(r);
202}

References fPtr, and rc.

Referenced by nnp::SymFncBaseExpAng::calculateRadialPart(), nnp::SymFncExpAngnWeighted::calculateRadialPart(), nnp::SymFncExpRad::calculateRadialPart(), nnp::SymFncExpRadWeighted::calculateRadialPart(), and runTest().

Here is the caller graph for this function:

◆ df()

double nnp::CutoffFunction::df ( double  r) const
inline

Derivative of cutoff function \(\frac{d f_c}{d r}\).

Parameters
[in]rDistance.
Returns
Value of cutoff function derivative.

Definition at line 204 of file CutoffFunction.h.

205{
206 if (r >= rc) return 0.0;
207 return (this->*dfPtr)(r);
208}

References dfPtr, and rc.

Referenced by runTest().

Here is the caller graph for this function:

◆ fdf()

void nnp::CutoffFunction::fdf ( double  r,
double &  fc,
double &  dfc 
) const
inline

Calculate cutoff function \(f_c\) and derivative \(\frac{d f_c}{d r}\).

Parameters
[in]rDistance.
[out]fcCutoff function value.
[out]dfcValue of cutoff function derivative.

Definition at line 210 of file CutoffFunction.h.

211{
212 if (r >= rc)
213 {
214 fc = 0.0;
215 dfc = 0.0;
216 return;
217 }
218 (this->*fdfPtr)(r, fc, dfc);
219 return;
220}
CutoffFunction fc
Definition: nnp-cutoff.cpp:27

References fc, fdfPtr, and rc.

Referenced by nnp::SymFncExpAngn::calculate(), nnp::SymFncExpAngnWeighted::calculate(), nnp::SymFncExpAngw::calculate(), nnp::SymFncExpRad::calculate(), nnp::SymFncExpRadWeighted::calculate(), nnp::SymGrpExpAngn::calculate(), nnp::SymGrpExpAngnWeighted::calculate(), nnp::SymGrpExpAngw::calculate(), nnp::SymGrpExpRad::calculate(), nnp::SymGrpExpRadWeighted::calculate(), and runTest().

Here is the caller graph for this function:

◆ fHARD()

double nnp::CutoffFunction::fHARD ( double  r) const
inlineprivate

Definition at line 222 of file CutoffFunction.h.

223{
224 return 1.0;
225}

Referenced by setCutoffType().

Here is the caller graph for this function:

◆ dfHARD()

double nnp::CutoffFunction::dfHARD ( double  r) const
inlineprivate

Definition at line 227 of file CutoffFunction.h.

228{
229 return 0.0;
230}

Referenced by setCutoffType().

Here is the caller graph for this function:

◆ fdfHARD()

void nnp::CutoffFunction::fdfHARD ( double  r,
double &  fc,
double &  dfc 
) const
inlineprivate

Definition at line 232 of file CutoffFunction.h.

235{
236 fc = 1.0;
237 dfc = 0.0;
238 return;
239}

References fc.

Referenced by setCutoffType().

Here is the caller graph for this function:

◆ fCOS()

double CutoffFunction::fCOS ( double  r) const
private

Definition at line 114 of file CutoffFunction.cpp.

115{
116 if (r < rci) return 1.0;
117 double const x = (r - rci) * iw;
118 return 0.5 * (cos(PI * x) + 1.0);
119}
static double const PI

References iw, PI, and rci.

Referenced by setCutoffType().

Here is the caller graph for this function:

◆ dfCOS()

double CutoffFunction::dfCOS ( double  r) const
private

Definition at line 121 of file CutoffFunction.cpp.

122{
123 if (r < rci) return 0.0;
124 double const x = (r - rci) * iw;
125 return -PI_2 * iw * sin(PI * x);
126}
static double const PI_2

References iw, PI, PI_2, and rci.

Referenced by setCutoffType().

Here is the caller graph for this function:

◆ fdfCOS()

void CutoffFunction::fdfCOS ( double  r,
double &  fc,
double &  dfc 
) const
private

Definition at line 128 of file CutoffFunction.cpp.

129{
130 if (r < rci)
131 {
132 fc = 1.0;
133 dfc = 0.0;
134 return;
135 }
136 double const x = (r - rci) * iw;
137 double const temp = cos(PI * x);
138 fc = 0.5 * (temp + 1.0);
139 dfc = -0.5 * iw * PI * sqrt(1.0 - temp * temp);
140 return;
141}

References fc, iw, PI, and rci.

Referenced by setCutoffType().

Here is the caller graph for this function:

◆ fTANHU()

double CutoffFunction::fTANHU ( double  r) const
private

Definition at line 143 of file CutoffFunction.cpp.

144{
145 double const temp = tanh(1.0 - r * rcinv);
146 return temp * temp * temp;
147}

References rcinv.

Referenced by setCutoffType().

Here is the caller graph for this function:

◆ dfTANHU()

double CutoffFunction::dfTANHU ( double  r) const
private

Definition at line 149 of file CutoffFunction.cpp.

150{
151 double temp = tanh(1.0 - r * rcinv);
152 temp *= temp;
153 return 3.0 * temp * (temp - 1.0) * rcinv;
154}

References rcinv.

Referenced by setCutoffType().

Here is the caller graph for this function:

◆ fdfTANHU()

void CutoffFunction::fdfTANHU ( double  r,
double &  fc,
double &  dfc 
) const
private

Definition at line 156 of file CutoffFunction.cpp.

157{
158 double const temp = tanh(1.0 - r * rcinv);
159 double const temp2 = temp * temp;
160 fc = temp * temp2;
161 dfc = 3.0 * temp2 * (temp2 - 1.0) * rcinv;
162 return;
163}

References fc, and rcinv.

Referenced by setCutoffType().

Here is the caller graph for this function:

◆ fTANH()

double CutoffFunction::fTANH ( double  r) const
private

Definition at line 165 of file CutoffFunction.cpp.

166{
167 double const temp = tanh(1.0 - r * rcinv);
168 return TANH_PRE * temp * temp * temp;
169}
static double const TANH_PRE

References rcinv, and TANH_PRE.

Referenced by setCutoffType().

Here is the caller graph for this function:

◆ dfTANH()

double CutoffFunction::dfTANH ( double  r) const
private

Definition at line 171 of file CutoffFunction.cpp.

172{
173 double temp = tanh(1.0 - r * rcinv);
174 temp *= temp;
175 return 3.0 * TANH_PRE * temp * (temp - 1.0) * rcinv;
176}

References rcinv, and TANH_PRE.

Referenced by setCutoffType().

Here is the caller graph for this function:

◆ fdfTANH()

void CutoffFunction::fdfTANH ( double  r,
double &  fc,
double &  dfc 
) const
private

Definition at line 178 of file CutoffFunction.cpp.

179{
180 double const temp = tanh(1.0 - r * rcinv);
181 double const temp2 = temp * temp;
182 fc = TANH_PRE * temp * temp2;
183 dfc = 3.0 * TANH_PRE * temp2 * (temp2 - 1.0) * rcinv;
184 return;
185}

References fc, rcinv, and TANH_PRE.

Referenced by setCutoffType().

Here is the caller graph for this function:

◆ fCORE()

double CutoffFunction::fCORE ( double  r) const
private

Definition at line 187 of file CutoffFunction.cpp.

188{
189 if (r < rci) return 1.0;
190 double const x = (r - rci) * iw;
191 return core.f(x);
192}
double f(double x) const
Calculate function value .
Definition: CoreFunction.h:171

References core, nnp::CoreFunction::f(), iw, and rci.

Referenced by setCutoffType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dfCORE()

double CutoffFunction::dfCORE ( double  r) const
private

Definition at line 194 of file CutoffFunction.cpp.

195{
196 if (r < rci) return 0.0;
197 double const x = (r - rci) * iw;
198 return iw * core.df(x);
199}
double df(double x) const
Calculate derivative of function at argument .
Definition: CoreFunction.h:179

References core, nnp::CoreFunction::df(), iw, and rci.

Referenced by setCutoffType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fdfCORE()

void CutoffFunction::fdfCORE ( double  r,
double &  fc,
double &  dfc 
) const
private

Definition at line 201 of file CutoffFunction.cpp.

202{
203 if (r < rci)
204 {
205 fc = 1.0;
206 dfc = 0.0;
207 return;
208 }
209 double const x = (r - rci) * iw;
210 core.fdf(x, fc, dfc);
211 dfc *= iw;
212 return;
213}
void fdf(double x, double &fx, double &dfx) const
Calculate function and derivative at once.
Definition: CoreFunction.h:189

References core, fc, nnp::CoreFunction::fdf(), iw, and rci.

Referenced by setCutoffType().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ PI

double const CutoffFunction::PI = 4.0 * atan(1.0)
staticprivate

Definition at line 129 of file CutoffFunction.h.

Referenced by dfCOS(), fCOS(), and fdfCOS().

◆ PI_2

double const CutoffFunction::PI_2 = 2.0 * atan(1.0)
staticprivate

Definition at line 130 of file CutoffFunction.h.

Referenced by dfCOS().

◆ E

double const CutoffFunction::E = exp(1.0)
staticprivate

Definition at line 131 of file CutoffFunction.h.

◆ TANH_PRE

double const CutoffFunction::TANH_PRE = pow((E + 1 / E) / (E - 1 / E), 3)
staticprivate

Definition at line 132 of file CutoffFunction.h.

Referenced by dfTANH(), fdfTANH(), and fTANH().

◆ cutoffType

CutoffType nnp::CutoffFunction::cutoffType
private

Cutoff function type.

Definition at line 135 of file CutoffFunction.h.

Referenced by getCutoffType(), and setCutoffType().

◆ rc

double nnp::CutoffFunction::rc
private

Outer cutoff radius \(r_c\).

Definition at line 137 of file CutoffFunction.h.

Referenced by df(), f(), fdf(), getCutoffRadius(), setCutoffParameter(), and setCutoffRadius().

◆ rcinv

double nnp::CutoffFunction::rcinv
private

Inverse cutoff radius \(\frac{1}{r_c}\).

Definition at line 139 of file CutoffFunction.h.

Referenced by dfTANH(), dfTANHU(), fdfTANH(), fdfTANHU(), fTANH(), fTANHU(), and setCutoffRadius().

◆ rci

double nnp::CutoffFunction::rci
private

Inner cutoff for cutoff function types which allow shifting.

Definition at line 141 of file CutoffFunction.h.

Referenced by dfCORE(), dfCOS(), fCORE(), fCOS(), fdfCORE(), fdfCOS(), and setCutoffParameter().

◆ alpha

double nnp::CutoffFunction::alpha
private

Cutoff function parameter for CT_POLYn and CT_EXP \(\alpha\).

Definition at line 143 of file CutoffFunction.h.

Referenced by getCutoffParameter(), and setCutoffParameter().

◆ iw

double nnp::CutoffFunction::iw
private

Inverse width of cutoff function \(\frac{1}{r_c - r_{ci}}\).

Definition at line 145 of file CutoffFunction.h.

Referenced by dfCORE(), dfCOS(), fCORE(), fCOS(), fdfCORE(), fdfCOS(), and setCutoffParameter().

◆ core

CoreFunction nnp::CutoffFunction::core
private

Core functions used by POLYN, if any.

Definition at line 147 of file CutoffFunction.h.

Referenced by dfCORE(), fCORE(), fdfCORE(), and setCutoffType().

◆ fPtr

double(CutoffFunction::* nnp::CutoffFunction::fPtr) (double r) const
private

Function pointer to f.

Definition at line 149 of file CutoffFunction.h.

Referenced by f(), and setCutoffType().

◆ dfPtr

double(CutoffFunction::* nnp::CutoffFunction::dfPtr) (double r) const
private

Function pointer to df.

Definition at line 151 of file CutoffFunction.h.

Referenced by df(), and setCutoffType().

◆ fdfPtr

void(CutoffFunction::* nnp::CutoffFunction::fdfPtr) (double r, double &fc, double &dfc) const
private

Function pointer to fdf.

Definition at line 153 of file CutoffFunction.h.

Referenced by fdf(), and setCutoffType().


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