# | Line 1 | Line 1 | |
---|---|---|
1 | #include <math.h> | |
2 | #include "OOPSEMinimizer.hpp" | |
3 | + | #include "ShakeMin.hpp" |
4 | + | #include "Integrator.cpp" |
5 | ||
6 | OOPSEMinimizer::OOPSEMinimizer( SimInfo *theInfo, ForceFields* the_ff , | |
7 | < | MinimizerParameterSet * param) |
8 | < | :RealIntegrator(theInfo, the_ff), bVerbose(false), bShake(true){ |
7 | > | MinimizerParameterSet * param) : |
8 | > | RealIntegrator(theInfo, the_ff), bShake(true), bVerbose(false) { |
9 | > | dumpOut = NULL; |
10 | > | statOut = NULL; |
11 | ||
12 | tStats = new Thermo(info); | |
13 | < | dumpOut = new DumpWriter(info); |
10 | < | statOut = new StatWriter(info); |
13 | > | |
14 | ||
15 | paramSet = param; | |
16 | ||
# | Line 16 | Line 19 | OOPSEMinimizer::OOPSEMinimizer( SimInfo *theInfo, Forc | |
19 | curX = getCoor(); | |
20 | curG.resize(ndim); | |
21 | ||
22 | < | preMove(); |
22 | > | shakeAlgo = new ShakeMinFramework(theInfo); |
23 | > | shakeAlgo->doPreConstraint(); |
24 | } | |
25 | ||
26 | OOPSEMinimizer::~OOPSEMinimizer(){ | |
27 | delete tStats; | |
28 | < | delete dumpOut; |
29 | < | delete statOut; |
28 | > | if(dumpOut) |
29 | > | delete dumpOut; |
30 | > | if(statOut) |
31 | > | delete statOut; |
32 | delete paramSet; | |
33 | } | |
34 | ||
# | Line 34 | Line 40 | void OOPSEMinimizer::calcEnergyGradient(vector<double> | |
40 | double force[3]; | |
41 | double dAtomGrad[6]; | |
42 | int shakeStatus; | |
43 | + | |
44 | + | status = 1; |
45 | ||
46 | setCoor(x); | |
47 | ||
48 | < | if (nConstrained && bShake){ |
49 | < | shakeStatus = shakeR(); |
48 | > | if (bShake){ |
49 | > | shakeStatus = shakeAlgo->doShakeR(); |
50 | > | if(shakeStatus < 0) |
51 | > | status = -1; |
52 | } | |
53 | < | |
53 | > | |
54 | calcForce(1, 1); | |
55 | < | |
56 | < | if (nConstrained && bShake){ |
57 | < | shakeStatus |= shakeF(); |
55 | > | |
56 | > | if (bShake){ |
57 | > | shakeStatus = shakeAlgo->doShakeF(); |
58 | > | if(shakeStatus < 0) |
59 | > | status = -1; |
60 | } | |
61 | < | |
61 | > | |
62 | x = getCoor(); | |
63 | ||
64 | ||
# | Line 80 | Line 92 | void OOPSEMinimizer::calcEnergyGradient(vector<double> | |
92 | ||
93 | energy = tStats->getPotential(); | |
94 | ||
83 | – | status = shakeStatus; |
95 | } | |
96 | ||
97 | /** | |
# | Line 159 | Line 170 | vector<double> OOPSEMinimizer::getCoor(){ | |
170 | ||
171 | } | |
172 | ||
173 | + | /* |
174 | int OOPSEMinimizer::shakeR(){ | |
175 | int i, j; | |
176 | int done; | |
# | Line 398 | Line 410 | int OOPSEMinimizer::shakeF(){ | |
410 | return 1; | |
411 | } | |
412 | ||
413 | < | //calculate the value of object function |
413 | > | */ |
414 | > | |
415 | > | //calculate the value of object function |
416 | void OOPSEMinimizer::calcF(){ | |
417 | calcEnergyGradient(curX, curG, curF, egEvalStatus); | |
418 | } | |
# | Line 483 | Line 497 | void OOPSEMinimizer::printMinimizerInfo(){ | |
497 | ||
498 | /** | |
499 | * In thoery, we need to find the minimum along the search direction | |
500 | < | * However, function evaluation is too expensive. I |
500 | > | * However, function evaluation is too expensive. |
501 | * At the very begining of the problem, we check the search direction and make sure | |
502 | * it is a descent direction | |
503 | * we will compare the energy of two end points, | |
# | Line 536 | Line 550 | int OOPSEMinimizer::doLineSearch(vector<double>& direc | |
550 | lsTol = paramSet->getLineSearchTol(); | |
551 | ||
552 | //calculate the derivative at a = 0 | |
553 | + | slopeA = 0; |
554 | for (size_t i = 0; i < ndim; i++) | |
555 | slopeA += curG[i]*direction[i]; | |
556 | ||
# | Line 692 | Line 707 | void OOPSEMinimizer::minimize(){ | |
707 | ||
708 | if (bVerbose) | |
709 | printMinimizerInfo(); | |
710 | + | |
711 | + | dumpOut = new DumpWriter(info); |
712 | + | statOut = new StatWriter(info); |
713 | ||
714 | init(); | |
715 | ||
# | Line 707 | Line 725 | void OOPSEMinimizer::minimize(){ | |
725 | ||
726 | stepStatus = step(); | |
727 | ||
728 | + | if (bShake) |
729 | + | shakeAlgo->doPreConstraint(); |
730 | + | |
731 | if (stepStatus < 0){ | |
732 | saveResult(); | |
733 | minStatus = MIN_LSERROR; | |
# | Line 719 | Line 740 | void OOPSEMinimizer::minimize(){ | |
740 | writeOut(curX, curIter); | |
741 | } | |
742 | ||
722 | – | //if (curIter == nextResetIter){ |
723 | – | // reset(); |
724 | – | // nextResetIter += resetFrq; |
725 | – | //} |
726 | – | |
743 | convgStatus = checkConvg(); | |
744 | ||
745 | if (convgStatus > 0){ |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |