n2p2 - A neural network potential package
CutoffFunction.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//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17#ifndef CUTOFFFUNCTION_H
18#define CUTOFFFUNCTION_H
19
20#include "CoreFunction.h"
21
22namespace nnp
23{
24
26{
27public:
43 {
72 };
73
91 void setCutoffRadius(double const cutoffRadius);
96 double getCutoffRadius() const;
101 void setCutoffParameter(double const alpha);
106 double getCutoffParameter() const;
112 double f(double r) const;
118 double df(double r) const;
126 void fdf(double r, double& fc, double& dfc) const;
127
128private:
129 static double const PI;
130 static double const PI_2;
131 static double const E;
132 static double const TANH_PRE;
133
137 double rc;
139 double rcinv;
141 double rci;
143 double alpha;
145 double iw;
149 double (CutoffFunction::*fPtr)(double r) const;
151 double (CutoffFunction::*dfPtr)(double r) const;
153 void (CutoffFunction::*fdfPtr)(double r,
154 double& fc,
155 double& dfc) const;
156
157 // Individual cutoff functions.
158 double fHARD (double r) const;
159 double dfHARD (double r) const;
160 void fdfHARD (double r, double& fc, double& dfc) const;
161
162 double fCOS (double r) const;
163 double dfCOS (double r) const;
164 void fdfCOS (double r, double& fc, double& dfc) const;
165
166 double fTANHU(double r) const;
167 double dfTANHU(double r) const;
168 void fdfTANHU(double r, double& fc, double& dfc) const;
169
170 double fTANH (double r) const;
171 double dfTANH (double r) const;
172 void fdfTANH (double r, double& fc, double& dfc) const;
173
174 double fCORE (double r) const;
175 double dfCORE (double r) const;
176 void fdfCORE (double r, double& fc, double& dfc) const;
177};
178
180// Inlined function definitions //
182
184{
185 return cutoffType;
186}
187
189{
190 return rc;
191}
192
194{
195 return alpha;
196}
197
198inline double CutoffFunction::f(double r) const
199{
200 if (r >= rc) return 0.0;
201 return (this->*fPtr)(r);
202}
203
204inline double CutoffFunction::df(double r) const
205{
206 if (r >= rc) return 0.0;
207 return (this->*dfPtr)(r);
208}
209
210inline void CutoffFunction::fdf(double r, double& fc, double& dfc) const
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}
221
222inline double CutoffFunction::fHARD(double /*r*/) const
223{
224 return 1.0;
225}
226
227inline double CutoffFunction::dfHARD(double /*r*/) const
228{
229 return 0.0;
230}
231
232inline void CutoffFunction::fdfHARD(double /*r*/,
233 double& fc,
234 double& dfc) const
235{
236 fc = 1.0;
237 dfc = 0.0;
238 return;
239}
240
241}
242
243#endif
double fHARD(double r) const
CutoffType
List of available cutoff function types.
double rci
Inner cutoff for cutoff function types which allow shifting.
static double const TANH_PRE
double fCORE(double r) const
void fdfCOS(double r, double &fc, double &dfc) const
void fdfHARD(double r, double &fc, double &dfc) const
double f(double r) const
Cutoff function .
void fdfTANH(double r, double &fc, double &dfc) const
double rcinv
Inverse cutoff radius .
double fTANHU(double r) const
void fdfTANHU(double r, double &fc, double &dfc) const
double iw
Inverse width of cutoff function .
void fdf(double r, double &fc, double &dfc) const
Calculate cutoff function and derivative .
static double const PI
void fdfCORE(double r, double &fc, double &dfc) const
CutoffType getCutoffType() const
Getter for cutoffType.
static double const PI_2
double fTANH(double r) const
void setCutoffParameter(double const alpha)
Set parameter for polynomial cutoff function (CT_POLY).
double(CutoffFunction::* fPtr)(double r) const
Function pointer to f.
double dfCOS(double r) const
double fCOS(double r) const
CutoffFunction()
Constructor, initializes to ´CT_HARD´.
double dfTANH(double r) const
double dfCORE(double r) const
double(CutoffFunction::* dfPtr)(double r) const
Function pointer to df.
double getCutoffParameter() const
Getter for alpha.
double dfTANHU(double r) const
void setCutoffType(CutoffType const cutoffType)
Set cutoff type.
double rc
Outer cutoff radius .
double getCutoffRadius() const
Getter for rc.
static double const E
CutoffType cutoffType
Cutoff function type.
double alpha
Cutoff function parameter for CT_POLYn and CT_EXP .
double dfHARD(double r) const
CoreFunction core
Core functions used by POLYN, if any.
double df(double r) const
Derivative of cutoff function .
void setCutoffRadius(double const cutoffRadius)
Set cutoff radius.
void(CutoffFunction::* fdfPtr)(double r, double &fc, double &dfc) const
Function pointer to fdf.
Definition: Atom.h:28
CutoffFunction fc
Definition: nnp-cutoff.cpp:27