GPRidge v1.0.0
GPR-accelerated saddle point searches on potential energy surfaces
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
ForceNorm.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <Eigen/Core>
4
#include <algorithm>
5
#include <limits>
6
#include <optional>
7
#include <stdexcept>
8
#include <string>
9
#include <string_view>
10
11
#include "
../Enums.h
"
12
13
namespace
gpr
{
14
16
inline
std::optional<ConvergenceNormType>
parseForceNorm
(std::string_view name)
17
{
18
if
(name.empty() || name ==
"auto"
)
return
std::nullopt;
19
if
(name ==
"l2"
|| name ==
"l2_norm"
|| name ==
"l2Norm"
)
20
return
ConvergenceNormType::L2_NORM
;
21
if
(name ==
"linf"
|| name ==
"linf_norm"
|| name ==
"linfNorm"
)
22
return
ConvergenceNormType::LINF_NORM
;
23
if
(name ==
"max_force_on_atom"
|| name ==
"maxForceOnAtom"
)
24
return
ConvergenceNormType::MAX_FORCE_ON_ATOM
;
25
throw
std::invalid_argument(
"unknown convergence force norm: "
+
26
std::string(name));
27
}
28
29
inline
std::string_view
forceNormName
(std::optional<ConvergenceNormType> norm)
30
{
31
if
(!norm)
return
"auto"
;
32
switch
(*norm) {
33
case
ConvergenceNormType::L2_NORM
:
34
return
"l2"
;
35
case
ConvergenceNormType::LINF_NORM
:
36
return
"linf"
;
37
case
ConvergenceNormType::MAX_FORCE_ON_ATOM
:
38
return
"max_force_on_atom"
;
39
}
40
throw
std::invalid_argument(
"invalid convergence force norm"
);
41
}
42
44
template
<
class
Derived>
45
double
forceNorm
(
const
Eigen::MatrixBase<Derived>& force,
46
ConvergenceNormType
norm)
47
{
48
if
(force.size() == 0 || !force.allFinite())
49
return
std::numeric_limits<double>::infinity();
50
switch
(norm) {
51
case
ConvergenceNormType::LINF_NORM
:
52
return
force.cwiseAbs().maxCoeff();
53
case
ConvergenceNormType::MAX_FORCE_ON_ATOM
: {
54
if
(force.size() % 3 != 0)
55
return
std::numeric_limits<double>::infinity();
56
double
maximum = 0.0;
57
for
(Eigen::Index i = 0; i < force.size(); i += 3)
58
maximum =
59
std::max(maximum, force.template segment<3>(i).norm());
60
return
maximum;
61
}
62
case
ConvergenceNormType::L2_NORM
:
63
default
:
64
return
force.norm();
65
}
66
}
67
70
template
<
class
Derived>
71
double
forceDualNorm
(
const
Eigen::MatrixBase<Derived>& direction,
72
ConvergenceNormType
norm)
73
{
74
if
(direction.size() == 0 || !direction.allFinite())
75
return
std::numeric_limits<double>::infinity();
76
switch
(norm) {
77
case
ConvergenceNormType::LINF_NORM
:
78
return
direction.cwiseAbs().sum();
79
case
ConvergenceNormType::MAX_FORCE_ON_ATOM
: {
80
if
(direction.size() % 3 != 0)
81
return
std::numeric_limits<double>::infinity();
82
double
total = 0.0;
83
for
(Eigen::Index i = 0; i < direction.size(); i += 3)
84
total += direction.template segment<3>(i).norm();
85
return
total;
86
}
87
case
ConvergenceNormType::L2_NORM
:
88
default
:
89
return
direction.norm();
90
}
91
}
92
93
}
// namespace gpr
Enums.h
ConvergenceNormType
ConvergenceNormType
Definition
Enums.h:48
ConvergenceNormType::MAX_FORCE_ON_ATOM
@ MAX_FORCE_ON_ATOM
Definition
Enums.h:48
ConvergenceNormType::L2_NORM
@ L2_NORM
Definition
Enums.h:48
ConvergenceNormType::LINF_NORM
@ LINF_NORM
Definition
Enums.h:48
gpr
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition
Macros.h:16
gpr::parseForceNorm
std::optional< ConvergenceNormType > parseForceNorm(std::string_view name)
Definition
ForceNorm.h:16
gpr::forceNorm
double forceNorm(const Eigen::MatrixBase< Derived > &force, ConvergenceNormType norm)
Definition
ForceNorm.h:45
gpr::forceNormName
std::string_view forceNormName(std::optional< ConvergenceNormType > norm)
Definition
ForceNorm.h:29
gpr::forceDualNorm
double forceDualNorm(const Eigen::MatrixBase< Derived > &direction, ConvergenceNormType norm)
Definition
ForceNorm.h:71
gpr
auxiliary
ForceNorm.h
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf