1 |
< |
#include <math.h> |
2 |
< |
#include "primitives/Atom.hpp" |
3 |
< |
#include "primitives/SRI.hpp" |
4 |
< |
#include "primitives/AbstractClasses.hpp" |
1 |
> |
#include "NPTi.hpp" |
2 |
|
#include "brains/SimInfo.hpp" |
6 |
– |
#include "UseTheForce/ForceFields.hpp" |
3 |
|
#include "brains/Thermo.hpp" |
4 |
< |
#include "io/ReadWrite.hpp" |
5 |
< |
#include "integrators/Integrator.hpp" |
4 |
> |
#include "integrators/IntegratorCreator.hpp" |
5 |
> |
#include "integrators/NPT.hpp" |
6 |
> |
#include "primitives/Molecule.hpp" |
7 |
> |
#include "utils/OOPSEConstant.hpp" |
8 |
|
#include "utils/simError.h" |
9 |
|
|
10 |
< |
#ifdef IS_MPI |
13 |
< |
#include "brains/mpiSimulation.hpp" |
14 |
< |
#endif |
10 |
> |
namespace oopse { |
11 |
|
|
12 |
|
// Basic isotropic thermostating and barostating via the Melchionna |
13 |
|
// modification of the Hoover algorithm: |
19 |
|
// |
20 |
|
// Hoover, W. G., 1986, Phys. Rev. A, 34, 2499. |
21 |
|
|
22 |
< |
template<typename T> NPTi<T>::NPTi ( SimInfo *theInfo, ForceFields* the_ff): |
27 |
< |
T( theInfo, the_ff ) |
28 |
< |
{ |
29 |
< |
GenericData* data; |
30 |
< |
DoubleArrayData * etaValue; |
31 |
< |
vector<double> etaArray; |
22 |
> |
NPTi::NPTi ( SimInfo *info) : NPT(info){ |
23 |
|
|
33 |
– |
eta = 0.0; |
34 |
– |
oldEta = 0.0; |
35 |
– |
|
36 |
– |
if( theInfo->useInitXSstate ){ |
37 |
– |
// retrieve eta from simInfo if |
38 |
– |
data = info->getProperty(ETAVALUE_ID); |
39 |
– |
if(data){ |
40 |
– |
etaValue = dynamic_cast<DoubleArrayData*>(data); |
41 |
– |
|
42 |
– |
if(etaValue){ |
43 |
– |
etaArray = etaValue->getData(); |
44 |
– |
eta = etaArray[0]; |
45 |
– |
oldEta = eta; |
46 |
– |
} |
47 |
– |
} |
48 |
– |
} |
24 |
|
} |
25 |
|
|
26 |
< |
template<typename T> NPTi<T>::~NPTi() { |
27 |
< |
//nothing for now |
26 |
> |
void NPTi::evolveEtaA() { |
27 |
> |
eta += dt2 * ( instaVol * (instaPress - targetPressure) / |
28 |
> |
(OOPSEConstant::pressureConvert*NkBT*tb2)); |
29 |
> |
oldEta = eta; |
30 |
|
} |
31 |
|
|
32 |
< |
template<typename T> void NPTi<T>::resetIntegrator() { |
56 |
< |
eta = 0.0; |
57 |
< |
T::resetIntegrator(); |
58 |
< |
} |
32 |
> |
void NPTi::evolveEtaB() { |
33 |
|
|
34 |
< |
template<typename T> void NPTi<T>::evolveEtaA() { |
35 |
< |
eta += dt2 * ( instaVol * (instaPress - targetPressure) / |
36 |
< |
(p_convert*NkBT*tb2)); |
63 |
< |
oldEta = eta; |
34 |
> |
prevEta = eta; |
35 |
> |
eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) / |
36 |
> |
(OOPSEConstant::pressureConvert*NkBT*tb2)); |
37 |
|
} |
38 |
|
|
39 |
< |
template<typename T> void NPTi<T>::evolveEtaB() { |
40 |
< |
|
68 |
< |
prevEta = eta; |
69 |
< |
eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) / |
70 |
< |
(p_convert*NkBT*tb2)); |
39 |
> |
void NPTi::calcVelScale() { |
40 |
> |
vScale = chi + eta; |
41 |
|
} |
42 |
|
|
43 |
< |
template<typename T> void NPTi<T>::calcVelScale(void) { |
44 |
< |
vScale = chi + eta; |
43 |
> |
void NPTi::getVelScaleA(Vector3d& sc, const Vector3d& vel) { |
44 |
> |
sc = vel * vScale; |
45 |
|
} |
46 |
|
|
47 |
< |
template<typename T> void NPTi<T>::getVelScaleA(double sc[3], double vel[3]) { |
48 |
< |
int i; |
79 |
< |
|
80 |
< |
for(i=0; i<3; i++) sc[i] = vel[i] * vScale; |
47 |
> |
void NPTi::getVelScaleB(Vector3d& sc, int index ){ |
48 |
> |
sc = oldVel[index] * vScale; |
49 |
|
} |
50 |
|
|
83 |
– |
template<typename T> void NPTi<T>::getVelScaleB(double sc[3], int index ){ |
84 |
– |
int i; |
51 |
|
|
52 |
< |
for(i=0; i<3; i++) sc[i] = oldVel[index*3 + i] * vScale; |
52 |
> |
void NPTi::getPosScale(const Vector3d& pos, const Vector3d& COM, |
53 |
> |
int index, Vector3d& sc){ |
54 |
> |
/**@todo*/ |
55 |
> |
sc = (oldPos[index] + pos)/2.0 -COM; |
56 |
> |
sc *= eta; |
57 |
|
} |
58 |
|
|
59 |
+ |
void NPTi::scaleSimBox(){ |
60 |
|
|
61 |
< |
template<typename T> void NPTi<T>::getPosScale(double pos[3], double COM[3], |
91 |
< |
int index, double sc[3]){ |
92 |
< |
int j; |
61 |
> |
double scaleFactor; |
62 |
|
|
63 |
< |
for(j=0; j<3; j++) |
95 |
< |
sc[j] = ( oldPos[index*3+j] + pos[j]) / 2.0 - COM[j]; |
63 |
> |
scaleFactor = exp(dt*eta); |
64 |
|
|
65 |
< |
for(j=0; j<3; j++) |
66 |
< |
sc[j] *= eta; |
99 |
< |
} |
100 |
< |
|
101 |
< |
template<typename T> void NPTi<T>::scaleSimBox( void ){ |
102 |
< |
|
103 |
< |
double scaleFactor; |
104 |
< |
|
105 |
< |
scaleFactor = exp(dt*eta); |
106 |
< |
|
107 |
< |
if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) { |
108 |
< |
sprintf( painCave.errMsg, |
65 |
> |
if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) { |
66 |
> |
sprintf( painCave.errMsg, |
67 |
|
"NPTi error: Attempting a Box scaling of more than 10 percent" |
68 |
|
" check your tauBarostat, as it is probably too small!\n" |
69 |
|
" eta = %lf, scaleFactor = %lf\n", eta, scaleFactor |
70 |
|
); |
71 |
< |
painCave.isFatal = 1; |
72 |
< |
simError(); |
73 |
< |
} else { |
74 |
< |
info->scaleBox(scaleFactor); |
75 |
< |
} |
71 |
> |
painCave.isFatal = 1; |
72 |
> |
simError(); |
73 |
> |
} else { |
74 |
> |
Mat3x3d hmat = currentSnapshot_->getHmat(); |
75 |
> |
hmat *= scaleFactor; |
76 |
> |
currentSnapshot_->setHmat(hmat); |
77 |
> |
} |
78 |
|
|
79 |
|
} |
80 |
|
|
81 |
< |
template<typename T> bool NPTi<T>::etaConverged() { |
81 |
> |
bool NPTi::etaConverged() { |
82 |
|
|
83 |
< |
return ( fabs(prevEta - eta) <= etaTolerance ); |
83 |
> |
return ( fabs(prevEta - eta) <= etaTolerance ); |
84 |
|
} |
85 |
|
|
86 |
< |
template<typename T> double NPTi<T>::getConservedQuantity(void){ |
86 |
> |
double NPTi::calcConservedQuantity(){ |
87 |
|
|
88 |
< |
double conservedQuantity; |
89 |
< |
double Energy; |
90 |
< |
double thermostat_kinetic; |
91 |
< |
double thermostat_potential; |
92 |
< |
double barostat_kinetic; |
93 |
< |
double barostat_potential; |
88 |
> |
chi= currentSnapshot_->getChi(); |
89 |
> |
integralOfChidt = currentSnapshot_->getIntegralOfChiDt(); |
90 |
> |
loadEta(); |
91 |
> |
// We need NkBT a lot, so just set it here: This is the RAW number |
92 |
> |
// of integrableObjects, so no subtraction or addition of constraints or |
93 |
> |
// orientational degrees of freedom: |
94 |
> |
NkBT = info_->getNGlobalIntegrableObjects()*OOPSEConstant::kB *targetTemp; |
95 |
|
|
96 |
< |
Energy = tStats->getTotalE(); |
96 |
> |
// fkBT is used because the thermostat operates on more degrees of freedom |
97 |
> |
// than the barostat (when there are particles with orientational degrees |
98 |
> |
// of freedom). |
99 |
> |
fkBT = info_->getNdf()*OOPSEConstant::kB *targetTemp; |
100 |
> |
|
101 |
> |
double conservedQuantity; |
102 |
> |
double Energy; |
103 |
> |
double thermostat_kinetic; |
104 |
> |
double thermostat_potential; |
105 |
> |
double barostat_kinetic; |
106 |
> |
double barostat_potential; |
107 |
|
|
108 |
< |
thermostat_kinetic = fkBT* tt2 * chi * chi / |
138 |
< |
(2.0 * eConvert); |
108 |
> |
Energy =thermo.getTotalE(); |
109 |
|
|
110 |
< |
thermostat_potential = fkBT* integralOfChidt / eConvert; |
110 |
> |
thermostat_kinetic = fkBT* tt2 * chi * chi / (2.0 * OOPSEConstant::energyConvert); |
111 |
|
|
112 |
+ |
thermostat_potential = fkBT* integralOfChidt / OOPSEConstant::energyConvert; |
113 |
|
|
143 |
– |
barostat_kinetic = 3.0 * NkBT * tb2 * eta * eta / |
144 |
– |
(2.0 * eConvert); |
114 |
|
|
115 |
< |
barostat_potential = (targetPressure * tStats->getVolume() / p_convert) / |
147 |
< |
eConvert; |
115 |
> |
barostat_kinetic = 3.0 * NkBT * tb2 * eta * eta /(2.0 * OOPSEConstant::energyConvert); |
116 |
|
|
117 |
< |
conservedQuantity = Energy + thermostat_kinetic + thermostat_potential + |
118 |
< |
barostat_kinetic + barostat_potential; |
117 |
> |
barostat_potential = (targetPressure * thermo.getVolume() / OOPSEConstant::pressureConvert) / |
118 |
> |
OOPSEConstant::energyConvert; |
119 |
|
|
120 |
< |
// cout.width(8); |
121 |
< |
// cout.precision(8); |
120 |
> |
conservedQuantity = Energy + thermostat_kinetic + thermostat_potential + |
121 |
> |
barostat_kinetic + barostat_potential; |
122 |
|
|
123 |
< |
// cerr << info->getTime() << "\t" << Energy << "\t" << thermostat_kinetic << |
124 |
< |
// "\t" << thermostat_potential << "\t" << barostat_kinetic << |
125 |
< |
// "\t" << barostat_potential << "\t" << conservedQuantity << endl; |
126 |
< |
return conservedQuantity; |
123 |
> |
std::cout << "--------------------------------------------------------------" << std::endl; |
124 |
> |
std::cout << "time: " << currentSnapshot_->getTime() << std:: endl; |
125 |
> |
std::cout << "chi : " << chi << std::endl; |
126 |
> |
std::cout << "integralOfChidt : " << integralOfChidt << std::endl; |
127 |
> |
std::cout << "eta : " << eta << std::endl; |
128 |
> |
std::cout << "NkBT: " << NkBT << std::endl; |
129 |
> |
std::cout << "fkBT: " << fkBT << std::endl; |
130 |
> |
std::cout << "thermostat_kinetic : " << thermostat_kinetic<< std::endl; |
131 |
> |
std::cout << "thermostat_potential : " << thermostat_potential << std::endl; |
132 |
> |
std::cout << "barostat_kinetic : " << barostat_kinetic << std::endl; |
133 |
> |
std::cout << "barostat_potential : " << barostat_potential << std::endl; |
134 |
> |
std::cout << "Total Energy: " << Energy << std::endl; |
135 |
> |
std::cout << "Conserved Quantity: " << conservedQuantity <<std::endl; |
136 |
> |
std::cout << "--------------------------------------------------------------" << std::endl; |
137 |
> |
return conservedQuantity; |
138 |
|
} |
139 |
|
|
140 |
< |
template<typename T> string NPTi<T>::getAdditionalParameters(void){ |
141 |
< |
string parameters; |
142 |
< |
const int BUFFERSIZE = 2000; // size of the read buffer |
143 |
< |
char buffer[BUFFERSIZE]; |
140 |
> |
void NPTi::loadEta() { |
141 |
> |
Mat3x3d etaMat = currentSnapshot_->getEta(); |
142 |
> |
eta = etaMat(0,0); |
143 |
> |
//if (fabs(etaMat(1,1) - eta) >= oopse::epsilon || fabs(etaMat(1,1) - eta) >= oopse::epsilon || !etaMat.isDiagonal()) { |
144 |
> |
// sprintf( painCave.errMsg, |
145 |
> |
// "NPTi error: the diagonal elements of eta matrix are not the same or etaMat is not a diagonal matrix"); |
146 |
> |
// painCave.isFatal = 1; |
147 |
> |
// simError(); |
148 |
> |
//} |
149 |
> |
} |
150 |
|
|
151 |
< |
sprintf(buffer,"\t%G\t%G;", chi, integralOfChidt); |
152 |
< |
parameters += buffer; |
151 |
> |
void NPTi::saveEta() { |
152 |
> |
Mat3x3d etaMat(0.0); |
153 |
> |
etaMat(0, 0) = eta; |
154 |
> |
etaMat(1, 1) = eta; |
155 |
> |
etaMat(2, 2) = eta; |
156 |
> |
currentSnapshot_->setEta(etaMat); |
157 |
> |
} |
158 |
|
|
169 |
– |
sprintf(buffer,"\t%G\t0\t0;", eta); |
170 |
– |
parameters += buffer; |
171 |
– |
|
172 |
– |
sprintf(buffer,"\t0\t%G\t0;", eta); |
173 |
– |
parameters += buffer; |
174 |
– |
|
175 |
– |
sprintf(buffer,"\t0\t0\t%G;", eta); |
176 |
– |
parameters += buffer; |
177 |
– |
|
178 |
– |
return parameters; |
179 |
– |
|
159 |
|
} |