| 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 |
|
#include <cmath> |
| 45 |
|
#include "io/StatWriter.hpp" |
| 46 |
|
#include "minimizers/Minimizer.hpp" |
| 47 |
|
#include "primitives/Molecule.hpp" |
| 48 |
< |
namespace oopse { |
| 49 |
< |
double dotProduct(const std::vector<double>& v1, const std::vector<double>& v2) { |
| 48 |
> |
#ifdef IS_MPI |
| 49 |
> |
#include <mpi.h> |
| 50 |
> |
#endif |
| 51 |
> |
namespace OpenMD { |
| 52 |
> |
RealType dotProduct(const std::vector<RealType>& v1, const std::vector<RealType>& v2) { |
| 53 |
|
if (v1.size() != v2.size()) { |
| 54 |
|
|
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
|
| 58 |
< |
double result = 0.0; |
| 58 |
> |
RealType result = 0.0; |
| 59 |
|
for (unsigned int i = 0; i < v1.size(); ++i) { |
| 60 |
|
result += v1[i] * v2[i]; |
| 61 |
|
} |
| 67 |
|
info(rhs), usingShake(false) { |
| 68 |
|
|
| 69 |
|
forceMan = new ForceManager(info); |
| 70 |
< |
paramSet= new MinimizerParameterSet(info), |
| 68 |
< |
calcDim(); |
| 70 |
> |
paramSet= new MinimizerParameterSet(info), calcDim(); |
| 71 |
|
curX = getCoor(); |
| 72 |
|
curG.resize(ndim); |
| 73 |
|
|
| 78 |
|
delete paramSet; |
| 79 |
|
} |
| 80 |
|
|
| 81 |
< |
void Minimizer::calcEnergyGradient(std::vector<double> &x, |
| 82 |
< |
std::vector<double> &grad, double&energy, int&status) { |
| 81 |
> |
void Minimizer::calcEnergyGradient(std::vector<RealType> &x, |
| 82 |
> |
std::vector<RealType> &grad, RealType&energy, int&status) { |
| 83 |
|
|
| 84 |
|
SimInfo::MoleculeIterator i; |
| 85 |
|
Molecule::IntegrableObjectIterator j; |
| 86 |
|
Molecule* mol; |
| 87 |
|
StuntDouble* integrableObject; |
| 88 |
< |
std::vector<double> myGrad; |
| 88 |
> |
std::vector<RealType> myGrad; |
| 89 |
|
int shakeStatus; |
| 90 |
|
|
| 91 |
|
status = 1; |
| 120 |
|
|
| 121 |
|
} |
| 122 |
|
|
| 123 |
< |
void Minimizer::setCoor(std::vector<double> &x) { |
| 123 |
> |
void Minimizer::setCoor(std::vector<RealType> &x) { |
| 124 |
|
Vector3d position; |
| 125 |
|
Vector3d eulerAngle; |
| 126 |
|
SimInfo::MoleculeIterator i; |
| 151 |
|
|
| 152 |
|
} |
| 153 |
|
|
| 154 |
< |
std::vector<double> Minimizer::getCoor() { |
| 154 |
> |
std::vector<RealType> Minimizer::getCoor() { |
| 155 |
|
Vector3d position; |
| 156 |
|
Vector3d eulerAngle; |
| 157 |
|
SimInfo::MoleculeIterator i; |
| 159 |
|
Molecule* mol; |
| 160 |
|
StuntDouble* integrableObject; |
| 161 |
|
int index = 0; |
| 162 |
< |
std::vector<double> x(getDim()); |
| 162 |
> |
std::vector<RealType> x(getDim()); |
| 163 |
|
|
| 164 |
|
for (mol = info->beginMolecule(i); mol != NULL; mol = info->nextMolecule(i)) { |
| 165 |
|
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
| 188 |
|
|
| 189 |
|
int done; |
| 190 |
|
|
| 191 |
< |
double posA[3], posB[3]; |
| 191 |
> |
RealType posA[3], posB[3]; |
| 192 |
|
|
| 193 |
< |
double velA[3], velB[3]; |
| 193 |
> |
RealType velA[3], velB[3]; |
| 194 |
|
|
| 195 |
< |
double pab[3]; |
| 195 |
> |
RealType pab[3]; |
| 196 |
|
|
| 197 |
< |
double rab[3]; |
| 197 |
> |
RealType rab[3]; |
| 198 |
|
|
| 199 |
|
int a, b, |
| 200 |
|
ax, ay, |
| 201 |
|
az, bx, |
| 202 |
|
by, bz; |
| 203 |
|
|
| 204 |
< |
double rma, rmb; |
| 204 |
> |
RealType rma, rmb; |
| 205 |
|
|
| 206 |
< |
double dx, dy, |
| 206 |
> |
RealType dx, dy, |
| 207 |
|
dz; |
| 208 |
|
|
| 209 |
< |
double rpab; |
| 209 |
> |
RealType rpab; |
| 210 |
|
|
| 211 |
< |
double rabsq, pabsq, |
| 211 |
> |
RealType rabsq, pabsq, |
| 212 |
|
rpabsq; |
| 213 |
|
|
| 214 |
< |
double diffsq; |
| 214 |
> |
RealType diffsq; |
| 215 |
|
|
| 216 |
< |
double gab; |
| 216 |
> |
RealType gab; |
| 217 |
|
|
| 218 |
|
int iteration; |
| 219 |
|
|
| 379 |
|
|
| 380 |
|
int done; |
| 381 |
|
|
| 382 |
< |
double posA[3], posB[3]; |
| 382 |
> |
RealType posA[3], posB[3]; |
| 383 |
|
|
| 384 |
< |
double frcA[3], frcB[3]; |
| 384 |
> |
RealType frcA[3], frcB[3]; |
| 385 |
|
|
| 386 |
< |
double rab[3], fpab[3]; |
| 386 |
> |
RealType rab[3], fpab[3]; |
| 387 |
|
|
| 388 |
|
int a, b, |
| 389 |
|
ax, ay, |
| 390 |
|
az, bx, |
| 391 |
|
by, bz; |
| 392 |
|
|
| 393 |
< |
double rma, rmb; |
| 393 |
> |
RealType rma, rmb; |
| 394 |
|
|
| 395 |
< |
double rvab; |
| 395 |
> |
RealType rvab; |
| 396 |
|
|
| 397 |
< |
double gab; |
| 397 |
> |
RealType gab; |
| 398 |
|
|
| 399 |
< |
double rabsq; |
| 399 |
> |
RealType rabsq; |
| 400 |
|
|
| 401 |
< |
double rfab; |
| 401 |
> |
RealType rfab; |
| 402 |
|
|
| 403 |
|
int iteration; |
| 404 |
|
|
| 526 |
|
calcEnergyGradient(curX, curG, curF, egEvalStatus); |
| 527 |
|
} |
| 528 |
|
|
| 529 |
< |
void Minimizer::calcF(std::vector < double > &x, double&f, int&status) { |
| 530 |
< |
std::vector < double > tempG; |
| 529 |
> |
void Minimizer::calcF(std::vector < RealType > &x, RealType&f, int&status) { |
| 530 |
> |
std::vector < RealType > tempG; |
| 531 |
|
|
| 532 |
|
tempG.resize(x.size()); |
| 533 |
|
|
| 540 |
|
calcEnergyGradient(curX, curG, curF, egEvalStatus); |
| 541 |
|
} |
| 542 |
|
|
| 543 |
< |
void Minimizer::calcG(std::vector<double>& x, std::vector<double>& g, double&f, int&status) { |
| 543 |
> |
void Minimizer::calcG(std::vector<RealType>& x, std::vector<RealType>& g, RealType&f, int&status) { |
| 544 |
|
calcEnergyGradient(x, g, f, status); |
| 545 |
|
} |
| 546 |
|
|
| 566 |
|
} |
| 567 |
|
} |
| 568 |
|
|
| 569 |
< |
void Minimizer::setX(std::vector < double > &x) { |
| 569 |
> |
void Minimizer::setX(std::vector < RealType > &x) { |
| 570 |
|
if (x.size() != ndim) { |
| 571 |
|
sprintf(painCave.errMsg, "Minimizer Error: dimesion of x and curX does not match\n"); |
| 572 |
|
painCave.isFatal = 1; |
| 576 |
|
curX = x; |
| 577 |
|
} |
| 578 |
|
|
| 579 |
< |
void Minimizer::setG(std::vector < double > &g) { |
| 579 |
> |
void Minimizer::setG(std::vector < RealType > &g) { |
| 580 |
|
if (g.size() != ndim) { |
| 581 |
|
sprintf(painCave.errMsg, "Minimizer Error: dimesion of g and curG does not match\n"); |
| 582 |
|
painCave.isFatal = 1; |
| 598 |
|
* @todo optimize this line search algorithm |
| 599 |
|
*/ |
| 600 |
|
|
| 601 |
< |
int Minimizer::doLineSearch(std::vector<double> &direction, |
| 602 |
< |
double stepSize) { |
| 601 |
> |
int Minimizer::doLineSearch(std::vector<RealType> &direction, |
| 602 |
> |
RealType stepSize) { |
| 603 |
|
|
| 604 |
< |
std::vector<double> xa; |
| 605 |
< |
std::vector<double> xb; |
| 606 |
< |
std::vector<double> xc; |
| 607 |
< |
std::vector<double> ga; |
| 608 |
< |
std::vector<double> gb; |
| 609 |
< |
std::vector<double> gc; |
| 610 |
< |
double fa; |
| 611 |
< |
double fb; |
| 612 |
< |
double fc; |
| 613 |
< |
double a; |
| 614 |
< |
double b; |
| 615 |
< |
double c; |
| 604 |
> |
std::vector<RealType> xa; |
| 605 |
> |
std::vector<RealType> xb; |
| 606 |
> |
std::vector<RealType> xc; |
| 607 |
> |
std::vector<RealType> ga; |
| 608 |
> |
std::vector<RealType> gb; |
| 609 |
> |
std::vector<RealType> gc; |
| 610 |
> |
RealType fa; |
| 611 |
> |
RealType fb; |
| 612 |
> |
RealType fc; |
| 613 |
> |
RealType a; |
| 614 |
> |
RealType b; |
| 615 |
> |
RealType c; |
| 616 |
|
int status; |
| 617 |
< |
double initSlope; |
| 618 |
< |
double slopeA; |
| 619 |
< |
double slopeB; |
| 620 |
< |
double slopeC; |
| 617 |
> |
RealType initSlope; |
| 618 |
> |
RealType slopeA; |
| 619 |
> |
RealType slopeB; |
| 620 |
> |
RealType slopeC; |
| 621 |
|
bool foundLower; |
| 622 |
|
int iter; |
| 623 |
|
int maxLSIter; |
| 624 |
< |
double mu; |
| 625 |
< |
double eta; |
| 626 |
< |
double ftol; |
| 627 |
< |
double lsTol; |
| 624 |
> |
RealType mu; |
| 625 |
> |
RealType eta; |
| 626 |
> |
RealType ftol; |
| 627 |
> |
RealType lsTol; |
| 628 |
|
|
| 629 |
|
xa.resize(ndim); |
| 630 |
|
xb.resize(ndim); |
| 832 |
|
int convgStatus; |
| 833 |
|
int stepStatus; |
| 834 |
|
int maxIter; |
| 835 |
< |
int writeFrq; |
| 835 |
> |
int writeFreq; |
| 836 |
|
int nextWriteIter; |
| 837 |
|
Snapshot* curSnapshot =info->getSnapshotManager()->getCurrentSnapshot(); |
| 838 |
|
DumpWriter dumpWriter(info); |
| 843 |
|
|
| 844 |
|
init(); |
| 845 |
|
|
| 846 |
< |
writeFrq = paramSet->getWriteFrq(); |
| 846 |
> |
writeFreq = paramSet->getWriteFreq(); |
| 847 |
|
|
| 848 |
< |
nextWriteIter = writeFrq; |
| 848 |
> |
nextWriteIter = writeFreq; |
| 849 |
|
|
| 850 |
|
maxIter = paramSet->getMaxIteration(); |
| 851 |
|
|
| 873 |
|
curSnapshot->increaseTime(1); |
| 874 |
|
|
| 875 |
|
if (curIter == nextWriteIter) { |
| 876 |
< |
nextWriteIter += writeFrq; |
| 876 |
> |
nextWriteIter += writeFreq; |
| 877 |
|
calcF(); |
| 878 |
< |
dumpWriter.writeDump(); |
| 878 |
> |
dumpWriter.writeDumpAndEor(); |
| 879 |
|
statWriter.writeStat(curSnapshot->statData); |
| 880 |
|
} |
| 881 |
|
|
| 904 |
|
} |
| 905 |
|
|
| 906 |
|
|
| 907 |
< |
double Minimizer::calcPotential() { |
| 908 |
< |
forceMan->calcForces(true, false); |
| 907 |
> |
RealType Minimizer::calcPotential() { |
| 908 |
> |
forceMan->calcForces(); |
| 909 |
|
|
| 910 |
|
Snapshot* curSnapshot = info->getSnapshotManager()->getCurrentSnapshot(); |
| 911 |
< |
double potential_local = curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] + |
| 911 |
> |
RealType potential_local = curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] + |
| 912 |
|
curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] ; |
| 913 |
< |
double potential; |
| 913 |
> |
RealType potential; |
| 914 |
|
|
| 915 |
|
#ifdef IS_MPI |
| 916 |
< |
MPI_Allreduce(&potential_local, &potential, 1, MPI_DOUBLE, MPI_SUM, |
| 916 |
> |
MPI_Allreduce(&potential_local, &potential, 1, MPI_REALTYPE, MPI_SUM, |
| 917 |
|
MPI_COMM_WORLD); |
| 918 |
|
#else |
| 919 |
|
potential = potential_local; |