Commit a711ce2a authored by Peter Eastman's avatar Peter Eastman
Browse files

Refactored ForceImpl, lots of KernelImpl subclasses, and other related classes...

Refactored ForceImpl, lots of KernelImpl subclasses, and other related classes to avoid redundant calculations when requesting a State with both forces and energies
parent 767ea1bd
...@@ -82,36 +82,26 @@ public: ...@@ -82,36 +82,26 @@ public:
*/ */
virtual void initialize(const System& system) = 0; virtual void initialize(const System& system) = 0;
/** /**
* This is called at the beginning of each force computation, before calcForces() has been called on * This is called at the beginning of each force/energy computation, before calcForcesAndEnergy() has been called on
* any ForceImpl. * any ForceImpl.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @param includeForce true if forces should be computed
* @param includeEnergy true if potential energy should be computed
*/ */
virtual void beginForceComputation(ContextImpl& context) = 0; virtual void beginComputation(ContextImpl& context, bool includeForce, bool includeEnergy) = 0;
/** /**
* This is called at the end of each force computation, after calcForces() has been called on * This is called at the end of each force/energy computation, after calcForcesAndEnergy() has been called on
* every ForceImpl. * every ForceImpl.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
*/ * @param includeForce true if forces should be computed
virtual void finishForceComputation(ContextImpl& context) = 0; * @param includeEnergy true if potential energy should be computed
/**
* This is called at the beginning of each energy computation, before calcEnergy() has been called on
* any ForceImpl.
*
* @param context the context in which to execute this kernel
*/
virtual void beginEnergyComputation(ContextImpl& context) = 0;
/**
* This is called at the end of each energy computation, after calcEnergy() has been called on
* every ForceImpl.
*
* @param context the context in which to execute this kernel
* @return the potential energy of the system. This value is added to all values returned by ForceImpls' * @return the potential energy of the system. This value is added to all values returned by ForceImpls'
* calcEnergy() methods. That is, each force kernel may <i>either</i> return its contribution to the * calcForcesAndEnergy() methods. That is, each force kernel may <i>either</i> return its contribution to the
* energy directly, <i>or</i> add it to an internal buffer so that it will be included here. * energy directly, <i>or</i> add it to an internal buffer so that it will be included here.
*/ */
virtual double finishEnergyComputation(ContextImpl& context) = 0; virtual double finishComputation(ContextImpl& context, bool includeForce, bool includeEnergy) = 0;
}; };
/** /**
...@@ -235,18 +225,14 @@ public: ...@@ -235,18 +225,14 @@ public:
*/ */
virtual void initialize(const System& system, const HarmonicBondForce& force) = 0; virtual void initialize(const System& system, const HarmonicBondForce& force) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces and/or energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/ */
virtual void executeForces(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicBondForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
}; };
/** /**
...@@ -267,18 +253,14 @@ public: ...@@ -267,18 +253,14 @@ public:
*/ */
virtual void initialize(const System& system, const CustomBondForce& force) = 0; virtual void initialize(const System& system, const CustomBondForce& force) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @return the potential energy due to the CustomBondForce * @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/ */
virtual double executeEnergy(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
}; };
/** /**
...@@ -299,18 +281,14 @@ public: ...@@ -299,18 +281,14 @@ public:
*/ */
virtual void initialize(const System& system, const HarmonicAngleForce& force) = 0; virtual void initialize(const System& system, const HarmonicAngleForce& force) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces and/or energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
*/ * @param includeForces true if forces should be calculated
virtual void executeForces(ContextImpl& context) = 0; * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the HarmonicAngleForce
*/ */
virtual double executeEnergy(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
}; };
/** /**
...@@ -331,18 +309,14 @@ public: ...@@ -331,18 +309,14 @@ public:
*/ */
virtual void initialize(const System& system, const CustomAngleForce& force) = 0; virtual void initialize(const System& system, const CustomAngleForce& force) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces and/or energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/ */
virtual void executeForces(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomAngleForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
}; };
/** /**
...@@ -363,18 +337,14 @@ public: ...@@ -363,18 +337,14 @@ public:
*/ */
virtual void initialize(const System& system, const PeriodicTorsionForce& force) = 0; virtual void initialize(const System& system, const PeriodicTorsionForce& force) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces and/or energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
*/ * @param includeForces true if forces should be calculated
virtual void executeForces(ContextImpl& context) = 0; * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the PeriodicTorsionForce
*/ */
virtual double executeEnergy(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
}; };
/** /**
...@@ -395,18 +365,14 @@ public: ...@@ -395,18 +365,14 @@ public:
*/ */
virtual void initialize(const System& system, const RBTorsionForce& force) = 0; virtual void initialize(const System& system, const RBTorsionForce& force) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces and/or energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
*/ * @param includeForces true if forces should be calculated
virtual void executeForces(ContextImpl& context) = 0; * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the RBTorsionForce
*/ */
virtual double executeEnergy(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
}; };
/** /**
...@@ -427,18 +393,14 @@ public: ...@@ -427,18 +393,14 @@ public:
*/ */
virtual void initialize(const System& system, const CMAPTorsionForce& force) = 0; virtual void initialize(const System& system, const CMAPTorsionForce& force) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces and/or energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/ */
virtual void executeForces(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CMAPTorsionForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
}; };
/** /**
...@@ -459,18 +421,14 @@ public: ...@@ -459,18 +421,14 @@ public:
*/ */
virtual void initialize(const System& system, const CustomTorsionForce& force) = 0; virtual void initialize(const System& system, const CustomTorsionForce& force) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces and/or energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/ */
virtual void executeForces(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
/**
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the CustomTorsionForce
*/
virtual double executeEnergy(ContextImpl& context) = 0;
}; };
/** /**
...@@ -498,18 +456,14 @@ public: ...@@ -498,18 +456,14 @@ public:
*/ */
virtual void initialize(const System& system, const NonbondedForce& force) = 0; virtual void initialize(const System& system, const NonbondedForce& force) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces and/or energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
*/ * @param includeForces true if forces should be calculated
virtual void executeForces(ContextImpl& context) = 0; * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the NonbondedForce
*/ */
virtual double executeEnergy(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
}; };
/** /**
...@@ -535,18 +489,14 @@ public: ...@@ -535,18 +489,14 @@ public:
*/ */
virtual void initialize(const System& system, const CustomNonbondedForce& force) = 0; virtual void initialize(const System& system, const CustomNonbondedForce& force) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @return the potential energy due to the CustomNonbondedForce * @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/ */
virtual double executeEnergy(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
}; };
/** /**
...@@ -567,18 +517,14 @@ public: ...@@ -567,18 +517,14 @@ public:
*/ */
virtual void initialize(const System& system, const GBSAOBCForce& force) = 0; virtual void initialize(const System& system, const GBSAOBCForce& force) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces and/or energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
*/ * @param includeForces true if forces should be calculated
virtual void executeForces(ContextImpl& context) = 0; * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the GBSAOBCForce
*/ */
virtual double executeEnergy(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
}; };
/** /**
...@@ -600,18 +546,14 @@ public: ...@@ -600,18 +546,14 @@ public:
*/ */
virtual void initialize(const System& system, const GBVIForce& force, const std::vector<double>& scaledRadii) = 0; virtual void initialize(const System& system, const GBVIForce& force, const std::vector<double>& scaledRadii) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces and/or energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
*/ * @param includeForces true if forces should be calculated
virtual void executeForces(ContextImpl& context) = 0; * @param includeEnergy true if the energy should be calculated
/** * @return the potential energy due to the force
* Execute the kernel to calculate the energy.
*
* @param context the context in which to execute this kernel
* @return the potential energy due to the GBVIForce
*/ */
virtual double executeEnergy(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
}; };
/** /**
...@@ -637,18 +579,14 @@ public: ...@@ -637,18 +579,14 @@ public:
*/ */
virtual void initialize(const System& system, const CustomGBForce& force) = 0; virtual void initialize(const System& system, const CustomGBForce& force) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @return the potential energy due to the CustomGBForce * @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/ */
virtual double executeEnergy(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
}; };
/** /**
...@@ -669,18 +607,14 @@ public: ...@@ -669,18 +607,14 @@ public:
*/ */
virtual void initialize(const System& system, const CustomExternalForce& force) = 0; virtual void initialize(const System& system, const CustomExternalForce& force) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @return the potential energy due to the CustomExternalForce * @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/ */
virtual double executeEnergy(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
}; };
/** /**
...@@ -706,18 +640,14 @@ public: ...@@ -706,18 +640,14 @@ public:
*/ */
virtual void initialize(const System& system, const CustomHbondForce& force) = 0; virtual void initialize(const System& system, const CustomHbondForce& force) = 0;
/** /**
* Execute the kernel to calculate the forces. * Execute the kernel to calculate the forces and/or energy.
*
* @param context the context in which to execute this kernel
*/
virtual void executeForces(ContextImpl& context) = 0;
/**
* Execute the kernel to calculate the energy.
* *
* @param context the context in which to execute this kernel * @param context the context in which to execute this kernel
* @return the potential energy due to the CustomHbondForce * @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy due to the force
*/ */
virtual double executeEnergy(ContextImpl& context) = 0; virtual double execute(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
}; };
/** /**
......
...@@ -51,11 +51,9 @@ public: ...@@ -51,11 +51,9 @@ public:
return owner; return owner;
} }
void updateContextState(ContextImpl& context); void updateContextState(ContextImpl& context);
void calcForces(ContextImpl& context) { double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy) {
// This force doesn't apply forces to particles. // This force doesn't apply forces to particles.
} return 0.0;
double calcEnergy(ContextImpl& context) {
return 0.0; // This force doesn't contribute to the potential energy.
} }
std::map<std::string, double> getDefaultParameters(); std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
......
...@@ -55,8 +55,7 @@ public: ...@@ -55,8 +55,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
......
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
return owner; return owner;
} }
void updateContextState(ContextImpl& context); void updateContextState(ContextImpl& context);
void calcForces(ContextImpl& context) { double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy) {
// This force doesn't apply forces to particles. // This force doesn't apply forces to particles.
} }
double calcEnergy(ContextImpl& context) { double calcEnergy(ContextImpl& context) {
......
...@@ -164,18 +164,18 @@ public: ...@@ -164,18 +164,18 @@ public:
*/ */
void applyConstraints(double tol); void applyConstraints(double tol);
/** /**
* Recalculate all of the forces in the system. After calling this, use getForces() to retrieve * Recalculate all of the forces in the system and/or the potential energy of the system (in kJ/mol).
* the forces that were calculated. * After calling this, use getForces() to retrieve the forces that were calculated.
*
* @param includeForces true if forces should be calculated
* @param includeEnergy true if the energy should be calculated
* @return the potential energy of the system, or 0 if includeEnergy is false
*/ */
void calcForces(); double calcForcesAndEnergy(bool includeForces, bool includeEnergy);
/** /**
* Calculate the kinetic energy of the system (in kJ/mol). * Calculate the kinetic energy of the system (in kJ/mol).
*/ */
double calcKineticEnergy(); double calcKineticEnergy();
/**
* Calculate the potential energy of the system (in kJ/mol).
*/
double calcPotentialEnergy();
/** /**
* This should be called at the start of each time step. It calls updateContextState() on each * This should be called at the start of each time step. It calls updateContextState() on each
* ForceImpl in the system, allowing them to modify the values of state variables. * ForceImpl in the system, allowing them to modify the values of state variables.
......
...@@ -56,8 +56,7 @@ public: ...@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters(); std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
private: private:
......
...@@ -56,8 +56,7 @@ public: ...@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters(); std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
std::vector<std::pair<int, int> > getBondedParticles() const; std::vector<std::pair<int, int> > getBondedParticles() const;
......
...@@ -56,8 +56,7 @@ public: ...@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters(); std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
private: private:
......
...@@ -56,8 +56,7 @@ public: ...@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters(); std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
private: private:
......
...@@ -59,8 +59,7 @@ public: ...@@ -59,8 +59,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters(); std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
/** /**
......
...@@ -56,8 +56,7 @@ public: ...@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters(); std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
private: private:
......
...@@ -56,8 +56,7 @@ public: ...@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters(); std::map<std::string, double> getDefaultParameters();
std::vector<std::string> getKernelNames(); std::vector<std::string> getKernelNames();
private: private:
......
...@@ -76,22 +76,16 @@ public: ...@@ -76,22 +76,16 @@ public:
*/ */
virtual void updateContextState(ContextImpl& context) = 0; virtual void updateContextState(ContextImpl& context) = 0;
/** /**
* Calculate the force on each particle generated by this ForceImpl. The forces should be <i>added</i> * Calculate the force on each particle generated by this ForceImpl and/or this ForceImpl's
* to the values already present in the array that is passed in. If this ForceImpl does not generate * contribution to the potential energy of the system.
* any new forces, it should simply return without modifying the array.
* *
* @param context the context in which the system is being simulated * @param context the context in which the system is being simulated
* @param forces new forces should be added to the value already stored in this * @param includeForces true if forces should be calculated
*/ * @param includeEnergy true if the energy should be calculated
virtual void calcForces(ContextImpl& context) = 0;
/**
* Calculate this ForceImpl's contribution to the potential energy of the system.
*
* @param context the context in which the system is being simulated
* @return this force's contribution to the potential energy of the system, or 0 if this * @return this force's contribution to the potential energy of the system, or 0 if this
* force does not contribute to potential energy * force does not contribute to potential energy (or if includeEnergy is false)
*/ */
virtual double calcEnergy(ContextImpl& context) = 0; virtual double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy) = 0;
/** /**
* Get a map containing the default values for all adjustable parameters defined by this ForceImpl. These * Get a map containing the default values for all adjustable parameters defined by this ForceImpl. These
* parameters and their default values will automatically be added to the Context. * parameters and their default values will automatically be added to the Context.
......
...@@ -53,8 +53,7 @@ public: ...@@ -53,8 +53,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
......
...@@ -62,8 +62,7 @@ public: ...@@ -62,8 +62,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
......
...@@ -56,8 +56,7 @@ public: ...@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
......
...@@ -56,8 +56,7 @@ public: ...@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
......
...@@ -52,7 +52,7 @@ public: ...@@ -52,7 +52,7 @@ public:
return owner; return owner;
} }
void updateContextState(ContextImpl& context); void updateContextState(ContextImpl& context);
void calcForces(ContextImpl& context) { double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy) {
// This force doesn't apply forces to particles. // This force doesn't apply forces to particles.
} }
double calcEnergy(ContextImpl& context) { double calcEnergy(ContextImpl& context) {
......
...@@ -58,8 +58,7 @@ public: ...@@ -58,8 +58,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
......
...@@ -56,8 +56,7 @@ public: ...@@ -56,8 +56,7 @@ public:
void updateContextState(ContextImpl& context) { void updateContextState(ContextImpl& context) {
// This force field doesn't update the state directly. // This force field doesn't update the state directly.
} }
void calcForces(ContextImpl& context); double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy);
double calcEnergy(ContextImpl& context);
std::map<std::string, double> getDefaultParameters() { std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters. return std::map<std::string, double>(); // This force field doesn't define any parameters.
} }
......
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