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

Properties

Name Value
svn:executable *