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

A general function with compact support. More...

#include <CompactFunction.h>

Collaboration diagram for nnp::CompactFunction:

Public Member Functions

 CompactFunction ()
 Constructor, initializes to #CoreFunction::Type::POLY2. More...
 
void setCoreFunction (CoreFunction::Type const type)
 Set type. More...
 
void setCenterWidth (double center, double width)
 Set center and width. More...
 
void setLeftRight (double left, double right)
 Set left and right boundary. More...
 
CoreFunction::Type getCoreFunctionType () const
 Getter for #type. More...
 
void setAsymmetric (bool asymmetric)
 Set asymmetric property in core function. More...
 
bool getAsymmetric () const
 Check if asymmetry is enabled in core function. More...
 
double getCenter () const
 Getter for center. More...
 
double getWidth () const
 Getter for width. More...
 
double getLeft () const
 Getter for left. More...
 
double getRight () const
 Getter for right. More...
 
double f (double a) const
 Compact function \(f_c\). More...
 
double df (double a) const
 Derivative of compact function \(\frac{d f_c}{d a}\). More...
 
void fdf (double a, double &fa, double &dfa) const
 Calculate compact function and derivative at once. More...
 

Private Attributes

double center
 Center of compact function. More...
 
double width
 Width of compact function. More...
 
double left
 Left boundary of compact function. More...
 
double right
 Right boundary of compact function. More...
 
double scale
 Inverse width. More...
 
CoreFunction core
 Core function to be used on either side of compact function. More...
 

Detailed Description

A general function with compact support.

Definition at line 27 of file CompactFunction.h.

Constructor & Destructor Documentation

◆ CompactFunction()

CompactFunction::CompactFunction ( )

Constructor, initializes to #CoreFunction::Type::POLY2.

Definition at line 24 of file CompactFunction.cpp.

24 : center (0.0 ),
25 width (0.0 ),
26 left (0.0 ),
27 right (0.0 ),
28 scale (0.0 )
29{
31}
double width
Width of compact function.
double center
Center of compact function.
double scale
Inverse width.
CoreFunction core
Core function to be used on either side of compact function.
double right
Right boundary of compact function.
double left
Left boundary of compact function.
void setType(Type const type)
Set function type.

References core, nnp::CoreFunction::POLY2, and nnp::CoreFunction::setType().

Here is the call graph for this function:

Member Function Documentation

◆ setCoreFunction()

void nnp::CompactFunction::setCoreFunction ( CoreFunction::Type const  type)
inline

Set type.

Parameters
[in]typeType of core function to use.

Definition at line 131 of file CompactFunction.h.

132{
133 core.setType(type);
134
135 return;
136}

References core, and nnp::CoreFunction::setType().

Referenced by nnp::SymFncBaseComp::setCompactFunction(), nnp::SymFncBaseCompAng::setParameters(), and nnp::SymFncBaseCompAngWeighted::setParameters().

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

◆ setCenterWidth()

void CompactFunction::setCenterWidth ( double  center,
double  width 
)

Set center and width.

Parameters
[in]centerCenter of compact function.
[in]widthWidth of compact function.
Note
Either use setCenterWidth() or setLeftRight() to initialize.

Definition at line 47 of file CompactFunction.cpp.

48{
49 if (width <= 0.0)
50 {
51 throw invalid_argument("ERROR: Width <= 0.\n");
52 }
53
54 this->center = center;
55 this->width = width;
56 this->left = center - width;
57 this->right = center + width;
58 this->scale = 1.0 / width;
59
60 return;
61}

References center, left, right, scale, and width.

◆ setLeftRight()

void CompactFunction::setLeftRight ( double  left,
double  right 
)

Set left and right boundary.

Parameters
[in]leftLeft boundary of compact function.
[in]rightRight boundary of compact function.
Note
Either use setCenterWidth() or setLeftRight() to initialize.

Definition at line 63 of file CompactFunction.cpp.

64{
65 if (left >= right)
66 {
67 throw invalid_argument("ERROR: Left >= Right.\n");
68 }
69
70 this->left = left;
71 this->right = right;
72 this->center = (right + left) / 2.0;
73 this->width = (right - left) / 2.0;
74 this->scale = 1.0 / width;
75
76 return;
77}

References center, left, right, scale, and width.

Referenced by nnp::SymFncBaseCompAng::changeLengthUnit(), nnp::SymFncBaseCompAngWeighted::changeLengthUnit(), nnp::SymFncCompRad::changeLengthUnit(), nnp::SymFncCompRadWeighted::changeLengthUnit(), nnp::SymFncBaseCompAng::setParameters(), nnp::SymFncBaseCompAngWeighted::setParameters(), nnp::SymFncCompRad::setParameters(), and nnp::SymFncCompRadWeighted::setParameters().

Here is the caller graph for this function:

◆ getCoreFunctionType()

CoreFunction::Type nnp::CompactFunction::getCoreFunctionType ( ) const
inline

Getter for #type.

Returns
Type used.

Definition at line 138 of file CompactFunction.h.

139{
140 return core.getType();
141}
Type getType() const
Getter for type.
Definition: CoreFunction.h:158

References core, and nnp::CoreFunction::getType().

Referenced by nnp::SymFncBaseCompAng::setParameters(), and nnp::SymFncBaseCompAngWeighted::setParameters().

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

◆ setAsymmetric()

void CompactFunction::setAsymmetric ( bool  asymmetric)

Set asymmetric property in core function.

Parameters
[in]asymmetricWhether asymmetry should be activated.

Definition at line 39 of file CompactFunction.cpp.

