Commit 35a4b156 authored by Peter Eastman's avatar Peter Eastman
Browse files

Created default constructor for State

parent 18a837c0
...@@ -57,6 +57,10 @@ public: ...@@ -57,6 +57,10 @@ public:
* a State, use these values to specify which data types it should contain. * a State, use these values to specify which data types it should contain.
*/ */
enum DataType {Positions=1, Velocities=2, Forces=4, Energy=8, Parameters=16}; enum DataType {Positions=1, Velocities=2, Forces=4, Energy=8, Parameters=16};
/**
* Construct an empty State containing no data. This exists so State objects can be used in STL containers.
*/
State();
/** /**
* Get the time for which this State was created. * Get the time for which this State was created.
*/ */
...@@ -95,14 +99,14 @@ public: ...@@ -95,14 +99,14 @@ public:
const std::map<std::string, double>& getParameters() const; const std::map<std::string, double>& getParameters() const;
private: private:
friend class Context; friend class Context;
State(double time, int numParticles, DataType types); State(double time, int numParticles, int types);
std::vector<Vec3>& updPositions(); std::vector<Vec3>& updPositions();
std::vector<Vec3>& updVelocities(); std::vector<Vec3>& updVelocities();
std::vector<Vec3>& updForces(); std::vector<Vec3>& updForces();
std::map<std::string, double>& updParameters(); std::map<std::string, double>& updParameters();
void setEnergy(double ke, double pe); void setEnergy(double ke, double pe);
void setPeriodicBoxVectors(const Vec3& a, const Vec3& b, const Vec3& c); void setPeriodicBoxVectors(const Vec3& a, const Vec3& b, const Vec3& c);
DataType types; int types;
double time, ke, pe; double time, ke, pe;
std::vector<Vec3> positions; std::vector<Vec3> positions;
std::vector<Vec3> velocities; std::vector<Vec3> velocities;
......
...@@ -78,7 +78,7 @@ Platform& Context::getPlatform() { ...@@ -78,7 +78,7 @@ Platform& Context::getPlatform() {
} }
State Context::getState(int types) const { State Context::getState(int types) const {
State state(impl->getTime(), impl->getSystem().getNumParticles(), State::DataType(types)); State state(impl->getTime(), impl->getSystem().getNumParticles(), types);
Vec3 periodicBoxSize[3]; Vec3 periodicBoxSize[3];
impl->getPeriodicBoxVectors(periodicBoxSize[0], periodicBoxSize[1], periodicBoxSize[2]); impl->getPeriodicBoxVectors(periodicBoxSize[0], periodicBoxSize[1], periodicBoxSize[2]);
state.setPeriodicBoxVectors(periodicBoxSize[0], periodicBoxSize[1], periodicBoxSize[2]); state.setPeriodicBoxVectors(periodicBoxSize[0], periodicBoxSize[1], periodicBoxSize[2]);
......
...@@ -73,10 +73,12 @@ const map<string, double>& State::getParameters() const { ...@@ -73,10 +73,12 @@ const map<string, double>& State::getParameters() const {
throw OpenMMException("Invoked getParameters() on a State which does not contain parameters."); throw OpenMMException("Invoked getParameters() on a State which does not contain parameters.");
return parameters; return parameters;
} }
State::State(double time, int numParticles, DataType types) : types(types), time(time), ke(0), pe(0), State::State(double time, int numParticles, int types) : types(types), time(time), ke(0), pe(0),
positions( (types & Positions) == 0 ? 0 : numParticles), velocities( (types & Velocities) == 0 ? 0 : numParticles), positions( (types & Positions) == 0 ? 0 : numParticles), velocities( (types & Velocities) == 0 ? 0 : numParticles),
forces( (types & Forces) == 0 ? 0 : numParticles) { forces( (types & Forces) == 0 ? 0 : numParticles) {
} }
State::State() : types(0), time(0.0), ke(0), pe(0), positions(0), velocities(0), forces(0) {
}
vector<Vec3>& State::updPositions() { vector<Vec3>& State::updPositions() {
return positions; return positions;
} }
......
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