Loading...
Searching...
No Matches
NEBObjectiveFunction Class Reference

#include <NudgedElasticBand.h>

Inheritance diagram for NEBObjectiveFunction:

Public Member Functions

 NEBObjectiveFunction (NudgedElasticBand *nebPassed, const Parameters &parametersPassed)
 ~NEBObjectiveFunction (void)
VectorXd getGradient (bool fdstep=false)
double getEnergy ()
void setPositions (const VectorXd &x)
VectorXd getPositions ()
int degreesOfFreedom ()
bool isConverged ()
bool isUncertain ()
double getConvergence ()
VectorXd difference (const VectorXd &a, const VectorXd &b)
VectorXd getMasses () const override
bool supportsFiniteDifferenceCurvature () const override
bool gradientMatchesEnergy () const override
bool reuseDisplacementCurvature () const override
Public Member Functions inherited from eonc::ObjectiveFunction
 ObjectiveFunction (const Parameters &paramsPassed)
virtual ~ObjectiveFunction ()
virtual bool pastClimbCeiling ()
virtual std::optional< double > knownCurvature () const
virtual void minimumImage (Eigen::Ref< Eigen::Vector3d >) const
virtual bool getPeriodic () const

Public Attributes

NudgedElasticBand::NEBStatus status

Private Attributes

NudgedElasticBand * neb

Additional Inherited Members

Protected Attributes inherited from eonc::ObjectiveFunction
const Parameters & params

Detailed Description

Definition at line 146 of file NudgedElasticBand.h.

Constructor & Destructor Documentation

◆ NEBObjectiveFunction()

eonc::NEBObjectiveFunction::NEBObjectiveFunction ( NudgedElasticBand * nebPassed,
const Parameters & parametersPassed )
inline

Definition at line 148 of file NudgedElasticBand.h.

150 : ObjectiveFunction(parametersPassed), neb{nebPassed} {}
NudgedElasticBand * neb
ObjectiveFunction(const Parameters &paramsPassed)

◆ ~NEBObjectiveFunction()

Definition at line 153 of file NudgedElasticBand.h.

153{};

Member Function Documentation

◆ degreesOfFreedom()

Implements eonc::ObjectiveFunction.

Definition at line 93 of file NEBObjectiveFunction.cpp.

93 {
94 return static_cast<int>(nebSegment(*neb) * neb->numImages);
95}

◆ difference()

VectorXd eonc::NEBObjectiveFunction::difference ( const VectorXd & a,
const VectorXd & b )
virtual

Implements eonc::ObjectiveFunction.

Definition at line 148 of file NEBObjectiveFunction.cpp.

149 {
150 const long seg = nebSegment(*neb);
151 const long atomDof = 3L * neb->atoms;
152 VectorXd pbcDiff(seg * neb->numImages);
153 for (int i = 1; i <= neb->numImages; i++) {
154 const int n = (i - 1) * static_cast<int>(seg);
155 pbcDiff.segment(n, atomDof) =
156 neb->path[i]->pbcV(a.segment(n, atomDof) - b.segment(n, atomDof));
157 if (neb->solidState()) {
158 pbcDiff.segment(n + atomDof, 9) =
159 a.segment(n + atomDof, 9) - b.segment(n + atomDof, 9);
160 }
161 }
162 return pbcDiff;
163}

◆ getConvergence()

Implements eonc::ObjectiveFunction.

Definition at line 118 of file NEBObjectiveFunction.cpp.

118 {
119 return neb->convergenceForce();
120}

◆ getEnergy()

Implements eonc::ObjectiveFunction.

Definition at line 47 of file NEBObjectiveFunction.cpp.

47 {
48 // The band update evaluates dirty images as one batch; summing image
49 // energies on a moved band would otherwise evaluate them one at a time.
50 if (neb->movedAfterForceCall)
51 neb->updateForces();
52 double Energy{0};
53 for (long i = 1; i <= neb->numImages; i++) {
54 Energy += neb->path[i]->getPotentialEnergy();
55 }
56 return Energy;
57}

◆ getGradient()

VectorXd eonc::NEBObjectiveFunction::getGradient ( bool fdstep = false)
virtual

Implements eonc::ObjectiveFunction.

Definition at line 24 of file NEBObjectiveFunction.cpp.

24 {
25 if (neb->movedAfterForceCall)
26 neb->updateForces();
27 const long seg = nebSegment(*neb);
28 const long atomDof = 3L * neb->atoms;
29 VectorXd gradV(seg * neb->numImages);
30 for (long i = 1; i <= neb->numImages; i++) {
31 // Negate in-place during copy to avoid a second pass over 40KB
32 gradV.segment(seg * (i - 1), atomDof) =
33 -VectorXd::Map(neb->projectedForce[i]->data(), atomDof);
34 if (neb->solidState()) {
35 const eonc::neb::CartesianStep step = eonc::neb::solidStateCartesianStep(
36 *neb->path[i], *neb->projectedForce[i], neb->cellForce(i),
37 neb->solidJacobian());
38 gradV.segment(seg * (i - 1), atomDof) =
39 -VectorXd::Map(step.positions.data(), atomDof);
40 gradV.segment(seg * (i - 1) + atomDof, 9) =
41 -VectorXd::Map(step.cell.data(), 9);
42 }
43 }
44 return gradV;
45}
CartesianStep solidStateCartesianStep(const Matter &image, const AtomMatrix &atomicForce, const Matrix3d &cellForce, double jacobian)

