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

#include <CoreFunction.h>

Collaboration diagram for nnp::CoreFunction:

Public Types

enum class  Type {
  POLY1 , POLY2 , POLY3 , POLY4 ,
  EXP
}
 List of available function types. More...
 

Public Member Functions

 CoreFunction ()
 Constructor, initializes to #Type::POLY2. More...
 
void setType (Type const type)
 Set function type. More...
 
Type getType () const
 Getter for type. More...
 
void setAsymmetric (bool asymmetric)
 Set asymmetric property. More...
 
bool getAsymmetric () const
 Getter for asymmetric. More...
 
double f (double x) const
 Calculate function value \(f(x)\). More...
 
double df (double x) const
 Calculate derivative of function at argument \(\frac{df(x)}{dx}\). More...
 
void fdf (double x, double &fx, double &dfx) const
 Calculate function and derivative at once. More...
 

Private Member Functions

double fPOLY1 (double x) const
 
double dfPOLY1 (double x) const
 
void fdfPOLY1 (double x, double &fx, double &dfx) const
 
double fPOLY2 (double x) const
 
double dfPOLY2 (double x) const
 
void fdfPOLY2 (double x, double &fx, double &dfx) const
 
double fPOLY3 (double x) const
 
double dfPOLY3 (double x) const
 
void fdfPOLY3 (double x, double &fx, double &dfx) const
 
double fPOLY4 (double x) const
 
double dfPOLY4 (double x) const
 
void fdfPOLY4 (double x, double &fx, double &dfx) const
 
double fEXP (double x) const
 
double dfEXP (double x) const
 
void fdfEXP (double x, double &fx, double &dfx) const
 

Private Attributes

Type type
 Core function type. More...
 
bool asymmetric
 Enables asymmetry modification (use with polynomials). More...
 
double(CoreFunction::* fPtr )(double x) const
 Function pointer to f. More...
 
double(CoreFunction::* dfPtr )(double x) const
 Function pointer to df. More...
 
void(CoreFunction::* fdfPtr )(double x, double &fx, double &dfx) const
 Function pointer to fdf. More...
 

Static Private Attributes

static double const E = exp(1.0)
 

Detailed Description

Definition at line 26 of file CoreFunction.h.

Member Enumeration Documentation

◆ Type

enum class nnp::CoreFunction::Type
strong

List of available function types.

Enumerator
POLY1 

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

POLY2 

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

POLY3 

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

POLY4 

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

EXP 

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

Definition at line 30 of file CoreFunction.h.

31 {
34 POLY1,
37 POLY2,
40 POLY3,
43 POLY4,
46 EXP
47 };

Constructor & Destructor Documentation

◆ CoreFunction()

CoreFunction::CoreFunction ( )

Constructor, initializes to #Type::POLY2.

Definition at line 26 of file CoreFunction.cpp.

26 : type (Type::POLY2 ),
27#ifndef N2P2_NO_ASYM_POLY
28 asymmetric(false ),
29#endif
30 fPtr (&CoreFunction:: fPOLY2),
33{
34}
double dfPOLY2(double x) const
Definition: CoreFunction.h:211
Type type
Core function type.
Definition: CoreFunction.h:97
void(CoreFunction::* fdfPtr)(double x, double &fx, double &dfx) const
Function pointer to fdf.
Definition: CoreFunction.h:107
double(CoreFunction::* dfPtr)(double x) const
Function pointer to df.
Definition: CoreFunction.h:105
bool asymmetric
Enables asymmetry modification (use with polynomials).
Definition: CoreFunction.h:100
void fdfPOLY2(double x, double &fx, double &dfx) const
Definition: CoreFunction.h:216
double(CoreFunction::* fPtr)(double x) const
Function pointer to f.
Definition: CoreFunction.h:103

Member Function Documentation

◆ setType()

void CoreFunction::setType ( Type const  type)

Set function type.

Parameters
[in]typeType of core function used.

Definition at line 36 of file CoreFunction.cpp.

