• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

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

コミットメタ情報

リビジョンda53aa73a47676fece7c7c572fb11894a1a3c7b1 (tree)
日時2014-01-10 17:04:35
作者Katsuhiko Nishimra <ktns.87@gmai...>
コミッターKatsuhiko Nishimra

ログメッセージ

Refactor UpdateSearchDirection using OptimizerState. #32881

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

変更サマリ

差分

--- a/src/optimization/ConjugateGradient.cpp
+++ b/src/optimization/ConjugateGradient.cpp
@@ -110,8 +110,7 @@ void ConjugateGradient::SearchMinimum(boost::shared_ptr<ElectronicStructure> ele
110110 // do line search
111111 this->LineSearch(electronicStructure, molecule, state.GetCurrentEnergyRef(), state.GetMatrixSearchDirection(), elecState, dt);
112112
113- // update matrixSearchDirection
114- this->UpdateSearchDirection(state.GetMatrixForcePtr(), state.GetOldMatrixForce(), state.GetMatrixSearchDirection(), electronicStructure, molecule, elecState);
113+ this->UpdateSearchDirection(state, electronicStructure, molecule, elecState);
115114
116115 // check convergence
117116 if(this->SatisfiesConvergenceCriterion(state.GetMatrixForce(),
@@ -128,33 +127,37 @@ void ConjugateGradient::SearchMinimum(boost::shared_ptr<ElectronicStructure> ele
128127 *lineSearchedEnergy = state.GetCurrentEnergy();
129128 }
130129
131-void ConjugateGradient::UpdateSearchDirection(double const* const** matrixForce,
132- double** oldMatrixForce,
133- double** matrixSearchDirection,
130+void ConjugateGradient::UpdateSearchDirection(OptimizerState& stateOrig,
134131 boost::shared_ptr<ElectronicStructure> electronicStructure,
135132 const MolDS_base::Molecule& molecule,
136133 int elecState) const{
137- for(int a=0;a<molecule.GetAtomVect().size();a++){
138- for(int i=0; i<CartesianType_end; i++){
139- oldMatrixForce[a][i] = (*matrixForce)[a][i];
134+ try{
135+ ConjugateGradientState& state = dynamic_cast<ConjugateGradientState&>(stateOrig);
136+ for(int a=0;a<molecule.GetAtomVect().size();a++){
137+ for(int i=0; i<CartesianType_end; i++){
138+ state.GetOldMatrixForce()[a][i] = state.GetMatrixForce()[a][i];
139+ }
140140 }
141- }
142- *matrixForce = electronicStructure->GetForce(elecState);
143- double beta=0.0;
144- double temp=0.0;
145- for(int a=0;a<molecule.GetAtomVect().size();a++){
146- for(int i=0; i<CartesianType_end; i++){
147- temp += pow(oldMatrixForce[a][i],2.0);
148- beta += ((*matrixForce)[a][i] - oldMatrixForce[a][i])*(*matrixForce)[a][i];
141+ state.SetMatrixForce(electronicStructure->GetForce(elecState));
142+ double beta=0.0;
143+ double temp=0.0;
144+ for(int a=0;a<molecule.GetAtomVect().size();a++){
145+ for(int i=0; i<CartesianType_end; i++){
146+ temp += pow(state.GetOldMatrixForce()[a][i],2.0);
147+ beta += (state.GetMatrixForce()[a][i] - state.GetOldMatrixForce()[a][i])*state.GetMatrixForce()[a][i];
148+ }
149149 }
150- }
151- beta /= temp;
152- for(int a=0;a<molecule.GetAtomVect().size();a++){
153- for(int i=0; i<CartesianType_end; i++){
154- matrixSearchDirection[a][i] *= beta;
155- matrixSearchDirection[a][i] += (*matrixForce)[a][i];
150+ beta /= temp;
151+ for(int a=0;a<molecule.GetAtomVect().size();a++){
152+ for(int i=0; i<CartesianType_end; i++){
153+ state.GetMatrixSearchDirection()[a][i] *= beta;
154+ state.GetMatrixSearchDirection()[a][i] += state.GetMatrixForce()[a][i];
155+ }
156156 }
157157 }
158+ catch(std::bad_cast& ex){
159+ throw MolDSException(this->errorMessageFailedToDowncastState);
160+ }
158161 }
159162
160163
--- a/src/optimization/ConjugateGradient.h
+++ b/src/optimization/ConjugateGradient.h
@@ -45,9 +45,7 @@ private:
4545 MolDS_base::Molecule& molecule,
4646 double* lineSearchedEnergy,
4747 bool* obainesOptimizedStructure) const;
48- void UpdateSearchDirection(double const* const** matrixForce,
49- double** oldMatrixForce,
50- double** matrixSearchDirection,
48+ void UpdateSearchDirection(OptimizerState& state,
5149 boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
5250 const MolDS_base::Molecule& molecule,
5351 int elecState) const;
--- a/src/optimization/Optimizer.cpp
+++ b/src/optimization/Optimizer.cpp
@@ -89,6 +89,8 @@ void Optimizer::Optimize(Molecule& molecule){
8989 void Optimizer::SetMessages(){
9090 this->errorMessageTheoryType = "\ttheory type = ";
9191 this->errorMessageTotalSteps = "\tTotal steps = ";
92+ this->errorMessageFailedToDowncastState
93+ = "Failed to downcast Optimizer::OptimizerState!";
9294 this->messageGeometyrOptimizationMetConvergence
9395 = "\t\tGeometry otimization met convergence criterion(^^b\n\n\n";
9496 this->messageStartGeometryOptimization = "********** START: Geometry optimization **********\n";
--- a/src/optimization/Optimizer.h
+++ b/src/optimization/Optimizer.h
@@ -48,6 +48,7 @@ public:
4848 protected:
4949 std::string errorMessageNotEnebleTheoryType;
5050 std::string errorMessageGeometyrOptimizationNotConverged;
51+ std::string errorMessageFailedToDowncastState;
5152 std::string messageLineSearchSteps;
5253 virtual void SetMessages();
5354 void UpdateMolecularCoordinates(MolDS_base::Molecule& molecule, double const* const* matrixForce, double dt) const;
--- a/src/optimization/SteepestDescent.cpp
+++ b/src/optimization/SteepestDescent.cpp
@@ -90,8 +90,7 @@ void SteepestDescent::SearchMinimum(boost::shared_ptr<ElectronicStructure> elect
9090 // do line search
9191 this->LineSearch(electronicStructure, molecule, state.GetCurrentEnergyRef(), state.GetMatrixForce(), elecState, dt);
9292
93- // update force
94- state.SetMatrixForce(electronicStructure->GetForce(elecState));
93+ this->UpdateSearchDirection(state, electronicStructure, molecule, elecState);
9594
9695 // check convergence
9796 if(this->SatisfiesConvergenceCriterion(state.GetMatrixForce(),
@@ -103,11 +102,16 @@ void SteepestDescent::SearchMinimum(boost::shared_ptr<ElectronicStructure> elect
103102 *obtainesOptimizedStructure = true;
104103 break;
105104 }
106-
107105 }
106+
108107 *lineSearchedEnergy = state.GetCurrentEnergy();
109108 }
110-}
111-
112-
113109
110+void SteepestDescent::UpdateSearchDirection(OptimizerState& state,
111+ boost::shared_ptr<ElectronicStructure> electronicStructure,
112+ const MolDS_base::Molecule& molecule,
113+ int elecState) const{
114+ // update force
115+ state.SetMatrixForce(electronicStructure->GetForce(elecState));
116+}
117+}
--- a/src/optimization/SteepestDescent.h
+++ b/src/optimization/SteepestDescent.h
@@ -33,6 +33,10 @@ private:
3333 MolDS_base::Molecule& molecule,
3434 double* lineSearchedEnergy,
3535 bool* obainesOptimizedStructure) const;
36+ void UpdateSearchDirection(OptimizerState& state,
37+ boost::shared_ptr<MolDS_base::ElectronicStructure> electronicStructure,
38+ const MolDS_base::Molecule& molecule,
39+ int elecState) const;
3640 };
3741
3842 }