eOn 3.2.0
Long-timescale dynamics: aKMC, NEB, parallel replica
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
FIRE.cpp
Go to the documentation of this file.
1
/*
2
** This file is part of eOn.
3
**
4
** SPDX-License-Identifier: BSD-3-Clause
5
**
6
** Copyright (c) 2010--present, eOn Development Team
7
** All rights reserved.
8
**
9
** Repo:
10
** https://github.com/TheochemUI/eOn
11
*/
12
#include "
eon/FIRE.h
"
13
#include "
eon/ExactReduction.h
"
14
#include "
eon/HelperFunctions.h
"
15
16
#include <algorithm>
17
#include <format>
18
#include <stdexcept>
19
20
namespace
eonc
{
21
22
int
FIRE::step
(
double
a_maxMove) {
23
double
P = 0;
24
// Check convergence.
25
if
(
m_objf
->isConverged()) {
26
return
1;
27
}
28
29
// Velocity Verlet
30
Eigen::VectorXd f = -
m_objf
->getGradient();
31
Eigen::VectorXd x =
m_objf
->getPositions();
32
33
m_vel
+= f *
m_dt
;
34
Eigen::VectorXd dx =
m_vel
*
m_dt
;
35
36
dx =
eonc::geometry::maxAtomMotionAppliedV
(dx, a_maxMove);
37
m_objf
->setPositions(x + dx);
38
39
// A climbing objective may already be past max_energy. Rotating the
40
// mode here spends a dimer or Lanczos solve the search will discard,
41
// and the rotation can throw before the pull-back runs. The centre
42
// was evaluated by the check, so a point under the limit still shares
43
// a batching solver's first image with the gradient below.
44
if
(
m_objf
->pastClimbCeiling()) {
45
m_iteration
++;
46
return
0;
47
}
48
49
f = -
m_objf
->getGradient();
50
const
double
fnorm =
eonc::exact::norm
(f);
51
Eigen::VectorXd f_unit = Eigen::VectorXd::Zero(f.size());
52
if
(fnorm > 0.0) {
53
f_unit = f / fnorm;
54
}
55
56
// FIRE
57
P =
eonc::exact::dot
(f,
m_vel
);
58
m_vel
= (1 -
m_alpha
) *
m_vel
+
m_alpha
* f_unit *
eonc::exact::norm
(
m_vel
);
59
QUILL_LOG_DEBUG(
m_log
,
60
"P: {:.4f}, v: {:.4f}, m_dt: {:.4f}, m_alpha: {:.4f}, N: {}"
,
61
P,
m_vel
.norm(),
m_dt
,
m_alpha
,
m_N
);
62
if
(P >= 0) {
63
m_N
++;
64
if
(
m_N
>
m_N_min
) {
65
m_dt
= std::min(
m_dt
*
m_f_inc
,
m_dt_max
);
66
m_alpha
=
m_alpha
*
m_f_a
;
67
}
68
}
else
{
69
m_dt
=
m_dt
*
m_f_dec
;
70
m_vel
.setZero();
71
m_alpha
=
m_alpha_start
;
72
m_N
= 0;
73
}
74
75
// add a sanity check on m_dt
76
if
(
m_dt
< 1e-6) {
77
QUILL_LOG_CRITICAL(
m_log
,
"[FIRE] [critical] m_dt is too small: {:.4f}"
,
78
m_dt
);
79
throw
std::runtime_error(
80
std::format(
"[FIRE] m_dt is too small: {:.4f}"
,
m_dt
));
81
}
82
83
m_iteration
++;
84
return
m_objf
->isConverged() ? 1 : 0;
85
}
86
87
void
FIRE::onTranslationPulledBack
() {
88
// The velocity was kicked toward the step that crossed the limit.
89
m_vel
.setZero();
90
}
91
92
int
FIRE::run
(
size_t
a_maxIterations,
double
a_maxMove) {
93
while
(!
m_objf
->isConverged() &&
m_iteration
< a_maxIterations) {
94
step
(a_maxMove);
95
}
96
return
m_objf
->isConverged() ? 1 : 0;
97
}
98
99
}
// namespace eonc
ExactReduction.h
FIRE.h
HelperFunctions.h
eonc::FIRE::onTranslationPulledBack
void onTranslationPulledBack() override
Definition
FIRE.cpp:87
eonc::FIRE::m_vel
Eigen::VectorXd m_vel
Definition
FIRE.h:39
eonc::FIRE::m_dt_max
double m_dt_max
Definition
FIRE.h:37
eonc::FIRE::m_f_inc
double m_f_inc
Definition
FIRE.h:42
eonc::FIRE::m_N_min
size_t m_N_min
Definition
FIRE.h:38
eonc::FIRE::m_alpha_start
double m_alpha_start
Definition
FIRE.h:40
eonc::FIRE::step
int step(double a_maxMove) override
Definition
FIRE.cpp:22
eonc::FIRE::m_f_a
double m_f_a
Definition
FIRE.h:44
eonc::FIRE::m_log
eonc::log::FileScoped m_log
Definition
FIRE.h:46
eonc::FIRE::m_iteration
size_t m_iteration
Definition
FIRE.h:45
eonc::FIRE::run
int run(size_t a_maxIterations, double a_maxMove) override
Definition
FIRE.cpp:92
eonc::FIRE::m_N
size_t m_N
Definition
FIRE.h:38
eonc::FIRE::m_alpha
double m_alpha
Definition
FIRE.h:41
eonc::FIRE::m_f_dec
double m_f_dec
Definition
FIRE.h:43
eonc::FIRE::m_dt
double m_dt
Definition
FIRE.h:37
eonc::Optimizer::m_objf
std::shared_ptr< ObjectiveFunction > m_objf
Definition
Optimizer.h:74
eonc::exact::norm
double norm(const Eigen::MatrixBase< A > &x)
sqrt of the correctly rounded squared norm; IEEE sqrt is itself correctly rounded,...
Definition
ExactReduction.h:92
eonc::exact::dot
double dot(const double *x, const double *y, std::size_t n)
Round-to-nearest-even value of the exact sum of x[i] * y[i].
Definition
ExactReduction.cpp:451
eonc::geometry::maxAtomMotionAppliedV
VectorXd maxAtomMotionAppliedV(const VectorXd v1, double maxMotion)
Definition
GeometryAnalysis.cpp:324
eonc
RAII resource manager for the ARTn C library with global synchronization.
Definition
ARTnSaddleSearch.cpp:23
client
FIRE.cpp
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf