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