n2p2 - A neural network potential package
CompactFunction.h
Go to the documentation of this file.
1// n2p2 - A neural network potential package
2// Copyright (C) 2018 Andreas Singraber (University of Vienna)
3// Copyright (C) 2020 Martin P. Bircher
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18#ifndef COMPACTFUNCTION_H
19#define COMPACTFUNCTION_H
20
21#include "CoreFunction.h"
22
23namespace nnp
24{
25
28{
29public:
37 void setCoreFunction(CoreFunction::Type const type);
45 void setCenterWidth(double center, double width);
53 void setLeftRight(double left, double right);
59#ifndef N2P2_NO_ASYM_POLY
64 void setAsymmetric(bool asymmetric);
69 bool getAsymmetric() const;
70#endif
75 double getCenter() const;
80 double getWidth() const;
85 double getLeft() const;
90 double getRight() const;
96 double f(double a) const;
102 double df(double a) const;
109 void fdf(double a, double& fa, double& dfa) const;
110
111private:
113 double center;
115 double width;
117 double left;
119 double right;
121 double scale;
124
125};
126
128// Inlined function definitions //
130
132{
133 core.setType(type);
134
135 return;
136}
137
139{
140 return core.getType();
141}
142
143inline double CompactFunction::getCenter() const { return center; }
144inline double CompactFunction::getWidth() const { return width; }
145inline double CompactFunction::getLeft() const { return left; }
146inline double CompactFunction::getRight() const { return right; }
147
148inline double CompactFunction::f(double a) const
149{
150 a = (a - center) * scale;
151 return core.f(std::abs(a));
152}
153
154inline double CompactFunction::df(double a) const
155{
156 a = (a - center) * scale;
157 return copysign(scale * core.df(std::abs(a)), a);
158}
159
160inline void CompactFunction::fdf(double a, double& fa, double& dfa) const
161{
162 a = (a - center) * scale;
163 core.fdf(std::abs(a), fa, dfa);
164 dfa *= copysign(scale, a);
165
166 return;
167}
168
169
170}
171
172#endif
A general function with compact support.
double width
Width of compact function.
void setCenterWidth(double center, double width)
Set center and width.
double getWidth() const
Getter for width.
void fdf(double a, double &fa, double &dfa) const
Calculate compact function and derivative at once.
void setCoreFunction(CoreFunction::Type const type)
Set type.
double f(double a) const
Compact function .
double center
Center of compact function.
CompactFunction()
Constructor, initializes to #CoreFunction::Type::POLY2.
CoreFunction::Type getCoreFunctionType() const
Getter for #type.
bool getAsymmetric() const
Check if asymmetry is enabled in core function.
void setLeftRight(double left, double right)
Set left and right boundary.
double getLeft() const
Getter for left.
double scale
Inverse width.
double getRight() const
Getter for right.
CoreFunction core
Core function to be used on either side of compact function.
double right
Right boundary of compact function.
double getCenter() const
Getter for center.
double df(double a) const
Derivative of compact function .
double left
Left boundary of compact function.
void setAsymmetric(bool asymmetric)
Set asymmetric property in core function.
void fdf(double x, double &fx, double &dfx) const
Calculate function and derivative at once.
Definition: CoreFunction.h:174
double df(double x) const
Calculate derivative of function at argument .
Definition: CoreFunction.h:164
void setType(Type const type)
Set function type.
Type getType() const
Getter for type.
Definition: CoreFunction.h:137
double f(double x) const
Calculate function value .
Definition: CoreFunction.h:156
Type
List of available function types.
Definition: CoreFunction.h:31
Definition: Atom.h:28