37{
38 this->type = type;
39
40 if (type == Type::POLY1)
41 {
45 }
46 else if (type == Type::POLY2)
47 {
51 }
52 else if (type == Type::POLY3)
53 {
57 }
58 else if (type == Type::POLY4)
59 {
63 }
64 else if (type == Type::EXP)
65 {
69 }
70 else
71 {
72 throw invalid_argument("ERROR: Unknown core function.\n");
73 }
74
75 return;
76}
double fPOLY4(double x) const
Definition: CoreFunction.h:243
void fdfEXP(double x, double &fx, double &dfx) const
Definition: CoreFunction.h:279
double fPOLY1(double x) const
Definition: CoreFunction.h:189
void fdfPOLY3(double x, double &fx, double &dfx) const
Definition: CoreFunction.h:235
double dfPOLY4(double x) const
Definition: CoreFunction.h:250
double dfEXP(double x) const
Definition: CoreFunction.h:273
double dfPOLY3(double x) const
Definition: CoreFunction.h:230
double fEXP(double x) const
Definition: CoreFunction.h:268
void fdfPOLY4(double x, double &fx, double &dfx) const
Definition: CoreFunction.h:257
void fdfPOLY1(double x, double &fx, double &dfx) const
Definition: CoreFunction.h:199
double fPOLY2(double x) const
Definition: CoreFunction.h:206
double dfPOLY1(double x) const
Definition: CoreFunction.h:194
double fPOLY3(double x) const
Definition: CoreFunction.h:224

References dfEXP(), dfPOLY1(), dfPOLY2(), dfPOLY3(), dfPOLY4(), dfPtr, EXP, fdfEXP(), fdfPOLY1(), fdfPOLY2(), fdfPOLY3(), fdfPOLY4(), fdfPtr, fEXP(), fPOLY1(), fPOLY2(), fPOLY3(), fPOLY4(), fPtr, POLY1, POLY2, POLY3, POLY4, and type.

Referenced by nnp::CompactFunction::CompactFunction(), nnp::CompactFunction::setCoreFunction(), and nnp::CutoffFunction::setCutoffType().

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

◆ getType()

CoreFunction::Type nnp::CoreFunction::getType ( ) const
inline

Getter for type.

Returns
Type used.

Definition at line 137 of file CoreFunction.h.

138{
139 return type;
140}

References type.

Referenced by nnp::CompactFunction::getCoreFunctionType().

Here is the caller graph for this function:

◆ setAsymmetric()

void nnp::CoreFunction::setAsymmetric ( bool  asymmetric)
inline

Set asymmetric property.

Parameters
[in]asymmetricWhether asymmetry should be activated.

Definition at line 143 of file CoreFunction.h.

144{
145 this->asymmetric = asymmetric;
146
147 return;
148}

References asymmetric.

Referenced by nnp::CompactFunction::setAsymmetric().

Here is the caller graph for this function:

◆ getAsymmetric()

bool nnp::CoreFunction::getAsymmetric ( ) const
inline

Getter for asymmetric.

Returns
Whether asymmetry is activated.

Definition at line 150 of file CoreFunction.h.

151{
152 return asymmetric;
153}

References asymmetric.

Referenced by nnp::CompactFunction::getAsymmetric().

Here is the caller graph for this function:

◆ f()

double nnp::CoreFunction::f ( double  x) const
inline

Calculate function value \(f(x)\).

Parameters
[in]xFunction argument.
Returns
Function value.

Definition at line 156 of file CoreFunction.h.

157{
158#ifndef N2P2_NO_ASYM_POLY
159 if (asymmetric) x = (2.0 - x) * x;
160#endif
161 return (this->*fPtr)(x);
162}

References asymmetric, and fPtr.

Referenced by nnp::CompactFunction::f(), and nnp::CutoffFunction::fCORE().

Here is the caller graph for this function:

◆ df()

double nnp::CoreFunction::df ( double  x) const
inline

Calculate derivative of function at argument \(\frac{df(x)}{dx}\).

Parameters
[in]xFunction argument.
Returns
Function derivative value.

Definition at line 164 of file CoreFunction.h.

165{
166#ifndef N2P2_NO_ASYM_POLY
167 if (asymmetric) return (2.0 - 2.0 * x) * (this->*dfPtr)((2.0 - x) * x);
168 else return (this->*dfPtr)(x);
169#else
170 return (this->*dfPtr)(x);
171#endif
172}

References asymmetric, and dfPtr.

Referenced by nnp::CompactFunction::df(), and nnp::CutoffFunction::dfCORE().

Here is the caller graph for this function:

◆ fdf()

void nnp::CoreFunction::fdf ( double  x,
double &  fx,
double &  dfx 
) const
inline

Calculate function and derivative at once.

Parameters
[in]xFunction argument.
[out]fxFunction value.
[out]dfxDerivative value.

Definition at line 174 of file CoreFunction.h.

175{
176#ifndef N2P2_NO_ASYM_POLY
177 if (asymmetric)
178 {
179 (this->*fdfPtr)((2.0 - x) * x, fx, dfx);
180 dfx *= 2.0 - 2.0 * x;
181 }
182 else (this->*fdfPtr)(x, fx, dfx);
183#else
184 (this->*fdfPtr)(x, fx, dfx);
185#endif
186 return;
187}

References asymmetric, and fdfPtr.

Referenced by nnp::CompactFunction::fdf(), and nnp::CutoffFunction::fdfCORE().

Here is the caller graph for this function:

◆ fPOLY1()

double nnp::CoreFunction::fPOLY1 ( double  x) const
inlineprivate

Definition at line 189 of file CoreFunction.h.

190{
191 return (2.0 * x - 3.0) * x * x + 1.0;
192}

Referenced by setType().

Here is the caller graph for this function:

◆ dfPOLY1()

double nnp::CoreFunction::dfPOLY1 ( double  x) const
inlineprivate

Definition at line 194 of file CoreFunction.h.

195{
196 return x * (6.0 * x - 6.0);
197}

Referenced by setType().

Here is the caller graph for this function:

◆ fdfPOLY1()

void nnp::CoreFunction::fdfPOLY1 ( double  x,
double &  fx,
double &  dfx 
) const
inlineprivate

Definition at line 199 of file CoreFunction.h.

200{
201 fx = (2.0 * x - 3.0) * x * x + 1.0;
202 dfx = x * (6.0 * x - 6.0);
203 return;
204}

Referenced by setType().

Here is the caller graph for this function:

◆ fPOLY2()

double nnp::CoreFunction::fPOLY2 ( double  x) const
inlineprivate

Definition at line 206 of file CoreFunction.h.

207{
208 return ((15.0 - 6.0 * x) * x - 10.0) * x * x * x + 1.0;
209}

Referenced by setType().

Here is the caller graph for this function:

◆ dfPOLY2()

double nnp::CoreFunction::dfPOLY2 ( double  x) const
inlineprivate

Definition at line 211 of file CoreFunction.h.

212{
213 return x * x * ((60.0 - 30.0 * x) * x - 30.0);
214}

Referenced by setType().

Here is the caller graph for this function:

◆ fdfPOLY2()

void nnp::CoreFunction::fdfPOLY2 ( double  x,
double &  fx,
double &  dfx 
) const
inlineprivate

Definition at line 216 of file CoreFunction.h.

217{
218 double const x2 = x * x;
219 fx = ((15.0 - 6.0 * x) * x - 10.0) * x * x2 + 1.0;
220 dfx = x2 * ((60.0 - 30.0 * x) * x - 30.0);
221 return;
222}

Referenced by setType().

Here is the caller graph for this function:

◆ fPOLY3()

double nnp::CoreFunction::fPOLY3 ( double  x) const
inlineprivate

Definition at line 224 of file CoreFunction.h.

225{
226 double const x2 = x * x;
227 return (x * (x * (20.0 * x - 70.0) + 84.0) - 35.0) * x2 * x2 + 1.0;
228}

Referenced by setType().

Here is the caller graph for this function:

◆ dfPOLY3()

double nnp::CoreFunction::dfPOLY3 ( double  x) const
inlineprivate

Definition at line 230 of file CoreFunction.h.

231{
232 return x * x * x * (x * (x * (140.0 * x - 420.0) + 420.0) - 140.0);
233}

Referenced by setType().

Here is the caller graph for this function:

◆ fdfPOLY3()

void nnp::CoreFunction::fdfPOLY3 ( double  x,
double &  fx,
double &  dfx 
) const
inlineprivate

Definition at line 235 of file CoreFunction.h.

236{
237 double const x2 = x * x;
238 fx = (x * (x * (20.0 * x - 70.0) + 84.0) - 35.0) * x2 * x2 + 1.0;
239 dfx = x2 * x * (x * (x * (140.0 * x - 420.0) + 420.0) - 140.0);
240 return;
241}

Referenced by setType().

Here is the caller graph for this function:

◆ fPOLY4()

double nnp::CoreFunction::fPOLY4 ( double  x) const
inlineprivate

Definition at line 243 of file CoreFunction.h.

244{
245 double const x2 = x * x;
246 return (x * (x * ((315.0 - 70.0 * x) * x - 540.0) + 420.0) - 126.0) *
247 x2 * x2 * x + 1.0;
248}

Referenced by setType().

Here is the caller graph for this function:

◆ dfPOLY4()

double nnp::CoreFunction::dfPOLY4 ( double  x) const
inlineprivate

Definition at line 250 of file CoreFunction.h.

251{
252 double const x2 = x * x;
253 return x2 * x2 *
254 (x * (x * ((2520.0 - 630.0 * x) * x - 3780.0) + 2520.0) - 630.0);
255}

Referenced by setType().

Here is the caller graph for this function:

◆ fdfPOLY4()

void nnp::CoreFunction::fdfPOLY4 ( double  x,
double &  fx,
double &  dfx 
) const
inlineprivate

Definition at line 257 of file CoreFunction.h.

258{
259 double x4 = x * x;
260 x4 *= x4;
261 fx = (x * (x * ((315.0 - 70.0 * x) * x - 540.0) + 420.0) - 126.0) *
262 x * x4 + 1.0;
263 dfx = x4 *
264 (x * (x * ((2520.0 - 630.0 * x) * x - 3780.0) + 2520.0) - 630.0);
265 return;
266}

Referenced by setType().

Here is the caller graph for this function:

◆ fEXP()

double nnp::CoreFunction::fEXP ( double  x) const
inlineprivate

Definition at line 268 of file CoreFunction.h.

269{
270 return E * exp(1.0 / (x * x - 1.0));
271}
static double const E
Definition: CoreFunction.h:95

References E.

Referenced by setType().

Here is the caller graph for this function:

◆ dfEXP()

double nnp::CoreFunction::dfEXP ( double  x) const
inlineprivate

Definition at line 273 of file CoreFunction.h.

274{
275 double const temp = 1.0 / (x * x - 1.0);
276 return -2.0 * E * x * temp * temp * exp(temp);
277}

References E.

Referenced by setType().

Here is the caller graph for this function:

◆ fdfEXP()

void nnp::CoreFunction::fdfEXP ( double  x,
double &  fx,
double &  dfx 
) const
inlineprivate

Definition at line 279 of file CoreFunction.h.

280{
281 double const temp = 1.0 / (x * x - 1.0);
282 double const temp2 = exp(temp);
283 fc = E * temp2;
284 dfc = -2.0 * E * x * temp * temp * temp2;
285 return;
286}
CutoffFunction fc
Definition: nnp-cutoff.cpp:27

References E, and fc.

Referenced by setType().

Here is the caller graph for this function:

Member Data Documentation

◆ E

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

Definition at line 95 of file CoreFunction.h.

Referenced by dfEXP(), fdfEXP(), and fEXP().

◆ type

Type nnp::CoreFunction::type
private

Core function type.

Definition at line 97 of file CoreFunction.h.

Referenced by getType(), and setType().

◆ asymmetric

bool nnp::CoreFunction::asymmetric
private

Enables asymmetry modification (use with polynomials).

Definition at line 100 of file CoreFunction.h.

Referenced by df(), f(), fdf(), getAsymmetric(), and setAsymmetric().

◆ fPtr

double(CoreFunction::* nnp::CoreFunction::fPtr) (double x) const
private

Function pointer to f.

Definition at line 103 of file CoreFunction.h.

Referenced by f(), and setType().

◆ dfPtr

double(CoreFunction::* nnp::CoreFunction::dfPtr) (double x) const
private

Function pointer to df.

Definition at line 105 of file CoreFunction.h.

Referenced by df(), and setType().

◆ fdfPtr

void(CoreFunction::* nnp::CoreFunction::fdfPtr) (double x, double &fx, double &dfx) const
private

Function pointer to fdf.

Definition at line 107 of file CoreFunction.h.

Referenced by fdf(), and setType().


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