40{
41 core.setAsymmetric(asymmetric);
42
43 return;
44}
void setAsymmetric(bool asymmetric)
Set asymmetric property.
Definition: CoreFunction.h:161

References core, and nnp::CoreFunction::setAsymmetric().

Referenced by nnp::SymFncBaseComp::setCompactFunction().

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

◆ getAsymmetric()

bool CompactFunction::getAsymmetric ( ) const

Check if asymmetry is enabled in core function.

Returns
Whether asymmetry is activated.

Definition at line 34 of file CompactFunction.cpp.

35{
36 return core.getAsymmetric();
37}
bool getAsymmetric() const
Getter for asymmetric.
Definition: CoreFunction.h:168

References core, and nnp::CoreFunction::getAsymmetric().

Here is the call graph for this function:

◆ getCenter()

double nnp::CompactFunction::getCenter ( ) const
inline

Getter for center.

Returns
Center of compact function.

Definition at line 143 of file CompactFunction.h.

143{ return center; }

References center.

◆ getWidth()

double nnp::CompactFunction::getWidth ( ) const
inline

Getter for width.

Returns
Width of compact function.

Definition at line 144 of file CompactFunction.h.

144{ return width; }

References width.

◆ getLeft()

double nnp::CompactFunction::getLeft ( ) const
inline

Getter for left.

Returns
Left boundary of compact function.

Definition at line 145 of file CompactFunction.h.

145{ return left; }

References left.

◆ getRight()

double nnp::CompactFunction::getRight ( ) const
inline

Getter for right.

Returns
Right boundary of compact function.

Definition at line 146 of file CompactFunction.h.

146{ return right; }

References right.

◆ f()

double nnp::CompactFunction::f ( double  a) const
inline

Compact function \(f_c\).

Parameters
[in]aFunction argument.
Returns
Function value.

Definition at line 148 of file CompactFunction.h.

149{
150 a = (a - center) * scale;
151 return core.f(std::abs(a));
152}
double f(double x) const
Calculate function value .
Definition: CoreFunction.h:171

References center, core, nnp::CoreFunction::f(), and scale.

Referenced by nnp::SymFncBaseCompAng::calculateAngularPart(), nnp::SymFncBaseCompAngWeighted::calculateAngularPart(), nnp::SymFncBaseCompAng::calculateRadialPart(), nnp::SymFncBaseCompAngWeighted::calculateRadialPart(), nnp::SymFncCompRad::calculateRadialPart(), and nnp::SymFncCompRadWeighted::calculateRadialPart().

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

◆ df()

double nnp::CompactFunction::df ( double  a) const
inline

Derivative of compact function \(\frac{d f_c}{d a}\).

Parameters
[in]aFunction argument.
Returns
Value of function derivative.

Definition at line 154 of file CompactFunction.h.

155{
156 a = (a - center) * scale;
157 return copysign(scale * core.df(std::abs(a)), a);
158}
double df(double x) const
Calculate derivative of function at argument .
Definition: CoreFunction.h:179

References center, core, nnp::CoreFunction::df(), and scale.

Here is the call graph for this function:

◆ fdf()

void nnp::CompactFunction::fdf ( double  a,
double &  fa,
double &  dfa 
) const
inline

Calculate compact function and derivative at once.

Parameters
[in]aFunction argument.
[out]faCutoff function value.
[out]dfaValue of cutoff function derivative.

Definition at line 160 of file CompactFunction.h.

161{
162 a = (a - center) * scale;
163 core.fdf(std::abs(a), fa, dfa);
164 dfa *= copysign(scale, a);
165
166 return;
167}
void fdf(double x, double &fx, double &dfx) const
Calculate function and derivative at once.
Definition: CoreFunction.h:189

References center, core, nnp::CoreFunction::fdf(), and scale.

Referenced by nnp::SymFncCompAngn::calculate(), nnp::SymFncCompAngnWeighted::calculate(), nnp::SymFncCompAngw::calculate(), nnp::SymFncCompAngwWeighted::calculate(), nnp::SymFncCompRad::calculate(), nnp::SymFncCompRadWeighted::calculate(), nnp::SymFncBaseCompAng::getCompactAngle(), nnp::SymFncBaseCompAngWeighted::getCompactAngle(), nnp::SymFncCompRad::getCompactOnly(), nnp::SymFncCompRadWeighted::getCompactOnly(), nnp::SymFncBaseCompAng::getCompactRadial(), and nnp::SymFncBaseCompAngWeighted::getCompactRadial().

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

Member Data Documentation

◆ center

double nnp::CompactFunction::center
private

Center of compact function.

Definition at line 113 of file CompactFunction.h.

Referenced by df(), f(), fdf(), getCenter(), setCenterWidth(), and setLeftRight().

◆ width

double nnp::CompactFunction::width
private

Width of compact function.

Definition at line 115 of file CompactFunction.h.

Referenced by getWidth(), setCenterWidth(), and setLeftRight().

◆ left

double nnp::CompactFunction::left
private

Left boundary of compact function.

Definition at line 117 of file CompactFunction.h.

Referenced by getLeft(), setCenterWidth(), and setLeftRight().

◆ right

double nnp::CompactFunction::right
private

Right boundary of compact function.

Definition at line 119 of file CompactFunction.h.

Referenced by getRight(), setCenterWidth(), and setLeftRight().

◆ scale

double nnp::CompactFunction::scale
private

Inverse width.

Definition at line 121 of file CompactFunction.h.

Referenced by df(), f(), fdf(), setCenterWidth(), and setLeftRight().

◆ core

CoreFunction nnp::CompactFunction::core
private

Core function to be used on either side of compact function.

Definition at line 123 of file CompactFunction.h.

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


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