◆ getMasses()

VectorXd eonc::NEBObjectiveFunction::getMasses ( ) const
overridevirtual

Reimplemented from eonc::ObjectiveFunction.

Definition at line 122 of file NEBObjectiveFunction.cpp.

122 {
123 long count = 0;
124 for (long i = 1; i <= neb->numImages; ++i) {
125 const Matter &image = *neb->path[static_cast<size_t>(i)];
126 const AtomMatrix mask = image.getFree();
127 for (long atom = 0; atom < image.numberOfAtoms(); ++atom) {
128 if (mask.row(atom).sum() > 0.5) {
129 ++count;
130 }
131 }
132 }
133 VectorXd masses(count);
134 long written = 0;
135 for (long i = 1; i <= neb->numImages; ++i) {
136 const Matter &image = *neb->path[static_cast<size_t>(i)];
137 const auto all = image.getMasses();
138 const AtomMatrix mask = image.getFree();
139 for (long atom = 0; atom < image.numberOfAtoms(); ++atom) {
140 if (mask.row(atom).sum() > 0.5) {
141 masses(written++) = all(atom);
142 }
143 }
144 }
145 return masses;
146}
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
AtomMatrix getFree() const
Definition Matter.cpp:796
long int numberOfAtoms() const
Definition Matter.cpp:340
Eigen::Matrix< double, Eigen::Dynamic, 1 > getMasses() const
Definition Matter.cpp:843

◆ getPositions()

Implements eonc::ObjectiveFunction.

Definition at line 77 of file NEBObjectiveFunction.cpp.

77 {
78 const long seg = nebSegment(*neb);
79 const long atomDof = 3L * neb->atoms;
80 VectorXd posV(seg * neb->numImages);
81 for (long i = 1; i <= neb->numImages; i++) {
82 const long offset = seg * (i - 1);
83 posV.segment(offset, atomDof) =
84 VectorXd::Map(neb->path[i]->getPositions().data(), atomDof);
85 if (neb->solidState()) {
86 posV.segment(offset + atomDof, 9) =
87 VectorXd::Map(neb->path[i]->getCell().data(), 9);
88 }
89 }
90 return posV;
91}

◆ gradientMatchesEnergy()

bool eonc::NEBObjectiveFunction::gradientMatchesEnergy ( ) const
inlineoverridevirtual

Reimplemented from eonc::ObjectiveFunction.

Definition at line 170 of file NudgedElasticBand.h.

170{ return false; }

◆ isConverged()

Implements eonc::ObjectiveFunction.

Definition at line 113 of file NEBObjectiveFunction.cpp.

113 {
114 bool force_conv = getConvergence() < params.neb_options().force_tolerance;
115 return force_conv;
116}
const Parameters & params

◆ isUncertain()

Definition at line 97 of file NEBObjectiveFunction.cpp.

97 {
98 double maxMaxUnc = std::numeric_limits<double>::lowest();
99 double currentMaxUnc{0};
100 for (long idx = 0; idx <= neb->numImages + 1; idx++) {
101 currentMaxUnc = neb->path[idx]->getEnergyVariance();
102 if (currentMaxUnc > maxMaxUnc) {
103 maxMaxUnc = currentMaxUnc;
104 }
105 }
106 bool unc_conv{maxMaxUnc > params.gp_surrogate_options().uncertainty};
107 if (unc_conv) {
108 this->status = NudgedElasticBand::NEBStatus::MAX_UNCERTAINTY;
109 }
110 return unc_conv;
111}
NudgedElasticBand::NEBStatus status

◆ reuseDisplacementCurvature()

bool eonc::NEBObjectiveFunction::reuseDisplacementCurvature ( ) const
inlineoverridevirtual

Reimplemented from eonc::ObjectiveFunction.

Definition at line 171 of file NudgedElasticBand.h.

171{ return true; }

◆ setPositions()

void eonc::NEBObjectiveFunction::setPositions ( const VectorXd & x)
virtual

Implements eonc::ObjectiveFunction.

Definition at line 59 of file NEBObjectiveFunction.cpp.

59 {
60 neb->movedAfterForceCall = true;
61 const long seg = nebSegment(*neb);
62 const long atomDof = 3L * neb->atoms;
63 for (long i = 1; i <= neb->numImages; i++) {
64 const long offset = seg * (i - 1);
65 if (neb->solidState()) {
66 Matrix3d cell = Matrix3d::Map(x.segment(offset + atomDof, 9).data());
67 cell(0, 1) = 0.0;
68 cell(0, 2) = 0.0;
69 cell(1, 2) = 0.0;
70 neb->path[i]->setCell(cell);
71 }
72 neb->path[i]->setPositions(
73 AtomMatrix::Map(x.segment(offset, atomDof).data(), neb->atoms, 3));
74 }
75}
Eigen::Matrix< double, 3, 3, eOnStorageOrder > Matrix3d
Definition Eigen.h:35

◆ supportsFiniteDifferenceCurvature()

Reimplemented from eonc::ObjectiveFunction.

Definition at line 167 of file NudgedElasticBand.h.

167{ return false; }

Member Data Documentation

◆ neb

◆ status


The documentation for this class was generated from the following files: