| 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 |
| 9 |
> |
* 1. Redistributions of source code must retain the above copyright |
| 10 |
|
* notice, this list of conditions and the following disclaimer. |
| 11 |
|
* |
| 12 |
< |
* 3. Redistributions in binary form must reproduce the above copyright |
| 12 |
> |
* 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
|
* notice, this list of conditions and the following disclaimer in the |
| 14 |
|
* documentation and/or other materials provided with the |
| 15 |
|
* distribution. |
| 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 |
+ |
* |
| 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 |
+ |
* [4] Vardeman & Gezelter, in progress (2009). |
| 40 |
|
*/ |
| 41 |
|
|
| 42 |
< |
#ifndef MINIMIZERS_OOPSEMINIMIZER_HPP |
| 43 |
< |
#define MINIMIZERS_OOPSEMINIMIZER_HPP |
| 42 |
> |
#ifndef MINIMIZERS_MINIMIZER_HPP |
| 43 |
> |
#define MINIMIZERS_MINIMIZER_HPP |
| 44 |
|
|
| 45 |
|
#include <iostream> |
| 46 |
|
|
| 51 |
|
|
| 52 |
|
// base class of minimizer |
| 53 |
|
|
| 54 |
< |
namespace oopse { |
| 54 |
> |
namespace OpenMD { |
| 55 |
|
|
| 56 |
|
/** @todo need refactorying */ |
| 57 |
|
const int MIN_LSERROR = -1; |
| 68 |
|
const int LS_ERROR = -1; |
| 69 |
|
|
| 70 |
|
/** @todo move to math module */ |
| 71 |
< |
double dotProduct(const std::vector<double>& v1, const std::vector<double>& v2); |
| 71 |
> |
RealType dotProduct(const std::vector<RealType>& v1, const std::vector<RealType>& v2); |
| 72 |
|
|
| 73 |
|
/** |
| 74 |
|
* @class Minimizer |
| 94 |
|
virtual void prepareStep() {}; |
| 95 |
|
|
| 96 |
|
//line search algorithm, for the time being, we use back track algorithm |
| 97 |
< |
virtual int doLineSearch(std::vector<double>& direction, double stepSize); |
| 97 |
> |
virtual int doLineSearch(std::vector<RealType>& direction, RealType stepSize); |
| 98 |
|
|
| 99 |
|
virtual int checkConvg() = 0; |
| 100 |
|
|
| 117 |
|
void setVerbose(bool verbose) { bVerbose = verbose;} |
| 118 |
|
|
| 119 |
|
//get and set the coordinate |
| 120 |
< |
std::vector<double> getX() { return curX; } |
| 121 |
< |
void setX(std::vector<double>& x); |
| 120 |
> |
std::vector<RealType> getX() { return curX; } |
| 121 |
> |
void setX(std::vector<RealType>& x); |
| 122 |
|
|
| 123 |
|
//get and set the value of object function |
| 124 |
< |
double getF() { return curF; } |
| 125 |
< |
void setF(double f) { curF = f; } |
| 124 |
> |
RealType getF() { return curF; } |
| 125 |
> |
void setF(RealType f) { curF = f; } |
| 126 |
|
|
| 127 |
< |
std::vector<double> getG() { return curG; } |
| 128 |
< |
void setG(std::vector<double>& g); |
| 127 |
> |
std::vector<RealType> getG() { return curG; } |
| 128 |
> |
void setG(std::vector<RealType>& g); |
| 129 |
|
|
| 130 |
|
//get and set the gradient |
| 131 |
< |
std::vector<double> getGrad() { return curG; } |
| 132 |
< |
void setGrad(std::vector<double>& g) { curG = g; } |
| 131 |
> |
std::vector<RealType> getGrad() { return curG; } |
| 132 |
> |
void setGrad(std::vector<RealType>& g) { curG = g; } |
| 133 |
|
|
| 134 |
< |
//interal function to evaluate the energy and gradient in OOPSE |
| 135 |
< |
void calcEnergyGradient(std::vector<double>& x, std::vector<double>& grad, double& |
| 134 |
> |
//interal function to evaluate the energy and gradient in OpenMD |
| 135 |
> |
void calcEnergyGradient(std::vector<RealType>& x, std::vector<RealType>& grad, RealType& |
| 136 |
|
energy, int& status); |
| 137 |
|
|
| 138 |
|
//calculate the value of object function |
| 139 |
|
virtual void calcF(); |
| 140 |
< |
virtual void calcF(std::vector<double>& x, double&f, int& status); |
| 140 |
> |
virtual void calcF(std::vector<RealType>& x, RealType&f, int& status); |
| 141 |
|
|
| 142 |
|
//calculate the gradient |
| 143 |
|
virtual void calcG(); |
| 144 |
< |
virtual void calcG(std::vector<double>& x, std::vector<double>& g, double& f, int& status); |
| 144 |
> |
virtual void calcG(std::vector<RealType>& x, std::vector<RealType>& g, RealType& f, int& status); |
| 145 |
|
|
| 146 |
|
//calculate the hessian |
| 147 |
|
//virtual void calcH(int& status); |
| 148 |
< |
//virtual void calcH(vector<double>& x, std::vector<dobule>& g, SymMatrix& h, int& status); |
| 148 |
> |
//virtual void calcH(vector<RealType>& x, std::vector<dobule>& g, SymMatrix& h, int& status); |
| 149 |
|
|
| 150 |
|
friend std::ostream& operator<<(std::ostream& os, const Minimizer& minimizer); |
| 151 |
|
|
| 152 |
|
protected: |
| 153 |
|
|
| 154 |
|
// transfrom cartesian and rotational coordinates into minimization coordinates |
| 155 |
< |
std::vector<double> getCoor(); |
| 155 |
> |
std::vector<RealType> getCoor(); |
| 156 |
|
|
| 157 |
|
// transfrom minimization coordinates into cartesian and rotational coordinates |
| 158 |
< |
void setCoor(std::vector<double>& x); |
| 158 |
> |
void setCoor(std::vector<RealType>& x); |
| 159 |
|
|
| 160 |
|
|
| 161 |
|
|
| 165 |
|
//remove the force component along the bond direction |
| 166 |
|
int shakeF() { return 0;} |
| 167 |
|
|
| 168 |
< |
double calcPotential(); |
| 168 |
> |
RealType calcPotential(); |
| 169 |
|
|
| 170 |
|
SimInfo* info; |
| 171 |
|
|
| 195 |
|
int egEvalStatus; |
| 196 |
|
|
| 197 |
|
//initial coordinates |
| 198 |
< |
//vector<double> initX; |
| 198 |
> |
//vector<RealType> initX; |
| 199 |
|
|
| 200 |
|
//current value of the function |
| 201 |
< |
double curF; |
| 201 |
> |
RealType curF; |
| 202 |
|
|
| 203 |
|
// current coordinates |
| 204 |
< |
std::vector<double> curX; |
| 204 |
> |
std::vector<RealType> curX; |
| 205 |
|
|
| 206 |
|
//gradient at curent coordinates |
| 207 |
< |
std::vector<double> curG; |
| 207 |
> |
std::vector<RealType> curG; |
| 208 |
|
|
| 209 |
|
//hessian at current coordinates |
| 210 |
|
//SymMatrix curH; |