# | Line 6 | Line 6 | |
---|---|---|
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. | |
# | Line 37 | Line 28 | |
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> | |
# | Line 45 | Line 45 | |
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 | > | namespace OpenMD { |
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 | } | |
# | Line 64 | Line 64 | namespace oopse { | |
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 | ||
# | Line 76 | Line 75 | namespace oopse { | |
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; | |
# | Line 110 | Line 109 | namespace oopse { | |
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; | |
# | Line 149 | Line 148 | namespace oopse { | |
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; | |
# | Line 157 | Line 156 | namespace oopse { | |
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; | |
# | Line 186 | Line 185 | namespace oopse { | |
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 | ||
# | Line 377 | Line 376 | namespace oopse { | |
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 | ||
# | Line 524 | Line 523 | namespace oopse { | |
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 | ||
# | Line 538 | Line 537 | namespace oopse { | |
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 | ||
# | Line 564 | Line 563 | namespace oopse { | |
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; | |
# | Line 574 | Line 573 | namespace oopse { | |
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; | |
# | Line 596 | Line 595 | namespace oopse { | |
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); | |
# | Line 873 | Line 872 | namespace oopse { | |
872 | if (curIter == nextWriteIter) { | |
873 | nextWriteIter += writeFrq; | |
874 | calcF(); | |
875 | < | dumpWriter.writeDump(); |
875 | > | dumpWriter.writeDumpAndEor(); |
876 | statWriter.writeStat(curSnapshot->statData); | |
877 | } | |
878 | ||
# | Line 902 | Line 901 | namespace oopse { | |
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; |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |