Commit 542ee547 authored by peastman's avatar peastman
Browse files

Added System::getNumDegreesOfFreedom()

parent b16bec99
...@@ -224,6 +224,12 @@ public: ...@@ -224,6 +224,12 @@ public:
* @param c the vector defining the third edge of the periodic box * @param c the vector defining the third edge of the periodic box
*/ */
void setDefaultPeriodicBoxVectors(const Vec3& a, const Vec3& b, const Vec3& c); void setDefaultPeriodicBoxVectors(const Vec3& a, const Vec3& b, const Vec3& c);
/**
* Get the total number of degrees of freedom in this system. This is equal to
* 3*(number of massive particles)-(number of constraints), where massive particles
* are ones whose mass does not equal zero.
*/
int getNumDegreesOfFreedom() const;
private: private:
class ConstraintInfo; class ConstraintInfo;
Vec3 periodicBoxVectors[3]; Vec3 periodicBoxVectors[3];
......
...@@ -119,3 +119,11 @@ void System::setDefaultPeriodicBoxVectors(const Vec3& a, const Vec3& b, const Ve ...@@ -119,3 +119,11 @@ void System::setDefaultPeriodicBoxVectors(const Vec3& a, const Vec3& b, const Ve
periodicBoxVectors[1] = b; periodicBoxVectors[1] = b;
periodicBoxVectors[2] = c; periodicBoxVectors[2] = c;
} }
int System::getNumDegreesOfFreedom() const {
int numMassiveParticles = 0;
for (int i = 0; i < (int) masses.size(); i++)
if (masses[i] != 0.0)
numMassiveParticles++;
return 3*numMassiveParticles-constraints.size();
}
...@@ -138,7 +138,7 @@ void testConstraints() { ...@@ -138,7 +138,7 @@ void testConstraints() {
integrator.step(1); integrator.step(1);
} }
ke /= numSteps; ke /= numSteps;
double expected = 0.5*(numParticles*3-system.getNumConstraints())*BOLTZ*temp; double expected = 0.5*system.getNumDegreesOfFreedom()*BOLTZ*temp;
ASSERT_USUALLY_EQUAL_TOL(expected, ke, 0.1); ASSERT_USUALLY_EQUAL_TOL(expected, ke, 0.1);
} }
......
...@@ -128,7 +128,7 @@ void testRandomVelocities() { ...@@ -128,7 +128,7 @@ void testRandomVelocities() {
Vec3 v = state.getVelocities()[i]; Vec3 v = state.getVelocities()[i];
ke += 0.5*system.getParticleMass(i)*v.dot(v); ke += 0.5*system.getParticleMass(i)*v.dot(v);
} }
double expected = 0.5*(numParticles*3-system.getNumConstraints())*BOLTZ*temperture; double expected = 0.5*system.getNumDegreesOfFreedom()*BOLTZ*temperture;
ASSERT_USUALLY_EQUAL_TOL(expected, ke, 4/sqrt((double) numParticles)); ASSERT_USUALLY_EQUAL_TOL(expected, ke, 4/sqrt((double) numParticles));
} }
......
...@@ -138,7 +138,7 @@ void testConstraints() { ...@@ -138,7 +138,7 @@ void testConstraints() {
integrator.step(1); integrator.step(1);
} }
ke /= numSteps; ke /= numSteps;
double expected = 0.5*(numParticles*3-system.getNumConstraints())*BOLTZ*temp; double expected = 0.5*system.getNumDegreesOfFreedom()*BOLTZ*temp;
ASSERT_USUALLY_EQUAL_TOL(expected, ke, 0.1); ASSERT_USUALLY_EQUAL_TOL(expected, ke, 0.1);
} }
......
...@@ -126,7 +126,7 @@ void testRandomVelocities() { ...@@ -126,7 +126,7 @@ void testRandomVelocities() {
Vec3 v = state.getVelocities()[i]; Vec3 v = state.getVelocities()[i];
ke += 0.5*system.getParticleMass(i)*v.dot(v); ke += 0.5*system.getParticleMass(i)*v.dot(v);
} }
double expected = 0.5*(numParticles*3-system.getNumConstraints())*BOLTZ*temperture; double expected = 0.5*system.getNumDegreesOfFreedom()*BOLTZ*temperture;
ASSERT_USUALLY_EQUAL_TOL(expected, ke, 4/sqrt((double) numParticles)); ASSERT_USUALLY_EQUAL_TOL(expected, ke, 4/sqrt((double) numParticles));
} }
......
...@@ -138,7 +138,7 @@ void testConstraints() { ...@@ -138,7 +138,7 @@ void testConstraints() {
integrator.step(1); integrator.step(1);
} }
ke /= numSteps; ke /= numSteps;
double expected = 0.5*(numParticles*3-system.getNumConstraints())*BOLTZ*temp; double expected = 0.5*system.getNumDegreesOfFreedom()*BOLTZ*temp;
ASSERT_USUALLY_EQUAL_TOL(expected, ke, 0.1); ASSERT_USUALLY_EQUAL_TOL(expected, ke, 0.1);
} }
......
...@@ -108,7 +108,7 @@ void testRandomVelocities() { ...@@ -108,7 +108,7 @@ void testRandomVelocities() {
Vec3 v = state.getVelocities()[i]; Vec3 v = state.getVelocities()[i];
ke += 0.5*system.getParticleMass(i)*v.dot(v); ke += 0.5*system.getParticleMass(i)*v.dot(v);
} }
double expected = 0.5*(numParticles*3-system.getNumConstraints())*BOLTZ*temperture; double expected = 0.5*system.getNumDegreesOfFreedom()*BOLTZ*temperture;
ASSERT_USUALLY_EQUAL_TOL(expected, ke, 4/sqrt((double) numParticles)); ASSERT_USUALLY_EQUAL_TOL(expected, ke, 4/sqrt((double) numParticles));
} }
......
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