n2p2 - A neural network potential package
ScreeningFunction.h
Go to the documentation of this file.
1// n2p2 - A neural network potential package
2// Copyright (C) 2021 Andreas Singraber
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 SCREENINGFUNCTION_H
18#define SCREENINGFUNCTION_H
19
20#include "CoreFunction.h"
21
22namespace nnp
23{
24
27{
28public:
36 void setCoreFunction(CoreFunction::Type const type);
41 void setCoreFunction(std::string const type);
48 void setInnerOuter(double inner, double outer);
58 double getInner() const;
63 double getOuter() const;
68 void changeLengthUnits(double const conv);
75 double f(double r) const;
82 double df(double r) const;
89 void fdf(double r, double& fr, double& dfr) const;
94 std::vector<std::string> info() const;
95
96
97private:
99 double inner;
101 double outer;
103 double scale;
106
107};
108
110// Inlined function definitions //
112
114{
115 core.setType(type);
116
117 return;
118}
119
120inline void ScreeningFunction::setCoreFunction(std::string const typeString)
121{
122 core.setType(typeString);
123
124 return;
125}
126
128{
129 return core.getType();
130}
131
132inline double ScreeningFunction::getInner() const { return inner; }
133inline double ScreeningFunction::getOuter() const { return outer; }
134
135inline double ScreeningFunction::f(double r) const
136{
137 if (r >= outer) return 1.0;
138 else if (r <= inner) return 0.0;
139 else return 1.0 - core.f((r - inner) * scale);
140}
141
142inline double ScreeningFunction::df(double r) const
143{
144 if (r >= outer || r <= inner) return 0.0;
145 else return -scale * core.df((r - inner) * scale);
146}
147
148inline void ScreeningFunction::fdf(double r, double& fr, double& dfr) const
149{
150 if (r >= outer)
151 {
152 fr = 1.0;
153 dfr = 0.0;
154 }
155 else if (r <= inner)
156 {
157 fr = 0.0;
158 dfr = 0.0;
159 }
160 else
161 {
162 core.fdf((r - inner) * scale, fr, dfr);
163 fr = 1.0 - fr;
164 dfr = -scale * dfr;
165 }
166
167 return;
168}
169
170}
171
172#endif
void fdf(double x, double &fx, double &dfx) const
Calculate function and derivative at once.
Definition: CoreFunction.h:189
double df(double x) const
Calculate derivative of function at argument .
Definition: CoreFunction.h:179
void setType(Type const type)
Set function type.
Type getType() const
Getter for type.
Definition: CoreFunction.h:158
double f(double x) const
Calculate function value .
Definition: CoreFunction.h:171
Type
List of available function types.
Definition: CoreFunction.h:33
A screening functions for use with electrostatics.
void setCoreFunction(CoreFunction::Type const type)
Set functional form of transition region.
ScreeningFunction()
Constructor, initializes to #CoreFunction::Type::POLY2.
double scale
Inverse width.
double getOuter() const
Getter for outer.
void fdf(double r, double &fr, double &dfr) const
Calculate screening function and derivative at once.
double df(double r) const
Derivative of screening function .
double inner
Inner radius where transition region starts.
CoreFunction::Type getCoreFunctionType() const
Getter for #type.
double f(double r) const
Screening function .
CoreFunction core
Core function to be used in the transition region.
void changeLengthUnits(double const conv)
Change length units of screening function.
double getInner() const
Getter for inner.
std::vector< std::string > info() const
Get string with information of screening function.
double outer
Outer radius where transition region ends.
void setInnerOuter(double inner, double outer)
Set inner and outer limit of transition region.
Definition: Atom.h:29