Loading...
Searching...
No Matches
Quickmin.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/Quickmin.h"
13#include "eon/ExactReduction.h"
14#include "eon/HelperFunctions.h"
15
16#include <cmath>
17
18namespace eonc {
19
20int Quickmin::step(double a_maxMove) {
21 Eigen::VectorXd force = -m_objf->getGradient();
22 const double fn = eonc::exact::norm(force);
23 if (!(fn > 0.0) || !std::isfinite(fn)) {
25 return 1;
26 }
27 if (m_optConfig.opts.quickmin.steepest_descent) {
28 m_vel.setZero();
29 } else {
30 if (eonc::exact::dot(m_vel, force) < 0) {
31 m_vel.setZero();
32 } else {
33 const Eigen::VectorXd f_unit = force / fn;
34 m_vel = eonc::exact::dot(m_vel, f_unit) * f_unit;
35 }
36 }
37
38 m_vel += force * m_dt;
39 Eigen::VectorXd dr = eonc::geometry::maxAtomMotionAppliedV(
40 m_vel * m_dt,
41 a_maxMove); // used to be m_optConfig.opts.max_time_step
42 QUILL_LOG_INFO(m_log, "{} M_Vel.norm() is {}", m_iteration, m_vel.norm());
43 m_objf->setPositions(m_objf->getPositions() + dr);
45 return m_objf->isConverged() ? 1 : 0;
46}
47
48int Quickmin::run(size_t a_maxSteps, double a_maxMove) {
49 while (!m_objf->isConverged() && m_iteration < a_maxSteps) {
50 step(a_maxMove);
51 }
52 return m_objf->isConverged() ? 1 : 0;
53}
54
55} // namespace eonc
const OptimizerConfig m_optConfig
Definition Optimizer.h:73
std::shared_ptr< ObjectiveFunction > m_objf
Definition Optimizer.h:74
double m_dt
Definition Quickmin.h:40
Eigen::VectorXd m_vel
Definition Quickmin.h:41
eonc::log::FileScoped m_log
Definition Quickmin.h:43
int run(size_t a_maxIterations, double a_maxMove) override
Definition Quickmin.cpp:48
size_t m_iteration
Definition Quickmin.h:42
int step(double a_maxMove) override
Definition Quickmin.cpp:20
double norm(const Eigen::MatrixBase< A > &x)
sqrt of the correctly rounded squared norm; IEEE sqrt is itself correctly rounded,...
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].
VectorXd maxAtomMotionAppliedV(const VectorXd v1, double maxMotion)
RAII resource manager for the ARTn C library with global synchronization.