-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathOpt3d.h
More file actions
67 lines (55 loc) · 2.12 KB
/
Copy pathOpt3d.h
File metadata and controls
67 lines (55 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef Opt3d_h
#define Opt3d_h
//#include "Vec2.h"
#include "Vec3.h"
class Opt3d{ public:
// "Fast Inertial Realxation Engine" according to
// Bitzek, E., Koskinen, P., Gähler, F., Moseler, M. & Gumbsch, P. Structural relaxation made simple. Phys. Rev. Lett. 97, 170201 (2006).
// Eidel, B., Stukowski, A. & Schröder, J. Energy-Minimization in Atomic-to-Continuum Scale-Bridging Methods. Pamm 11, 509–510 (2011).
// http://users.jyu.fi/~pekkosk/resources/pdf/FIRE.pdf
// parameters
double fTinc = 1.1; // factor by which time step is increased if going downhill
double fTdec = 0.5; // factor by which timestep is decreased if going uphill
double fDamp = 0.95; // rate of decrease of damping when going downhill
//
double dtmax = 0.2; // maximal timestep
double dtmin = 0.02;
double dampMax = 0.5; // default damping
// variables
double dt = dtmax; // time-step ( variable
double damp = dampMax; // damping ( variable
inline void setup( double dtmax_, double dtmin_, double dampMax_=0.5){
dtmax = dtmax_;
dtmin = dtmin_;
dampMax = dampMax_;
dt = dtmax;
damp = dampMax;
}
inline void moveMD( const Vec3d& f, Vec3d& p, Vec3d& v ){
v.mul( 1 - damp );
v.add_mul( f, dt );
p.add_mul( v, dt );
}
// relaxation step using FIRE algorithm
inline void move( const Vec3d& f, Vec3d& p, Vec3d& v ){
double ff = f.norm2();
double vv = v.norm2();
double vf = f.dot(v);
if( vf < 0 ){ // if velocity along direction of force
v.set( 0.0d );
dt = fmax( dt * fTdec, dtmin );
damp = dampMax;
}else{ // if velocity against direction of force
double cf = damp * sqrt(vv/ff);
double cv = 1 - damp;
v.mul ( cv );
v.add_mul( f, cf ); // v = cV * v + cF * F
dt = fmin( dt * fTinc, dtmax );
damp = damp * fDamp;
}
// normal leap-frog times step
v.add_mul( f , dt );
p.add_mul( v , dt );
}
};
#endif