ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/minimizers/OOPSEMinimizer.hpp
Revision: 1900
Committed: Tue Jan 4 22:18:06 2005 UTC (20 years, 7 months ago) by tim
File size: 6240 byte(s)
Log Message:
minimizers in progress

File Contents

# User Rev Content
1 tim 1884 /*
2     * Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project
3     *
4     * Contact: oopse@oopse.org
5     *
6     * This program is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU Lesser General Public License
8     * as published by the Free Software Foundation; either version 2.1
9     * of the License, or (at your option) any later version.
10     * All we ask is that proper credit is given for our work, which includes
11     * - but is not limited to - adding the above copyright notice to the beginning
12     * of your source code files, and to any copyright notice that you may distribute
13     * with programs based on this work.
14     *
15     * This program is distributed in the hope that it will be useful,
16     * but WITHOUT ANY WARRANTY; without even the implied warranty of
17     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     * GNU Lesser General Public License for more details.
19     *
20     * You should have received a copy of the GNU Lesser General Public License
21     * along with this program; if not, write to the Free Software
22     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23     *
24     */
25 gezelter 1490
26 tim 1884 #ifndef MINIMIZERS_OOPSEMINIMIZER_HPP
27     #define MINIMIZERS_OOPSEMINIMIZER_HPP
28    
29 gezelter 1490 #include <iostream>
30    
31 tim 1492 #include "integrators/Integrator.hpp"
32 tim 1900 #include "io/DumpWriter.hpp"
33     #include "io/StatWriter.hpp"
34 tim 1492 #include "minimizers/MinimizerParameterSet.hpp"
35 tim 1900 #include "brains/ForceManager.hpp"
36 gezelter 1490
37 tim 1884 // base class of minimizer
38    
39     namespace oopse {
40    
41     /** @todo need refactorying */
42 gezelter 1490 const int MIN_LSERROR = -1;
43     const int MIN_MAXITER = 0;
44     const int MIN_CONVERGE = 1;
45    
46     const int CONVG_UNCONVG = 0;
47     const int CONVG_FTOL = 1;
48     const int CONVG_GTOL = 2;
49     const int CONVG_ABSGTOL = 3;
50     const int CONVG_STEPTOL = 4;
51    
52     const int LS_SUCCEED =1;
53     const int LS_ERROR = -1;
54    
55 tim 1900 /** @todo move to math module */
56     double dotProduct(const std::vector<double>& v1, const std::vector<double>& v2) {
57     if (v1.size() != v2.size()) {
58 gezelter 1490
59 tim 1900 }
60    
61    
62     double result = 0.0;
63     for (unsigned int i = 0; i < v1.size(); ++i) {
64     result += v1[i] * v2[i];
65     }
66    
67     return result;
68     }
69    
70     /**
71     * @class OOPSEMinimizer
72     * base minimizer class
73     */
74 tim 1884 class OOPSEMinimizer {
75     public:
76 gezelter 1490
77 tim 1900 OOPSEMinimizer(SimInfo *rhs);
78 gezelter 1490
79 tim 1884 virtual ~OOPSEMinimizer();
80 gezelter 1490
81 tim 1884 //
82     virtual void init() {}
83 gezelter 1490
84 tim 1884 //driver function of minimization method
85     virtual void minimize();
86 gezelter 1490
87 tim 1884 //
88     virtual int step() = 0;
89 gezelter 1490
90 tim 1884 //
91     virtual void prepareStep() {};
92 gezelter 1490
93 tim 1884 //line search algorithm, for the time being, we use back track algorithm
94     virtual int doLineSearch(std::vector<double>& direction, double stepSize);
95 gezelter 1490
96 tim 1884 virtual int checkConvg() = 0;
97 gezelter 1490
98 tim 1884 //print detail information of the minimization method
99     virtual void printMinimizerInfo();
100 gezelter 1490
101 tim 1884 //save the result when minimization method is done
102     virtual void saveResult(){}
103 gezelter 1490
104 tim 1884 //get the status of minimization
105     int getMinStatus() {return minStatus;}
106 gezelter 1490
107 tim 1884 // get the dimension of the model
108     int getDim() { return ndim; }
109 gezelter 1490
110 tim 1884 //get the name of minimizer method
111     std::string getMinimizerName() { return minimizerName; }
112 gezelter 1490
113 tim 1884 //return number of current Iteration
114     int getCurIter() { return curIter; }
115 gezelter 1490
116 tim 1884 // set the verbose mode of minimizer
117     void setVerbose(bool verbose) { bVerbose = verbose;}
118 gezelter 1490
119 tim 1884 //get and set the coordinate
120     std::vector<double> getX() { return curX; }
121     void setX(std::vector<double>& x);
122 gezelter 1490
123 tim 1884 //get and set the value of object function
124     double getF() { return curF; }
125     void setF(double f) { curF = f; }
126 gezelter 1490
127 tim 1884 std::vector<double> getG() { return curG; }
128     void setG(std::vector<double>& g);
129 gezelter 1490
130 tim 1884 //get and set the gradient
131     std::vector<double> getGrad() { return curG; }
132     void setGrad(std::vector<double>& g) { curG = g; }
133 gezelter 1490
134 tim 1884 //interal function to evaluate the energy and gradient in OOPSE
135 tim 1900 void calcEnergyGradient(std::vector<double>& x, std::vector<double>& grad, double&
136 tim 1884 energy, int& status);
137 gezelter 1490
138 tim 1884 //calculate the value of object function
139     virtual void calcF();
140     virtual void calcF(std::vector<double>& x, double&f, int& status);
141 gezelter 1490
142 tim 1884 //calculate the gradient
143     virtual void calcG();
144     virtual void calcG(std::vector<double>& x, std::vector<double>& g, double& f, int& status);
145 gezelter 1490
146 tim 1884 //calculate the hessian
147     //virtual void calcH(int& status);
148     //virtual void calcH(vector<double>& x, std::vector<dobule>& g, SymMatrix& h, int& status);
149 gezelter 1490
150 tim 1900 friend std::ostream& operator<<(std::ostream& os, const OOPSEMinimizer& minimizer);
151 gezelter 1490
152 tim 1884 protected:
153 gezelter 1490
154 tim 1884 // transfrom cartesian and rotational coordinates into minimization coordinates
155     std::vector<double> getCoor();
156 gezelter 1490
157 tim 1884 // transfrom minimization coordinates into cartesian and rotational coordinates
158     void setCoor(std::vector<double>& x);
159 gezelter 1490
160    
161 tim 1900
162 tim 1884 //constraint the bonds;
163     int shakeR();
164 gezelter 1490
165 tim 1884 //remove the force component along the bond direction
166     int shakeF();
167 gezelter 1490
168 tim 1900 double calcPotential();
169    
170     SimInfo* info;
171 gezelter 1490
172 tim 1900 ForceManager* forceMan;
173 tim 1884
174     //parameter set of minimization method
175     MinimizerParameterSet* paramSet;
176 gezelter 1490
177 tim 1900 //flag of turning on shake algorithm
178     bool usingShake;
179    
180 tim 1884 // dimension of the model
181     int ndim;
182 gezelter 1490
183 tim 1884 //name of the minimizer
184     std::string minimizerName;
185 gezelter 1490
186 tim 1884 // current iteration number
187     int curIter;
188     //status of minimization
189     int minStatus;
190 gezelter 1490
191 tim 1884 //flag of verbose mode
192     bool bVerbose;
193 gezelter 1490
194 tim 1884 //status of energy and gradient evaluation
195     int egEvalStatus;
196 gezelter 1490
197 tim 1884 //initial coordinates
198     //vector<double> initX;
199 gezelter 1490
200 tim 1884 //current value of the function
201     double curF;
202 tim 1900
203 tim 1884 // current coordinates
204     std::vector<double> curX;
205 tim 1900
206 tim 1884 //gradient at curent coordinates
207     std::vector<double> curG;
208 gezelter 1490
209 tim 1884 //hessian at current coordinates
210     //SymMatrix curH;
211 gezelter 1490
212 tim 1884 private:
213 gezelter 1490
214 tim 1884 //calculate the dimension od the model for minimization
215     void calcDim();
216 gezelter 1490
217     };
218    
219 tim 1884 }
220     #endif
221 gezelter 1490

Properties

Name Value
svn:executable *