• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisãoc321747c7526ff3c4f5ca03f73a30b87cb839377 (tree)
Hora2013-08-23 16:06:31
AutorKatsuhiko Nishimra <ktns.87@gmai...>
CommiterKatsuhiko Nishimra

Mensagem de Log

Implement GEDIIS::SearchMinimum. #31854

git-svn-id: https://svn.sourceforge.jp/svnroot/molds/trunk@1491 1136aad2-a195-0410-b898-f5ea1d11b9d8

Mudança Sumário

Diff

--- a/src/optimization/GEDIIS.cpp
+++ b/src/optimization/GEDIIS.cpp
@@ -66,13 +66,18 @@ void GEDIIS::SetMessages(){
6666 = "Error in optimization::GEDIIS::Optimize: Optimization did not met convergence criterion.\n";
6767 this->messageStartGEDIISStep
6868 = "\n========== START: GEDIIS step ";
69+ this->messageTakingGEDIISStep
70+ = "Taking GEDIIS step.\n";
71+ this->messageTakingRFOStep
72+ = "Taking RFO step.\n";
73+ this->messageDiscardHistory
74+ = "GDIIS: Discarding all entries from history.\n";
6975 }
7076
7177 void GEDIIS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStructure,
7278 Molecule& molecule,
7379 double* lineSearchedEnergy,
7480 bool* obtainesOptimizedStructure) const {
75- throw MolDSException("GEDIIS not yet implemented");
7681 int elecState = Parameters::GetInstance()->GetElectronicStateIndexOptimization();
7782 double dt = Parameters::GetInstance()->GetTimeWidthOptimization();
7883 int totalSteps = Parameters::GetInstance()->GetTotalStepsOptimization();
@@ -83,15 +88,19 @@ void GEDIIS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStru
8388 double const* const* matrixForce = NULL;
8489 double const* vectorForce = NULL;
8590 const int dimension = molecule.GetNumberAtoms()*CartesianType_end;
86- double** matrixHessian = NULL;
87- double* vectorOldForce = NULL;
88- double* vectorStep = NULL;
89- double** matrixStep = NULL;
90- double** matrixOldCoordinates = NULL;
91- double* vectorOldCoordinates = NULL;
92- double** matrixDisplacement = NULL;
91+ double** matrixHessian = NULL;
92+ double* vectorOldForce = NULL;
93+ double* vectorStep = NULL;
94+ double** matrixStep = NULL;
95+ double** matrixOldCoordinates = NULL;
96+ double* vectorOldCoordinates = NULL;
97+ double** matrixDisplacement = NULL;
98+ double** matrixGEDIISCoordinates = NULL;
99+ double** matrixGEDIISForce = NULL;
100+ double* vectorGEDIISForce = NULL;
93101 double trustRadius = Parameters::GetInstance()->GetInitialTrustRadiusOptimization();
94102 const double maxNormStep = Parameters::GetInstance()->GetMaxNormStepOptimization();
103+ GEDIISHistory history;
95104
96105 try{
97106 // initialize Hessian with unit matrix
@@ -108,6 +117,9 @@ void GEDIIS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStru
108117 matrixForce = electronicStructure->GetForce(elecState);
109118 vectorForce = &matrixForce[0][0];
110119
120+ // Add initial entry into GEDIIS history
121+ history.AddEntry(lineSearchCurrentEnergy, molecule, matrixForce);
122+
111123 for(int s=0; s<totalSteps; s++){
112124 this->OutputLog(boost::format("%s%d\n\n") % this->messageStartGEDIISStep % (s+1));
113125
@@ -117,23 +129,60 @@ void GEDIIS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStru
117129
118130 this->StoreMolecularGeometry(matrixOldCoordinates, molecule);
119131
120- // Level shift Hessian redundant modes
121- this->ShiftHessianRedundantMode(matrixHessian, molecule);
122-
123132 // Limit the trustRadius to maxNormStep
124133 trustRadius=min(trustRadius,maxNormStep);
125134
135+ lineSearchInitialEnergy = lineSearchCurrentEnergy;
136+ double preRFOEnergy = lineSearchInitialEnergy;
137+
138+ MallocerFreer::GetInstance()->Malloc(&matrixGEDIISCoordinates, molecule.GetNumberAtoms(), CartesianType_end);
139+ MallocerFreer::GetInstance()->Malloc(&matrixGEDIISForce, molecule.GetNumberAtoms(), CartesianType_end);
140+ try{
141+ history.SolveGEDIISEquation(&preRFOEnergy, matrixGEDIISCoordinates, matrixGEDIISForce);
142+
143+ this->OutputLog(this->messageTakingGEDIISStep);
144+ this->RollbackMolecularGeometry(molecule, matrixGEDIISCoordinates);
145+
146+ bool tempCanOutputLogs = false;
147+ this->UpdateElectronicStructure(electronicStructure, molecule, requireGuess, tempCanOutputLogs);
148+ lineSearchCurrentEnergy = electronicStructure->GetElectronicEnergy(elecState);
149+ vectorGEDIISForce = &matrixGEDIISForce[0][0];
150+ }
151+ catch(MolDSException ex){
152+ //Check whether the exception is from GEDIIS routine
153+ if(!ex.HasKey(GEDIISErrorID)){
154+ throw ex;
155+ }
156+ else{
157+ // Show GEDIIS error message
158+ this->OutputLog(ex.What());
159+ this->OutputLog("\n");
160+
161+ // If the error is not about insufficient history
162+ if(ex.GetKeyValue<int>(GEDIISErrorID) != GEDIISNotSufficientHistory){
163+ history.DiscardEntries();
164+ }
165+
166+ // Skip GEDIIS step and proceed to RFO step
167+ preRFOEnergy = lineSearchCurrentEnergy;
168+ vectorGEDIISForce = vectorOldForce;
169+ }
170+ }
171+ this->OutputLog(messageTakingRFOStep);
172+
173+ // Level shift Hessian redundant modes
174+ this->ShiftHessianRedundantMode(matrixHessian, molecule);
175+
126176 //Calculate RFO step
127177 MallocerFreer::GetInstance()->Malloc(&matrixStep, molecule.GetNumberAtoms(), CartesianType_end);
128178 vectorStep = &matrixStep[0][0];
129179 this->CalcRFOStep(vectorStep, matrixHessian, vectorForce, trustRadius, dimension);
130180
131- double approximateChange = this->ApproximateEnergyChange(dimension, matrixHessian, vectorForce, vectorStep);
181+ double approximateChange = this->ApproximateEnergyChange(dimension, matrixHessian, vectorGEDIISForce, vectorStep);
132182
133183 // Take a RFO step
134184 bool doLineSearch = false;
135185 bool tempCanOutputLogs = false;
136- lineSearchInitialEnergy = lineSearchCurrentEnergy;
137186 if(doLineSearch){
138187 this->LineSearch(electronicStructure, molecule, lineSearchCurrentEnergy, matrixStep, elecState, dt);
139188 }
@@ -147,9 +196,9 @@ void GEDIIS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStru
147196 this->UpdateElectronicStructure(electronicStructure, molecule, requireGuess, tempCanOutputLogs);
148197 lineSearchCurrentEnergy = electronicStructure->GetElectronicEnergy(elecState);
149198 }
150- this->OutputMoleculeElectronicStructure(electronicStructure, molecule, this->CanOutputLogs());
199+ this->UpdateTrustRadius(trustRadius, approximateChange, preRFOEnergy, lineSearchCurrentEnergy);
151200
152- this->UpdateTrustRadius(trustRadius, approximateChange, lineSearchInitialEnergy, lineSearchCurrentEnergy);
201+ this->OutputMoleculeElectronicStructure(electronicStructure, molecule, this->CanOutputLogs());
153202
154203 // check convergence
155204 if(this->SatisfiesConvergenceCriterion(matrixForce,
@@ -162,37 +211,44 @@ void GEDIIS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStru
162211 break;
163212 }
164213
165- if(lineSearchCurrentEnergy > lineSearchInitialEnergy){
166- this->OutputLog(this->messageHillClimbing);
167- this->RollbackMolecularGeometry(molecule, matrixOldCoordinates);
168- lineSearchCurrentEnergy = lineSearchInitialEnergy;
169- }
170-
171214 //Calculate displacement (K_k at Eq. (15) in [SJTO_1983])
172215 this->CalcDisplacement(matrixDisplacement, matrixOldCoordinates, molecule);
173216
174217 matrixForce = electronicStructure->GetForce(elecState);
175218 vectorForce = &matrixForce[0][0];
176219
220+ history.AddEntry(lineSearchCurrentEnergy, molecule, matrixForce);
221+
177222 // Update Hessian
178223 this->UpdateHessian(matrixHessian, dimension, vectorForce, vectorOldForce, &matrixDisplacement[0][0]);
179224
225+ // Check for hill climbing
226+ if(lineSearchCurrentEnergy > lineSearchInitialEnergy){
227+ this->OutputLog(this->messageHillClimbing);
228+ this->RollbackMolecularGeometry(molecule, matrixOldCoordinates);
229+ lineSearchCurrentEnergy = lineSearchInitialEnergy;
230+ }
231+
180232 }
181233 *lineSearchedEnergy = lineSearchCurrentEnergy;
182234 }
183235 catch(MolDSException ex){
184236 MallocerFreer::GetInstance()->Free(&matrixHessian, dimension, dimension);
185237 MallocerFreer::GetInstance()->Free(&vectorOldForce, dimension);
186- MallocerFreer::GetInstance()->Free(&matrixStep, molecule.GetNumberAtoms(), CartesianType_end);
187- MallocerFreer::GetInstance()->Free(&matrixDisplacement, molecule.GetNumberAtoms(), CartesianType_end);
188- MallocerFreer::GetInstance()->Free(&matrixOldCoordinates, molecule.GetNumberAtoms(), CartesianType_end);
238+ MallocerFreer::GetInstance()->Free(&matrixStep , molecule.GetNumberAtoms(), CartesianType_end);
239+ MallocerFreer::GetInstance()->Free(&matrixDisplacement , molecule.GetNumberAtoms(), CartesianType_end);
240+ MallocerFreer::GetInstance()->Free(&matrixOldCoordinates , molecule.GetNumberAtoms(), CartesianType_end);
241+ MallocerFreer::GetInstance()->Free(&matrixGEDIISCoordinates, molecule.GetNumberAtoms(), CartesianType_end);
242+ MallocerFreer::GetInstance()->Free(&matrixGEDIISForce , molecule.GetNumberAtoms(), CartesianType_end);
189243 throw ex;
190244 }
191245 MallocerFreer::GetInstance()->Free(&matrixHessian, dimension, dimension);
192246 MallocerFreer::GetInstance()->Free(&vectorOldForce, dimension);
193- MallocerFreer::GetInstance()->Free(&matrixStep, molecule.GetNumberAtoms(), CartesianType_end);
194- MallocerFreer::GetInstance()->Free(&matrixDisplacement, molecule.GetNumberAtoms(), CartesianType_end);
195- MallocerFreer::GetInstance()->Free(&matrixOldCoordinates, molecule.GetNumberAtoms(), CartesianType_end);
247+ MallocerFreer::GetInstance()->Free(&matrixStep , molecule.GetNumberAtoms(), CartesianType_end);
248+ MallocerFreer::GetInstance()->Free(&matrixDisplacement , molecule.GetNumberAtoms(), CartesianType_end);
249+ MallocerFreer::GetInstance()->Free(&matrixOldCoordinates , molecule.GetNumberAtoms(), CartesianType_end);
250+ MallocerFreer::GetInstance()->Free(&matrixGEDIISCoordinates, molecule.GetNumberAtoms(), CartesianType_end);
251+ MallocerFreer::GetInstance()->Free(&matrixGEDIISForce , molecule.GetNumberAtoms(), CartesianType_end);
196252 }
197253
198254 GEDIIS::GEDIISHistory::GEDIISHistory(){
--- a/src/optimization/GEDIIS.h
+++ b/src/optimization/GEDIIS.h
@@ -34,6 +34,7 @@ protected:
3434 std::string messageStartGEDIISStep;
3535 std::string messageTakingGEDIISStep;
3636 std::string messageTakingRFOStep;
37+ std::string messageDiscardHistory;
3738
3839 class GEDIISHistory{
3940 public: