Loading...
Searching...
No Matches
ObjectiveFunction.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
14#include "Matter.h"
15
16#include <optional>
17
18namespace eonc {
19
21protected:
23
24public:
25 ObjectiveFunction(const Parameters &paramsPassed) : params{paramsPassed} {}
26 virtual ~ObjectiveFunction() {}
27 virtual double getEnergy() = 0;
28 virtual VectorXd getGradient(bool fdstep = false) = 0;
29 virtual void setPositions(const VectorXd &x) = 0;
30 virtual VectorXd getPositions() = 0;
31 virtual int degreesOfFreedom() = 0;
32 virtual bool isConverged() = 0;
33 virtual double getConvergence() = 0;
34 virtual VectorXd difference(const VectorXd &a, const VectorXd &b) = 0;
35 // Allow the initial finite-difference curvature estimate used by L-BFGS.
36 virtual bool supportsFiniteDifferenceCurvature() const { return true; }
37 // True when getGradient() is the gradient of getEnergy(). Only then can
38 // an energy test accept or shape a step (lbfgs_accept, the Zhang-Xu
39 // secant); an objective that climbs its energy rejects every good step.
40 virtual bool gradientMatchesEnergy() const { return true; }
41 // True when the current geometry is already past the climbing energy
42 // limit. FIRE asks before the post-step getGradient(), which would
43 // rotate the mode at a point the search is about to pull back.
44 // The default is a minimization: the gradient descends the energy
45 // and there is no such limit. A true answer has already evaluated
46 // the centre, and a batching mode solver's first displaced image
47 // with it, so a following getGradient() still uses that image.
48 virtual bool pastClimbCeiling() { return false; }
49 // The band reuses the previous displacement as a secant. A minimizer
50 // and a dimer translation keep a finite-difference probe each step.
51 virtual bool reuseDisplacementCurvature() const { return false; }
52 // A curvature the objective already knows (eV / A^2, magnitude), so
53 // L-BFGS can seed H0 from it instead of spending a force call on the
54 // finite-difference probe. Empty when nothing is known.
55 virtual std::optional<double> knownCurvature() const { return std::nullopt; }
56 // Packwood/Kermode pair preconditioner: MIC of one Cartesian pair.
57 // Default leaves dr unchanged (no cell).
58 virtual void minimumImage(Eigen::Ref<Eigen::Vector3d> /*dr*/) const {}
59 // Per-atom masses of the free atoms (length N, not 3N). Empty if unknown.
60 virtual VectorXd getMasses() const { return VectorXd(); }
61 // True when the geometry uses periodic boundaries (Sella proj_rot off).
62 virtual bool getPeriodic() const { return false; }
63};
64
65} // namespace eonc
virtual bool supportsFiniteDifferenceCurvature() const
virtual VectorXd getGradient(bool fdstep=false)=0
virtual VectorXd difference(const VectorXd &a, const VectorXd &b)=0
ObjectiveFunction(const Parameters &paramsPassed)
virtual VectorXd getMasses() const
virtual bool getPeriodic() const
virtual bool isConverged()=0
const Parameters & params
virtual VectorXd getPositions()=0
virtual std::optional< double > knownCurvature() const
virtual bool gradientMatchesEnergy() const
virtual void setPositions(const VectorXd &x)=0
virtual double getEnergy()=0
virtual double getConvergence()=0
virtual int degreesOfFreedom()=0
virtual bool pastClimbCeiling()
virtual bool reuseDisplacementCurvature() const
virtual void minimumImage(Eigen::Ref< Eigen::Vector3d >) const
RAII resource manager for the ARTn C library with global synchronization.