Commit a783b996 authored by peastman's avatar peastman
Browse files

Eliminated RealOpenMM type

parent 9500f3af
......@@ -25,7 +25,6 @@
#ifndef __AmoebaReferenceWcaDispersionForce_H__
#define __AmoebaReferenceWcaDispersionForce_H__
#include "RealVec.h"
#include "openmm/Vec3.h"
#include <string>
#include <vector>
......@@ -51,8 +50,8 @@ public:
--------------------------------------------------------------------------------------- */
AmoebaReferenceWcaDispersionForce(RealOpenMM epso, RealOpenMM epsh, RealOpenMM rmino, RealOpenMM rminh,
RealOpenMM awater, RealOpenMM shctd, RealOpenMM dispoff, RealOpenMM slevy);
AmoebaReferenceWcaDispersionForce(double epso, double epsh, double rmino, double rminh,
double awater, double shctd, double dispoff, double slevy);
/**---------------------------------------------------------------------------------------
......@@ -77,20 +76,20 @@ public:
--------------------------------------------------------------------------------------- */
RealOpenMM calculateForceAndEnergy(int numParticles, const std::vector<OpenMM::RealVec>& particlePositions,
const std::vector<RealOpenMM>& radii,
const std::vector<RealOpenMM>& epsilons,
RealOpenMM totalMaximumDispersionEnergy, std::vector<OpenMM::RealVec>& forces) const;
double calculateForceAndEnergy(int numParticles, const std::vector<OpenMM::Vec3>& particlePositions,
const std::vector<double>& radii,
const std::vector<double>& epsilons,
double totalMaximumDispersionEnergy, std::vector<OpenMM::Vec3>& forces) const;
private:
RealOpenMM _epso;
RealOpenMM _epsh;
RealOpenMM _rmino;
RealOpenMM _rminh;
RealOpenMM _awater;
RealOpenMM _shctd;
RealOpenMM _dispoff;
RealOpenMM _slevy;
double _epso;
double _epsh;
double _rmino;
double _rminh;
double _awater;
double _shctd;
double _dispoff;
double _slevy;
enum { EMIXO, RMIXO, RMIXO7, AO, EMIXH, RMIXH, RMIXH7, AH, LastIntermediateValueIndex };
......@@ -109,10 +108,10 @@ private:
--------------------------------------------------------------------------------------- */
RealOpenMM calculatePairIxn(RealOpenMM radiusI, RealOpenMM radiusJ,
const OpenMM::RealVec& particleIPosition, const OpenMM::RealVec& particleJPosition,
const RealOpenMM* const intermediateValues,
Vec3& force) const;
double calculatePairIxn(double radiusI, double radiusJ,
const OpenMM::Vec3& particleIPosition, const OpenMM::Vec3& particleJPosition,
const double* const intermediateValues,
Vec3& force) const;
};
......
......@@ -41,19 +41,19 @@
using namespace OpenMM;
using namespace std;
static vector<RealVec>& extractPositions(ContextImpl& context) {
static vector<Vec3>& extractPositions(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<RealVec>*) data->positions);
return *((vector<Vec3>*) data->positions);
}
static vector<RealVec>& extractVelocities(ContextImpl& context) {
static vector<Vec3>& extractVelocities(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<RealVec>*) data->velocities);
return *((vector<Vec3>*) data->velocities);
}
static vector<RealVec>& extractForces(ContextImpl& context) {
static vector<Vec3>& extractForces(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<RealVec>*) data->forces);
return *((vector<Vec3>*) data->forces);
}
static ReferenceConstraints& extractConstraints(ContextImpl& context) {
......@@ -64,13 +64,13 @@ static ReferenceConstraints& extractConstraints(ContextImpl& context) {
static double computeShiftedKineticEnergy(ContextImpl& context, vector<double>& inverseMasses, double timeShift) {
const System& system = context.getSystem();
int numParticles = system.getNumParticles();
vector<RealVec>& posData = extractPositions(context);
vector<RealVec>& velData = extractVelocities(context);
vector<RealVec>& forceData = extractForces(context);
vector<Vec3>& posData = extractPositions(context);
vector<Vec3>& velData = extractVelocities(context);
vector<Vec3>& forceData = extractForces(context);
// Compute the shifted velocities.
vector<RealVec> shiftedVel(numParticles);
vector<Vec3> shiftedVel(numParticles);
for (int i = 0; i < numParticles; ++i) {
if (inverseMasses[i] > 0)
shiftedVel[i] = velData[i]+forceData[i]*(timeShift*inverseMasses[i]);
......@@ -119,8 +119,8 @@ void ReferenceCalcDrudeForceKernel::initialize(const System& system, const Drude
}
double ReferenceCalcDrudeForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
vector<RealVec>& pos = extractPositions(context);
vector<RealVec>& force = extractForces(context);
vector<Vec3>& pos = extractPositions(context);
vector<Vec3>& force = extractForces(context);
int numParticles = particle.size();
double energy = 0;
......@@ -133,17 +133,17 @@ double ReferenceCalcDrudeForceKernel::execute(ContextImpl& context, bool include
int p3 = particle3[i];
int p4 = particle4[i];
RealOpenMM a1 = (p2 == -1 ? 1 : aniso12[i]);
RealOpenMM a2 = (p3 == -1 || p4 == -1 ? 1 : aniso34[i]);
RealOpenMM a3 = 3-a1-a2;
RealOpenMM k3 = ONE_4PI_EPS0*charge[i]*charge[i]/(polarizability[i]*a3);
RealOpenMM k1 = ONE_4PI_EPS0*charge[i]*charge[i]/(polarizability[i]*a1) - k3;
RealOpenMM k2 = ONE_4PI_EPS0*charge[i]*charge[i]/(polarizability[i]*a2) - k3;
double a1 = (p2 == -1 ? 1 : aniso12[i]);
double a2 = (p3 == -1 || p4 == -1 ? 1 : aniso34[i]);
double a3 = 3-a1-a2;
double k3 = ONE_4PI_EPS0*charge[i]*charge[i]/(polarizability[i]*a3);
double k1 = ONE_4PI_EPS0*charge[i]*charge[i]/(polarizability[i]*a1) - k3;
double k2 = ONE_4PI_EPS0*charge[i]*charge[i]/(polarizability[i]*a2) - k3;
// Compute the isotropic force.
RealVec delta = pos[p]-pos[p1];
RealOpenMM r2 = delta.dot(delta);
Vec3 delta = pos[p]-pos[p1];
double r2 = delta.dot(delta);
energy += 0.5*k3*r2;
force[p] -= delta*k3;
force[p1] += delta*k3;
......@@ -151,13 +151,13 @@ double ReferenceCalcDrudeForceKernel::execute(ContextImpl& context, bool include
// Compute the first anisotropic force.
if (p2 != -1) {
RealVec dir = pos[p1]-pos[p2];
RealOpenMM invDist = 1.0/sqrt(dir.dot(dir));
Vec3 dir = pos[p1]-pos[p2];
double invDist = 1.0/sqrt(dir.dot(dir));
dir *= invDist;
RealOpenMM rprime = dir.dot(delta);
double rprime = dir.dot(delta);
energy += 0.5*k1*rprime*rprime;
RealVec f1 = dir*(k1*rprime);
RealVec f2 = (delta-dir*rprime)*(k1*rprime*invDist);
Vec3 f1 = dir*(k1*rprime);
Vec3 f2 = (delta-dir*rprime)*(k1*rprime*invDist);
force[p] -= f1;
force[p1] += f1-f2;
force[p2] += f2;
......@@ -166,13 +166,13 @@ double ReferenceCalcDrudeForceKernel::execute(ContextImpl& context, bool include
// Compute the second anisotropic force.
if (p3 != -1 && p4 != -1) {
RealVec dir = pos[p3]-pos[p4];
RealOpenMM invDist = 1.0/sqrt(dir.dot(dir));
Vec3 dir = pos[p3]-pos[p4];
double invDist = 1.0/sqrt(dir.dot(dir));
dir *= invDist;
RealOpenMM rprime = dir.dot(delta);
double rprime = dir.dot(delta);
energy += 0.5*k2*rprime*rprime;
RealVec f1 = dir*(k2*rprime);
RealVec f2 = (delta-dir*rprime)*(k2*rprime*invDist);
Vec3 f1 = dir*(k2*rprime);
Vec3 f2 = (delta-dir*rprime)*(k2*rprime*invDist);
force[p] -= f1;
force[p1] += f1;
force[p3] -= f2;
......@@ -188,18 +188,18 @@ double ReferenceCalcDrudeForceKernel::execute(ContextImpl& context, bool include
int dipole2 = pair2[i];
int dipole1Particles[] = {particle[dipole1], particle1[dipole1]};
int dipole2Particles[] = {particle[dipole2], particle1[dipole2]};
RealOpenMM uscale = pairThole[i]/pow(polarizability[dipole1]*polarizability[dipole2], 1.0/6.0);
double uscale = pairThole[i]/pow(polarizability[dipole1]*polarizability[dipole2], 1.0/6.0);
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++) {
int p1 = dipole1Particles[j];
int p2 = dipole2Particles[k];
RealOpenMM chargeProduct = charge[dipole1]*charge[dipole2]*(j == k ? 1 : -1);
RealVec delta = pos[p1]-pos[p2];
RealOpenMM r = sqrt(delta.dot(delta));
RealOpenMM u = r*uscale;
RealOpenMM screening = 1.0 - (1.0+0.5*u)*exp(-u);
double chargeProduct = charge[dipole1]*charge[dipole2]*(j == k ? 1 : -1);
Vec3 delta = pos[p1]-pos[p2];
double r = sqrt(delta.dot(delta));
double u = r*uscale;
double screening = 1.0 - (1.0+0.5*u)*exp(-u);
energy += ONE_4PI_EPS0*chargeProduct*screening/r;
RealVec f = delta*(ONE_4PI_EPS0*chargeProduct/(r*r))*(screening/r-0.5*(1+u)*exp(-u)*uscale);
Vec3 f = delta*(ONE_4PI_EPS0*chargeProduct/(r*r))*(screening/r-0.5*(1+u)*exp(-u)*uscale);
force[p1] += f;
force[p2] -= f;
}
......@@ -257,21 +257,21 @@ void ReferenceIntegrateDrudeLangevinStepKernel::initialize(const System& system,
}
void ReferenceIntegrateDrudeLangevinStepKernel::execute(ContextImpl& context, const DrudeLangevinIntegrator& integrator) {
vector<RealVec>& pos = extractPositions(context);
vector<RealVec>& vel = extractVelocities(context);
vector<RealVec>& force = extractForces(context);
vector<Vec3>& pos = extractPositions(context);
vector<Vec3>& vel = extractVelocities(context);
vector<Vec3>& force = extractForces(context);
// Update velocities of ordinary particles.
const RealOpenMM vscale = exp(-integrator.getStepSize()*integrator.getFriction());
const RealOpenMM fscale = (1-vscale)/integrator.getFriction();
const RealOpenMM kT = BOLTZ*integrator.getTemperature();
const RealOpenMM noisescale = sqrt(2*kT*integrator.getFriction())*sqrt(0.5*(1-vscale*vscale)/integrator.getFriction());
const double vscale = exp(-integrator.getStepSize()*integrator.getFriction());
const double fscale = (1-vscale)/integrator.getFriction();
const double kT = BOLTZ*integrator.getTemperature();
const double noisescale = sqrt(2*kT*integrator.getFriction())*sqrt(0.5*(1-vscale*vscale)/integrator.getFriction());
for (int i = 0; i < (int) normalParticles.size(); i++) {
int index = normalParticles[i];
RealOpenMM invMass = particleInvMass[index];
double invMass = particleInvMass[index];
if (invMass != 0.0) {
RealOpenMM sqrtInvMass = sqrt(invMass);
double sqrtInvMass = sqrt(invMass);
for (int j = 0; j < 3; j++)
vel[index][j] = vscale*vel[index][j] + fscale*invMass*force[index][j] + noisescale*sqrtInvMass*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber();
}
......@@ -279,21 +279,21 @@ void ReferenceIntegrateDrudeLangevinStepKernel::execute(ContextImpl& context, co
// Update velocities of Drude particle pairs.
const RealOpenMM vscaleDrude = exp(-integrator.getStepSize()*integrator.getDrudeFriction());
const RealOpenMM fscaleDrude = (1-vscaleDrude)/integrator.getDrudeFriction();
const RealOpenMM kTDrude = BOLTZ*integrator.getDrudeTemperature();
const RealOpenMM noisescaleDrude = sqrt(2*kTDrude*integrator.getDrudeFriction())*sqrt(0.5*(1-vscaleDrude*vscaleDrude)/integrator.getDrudeFriction());
const double vscaleDrude = exp(-integrator.getStepSize()*integrator.getDrudeFriction());
const double fscaleDrude = (1-vscaleDrude)/integrator.getDrudeFriction();
const double kTDrude = BOLTZ*integrator.getDrudeTemperature();
const double noisescaleDrude = sqrt(2*kTDrude*integrator.getDrudeFriction())*sqrt(0.5*(1-vscaleDrude*vscaleDrude)/integrator.getDrudeFriction());
for (int i = 0; i < (int) pairParticles.size(); i++) {
int p1 = pairParticles[i].first;
int p2 = pairParticles[i].second;
RealOpenMM mass1fract = pairInvTotalMass[i]/particleInvMass[p1];
RealOpenMM mass2fract = pairInvTotalMass[i]/particleInvMass[p2];
RealOpenMM sqrtInvTotalMass = sqrt(pairInvTotalMass[i]);
RealOpenMM sqrtInvReducedMass = sqrt(pairInvReducedMass[i]);
RealVec cmVel = vel[p1]*mass1fract+vel[p2]*mass2fract;
RealVec relVel = vel[p2]-vel[p1];
RealVec cmForce = force[p1]+force[p2];
RealVec relForce = force[p2]*mass1fract - force[p1]*mass2fract;
double mass1fract = pairInvTotalMass[i]/particleInvMass[p1];
double mass2fract = pairInvTotalMass[i]/particleInvMass[p2];
double sqrtInvTotalMass = sqrt(pairInvTotalMass[i]);
double sqrtInvReducedMass = sqrt(pairInvReducedMass[i]);
Vec3 cmVel = vel[p1]*mass1fract+vel[p2]*mass2fract;
Vec3 relVel = vel[p2]-vel[p1];
Vec3 cmForce = force[p1]+force[p2];
Vec3 relForce = force[p2]*mass1fract - force[p1]*mass2fract;
for (int j = 0; j < 3; j++) {
cmVel[j] = vscale*cmVel[j] + fscale*pairInvTotalMass[i]*cmForce[j] + noisescale*sqrtInvTotalMass*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber();
relVel[j] = vscaleDrude*relVel[j] + fscaleDrude*pairInvReducedMass[i]*relForce[j] + noisescaleDrude*sqrtInvReducedMass*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber();
......@@ -305,8 +305,8 @@ void ReferenceIntegrateDrudeLangevinStepKernel::execute(ContextImpl& context, co
// Update the particle positions.
int numParticles = particleInvMass.size();
vector<RealVec> xPrime(numParticles);
RealOpenMM dt = integrator.getStepSize();
vector<Vec3> xPrime(numParticles);
double dt = integrator.getStepSize();
for (int i = 0; i < numParticles; i++)
if (particleInvMass[i] != 0.0)
xPrime[i] = pos[i]+vel[i]*dt;
......@@ -317,7 +317,7 @@ void ReferenceIntegrateDrudeLangevinStepKernel::execute(ContextImpl& context, co
// Record the constrained positions and velocities.
RealOpenMM dtInv = 1.0/dt;
double dtInv = 1.0/dt;
for (int i = 0; i < numParticles; i++) {
if (particleInvMass[i] != 0.0) {
vel[i] = (xPrime[i]-pos[i])*dtInv;
......@@ -327,31 +327,31 @@ void ReferenceIntegrateDrudeLangevinStepKernel::execute(ContextImpl& context, co
// Apply hard wall constraints.
const RealOpenMM maxDrudeDistance = integrator.getMaxDrudeDistance();
const double maxDrudeDistance = integrator.getMaxDrudeDistance();
if (maxDrudeDistance > 0) {
const RealOpenMM hardwallscaleDrude = sqrt(kTDrude);
const double hardwallscaleDrude = sqrt(kTDrude);
for (int i = 0; i < (int) pairParticles.size(); i++) {
int p1 = pairParticles[i].first;
int p2 = pairParticles[i].second;
RealVec delta = pos[p1]-pos[p2];
RealOpenMM r = sqrt(delta.dot(delta));
RealOpenMM rInv = 1/r;
Vec3 delta = pos[p1]-pos[p2];
double r = sqrt(delta.dot(delta));
double rInv = 1/r;
if (rInv*maxDrudeDistance < 1.0) {
// The constraint has been violated, so make the inter-particle distance "bounce"
// off the hard wall.
if (rInv*maxDrudeDistance < 0.5)
throw OpenMMException("Drude particle moved too far beyond hard wall constraint");
RealVec bondDir = delta*rInv;
RealVec vel1 = vel[p1];
RealVec vel2 = vel[p2];
RealOpenMM mass1 = particleMass[p1];
RealOpenMM mass2 = particleMass[p2];
RealOpenMM deltaR = r-maxDrudeDistance;
RealOpenMM deltaT = dt;
RealOpenMM dotvr1 = vel1.dot(bondDir);
RealVec vb1 = bondDir*dotvr1;
RealVec vp1 = vel1-vb1;
Vec3 bondDir = delta*rInv;
Vec3 vel1 = vel[p1];
Vec3 vel2 = vel[p2];
double mass1 = particleMass[p1];
double mass2 = particleMass[p2];
double deltaR = r-maxDrudeDistance;
double deltaT = dt;
double dotvr1 = vel1.dot(bondDir);
Vec3 vb1 = bondDir*dotvr1;
Vec3 vp1 = vel1-vb1;
if (mass2 == 0) {
// The parent particle is massless, so move only the Drude particle.
......@@ -360,29 +360,29 @@ void ReferenceIntegrateDrudeLangevinStepKernel::execute(ContextImpl& context, co
if (deltaT > dt)
deltaT = dt;
dotvr1 = -dotvr1*hardwallscaleDrude/(abs(dotvr1)*sqrt(mass1));
RealOpenMM dr = -deltaR + deltaT*dotvr1;
double dr = -deltaR + deltaT*dotvr1;
pos[p1] += bondDir*dr;
vel[p1] = vp1 + bondDir*dotvr1;
}
else {
// Move both particles.
RealOpenMM invTotalMass = pairInvTotalMass[i];
RealOpenMM dotvr2 = vel2.dot(bondDir);
RealVec vb2 = bondDir*dotvr2;
RealVec vp2 = vel2-vb2;
RealOpenMM vbCMass = (mass1*dotvr1 + mass2*dotvr2)*invTotalMass;
double invTotalMass = pairInvTotalMass[i];
double dotvr2 = vel2.dot(bondDir);
Vec3 vb2 = bondDir*dotvr2;
Vec3 vp2 = vel2-vb2;
double vbCMass = (mass1*dotvr1 + mass2*dotvr2)*invTotalMass;
dotvr1 -= vbCMass;
dotvr2 -= vbCMass;
if (dotvr1 != dotvr2)
deltaT = deltaR/abs(dotvr1-dotvr2);
if (deltaT > dt)
deltaT = dt;
RealOpenMM vBond = hardwallscaleDrude/sqrt(mass1);
double vBond = hardwallscaleDrude/sqrt(mass1);
dotvr1 = -dotvr1*vBond*mass2*invTotalMass/abs(dotvr1);
dotvr2 = -dotvr2*vBond*mass1*invTotalMass/abs(dotvr2);
RealOpenMM dr1 = -deltaR*mass2*invTotalMass + deltaT*dotvr1;
RealOpenMM dr2 = deltaR*mass1*invTotalMass + deltaT*dotvr2;
double dr1 = -deltaR*mass2*invTotalMass + deltaT*dotvr1;
double dr2 = deltaR*mass1*invTotalMass + deltaT*dotvr2;
dotvr1 += vbCMass;
dotvr2 += vbCMass;
pos[p1] += bondDir*dr1;
......@@ -419,7 +419,7 @@ void ReferenceIntegrateDrudeSCFStepKernel::initialize(const System& system, cons
// Record particle masses.
vector<RealOpenMM> particleMass;
vector<double> particleMass;
for (int i = 0; i < system.getNumParticles(); i++) {
double mass = system.getParticleMass(i);
particleMass.push_back(mass);
......@@ -433,20 +433,20 @@ void ReferenceIntegrateDrudeSCFStepKernel::initialize(const System& system, cons
throw OpenMMException("DrudeSCFIntegrator: Failed to allocate memory");
lbfgs_parameter_init(&minimizerParams);
minimizerParams.linesearch = LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE;
if (sizeof(RealOpenMM) < 8)
if (sizeof(double) < 8)
minimizerParams.xtol = 1e-7;
}
void ReferenceIntegrateDrudeSCFStepKernel::execute(ContextImpl& context, const DrudeSCFIntegrator& integrator) {
vector<RealVec>& pos = extractPositions(context);
vector<RealVec>& vel = extractVelocities(context);
vector<RealVec>& force = extractForces(context);
vector<Vec3>& pos = extractPositions(context);
vector<Vec3>& vel = extractVelocities(context);
vector<Vec3>& force = extractForces(context);
// Update the positions and velocities.
int numParticles = particleInvMass.size();
vector<RealVec> xPrime(numParticles);
RealOpenMM dt = integrator.getStepSize();
vector<Vec3> xPrime(numParticles);
double dt = integrator.getStepSize();
for (int i = 0; i < numParticles; i++) {
if (particleInvMass[i] != 0.0) {
vel[i] += force[i]*particleInvMass[i]*dt;
......@@ -460,7 +460,7 @@ void ReferenceIntegrateDrudeSCFStepKernel::execute(ContextImpl& context, const D
// Record the constrained positions and velocities.
RealOpenMM dtInv = 1.0/dt;
double dtInv = 1.0/dt;
for (int i = 0; i < numParticles; i++) {
if (particleInvMass[i] != 0.0) {
vel[i] = (xPrime[i]-pos[i])*dtInv;
......@@ -494,13 +494,13 @@ static lbfgsfloatval_t evaluate(void *instance, const lbfgsfloatval_t *x, lbfgsf
// Compute the force and energy for this configuration.
vector<RealVec>& pos = extractPositions(context);
vector<RealVec>& force = extractForces(context);
vector<Vec3>& pos = extractPositions(context);
vector<Vec3>& force = extractForces(context);
for (int i = 0; i < numDrudeParticles; i++)
pos[drudeParticles[i]] = RealVec(x[3*i], x[3*i+1], x[3*i+2]);
pos[drudeParticles[i]] = Vec3(x[3*i], x[3*i+1], x[3*i+2]);
double energy = context.calcForcesAndEnergy(true, true);
for (int i = 0; i < numDrudeParticles; i++) {
RealVec f = force[drudeParticles[i]];
Vec3 f = force[drudeParticles[i]];
g[3*i] = -f[0];
g[3*i+1] = -f[1];
g[3*i+2] = -f[2];
......@@ -511,11 +511,11 @@ static lbfgsfloatval_t evaluate(void *instance, const lbfgsfloatval_t *x, lbfgsf
void ReferenceIntegrateDrudeSCFStepKernel::minimize(ContextImpl& context, double tolerance) {
// Record the initial positions and determine a normalization constant for scaling the tolerance.
vector<RealVec>& pos = extractPositions(context);
vector<Vec3>& pos = extractPositions(context);
int numDrudeParticles = drudeParticles.size();
double norm = 0.0;
for (int i = 0; i < numDrudeParticles; i++) {
RealVec p = pos[drudeParticles[i]];
Vec3 p = pos[drudeParticles[i]];
minimizerPos[3*i] = p[0];
minimizerPos[3*i+1] = p[1];
minimizerPos[3*i+2] = p[2];
......
......@@ -34,7 +34,7 @@
#include "ReferencePlatform.h"
#include "openmm/DrudeKernels.h"
#include "RealVec.h"
#include "openmm/Vec3.h"
#include "lbfgs.h"
#include <utility>
#include <vector>
......
......@@ -78,7 +78,7 @@ void testFreeParticles() {
integ.step(1000);
vector<double> ke(numCopies, 0.0);
vector<double> rg(numParticles, 0.0);
const RealOpenMM hbar = 1.054571628e-34*AVOGADRO/(1000*1e-12);
const double hbar = 1.054571628e-34*AVOGADRO/(1000*1e-12);
for (int i = 0; i < numSteps; i++) {
integ.step(1);
vector<State> state(numCopies);
......
......@@ -78,7 +78,7 @@ void testFreeParticles() {
integ.step(1000);
vector<double> ke(numCopies, 0.0);
vector<double> rg(numParticles, 0.0);
const RealOpenMM hbar = 1.054571628e-34*AVOGADRO/(1000*1e-12);
const double hbar = 1.054571628e-34*AVOGADRO/(1000*1e-12);
for (int i = 0; i < numSteps; i++) {
integ.step(1);
vector<State> state(numCopies);
......@@ -171,7 +171,7 @@ void testParaHydrogen() {
vector<int> counts(numBins, 0);
const double invBoxSize = 1.0/boxSize;
double meanKE = 0.0;
const RealOpenMM hbar = 1.054571628e-34*AVOGADRO/(1000*1e-12);
const double hbar = 1.054571628e-34*AVOGADRO/(1000*1e-12);
for (int step = 0; step < numSteps; step++) {
integ.step(20);
vector<State> states(numCopies);
......
......@@ -37,19 +37,19 @@
using namespace OpenMM;
using namespace std;
static vector<RealVec>& extractPositions(ContextImpl& context) {
static vector<Vec3>& extractPositions(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<RealVec>*) data->positions);
return *((vector<Vec3>*) data->positions);
}
static vector<RealVec>& extractVelocities(ContextImpl& context) {
static vector<Vec3>& extractVelocities(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<RealVec>*) data->velocities);
return *((vector<Vec3>*) data->velocities);
}
static vector<RealVec>& extractForces(ContextImpl& context) {
static vector<Vec3>& extractForces(ContextImpl& context) {
ReferencePlatform::PlatformData* data = reinterpret_cast<ReferencePlatform::PlatformData*>(context.getPlatformData());
return *((vector<RealVec>*) data->forces);
return *((vector<Vec3>*) data->forces);
}
ReferenceIntegrateRPMDStepKernel::~ReferenceIntegrateRPMDStepKernel() {
......@@ -113,12 +113,12 @@ void ReferenceIntegrateRPMDStepKernel::initialize(const System& system, const RP
void ReferenceIntegrateRPMDStepKernel::execute(ContextImpl& context, const RPMDIntegrator& integrator, bool forcesAreValid) {
const int numCopies = positions.size();
const int numParticles = positions[0].size();
const RealOpenMM dt = integrator.getStepSize();
const RealOpenMM halfdt = 0.5*dt;
const double dt = integrator.getStepSize();
const double halfdt = 0.5*dt;
const System& system = context.getSystem();
vector<RealVec>& pos = extractPositions(context);
vector<RealVec>& vel = extractVelocities(context);
vector<RealVec>& f = extractForces(context);
vector<Vec3>& pos = extractPositions(context);
vector<Vec3>& vel = extractVelocities(context);
vector<Vec3>& f = extractForces(context);
// Loop over copies and compute the force on each one.
......@@ -129,17 +129,17 @@ void ReferenceIntegrateRPMDStepKernel::execute(ContextImpl& context, const RPMDI
vector<t_complex> v(numCopies);
vector<t_complex> q(numCopies);
const RealOpenMM hbar = 1.054571628e-34*AVOGADRO/(1000*1e-12);
const RealOpenMM scale = 1.0/sqrt((RealOpenMM) numCopies);
const RealOpenMM nkT = numCopies*BOLTZ*integrator.getTemperature();
const RealOpenMM twown = 2.0*nkT/hbar;
const RealOpenMM c1_0 = exp(-halfdt*integrator.getFriction());
const RealOpenMM c2_0 = sqrt(1.0-c1_0*c1_0);
const double hbar = 1.054571628e-34*AVOGADRO/(1000*1e-12);
const double scale = 1.0/sqrt((double) numCopies);
const double nkT = numCopies*BOLTZ*integrator.getTemperature();
const double twown = 2.0*nkT/hbar;
const double c1_0 = exp(-halfdt*integrator.getFriction());
const double c2_0 = sqrt(1.0-c1_0*c1_0);
if (integrator.getApplyThermostat()) {
for (int particle = 0; particle < numParticles; particle++) {
if (system.getParticleMass(particle) == 0.0)
continue;
const RealOpenMM c3_0 = c2_0*sqrt(nkT/system.getParticleMass(particle));
const double c3_0 = c2_0*sqrt(nkT/system.getParticleMass(particle));
for (int component = 0; component < 3; component++) {
for (int k = 0; k < numCopies; k++)
v[k] = t_complex(scale*velocities[k][particle][component], 0.0);
......@@ -153,12 +153,12 @@ void ReferenceIntegrateRPMDStepKernel::execute(ContextImpl& context, const RPMDI
for (int k = 1; k <= numCopies/2; k++) {
const bool isCenter = (numCopies%2 == 0 && k == numCopies/2);
const RealOpenMM wk = twown*sin(k*M_PI/numCopies);
const RealOpenMM c1 = exp(-2.0*wk*halfdt);
const RealOpenMM c2 = sqrt((1.0-c1*c1)/2) * (isCenter ? sqrt(2.0) : 1.0);
const RealOpenMM c3 = c2*sqrt(nkT/system.getParticleMass(particle));
RealOpenMM rand1 = c3*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber();
RealOpenMM rand2 = (isCenter ? 0.0 : c3*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber());
const double wk = twown*sin(k*M_PI/numCopies);
const double c1 = exp(-2.0*wk*halfdt);
const double c2 = sqrt((1.0-c1*c1)/2) * (isCenter ? sqrt(2.0) : 1.0);
const double c3 = c2*sqrt(nkT/system.getParticleMass(particle));
double rand1 = c3*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber();
double rand2 = (isCenter ? 0.0 : c3*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber());
v[k] = v[k]*c1 + t_complex(rand1, rand2);
if (k < numCopies-k)
v[numCopies-k] = v[numCopies-k]*c1 + t_complex(rand1, -rand2);
......@@ -191,11 +191,11 @@ void ReferenceIntegrateRPMDStepKernel::execute(ContextImpl& context, const RPMDI
fftpack_exec_1d(fft, FFTPACK_FORWARD, &v[0], &v[0]);
q[0] += v[0]*dt;
for (int k = 1; k < numCopies; k++) {
const RealOpenMM wk = twown*sin(k*M_PI/numCopies);
const RealOpenMM wt = wk*dt;
const RealOpenMM coswt = cos(wt);
const RealOpenMM sinwt = sin(wt);
const RealOpenMM wm = wk*system.getParticleMass(particle);
const double wk = twown*sin(k*M_PI/numCopies);
const double wt = wk*dt;
const double coswt = cos(wt);
const double sinwt = sin(wt);
const double wm = wk*system.getParticleMass(particle);
const t_complex vprime = v[k]*coswt - q[k]*(wk*sinwt); // Advance velocity from t to t+dt
q[k] = v[k]*(sinwt/wk) + q[k]*coswt; // Advance position from t to t+dt
v[k] = vprime;
......@@ -226,7 +226,7 @@ void ReferenceIntegrateRPMDStepKernel::execute(ContextImpl& context, const RPMDI
for (int particle = 0; particle < numParticles; particle++) {
if (system.getParticleMass(particle) == 0.0)
continue;
const RealOpenMM c3_0 = c2_0*sqrt(nkT/system.getParticleMass(particle));
const double c3_0 = c2_0*sqrt(nkT/system.getParticleMass(particle));
for (int component = 0; component < 3; component++) {
for (int k = 0; k < numCopies; k++)
v[k] = t_complex(scale*velocities[k][particle][component], 0.0);
......@@ -240,12 +240,12 @@ void ReferenceIntegrateRPMDStepKernel::execute(ContextImpl& context, const RPMDI
for (int k = 1; k <= numCopies/2; k++) {
const bool isCenter = (numCopies%2 == 0 && k == numCopies/2);
const RealOpenMM wk = twown*sin(k*M_PI/numCopies);
const RealOpenMM c1 = exp(-2.0*wk*halfdt);
const RealOpenMM c2 = sqrt((1.0-c1*c1)/2) * (isCenter ? sqrt(2.0) : 1.0);
const RealOpenMM c3 = c2*sqrt(nkT/system.getParticleMass(particle));
RealOpenMM rand1 = c3*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber();
RealOpenMM rand2 = (isCenter ? 0.0 : c3*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber());
const double wk = twown*sin(k*M_PI/numCopies);
const double c1 = exp(-2.0*wk*halfdt);
const double c2 = sqrt((1.0-c1*c1)/2) * (isCenter ? sqrt(2.0) : 1.0);
const double c3 = c2*sqrt(nkT/system.getParticleMass(particle));
double rand1 = c3*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber();
double rand2 = (isCenter ? 0.0 : c3*SimTKOpenMMUtilities::getNormallyDistributedRandomNumber());
v[k] = v[k]*c1 + t_complex(rand1, rand2);
if (k < numCopies-k)
v[numCopies-k] = v[numCopies-k]*c1 + t_complex(rand1, -rand2);
......@@ -265,9 +265,9 @@ void ReferenceIntegrateRPMDStepKernel::execute(ContextImpl& context, const RPMDI
void ReferenceIntegrateRPMDStepKernel::computeForces(ContextImpl& context, const RPMDIntegrator& integrator) {
const int totalCopies = positions.size();
const int numParticles = positions[0].size();
vector<RealVec>& pos = extractPositions(context);
vector<RealVec>& vel = extractVelocities(context);
vector<RealVec>& f = extractForces(context);
vector<Vec3>& pos = extractPositions(context);
vector<Vec3>& vel = extractVelocities(context);
vector<Vec3>& f = extractForces(context);
// Compute forces from all groups that didn't have a specified contraction.
......@@ -298,7 +298,7 @@ void ReferenceIntegrateRPMDStepKernel::computeForces(ContextImpl& context, const
// Find the contracted positions.
vector<t_complex> q(totalCopies);
const RealOpenMM scale1 = 1.0/totalCopies;
const double scale1 = 1.0/totalCopies;
for (int particle = 0; particle < numParticles; particle++) {
for (int component = 0; component < 3; component++) {
// Transform to the frequency domain, set high frequency components to zero, and transform back.
......@@ -329,7 +329,7 @@ void ReferenceIntegrateRPMDStepKernel::computeForces(ContextImpl& context, const
// Apply the forces to the original copies.
const RealOpenMM scale2 = 1.0/copies;
const double scale2 = 1.0/copies;
for (int particle = 0; particle < numParticles; particle++) {
for (int component = 0; component < 3; component++) {
// Transform to the frequency domain, pad with zeros, and transform back.
......@@ -355,12 +355,12 @@ void ReferenceIntegrateRPMDStepKernel::computeForces(ContextImpl& context, const
double ReferenceIntegrateRPMDStepKernel::computeKineticEnergy(ContextImpl& context, const RPMDIntegrator& integrator) {
const System& system = context.getSystem();
int numParticles = system.getNumParticles();
vector<RealVec>& velData = extractVelocities(context);
vector<Vec3>& velData = extractVelocities(context);
double energy = 0.0;
for (int i = 0; i < numParticles; ++i) {
double mass = system.getParticleMass(i);
if (mass > 0) {
RealVec v = velData[i];
Vec3 v = velData[i];
energy += mass*(v.dot(v));
}
}
......
......@@ -34,7 +34,7 @@
#include "ReferencePlatform.h"
#include "openmm/RpmdKernels.h"
#include "RealVec.h"
#include "openmm/Vec3.h"
#include "fftpack.h"
namespace OpenMM {
......@@ -86,11 +86,11 @@ public:
void copyToContext(int copy, ContextImpl& context);
private:
void computeForces(ContextImpl& context, const RPMDIntegrator& integrator);
std::vector<std::vector<RealVec> > positions;
std::vector<std::vector<RealVec> > velocities;
std::vector<std::vector<RealVec> > forces;
std::vector<std::vector<RealVec> > contractedPositions;
std::vector<std::vector<RealVec> > contractedForces;
std::vector<std::vector<Vec3> > positions;
std::vector<std::vector<Vec3> > velocities;
std::vector<std::vector<Vec3> > forces;
std::vector<std::vector<Vec3> > contractedPositions;
std::vector<std::vector<Vec3> > contractedForces;
std::map<int, int> groupsByCopies;
int groupsNotContracted;
fftpack* fft;
......
......@@ -77,7 +77,7 @@ void testFreeParticles() {
integ.step(1000);
vector<double> ke(numCopies, 0.0);
vector<double> rg(numParticles, 0.0);
const RealOpenMM hbar = 1.054571628e-34*AVOGADRO/(1000*1e-12);
const double hbar = 1.054571628e-34*AVOGADRO/(1000*1e-12);
for (int i = 0; i < numSteps; i++) {
integ.step(1);
vector<State> state(numCopies);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment