修訂 | 5e5e06ef01b08a5c0f03ee5eba75f5237038d311 (tree) |
---|---|
時間 | 2014-01-17 11:24:08 |
作者 | Katsuhiko Nishimra <ktns.87@gmai...> |
Commiter | Katsuhiko Nishimra |
Factor out Optimizer::CalcNextStepGeometry. #32881
git-svn-id: https://svn.sourceforge.jp/svnroot/molds/branches/refactor_opt@1646 1136aad2-a195-0410-b898-f5ea1d11b9d8
@@ -144,7 +144,6 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct | ||
144 | 144 | this->UpdateElectronicStructure(electronicStructure, molecule, requireGuess, this->CanOutputLogs()); |
145 | 145 | state.SetCurrentEnergy(electronicStructure->GetElectronicEnergy(elecState)); |
146 | 146 | |
147 | - requireGuess = false; | |
148 | 147 | state.SetMatrixForce(electronicStructure->GetForce(elecState)); |
149 | 148 | |
150 | 149 | this->InitializeState(state, molecule); |
@@ -154,24 +153,7 @@ void BFGS::SearchMinimum(boost::shared_ptr<ElectronicStructure> electronicStruct | ||
154 | 153 | |
155 | 154 | this->PrepareState(state, molecule, electronicStructure, elecState); |
156 | 155 | |
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); | |
175 | 157 | |
176 | 158 | this->UpdateTrustRadius(state.GetTrustRadiusRef(), state.GetApproximateChange(), state.GetInitialEnergy(), state.GetCurrentEnergy()); |
177 | 159 |
@@ -246,6 +228,35 @@ void BFGS::PrepareState(OptimizerState& stateOrig, | ||
246 | 228 | state.GetVectorStep()) |
247 | 229 | ); |
248 | 230 | } |
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 | +} | |
249 | 260 | |
250 | 261 | void BFGS::CalcRFOStep(double* vectorStep, |
251 | 262 | double const* const* matrixHessian, |
@@ -96,6 +96,11 @@ protected: | ||
96 | 96 | const MolDS_base::Molecule& molecule, |
97 | 97 | const boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure, |
98 | 98 | 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; | |
99 | 104 | void CalcRFOStep(double* vectorStep, |
100 | 105 | double const* const* matrixHessian, |
101 | 106 | double const* vectorForce, |
@@ -104,10 +104,7 @@ void ConjugateGradient::SearchMinimum(boost::shared_ptr<ElectronicStructure> ele | ||
104 | 104 | |
105 | 105 | this->PrepareState(state, molecule, electronicStructure, elecState); |
106 | 106 | |
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); | |
111 | 108 | |
112 | 109 | this->UpdateSearchDirection(state, electronicStructure, molecule, elecState); |
113 | 110 |
@@ -135,6 +132,18 @@ void ConjugateGradient::InitializeState(OptimizerState &stateOrig, const Molecul | ||
135 | 132 | } |
136 | 133 | } |
137 | 134 | |
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 | + | |
138 | 147 | void ConjugateGradient::UpdateSearchDirection(OptimizerState& stateOrig, |
139 | 148 | boost::shared_ptr<ElectronicStructure> electronicStructure, |
140 | 149 | const MolDS_base::Molecule& molecule, |
@@ -53,6 +53,11 @@ private: | ||
53 | 53 | const MolDS_base::Molecule& molecule, |
54 | 54 | const boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure, |
55 | 55 | 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; | |
56 | 61 | void UpdateSearchDirection(OptimizerState& state, |
57 | 62 | boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure, |
58 | 63 | const MolDS_base::Molecule& molecule, |
@@ -108,6 +108,11 @@ private: | ||
108 | 108 | const MolDS_base::Molecule& molecule, |
109 | 109 | const boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure, |
110 | 110 | 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; | |
111 | 116 | virtual const std::string& OptimizationStepMessage() const = 0; |
112 | 117 | }; |
113 | 118 |
@@ -87,8 +87,7 @@ void SteepestDescent::SearchMinimum(boost::shared_ptr<ElectronicStructure> elect | ||
87 | 87 | this->OutputLog(boost::format("%s%d\n\n") % this->messageStartSteepestDescentStep.c_str() % (s+1)); |
88 | 88 | state.SetInitialEnergy(state.GetCurrentEnergy()); |
89 | 89 | |
90 | - // do line search | |
91 | - this->LineSearch(electronicStructure, molecule, state.GetCurrentEnergyRef(), state.GetMatrixForce(), elecState, dt); | |
90 | + this->CalcNextStepGeometry(molecule, state, electronicStructure, elecState, dt); | |
92 | 91 | |
93 | 92 | this->UpdateSearchDirection(state, electronicStructure, molecule, elecState); |
94 | 93 |
@@ -107,6 +106,16 @@ void SteepestDescent::SearchMinimum(boost::shared_ptr<ElectronicStructure> elect | ||
107 | 106 | *lineSearchedEnergy = state.GetCurrentEnergy(); |
108 | 107 | } |
109 | 108 | |
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 | + | |
110 | 119 | void SteepestDescent::UpdateSearchDirection(OptimizerState& state, |
111 | 120 | boost::shared_ptr<ElectronicStructure> electronicStructure, |
112 | 121 | const MolDS_base::Molecule& molecule, |
@@ -41,6 +41,11 @@ private: | ||
41 | 41 | const MolDS_base::Molecule& molecule, |
42 | 42 | const boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure, |
43 | 43 | 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; | |
44 | 49 | void UpdateSearchDirection(OptimizerState& state, |
45 | 50 | boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure, |
46 | 51 | const MolDS_base::Molecule& molecule, |