Loading...
Searching...
No Matches
ConjugateGradients.h
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#pragma once
13#include "Eigen.h"
14#include "EonLogger.h"
15#include "HelperFunctions.h"
16#include "Matter.h"
17#include "Optimizer.h"
18#include "Parameters.h"
19
20namespace eonc {
21
33
37
38class ConjugateGradients final : public Optimizer {
39public:
41
46 ConjugateGradients(std::shared_ptr<ObjectiveFunction> a_objf,
47 const Parameters &a_params)
48 : Optimizer(a_objf, OptType::CG, OptimizerConfig::fromParams(a_params)),
49 m_direction{Eigen::VectorXd::Zero(a_objf->degreesOfFreedom())},
50 m_directionOld{Eigen::VectorXd::Zero(a_objf->degreesOfFreedom())},
51 m_directionNorm{Eigen::VectorXd::Zero(a_objf->degreesOfFreedom())},
52 m_force{Eigen::VectorXd::Zero(a_objf->degreesOfFreedom())},
53 m_forceOld{Eigen::VectorXd::Zero(a_objf->degreesOfFreedom())} {}
54
56
58
62 int step(double a_maxMove) override;
64
68 int run(size_t a_maxIterations, double a_maxMove) override;
70 Eigen::VectorXd getStep();
71
72private:
74 Eigen::VectorXd m_direction;
76 Eigen::VectorXd m_directionOld;
78 Eigen::VectorXd m_directionNorm;
80 Eigen::VectorXd m_force;
82 Eigen::VectorXd m_forceOld;
83 eonc::log::FileScoped m_log{"cg", "_cg.log"};
84
86 size_t m_cg_i{0};
87
89
92 int single_step(double a_maxMove);
94
98 int line_search(double a_maxMove);
99};
100
101} // namespace eonc
The optimizer class is used to serve as an abstract class for all optimizers, as well as to call an o...
int single_step(double a_maxMove)
Steps the conjugate gradient.
Eigen::VectorXd m_force
Current force vector.
Eigen::VectorXd getStep()
Gets the direction of the next step.
Eigen::VectorXd m_directionNorm
Normalised version of the current direction vector.
Eigen::VectorXd m_directionOld
Algorithms previous step direction.
~ConjugateGradients()=default
Conjugant Gradient deconstructor.
int run(size_t a_maxIterations, double a_maxMove) override
Runs the conjugate gradient.
size_t m_cg_i
Counts the number of discrete steps until algorithm convergence.
ConjugateGradients(std::shared_ptr< ObjectiveFunction > a_objf, const Parameters &a_params)
Conjugate Gradients optimizer constructor.
Eigen::VectorXd m_direction
Current step direction of the conjugate gradient.
int step(double a_maxMove) override
Calls the next step in the algorithm.
Eigen::VectorXd m_forceOld
Previous force vector.
eonc::log::FileScoped m_log
int line_search(double a_maxMove)
Steps the conjugate gradient.
Optimizer(std::shared_ptr< ObjectiveFunction > a_objf, const OptimizerConfig &a_config)
Definition Optimizer.h:73
RAII resource manager for the ARTn C library with global synchronization.
Declaration of the optimizer class.
Definition Optimizer.h:51
RAII helper for file-based logging in a class.
Definition EonLogger.h:207