ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/minimizers/Minimizer.hpp
Revision: 1665
Committed: Tue Nov 22 20:38:56 2011 UTC (13 years, 5 months ago) by gezelter
File size: 6637 byte(s)
Log Message:
updated copyright notices

File Contents

# User Rev Content
1 gezelter 507 /*
2 gezelter 246 * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3     *
4     * The University of Notre Dame grants you ("Licensee") a
5     * non-exclusive, royalty free, license to use, modify and
6     * redistribute this software in source and binary code form, provided
7     * that the following conditions are met:
8     *
9 gezelter 1390 * 1. Redistributions of source code must retain the above copyright
10 gezelter 246 * notice, this list of conditions and the following disclaimer.
11     *
12 gezelter 1390 * 2. Redistributions in binary form must reproduce the above copyright
13 gezelter 246 * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the
15     * distribution.
16     *
17     * This software is provided "AS IS," without a warranty of any
18     * kind. All express or implied conditions, representations and
19     * warranties, including any implied warranty of merchantability,
20     * fitness for a particular purpose or non-infringement, are hereby
21     * excluded. The University of Notre Dame and its licensors shall not
22     * be liable for any damages suffered by licensee as a result of
23     * using, modifying or distributing the software or its
24     * derivatives. In no event will the University of Notre Dame or its
25     * licensors be liable for any lost revenue, profit or data, or for
26     * direct, indirect, special, consequential, incidental or punitive
27     * damages, however caused and regardless of the theory of liability,
28     * arising out of the use of or inability to use software, even if the
29     * University of Notre Dame has been advised of the possibility of
30     * such damages.
31 gezelter 1390 *
32     * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
33     * research, please cite the appropriate papers when you publish your
34     * work. Good starting points are:
35     *
36     * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
37     * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
38     * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).
39 gezelter 1665 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40     * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 gezelter 246 */
42    
43 gezelter 1390 #ifndef MINIMIZERS_MINIMIZER_HPP
44     #define MINIMIZERS_MINIMIZER_HPP
45 gezelter 246
46     #include <iostream>
47    
48     #include "io/DumpWriter.hpp"
49     #include "io/StatWriter.hpp"
50     #include "minimizers/MinimizerParameterSet.hpp"
51     #include "brains/ForceManager.hpp"
52    
53     // base class of minimizer
54    
55 gezelter 1390 namespace OpenMD {
56 gezelter 246
57 gezelter 507 /** @todo need refactorying */
58     const int MIN_LSERROR = -1;
59     const int MIN_MAXITER = 0;
60     const int MIN_CONVERGE = 1;
61 gezelter 246
62 gezelter 507 const int CONVG_UNCONVG = 0;
63     const int CONVG_FTOL = 1;
64     const int CONVG_GTOL = 2;
65     const int CONVG_ABSGTOL = 3;
66     const int CONVG_STEPTOL = 4;
67 gezelter 246
68 gezelter 507 const int LS_SUCCEED =1;
69     const int LS_ERROR = -1;
70 gezelter 246
71 gezelter 507 /** @todo move to math module */
72 tim 963 RealType dotProduct(const std::vector<RealType>& v1, const std::vector<RealType>& v2);
73 gezelter 246
74 gezelter 507 /**
75     * @class Minimizer
76     * base minimizer class
77     */
78     class Minimizer {
79     public:
80 gezelter 246
81 gezelter 507 Minimizer(SimInfo *rhs);
82 gezelter 246
83 gezelter 507 virtual ~Minimizer();
84 gezelter 246
85 gezelter 507 //
86     virtual void init() {}
87 gezelter 246
88 gezelter 507 //driver function of minimization method
89     virtual void minimize();
90 gezelter 246
91 gezelter 507 //
92     virtual int step() = 0;
93 gezelter 246
94 gezelter 507 //
95     virtual void prepareStep() {};
96 gezelter 246
97 gezelter 507 //line search algorithm, for the time being, we use back track algorithm
98 tim 963 virtual int doLineSearch(std::vector<RealType>& direction, RealType stepSize);
99 gezelter 246
100 gezelter 507 virtual int checkConvg() = 0;
101 gezelter 246
102 gezelter 507 //save the result when minimization method is done
103     virtual void saveResult(){}
104 gezelter 246
105 gezelter 507 //get the status of minimization
106     int getMinStatus() {return minStatus;}
107 gezelter 246
108 gezelter 507 // get the dimension of the model
109     int getDim() { return ndim; }
110 gezelter 246
111 gezelter 507 //get the name of minimizer method
112     std::string getMinimizerName() { return minimizerName; }
113 gezelter 246
114 gezelter 507 //return number of current Iteration
115     int getCurIter() { return curIter; }
116 gezelter 246
117 gezelter 507 // set the verbose mode of minimizer
118     void setVerbose(bool verbose) { bVerbose = verbose;}
119 gezelter 246
120 gezelter 507 //get and set the coordinate
121 tim 963 std::vector<RealType> getX() { return curX; }
122     void setX(std::vector<RealType>& x);
123 gezelter 246
124 gezelter 507 //get and set the value of object function
125 tim 963 RealType getF() { return curF; }
126     void setF(RealType f) { curF = f; }
127 gezelter 246
128 tim 963 std::vector<RealType> getG() { return curG; }
129     void setG(std::vector<RealType>& g);
130 gezelter 246
131 gezelter 507 //get and set the gradient
132 tim 963 std::vector<RealType> getGrad() { return curG; }
133     void setGrad(std::vector<RealType>& g) { curG = g; }
134 gezelter 246
135 gezelter 1390 //interal function to evaluate the energy and gradient in OpenMD
136 tim 963 void calcEnergyGradient(std::vector<RealType>& x, std::vector<RealType>& grad, RealType&
137 gezelter 507 energy, int& status);
138 gezelter 246
139 gezelter 507 //calculate the value of object function
140     virtual void calcF();
141 tim 963 virtual void calcF(std::vector<RealType>& x, RealType&f, int& status);
142 gezelter 246
143 gezelter 507 //calculate the gradient
144     virtual void calcG();
145 tim 963 virtual void calcG(std::vector<RealType>& x, std::vector<RealType>& g, RealType& f, int& status);
146 gezelter 246
147 gezelter 507 //calculate the hessian
148     //virtual void calcH(int& status);
149 tim 963 //virtual void calcH(vector<RealType>& x, std::vector<dobule>& g, SymMatrix& h, int& status);
150 gezelter 246
151 gezelter 507 friend std::ostream& operator<<(std::ostream& os, const Minimizer& minimizer);
152 gezelter 246
153 gezelter 507 protected:
154 gezelter 246
155 gezelter 507 // transfrom cartesian and rotational coordinates into minimization coordinates
156 tim 963 std::vector<RealType> getCoor();
157 gezelter 246
158 gezelter 507 // transfrom minimization coordinates into cartesian and rotational coordinates
159 tim 963 void setCoor(std::vector<RealType>& x);
160 gezelter 246
161    
162    
163 gezelter 507 //constraint the bonds;
164     int shakeR() { return 0;}
165 gezelter 246
166 gezelter 507 //remove the force component along the bond direction
167     int shakeF() { return 0;}
168 gezelter 246
169 tim 963 RealType calcPotential();
170 gezelter 246
171 gezelter 507 SimInfo* info;
172 gezelter 246
173 gezelter 507 ForceManager* forceMan;
174 gezelter 246
175 gezelter 507 //parameter set of minimization method
176     MinimizerParameterSet* paramSet;
177 gezelter 246
178 gezelter 507 //flag of turning on shake algorithm
179     bool usingShake;
180 gezelter 246
181 gezelter 507 // dimension of the model
182     int ndim;
183 gezelter 246
184 gezelter 507 //name of the minimizer
185     std::string minimizerName;
186 gezelter 246
187 gezelter 507 // current iteration number
188     int curIter;
189     //status of minimization
190     int minStatus;
191 gezelter 246
192 gezelter 507 //flag of verbose mode
193     bool bVerbose;
194 gezelter 246
195 gezelter 507 //status of energy and gradient evaluation
196     int egEvalStatus;
197 gezelter 246
198 gezelter 507 //initial coordinates
199 tim 963 //vector<RealType> initX;
200 gezelter 246
201 gezelter 507 //current value of the function
202 tim 963 RealType curF;
203 gezelter 246
204 gezelter 507 // current coordinates
205 tim 963 std::vector<RealType> curX;
206 gezelter 246
207 gezelter 507 //gradient at curent coordinates
208 tim 963 std::vector<RealType> curG;
209 gezelter 246
210 gezelter 507 //hessian at current coordinates
211     //SymMatrix curH;
212 gezelter 246
213 gezelter 507 private:
214 gezelter 246
215 gezelter 507 //calculate the dimension od the model for minimization
216     void calcDim();
217 gezelter 246
218 gezelter 507 };
219 gezelter 246
220     }
221     #endif
222    

Properties

Name Value
svn:executable *
svn:keywords Author Id Revision Date