Révision | 58525f1df6f49bf6e6f24a5d0c277365730007f3 (tree) |
---|---|
l'heure | 2014-01-09 14:47:43 |
Auteur | Katsuhiko Nishimra <ktns.87@gmai...> |
Commiter | Katsuhiko Nishimra |
Fix BFGS rollback code. #32879
git-svn-id: https://svn.sourceforge.jp/svnroot/molds/trunk@1624 1136aad2-a195-0410-b898-f5ea1d11b9d8
@@ -145,7 +145,9 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct | ||
145 | 145 | |
146 | 146 | // Store old Force data |
147 | 147 | MallocerFreer::GetInstance()->Malloc(&vectorOldForce, dimension); |
148 | - MolDS_wrappers::Blas::GetInstance()->Dcopy(dimension, vectorForce, vectorOldForce); | |
148 | + MolDS_wrappers::Blas::GetInstance()->Dcopy(dimension, | |
149 | + static_cast<double const*>(vectorForce), | |
150 | + vectorOldForce); | |
149 | 151 | |
150 | 152 | this->StoreMolecularGeometry(matrixOldCoordinates, molecule); |
151 | 153 |
@@ -194,21 +196,27 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct | ||
194 | 196 | break; |
195 | 197 | } |
196 | 198 | |
197 | - if(lineSearchCurrentEnergy > lineSearchInitialEnergy){ | |
199 | + //Calculate displacement (K_k at Eq. (15) in [SJTO_1983]) | |
200 | + this->CalcDisplacement(matrixDisplacement, matrixOldCoordinates, molecule); | |
201 | + | |
202 | + //Rollback geometry and energy if energy increases | |
203 | + bool isHillClimbing = lineSearchCurrentEnergy > lineSearchInitialEnergy; | |
204 | + if(isHillClimbing){ | |
198 | 205 | this->OutputLog(this->messageHillClimbing); |
199 | 206 | this->RollbackMolecularGeometry(molecule, matrixOldCoordinates); |
200 | 207 | lineSearchCurrentEnergy = lineSearchInitialEnergy; |
201 | 208 | } |
202 | 209 | |
203 | - //Calculate displacement (K_k at Eq. (15) in [SJTO_1983]) | |
204 | - this->CalcDisplacement(matrixDisplacement, matrixOldCoordinates, molecule); | |
205 | - | |
206 | 210 | matrixForce = electronicStructure->GetForce(elecState); |
207 | 211 | vectorForce = &matrixForce[0][0]; |
208 | 212 | |
209 | 213 | // Update Hessian |
210 | 214 | this->UpdateHessian(matrixHessian, dimension, vectorForce, vectorOldForce, &matrixDisplacement[0][0]); |
211 | 215 | |
216 | + //Rollback gradient if energy increases | |
217 | + if(isHillClimbing){ | |
218 | + vectorForce = vectorOldForce; | |
219 | + } | |
212 | 220 | } |
213 | 221 | *lineSearchedEnergy = lineSearchCurrentEnergy; |
214 | 222 | } |