• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

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

Commit MetaInfo

修訂5e5e06ef01b08a5c0f03ee5eba75f5237038d311 (tree)
時間2014-01-17 11:24:08
作者Katsuhiko Nishimra <ktns.87@gmai...>
CommiterKatsuhiko Nishimra

Log Message

Factor out Optimizer::CalcNextStepGeometry. #32881

git-svn-id: https://svn.sourceforge.jp/svnroot/molds/branches/refactor_opt@1646 1136aad2-a195-0410-b898-f5ea1d11b9d8

Change Summary

差異

--- a/src/optimization/BFGS.cpp
+++ b/src/optimization/BFGS.cpp
@@ -144,7 +144,6 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct
144144 this->UpdateElectronicStructure(electronicStructure, molecule, requireGuess, this->CanOutputLogs());
145145 state.SetCurrentEnergy(electronicStructure->GetElectronicEnergy(elecState));
146146
147- requireGuess = false;
148147 state.SetMatrixForce(electronicStructure->GetForce(elecState));
149148
150149 this->InitializeState(state, molecule);
@@ -154,24 +153,7 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct
154153
155154 this->PrepareState(state, molecule, electronicStructure, elecState);
156155
157- // Take a RFO step
158- bool doLineSearch = false;
159- bool tempCanOutputLogs = false;
160- state.SetInitialEnergy(state.GetCurrentEnergy());
161- if(doLineSearch){
162- this->LineSearch(electronicStructure, molecule, state.GetCurrentEnergyRef(), state.GetMatrixStep(), elecState, dt);
163- }
164- else{
165- this->UpdateMolecularCoordinates(molecule, state.GetMatrixStep());
166-
167- // Broadcast to all processes
168- int root = MolDS_mpi::MpiProcess::GetInstance()->GetHeadRank();
169- molecule.BroadcastConfigurationToAllProcesses(root);
170-
171- this->UpdateElectronicStructure(electronicStructure, molecule, requireGuess, tempCanOutputLogs);
172- state.SetCurrentEnergy(electronicStructure->GetElectronicEnergy(elecState));
173- }
174- this->OutputMoleculeElectronicStructure(electronicStructure, molecule, this->CanOutputLogs());
156+ this->CalcNextStepGeometry(molecule, state, electronicStructure, elecState, dt);
175157
176158 this->UpdateTrustRadius(state.GetTrustRadiusRef(), state.GetApproximateChange(), state.GetInitialEnergy(), state.GetCurrentEnergy());
177159
@@ -246,6 +228,35 @@ void BFGS::PrepareState(OptimizerState& stateOrig,
246228 state.GetVectorStep())
247229 );
248230 }
231+
232+void BFGS::CalcNextStepGeometry(Molecule &molecule,
233+ OptimizerState& stateOrig,
234+ boost::shared_ptr<ElectronicStructure> electronicStructure,
235+ const int elecState,
236+ const double dt) const{
237+ BFGSState& state = stateOrig.CastRef<BFGSState>();
238+
239+ // Take a RFO step
240+ bool doLineSearch = false;
241+ bool tempCanOutputLogs = false;
242+ bool requireGuess = false;
243+ state.SetInitialEnergy(state.GetCurrentEnergy());
244+ if(doLineSearch){
245+ this->LineSearch(electronicStructure, molecule, state.GetCurrentEnergyRef(), state.GetMatrixStep(), elecState, dt);
246+ }
247+ else{
248+ this->UpdateMolecularCoordinates(molecule, state.GetMatrixStep());
249+
250+ // Broadcast to all processes
251+ int root = MolDS_mpi::MpiProcess::GetInstance()->GetHeadRank();
252+ molecule.BroadcastConfigurationToAllProcesses(root);
253+
254+ this->UpdateElectronicStructure(electronicStructure, molecule, requireGuess, tempCanOutputLogs);
255+ state.SetCurrentEnergy(electronicStructure->GetElectronicEnergy(elecState));
256+ }
257+
258+ this->OutputMoleculeElectronicStructure(electronicStructure, molecule, this->CanOutputLogs());
259+}
249260
250261 void BFGS::CalcRFOStep(double* vectorStep,
251262 double const* const* matrixHessian,
--- a/src/optimization/BFGS.h
+++ b/src/optimization/BFGS.h
@@ -96,6 +96,11 @@ protected:
9696 const MolDS_base::Molecule& molecule,
9797 const boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
9898 const int elecState) const;
99+ void CalcNextStepGeometry(MolDS_base::Molecule &molecule,
100+ OptimizerState& state,
101+ boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
102+ const int elecState,
103+ const double dt) const;
99104 void CalcRFOStep(double* vectorStep,
100105 double const* const* matrixHessian,
101106 double const* vectorForce,
--- a/src/optimization/ConjugateGradient.cpp
+++ b/src/optimization/ConjugateGradient.cpp
@@ -104,10 +104,7 @@ void ConjugateGradient::SearchMinimum(boost::shared_ptr<ElectronicStructure> ele
104104
105105 this->PrepareState(state, molecule, electronicStructure, elecState);
106106
107- state.SetInitialEnergy(state.GetCurrentEnergy());
108-
109- // do line search
110- this->LineSearch(electronicStructure, molecule, state.GetCurrentEnergyRef(), state.GetMatrixSearchDirection(), elecState, dt);
107+ this->CalcNextStepGeometry(molecule, state, electronicStructure, elecState, dt);
111108
112109 this->UpdateSearchDirection(state, electronicStructure, molecule, elecState);
113110
@@ -135,6 +132,18 @@ void ConjugateGradient::InitializeState(OptimizerState &stateOrig, const Molecul
135132 }
136133 }
137134
135+void ConjugateGradient::CalcNextStepGeometry(Molecule &molecule,
136+ OptimizerState& stateOrig,
137+ boost::shared_ptr<ElectronicStructure> electronicStructure,
138+ const int elecState,
139+ const double dt) const{
140+ ConjugateGradientState& state = stateOrig.CastRef<ConjugateGradientState>();
141+
142+ state.SetInitialEnergy(state.GetCurrentEnergy());
143+
144+ this->LineSearch(electronicStructure, molecule, state.GetCurrentEnergyRef(), state.GetMatrixSearchDirection(), elecState, dt);
145+}
146+
138147 void ConjugateGradient::UpdateSearchDirection(OptimizerState& stateOrig,
139148 boost::shared_ptr<ElectronicStructure> electronicStructure,
140149 const MolDS_base::Molecule& molecule,
--- a/src/optimization/ConjugateGradient.h
+++ b/src/optimization/ConjugateGradient.h
@@ -53,6 +53,11 @@ private:
5353 const MolDS_base::Molecule& molecule,
5454 const boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
5555 const int elecState) const{};
56+ void CalcNextStepGeometry(MolDS_base::Molecule &molecule,
57+ OptimizerState& state,
58+ boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
59+ const int elecState,
60+ const double dt) const;
5661 void UpdateSearchDirection(OptimizerState& state,
5762 boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
5863 const MolDS_base::Molecule& molecule,
--- a/src/optimization/Optimizer.h
+++ b/src/optimization/Optimizer.h
@@ -108,6 +108,11 @@ private:
108108 const MolDS_base::Molecule& molecule,
109109 const boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
110110 const int elecState) const = 0;
111+ virtual void CalcNextStepGeometry(MolDS_base::Molecule& molecule,
112+ OptimizerState& state,
113+ boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
114+ const int elecState,
115+ const double dt) const= 0;
111116 virtual const std::string& OptimizationStepMessage() const = 0;
112117 };
113118
--- a/src/optimization/SteepestDescent.cpp
+++ b/src/optimization/SteepestDescent.cpp
@@ -87,8 +87,7 @@ void SteepestDescent::SearchMinimum(boost::shared_ptr<ElectronicStructure> elect
8787 this->OutputLog(boost::format("%s%d\n\n") % this->messageStartSteepestDescentStep.c_str() % (s+1));
8888 state.SetInitialEnergy(state.GetCurrentEnergy());
8989
90- // do line search
91- this->LineSearch(electronicStructure, molecule, state.GetCurrentEnergyRef(), state.GetMatrixForce(), elecState, dt);
90+ this->CalcNextStepGeometry(molecule, state, electronicStructure, elecState, dt);
9291
9392 this->UpdateSearchDirection(state, electronicStructure, molecule, elecState);
9493
@@ -107,6 +106,16 @@ void SteepestDescent::SearchMinimum(boost::shared_ptr<ElectronicStructure> elect
107106 *lineSearchedEnergy = state.GetCurrentEnergy();
108107 }
109108
109+void SteepestDescent::CalcNextStepGeometry(Molecule &molecule,
110+ OptimizerState& state,
111+ boost::shared_ptr<ElectronicStructure> electronicStructure,
112+ const int elecState,
113+ const double dt) const{
114+ state.SetInitialEnergy(state.GetCurrentEnergy());
115+
116+ this->LineSearch(electronicStructure, molecule, state.GetCurrentEnergyRef(), state.GetMatrixForce(), elecState, dt);
117+}
118+
110119 void SteepestDescent::UpdateSearchDirection(OptimizerState& state,
111120 boost::shared_ptr<ElectronicStructure> electronicStructure,
112121 const MolDS_base::Molecule& molecule,
--- a/src/optimization/SteepestDescent.h
+++ b/src/optimization/SteepestDescent.h
@@ -41,6 +41,11 @@ private:
4141 const MolDS_base::Molecule& molecule,
4242 const boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
4343 const int elecState) const{};
44+ void CalcNextStepGeometry(MolDS_base::Molecule &molecule,
45+ OptimizerState& state,
46+ boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
47+ const int elecState,
48+ const double dt) const;
4449 void UpdateSearchDirection(OptimizerState& state,
4550 boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
4651 const MolDS_base::Molecule& molecule,