| 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) { |
| 49 |
> |
RealType dotProduct(const std::vector<RealType>& v1, const std::vector<RealType>& v2) { |
| 50 |
|
if (v1.size() != v2.size()) { |
| 51 |
|
|
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
|
| 55 |
< |
double result = 0.0; |
| 55 |
> |
RealType result = 0.0; |
| 56 |
|
for (unsigned int i = 0; i < v1.size(); ++i) { |
| 57 |
|
result += v1[i] * v2[i]; |
| 58 |
|
} |
| 64 |
|
info(rhs), usingShake(false) { |
| 65 |
|
|
| 66 |
|
forceMan = new ForceManager(info); |
| 67 |
< |
paramSet= new MinimizerParameterSet(info), |
| 68 |
< |
calcDim(); |
| 67 |
> |
paramSet= new MinimizerParameterSet(info), calcDim(); |
| 68 |
|
curX = getCoor(); |
| 69 |
|
curG.resize(ndim); |
| 70 |
|
|
| 75 |
|
delete paramSet; |
| 76 |
|
} |
| 77 |
|
|
| 78 |
< |
void Minimizer::calcEnergyGradient(std::vector<double> &x, |
| 79 |
< |
std::vector<double> &grad, double&energy, int&status) { |
| 78 |
> |
void Minimizer::calcEnergyGradient(std::vector<RealType> &x, |
| 79 |
> |
std::vector<RealType> &grad, RealType&energy, int&status) { |
| 80 |
|
|
| 81 |
|
SimInfo::MoleculeIterator i; |
| 82 |
|
Molecule::IntegrableObjectIterator j; |
| 83 |
|
Molecule* mol; |
| 84 |
|
StuntDouble* integrableObject; |
| 85 |
< |
std::vector<double> myGrad; |
| 85 |
> |
std::vector<RealType> myGrad; |
| 86 |
|
int shakeStatus; |
| 87 |
|
|
| 88 |
|
status = 1; |
| 109 |
|
|
| 110 |
|
myGrad = integrableObject->getGrad(); |
| 111 |
|
for (unsigned int k = 0; k < myGrad.size(); ++k) { |
| 112 |
< |
//gradient is equal to -f |
| 113 |
< |
grad[index++] = -myGrad[k]; |
| 112 |
> |
|
| 113 |
> |
grad[index++] = myGrad[k]; |
| 114 |
|
} |
| 115 |
|
} |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
} |
| 119 |
|
|
| 120 |
< |
void Minimizer::setCoor(std::vector<double> &x) { |
| 120 |
> |
void Minimizer::setCoor(std::vector<RealType> &x) { |
| 121 |
|
Vector3d position; |
| 122 |
|
Vector3d eulerAngle; |
| 123 |
|
SimInfo::MoleculeIterator i; |
| 148 |
|
|
| 149 |
|
} |
| 150 |
|
|
| 151 |
< |
std::vector<double> Minimizer::getCoor() { |
| 151 |
> |
std::vector<RealType> Minimizer::getCoor() { |
| 152 |
|
Vector3d position; |
| 153 |
|
Vector3d eulerAngle; |
| 154 |
|
SimInfo::MoleculeIterator i; |
| 156 |
|
Molecule* mol; |
| 157 |
|
StuntDouble* integrableObject; |
| 158 |
|
int index = 0; |
| 159 |
< |
std::vector<double> x(getDim()); |
| 159 |
> |
std::vector<RealType> x(getDim()); |
| 160 |
|
|
| 161 |
|
for (mol = info->beginMolecule(i); mol != NULL; mol = info->nextMolecule(i)) { |
| 162 |
|
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
| 185 |
|
|
| 186 |
|
int done; |
| 187 |
|
|
| 188 |
< |
double posA[3], posB[3]; |
| 188 |
> |
RealType posA[3], posB[3]; |
| 189 |
|
|
| 190 |
< |
double velA[3], velB[3]; |
| 190 |
> |
RealType velA[3], velB[3]; |
| 191 |
|
|
| 192 |
< |
double pab[3]; |
| 192 |
> |
RealType pab[3]; |
| 193 |
|
|
| 194 |
< |
double rab[3]; |
| 194 |
> |
RealType rab[3]; |
| 195 |
|
|
| 196 |
|
int a, b, |
| 197 |
|
ax, ay, |
| 198 |
|
az, bx, |
| 199 |
|
by, bz; |
| 200 |
|
|
| 201 |
< |
double rma, rmb; |
| 201 |
> |
RealType rma, rmb; |
| 202 |
|
|
| 203 |
< |
double dx, dy, |
| 203 |
> |
RealType dx, dy, |
| 204 |
|
dz; |
| 205 |
|
|
| 206 |
< |
double rpab; |
| 206 |
> |
RealType rpab; |
| 207 |
|
|
| 208 |
< |
double rabsq, pabsq, |
| 208 |
> |
RealType rabsq, pabsq, |
| 209 |
|
rpabsq; |
| 210 |
|
|
| 211 |
< |
double diffsq; |
| 211 |
> |
RealType diffsq; |
| 212 |
|
|
| 213 |
< |
double gab; |
| 213 |
> |
RealType gab; |
| 214 |
|
|
| 215 |
|
int iteration; |
| 216 |
|
|
| 376 |
|
|
| 377 |
|
int done; |
| 378 |
|
|
| 379 |
< |
double posA[3], posB[3]; |
| 379 |
> |
RealType posA[3], posB[3]; |
| 380 |
|
|
| 381 |
< |
double frcA[3], frcB[3]; |
| 381 |
> |
RealType frcA[3], frcB[3]; |
| 382 |
|
|
| 383 |
< |
double rab[3], fpab[3]; |
| 383 |
> |
RealType rab[3], fpab[3]; |
| 384 |
|
|
| 385 |
|
int a, b, |
| 386 |
|
ax, ay, |
| 387 |
|
az, bx, |
| 388 |
|
by, bz; |
| 389 |
|
|
| 390 |
< |
double rma, rmb; |
| 390 |
> |
RealType rma, rmb; |
| 391 |
|
|
| 392 |
< |
double rvab; |
| 392 |
> |
RealType rvab; |
| 393 |
|
|
| 394 |
< |
double gab; |
| 394 |
> |
RealType gab; |
| 395 |
|
|
| 396 |
< |
double rabsq; |
| 396 |
> |
RealType rabsq; |
| 397 |
|
|
| 398 |
< |
double rfab; |
| 398 |
> |
RealType rfab; |
| 399 |
|
|
| 400 |
|
int iteration; |
| 401 |
|
|
| 523 |
|
calcEnergyGradient(curX, curG, curF, egEvalStatus); |
| 524 |
|
} |
| 525 |
|
|
| 526 |
< |
void Minimizer::calcF(std::vector < double > &x, double&f, int&status) { |
| 527 |
< |
std::vector < double > tempG; |
| 526 |
> |
void Minimizer::calcF(std::vector < RealType > &x, RealType&f, int&status) { |
| 527 |
> |
std::vector < RealType > tempG; |
| 528 |
|
|
| 529 |
|
tempG.resize(x.size()); |
| 530 |
|
|
| 537 |
|
calcEnergyGradient(curX, curG, curF, egEvalStatus); |
| 538 |
|
} |
| 539 |
|
|
| 540 |
< |
void Minimizer::calcG(std::vector<double>& x, std::vector<double>& g, double&f, int&status) { |
| 540 |
> |
void Minimizer::calcG(std::vector<RealType>& x, std::vector<RealType>& g, RealType&f, int&status) { |
| 541 |
|
calcEnergyGradient(x, g, f, status); |
| 542 |
|
} |
| 543 |
|
|
| 563 |
|
} |
| 564 |
|
} |
| 565 |
|
|
| 566 |
< |
void Minimizer::setX(std::vector < double > &x) { |
| 566 |
> |
void Minimizer::setX(std::vector < RealType > &x) { |
| 567 |
|
if (x.size() != ndim) { |
| 568 |
|
sprintf(painCave.errMsg, "Minimizer Error: dimesion of x and curX does not match\n"); |
| 569 |
|
painCave.isFatal = 1; |
| 573 |
|
curX = x; |
| 574 |
|
} |
| 575 |
|
|
| 576 |
< |
void Minimizer::setG(std::vector < double > &g) { |
| 576 |
> |
void Minimizer::setG(std::vector < RealType > &g) { |
| 577 |
|
if (g.size() != ndim) { |
| 578 |
|
sprintf(painCave.errMsg, "Minimizer Error: dimesion of g and curG does not match\n"); |
| 579 |
|
painCave.isFatal = 1; |
| 595 |
|
* @todo optimize this line search algorithm |
| 596 |
|
*/ |
| 597 |
|
|
| 598 |
< |
int Minimizer::doLineSearch(std::vector<double> &direction, |
| 599 |
< |
double stepSize) { |
| 598 |
> |
int Minimizer::doLineSearch(std::vector<RealType> &direction, |
| 599 |
> |
RealType stepSize) { |
| 600 |
|
|
| 601 |
< |
std::vector<double> xa; |
| 602 |
< |
std::vector<double> xb; |
| 603 |
< |
std::vector<double> xc; |
| 604 |
< |
std::vector<double> ga; |
| 605 |
< |
std::vector<double> gb; |
| 606 |
< |
std::vector<double> gc; |
| 607 |
< |
double fa; |
| 608 |
< |
double fb; |
| 609 |
< |
double fc; |
| 610 |
< |
double a; |
| 611 |
< |
double b; |
| 612 |
< |
double c; |
| 601 |
> |
std::vector<RealType> xa; |
| 602 |
> |
std::vector<RealType> xb; |
| 603 |
> |
std::vector<RealType> xc; |
| 604 |
> |
std::vector<RealType> ga; |
| 605 |
> |
std::vector<RealType> gb; |
| 606 |
> |
std::vector<RealType> gc; |
| 607 |
> |
RealType fa; |
| 608 |
> |
RealType fb; |
| 609 |
> |
RealType fc; |
| 610 |
> |
RealType a; |
| 611 |
> |
RealType b; |
| 612 |
> |
RealType c; |
| 613 |
|
int status; |
| 614 |
< |
double initSlope; |
| 615 |
< |
double slopeA; |
| 616 |
< |
double slopeB; |
| 617 |
< |
double slopeC; |
| 614 |
> |
RealType initSlope; |
| 615 |
> |
RealType slopeA; |
| 616 |
> |
RealType slopeB; |
| 617 |
> |
RealType slopeC; |
| 618 |
|
bool foundLower; |
| 619 |
|
int iter; |
| 620 |
|
int maxLSIter; |
| 621 |
< |
double mu; |
| 622 |
< |
double eta; |
| 623 |
< |
double ftol; |
| 624 |
< |
double lsTol; |
| 621 |
> |
RealType mu; |
| 622 |
> |
RealType eta; |
| 623 |
> |
RealType ftol; |
| 624 |
> |
RealType lsTol; |
| 625 |
|
|
| 626 |
|
xa.resize(ndim); |
| 627 |
|
xb.resize(ndim); |
| 872 |
|
if (curIter == nextWriteIter) { |
| 873 |
|
nextWriteIter += writeFrq; |
| 874 |
|
calcF(); |
| 875 |
< |
dumpWriter.writeDump(); |
| 875 |
> |
dumpWriter.writeDumpAndEor(); |
| 876 |
|
statWriter.writeStat(curSnapshot->statData); |
| 877 |
|
} |
| 878 |
|
|
| 901 |
|
} |
| 902 |
|
|
| 903 |
|
|
| 904 |
< |
double Minimizer::calcPotential() { |
| 904 |
> |
RealType Minimizer::calcPotential() { |
| 905 |
|
forceMan->calcForces(true, false); |
| 906 |
|
|
| 907 |
|
Snapshot* curSnapshot = info->getSnapshotManager()->getCurrentSnapshot(); |
| 908 |
< |
double potential_local = curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] + |
| 908 |
> |
RealType potential_local = curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] + |
| 909 |
|
curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] ; |
| 910 |
< |
double potential; |
| 910 |
> |
RealType potential; |
| 911 |
|
|
| 912 |
|
#ifdef IS_MPI |
| 913 |
< |
MPI_Allreduce(&potential_local, &potential, 1, MPI_DOUBLE, MPI_SUM, |
| 913 |
> |
MPI_Allreduce(&potential_local, &potential, 1, MPI_REALTYPE, MPI_SUM, |
| 914 |
|
MPI_COMM_WORLD); |
| 915 |
|
#else |
| 916 |
|
potential = potential_local; |