eOn 3.2.0
Long-timescale dynamics: aKMC, NEB, parallel replica
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
SteepestDescent.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
13
// Based on the SteepestDescent minimizer written in ASE.
14
15
#include "
eon/SteepestDescent.h
"
16
#include "
eon/ExactReduction.h
"
17
#include "
eon/SafeMath.h
"
18
19
namespace
eonc
{
20
21
int
SteepestDescent::step
(
double
a_maxMove) {
22
Eigen::VectorXd r =
m_objf
->getPositions();
23
Eigen::VectorXd f = -
m_objf
->getGradient();
24
25
Eigen::VectorXd dr;
26
double
alpha =
m_optConfig
.opts.sd.alpha;
27
if
(
m_optConfig
.opts.sd.two_point &&
iteration
> 0) {
28
Eigen::VectorXd dx =
m_objf
->difference(r,
m_rPrev
);
29
Eigen::VectorXd dg = -f +
m_fPrev
;
30
alpha =
eonc::safemath::safe_div
(
eonc::exact::squaredNorm
(dx),
31
eonc::exact::dot
(dx, dg), 0.0);
32
if
(alpha < 0) {
33
alpha =
m_optConfig
.opts.sd.alpha;
34
}
35
QUILL_LOG_DEBUG(
m_log
,
"[SD] alpha: {:.4e}"
, alpha);
36
}
37
38
dr = alpha * f;
39
dr =
eonc::geometry::maxAtomMotionAppliedV
(dr, a_maxMove);
40
41
m_objf
->setPositions(r + dr);
42
43
m_rPrev
= r;
44
m_fPrev
= f;
45
46
iteration
++;
47
48
return
m_objf
->isConverged() ? 1 : 0;
49
}
50
51
int
SteepestDescent::run
(
size_t
a_maxIteration,
double
a_maxMove) {
52
while
(!
m_objf
->isConverged() &&
iteration
< a_maxIteration) {
53
step
(a_maxMove);
54
}
55
return
m_objf
->isConverged() ? 1 : 0;
56
}
57
58
}
// namespace eonc
ExactReduction.h
SafeMath.h
SteepestDescent.h
eonc::Optimizer::m_optConfig
const OptimizerConfig m_optConfig
Definition
Optimizer.h:73
eonc::Optimizer::m_objf
std::shared_ptr< ObjectiveFunction > m_objf
Definition
Optimizer.h:74
eonc::SteepestDescent::run
int run(size_t a_maxIterations, double a_maxMove) override
Definition
SteepestDescent.cpp:51
eonc::SteepestDescent::iteration
size_t iteration
Definition
SteepestDescent.h:39
eonc::SteepestDescent::m_fPrev
Eigen::VectorXd m_fPrev
Definition
SteepestDescent.h:41
eonc::SteepestDescent::m_log
eonc::log::FileScoped m_log
Definition
SteepestDescent.h:37
eonc::SteepestDescent::m_rPrev
Eigen::VectorXd m_rPrev
Definition
SteepestDescent.h:40
eonc::SteepestDescent::step
int step(double a_maxMove) override
Definition
SteepestDescent.cpp:21
eonc::exact::squaredNorm
double squaredNorm(const Eigen::MatrixBase< A > &x)
Definition
ExactReduction.h:85
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::safemath::safe_div
constexpr double safe_div(double num, double denom, double fallback=0.0)
Definition
SafeMath.h:21
eonc
RAII resource manager for the ARTn C library with global synchronization.
Definition
ARTnSaddleSearch.cpp:23
client
SteepestDescent.cpp
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf