ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/OOPSEMinimizer.hpp
Revision: 1234
Committed: Fri Jun 4 03:15:31 2004 UTC (20 years, 1 month ago) by tim
File size: 5656 byte(s)
Log Message:
new rattle algorithm is working

File Contents

# Content
1 #ifndef _OOPSEMINIMIZER_H_
2 #define _OOPSEMINIMIZER_H_
3
4 #include <iostream>
5
6 #include "Integrator.hpp"
7 #include "MinimizerParameterSet.hpp"
8
9
10 using namespace std;
11
12 const int MIN_LSERROR = -1;
13 const int MIN_MAXITER = 0;
14 const int MIN_CONVERGE = 1;
15
16 const int CONVG_UNCONVG = 0;
17 const int CONVG_FTOL = 1;
18 const int CONVG_GTOL = 2;
19 const int CONVG_ABSGTOL = 3;
20 const int CONVG_STEPTOL = 4;
21
22 const int LS_SUCCEED =1;
23 const int LS_ERROR = -1;
24
25 // base class of minimizer
26 class ShakeMinFramework;
27 class OOPSEMinimizer : public RealIntegrator{
28 public:
29
30 OOPSEMinimizer(SimInfo *theInfo, ForceFields* the_ff,
31 MinimizerParameterSet* param);
32 virtual ~OOPSEMinimizer();
33
34 //
35 virtual void init() {}
36
37 //driver function of minimization method
38 virtual void minimize();
39
40 //
41 virtual int step() = 0;
42
43 //
44 virtual void prepareStep() {};
45
46 //line search algorithm, for the time being, we use back track algorithm
47 virtual int doLineSearch(vector<double>& direction, double stepSize);
48
49 virtual int checkConvg() = 0;
50
51 //print detail information of the minimization method
52 virtual void printMinimizerInfo();
53
54 //save the result when minimization method is done
55 virtual void saveResult(){}
56
57 //write out the trajectory
58 virtual void writeOut(vector<double>&x, double curIter);
59
60
61 //get the status of minimization
62 int getMinStatus() {return minStatus;}
63
64 // get the dimension of the model
65 int getDim() { return ndim; }
66
67 //get the name of minimizer method
68 string getMinimizerName() { return minimizerName; }
69
70 //return number of current Iteration
71 int getCurIter() { return curIter; }
72
73 // set the verbose mode of minimizer
74 void setVerbose(bool verbose) { bVerbose = verbose;}
75
76 //get and set the coordinate
77 vector<double> getX() { return curX; }
78 void setX(vector<double>& x);
79
80 //get and set the value of object function
81 double getF() { return curF; }
82 void setF(double f) { curF = f; }
83
84 vector<double> getG() { return curG; }
85 void setG(vector<double>& g);
86
87 //get and set the gradient
88 vector<double> getGrad() { return curG; }
89 void setGrad(vector<double>& g) { curG = g; }
90
91 //interal function to evaluate the energy and gradient in OOPSE
92 void calcEnergyGradient(vector<double>& x, vector<double>& grad, double&
93 energy, int& status);
94
95 //calculate the value of object function
96 virtual void calcF();
97 virtual void calcF(vector<double>& x, double&f, int& status);
98
99 //calculate the gradient
100 virtual void calcG();
101 virtual void calcG(vector<double>& x, vector<double>& g, double& f, int& status);
102
103 //calculate the hessian
104 //virtual void calcH(int& status);
105 //virtual void calcH(vector<double>& x, vector<dobule>& g, SymMatrix& h, int& status);
106
107
108 protected:
109
110 // transfrom cartesian and rotational coordinates into minimization coordinates
111 vector<double> getCoor();
112
113 // transfrom minimization coordinates into cartesian and rotational coordinates
114 void setCoor(vector<double>& x);
115
116 //flag of turning on shake algorithm
117 bool bShake;
118
119 //constraint the bonds;
120 //int shakeR();
121
122 //remove the force component along the bond direction
123 //int shakeF();
124
125 // dimension of the model
126 int ndim;
127
128 //name of the minimizer
129 string minimizerName;
130
131 // current iteration number
132 int curIter;
133 //status of minimization
134 int minStatus;;
135
136 //flag of verbose mode
137 bool bVerbose;
138
139
140 //parameter set of minimization method
141 MinimizerParameterSet* paramSet;
142
143 //status of energy and gradient evaluation
144 int egEvalStatus;
145
146 //initial coordinates
147 //vector<double> initX;
148
149 //current value of the function
150 double curF;
151 // current coordinates
152 vector<double> curX;
153 //gradient at curent coordinates
154 vector<double> curG;
155
156 //hessian at current coordinates
157 //SymMatrix curH;
158
159 private:
160
161 //calculate the dimension od the model for minimization
162 void calcDim();
163
164 ShakeMinFramework* shakeAlgo;
165
166 };
167
168 // steepest descent minimizer
169 class SDMinimizer : public OOPSEMinimizer{
170 public:
171 SDMinimizer(SimInfo *theInfo, ForceFields* the_ff,
172 MinimizerParameterSet* param);
173
174 virtual void init();
175 virtual int step();
176 virtual void prepareStep();
177 virtual int checkConvg();
178 protected:
179
180 vector<double> direction;
181 double prevF;
182 double stepSize;
183
184 };
185
186 // conjugate gradient famlily minimzier
187 class CGFamilyMinmizer : public OOPSEMinimizer{
188 public:
189 CGFamilyMinmizer(SimInfo *theInfo, ForceFields* the_ff,
190 MinimizerParameterSet* param);
191
192 //check the convergence
193 virtual int checkConvg();
194
195
196 protected:
197
198 vector<double> direction;
199 vector<double> prevX;
200 vector<double> prevG;
201 double prevF;
202 double stepSize;
203 };
204
205 //Polak-Ribiere Conjugate Gradient Method
206 class PRCGMinimizer : public CGFamilyMinmizer{
207 public:
208 PRCGMinimizer(SimInfo *theInfo, ForceFields* the_ff,
209 MinimizerParameterSet* param)
210 :CGFamilyMinmizer(theInfo, the_ff, param) {}
211 virtual int step();
212 virtual void init();
213 virtual void prepareStep();
214 };
215
216 #endif

Properties

Name Value
svn:executable *