ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/OOPSEMinimizer.hpp
Revision: 1330
Committed: Fri Jul 16 16:29:44 2004 UTC (19 years, 11 months ago) by gezelter
File size: 5658 byte(s)
Log Message:
Minor changes

File Contents

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

Properties

Name Value
svn:executable *