eOn 3.2.0
Long-timescale dynamics: aKMC, NEB, parallel replica
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
FiniteDifference.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 "
Eigen.h
"
15
16
#include <cctype>
17
#include <string>
18
#include <string_view>
19
20
namespace
eonc
{
21
25
enum class
FdScheme
{
OneSided
,
Central
,
Fourth
};
26
27
inline
FdScheme
parseFdScheme
(std::string_view scheme) {
28
std::string lower;
29
lower.reserve(scheme.size());
30
for
(
unsigned
char
c : scheme) {
31
lower.push_back(
static_cast<
char
>
(std::tolower(c)));
32
}
33
if
(lower ==
"central"
) {
34
return
FdScheme::Central
;
35
}
36
if
(lower ==
"fourth"
|| lower ==
"fourth_order"
|| lower ==
"central4"
) {
37
return
FdScheme::Fourth
;
38
}
39
return
FdScheme::OneSided
;
40
}
41
45
template
<
class
M>
46
M
fdForceDerivative
(
FdScheme
scheme,
double
dr,
const
M &f0,
const
M &fPlus,
47
const
M &fMinus,
const
M &fPlus2,
const
M &fMinus2) {
48
M slope = fPlus;
49
switch
(scheme) {
50
case
FdScheme::Fourth
:
51
slope = (-fPlus2 + 8.0 * fPlus - 8.0 * fMinus + fMinus2) / (12.0 * dr);
52
break
;
53
case
FdScheme::Central
:
54
slope = (fPlus - fMinus) / (2.0 * dr);
55
break
;
56
case
FdScheme::OneSided
:
57
slope = (fPlus - f0) / dr;
58
break
;
59
}
60
return
slope;
61
}
62
66
template
<
class
Eval>
67
VectorXd
fdHessianVector
(
FdScheme
scheme,
double
dr,
const
VectorXd &force0,
68
Eval &&eval) {
69
const
VectorXd zero = VectorXd::Zero(force0.size());
70
switch
(scheme) {
71
case
FdScheme::Fourth
: {
72
const
VectorXd fPlus = eval(1.0);
73
const
VectorXd fMinus = eval(-1.0);
74
const
VectorXd fPlus2 = eval(2.0);
75
const
VectorXd fMinus2 = eval(-2.0);
76
return
-
fdForceDerivative
(scheme, dr, force0, fPlus, fMinus, fPlus2,
77
fMinus2);
78
}
79
case
FdScheme::Central
: {
80
const
VectorXd fPlus = eval(1.0);
81
const
VectorXd fMinus = eval(-1.0);
82
return
-
fdForceDerivative
(scheme, dr, force0, fPlus, fMinus, zero, zero);
83
}
84
case
FdScheme::OneSided
:
85
break
;
86
}
87
const
VectorXd fPlus = eval(1.0);
88
return
-
fdForceDerivative
(
FdScheme::OneSided
, dr, force0, fPlus, zero, zero,
89
zero);
90
}
91
92
}
// namespace eonc
Eigen.h
eonc
RAII resource manager for the ARTn C library with global synchronization.
Definition
ARTnSaddleSearch.cpp:23
eonc::FdScheme
FdScheme
Real finite-difference scheme for the assembled Hessian and for Lanczos/Davidson Hessian-vector produ...
Definition
FiniteDifference.h:25
eonc::FdScheme::Central
@ Central
Definition
FiniteDifference.h:25
eonc::FdScheme::Fourth
@ Fourth
Definition
FiniteDifference.h:25
eonc::FdScheme::OneSided
@ OneSided
Definition
FiniteDifference.h:25
eonc::fdForceDerivative
M fdForceDerivative(FdScheme scheme, double dr, const M &f0, const M &fPlus, const M &fMinus, const M &fPlus2, const M &fMinus2)
Derivative of a sampled force map along one real step of length dr.
Definition
FiniteDifference.h:46
eonc::fdHessianVector
VectorXd fdHessianVector(FdScheme scheme, double dr, const VectorXd &force0, Eval &&eval)
Energy Hessian-vector product -dF.
Definition
FiniteDifference.h:67
eonc::parseFdScheme
FdScheme parseFdScheme(std::string_view scheme)
Definition
FiniteDifference.h:27
include
eon
FiniteDifference.h
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf