1 #ifndef DDMD_ANGLE_POTENTIAL_IMPL_H 2 #define DDMD_ANGLE_POTENTIAL_IMPL_H 11 #include "AnglePotential.h" 25 template <
int N>
class GroupStorage;
32 template <
class Interaction>
56 virtual void setNAngleType(
int nAtomType);
65 virtual void readParameters(std::istream& in);
92 double angleEnergy(
double cosTheta,
int type)
const;
114 void set(std::string name,
int type,
double value)
115 { interactionPtr_->set(name, type, value); }
123 double get(std::string name,
int type)
const 124 {
return interactionPtr_->get(name, type); }
129 virtual std::string interactionClassName()
const;
134 const Interaction& interaction()
const;
139 Interaction& interaction();
150 virtual void computeForces();
158 virtual void computeEnergy(MPI::Intracomm& communicator);
160 virtual void computeEnergy();
169 virtual void computeStress(MPI::Intracomm& communicator);
171 virtual void computeStress();
181 Interaction* interactionPtr_;
192 #include "AnglePotential.h" 193 #include <ddMd/simulation/Simulation.h> 194 #include <ddMd/storage/GroupStorage.h> 195 #include <ddMd/storage/GroupIterator.h> 197 #include <simp/boundary/Boundary.h> 198 #include <util/space/Dimension.h> 199 #include <util/space/Vector.h> 200 #include <util/space/Tensor.h> 208 using namespace Util;
209 using namespace Simp;
214 template <
class Interaction>
218 isInitialized_(false)
220 interactionPtr_ =
new Interaction();
227 template <
class Interaction>
231 isInitialized_(false)
232 { interactionPtr_ =
new Interaction(); }
237 template <
class Interaction>
240 if (interactionPtr_) {
241 delete interactionPtr_;
248 template <
class Interaction>
255 template <
class Interaction>
259 bool nextIndent =
false;
262 isInitialized_ =
true;
268 template <
class Interaction>
273 bool nextIndent =
false;
276 isInitialized_ =
true;
282 template <
class Interaction>
289 template <
class Interaction>
293 {
return interaction().energy(cosTheta, angleTypeId); }
298 template <
class Interaction>
void 308 template <
class Interaction>
315 template <
class Interaction>
317 {
return *interactionPtr_; }
322 template <
class Interaction>
324 {
return *interactionPtr_; }
329 template <
class Interaction>
343 for ( ; iter.
notEnd(); ++iter) {
344 type = iter->typeId();
345 atom0Ptr = iter->atomPtr(0);
346 atom1Ptr = iter->atomPtr(1);
347 atom2Ptr = iter->atomPtr(2);
355 atom0Ptr->
force() += f1;
358 atom1Ptr->
force() -= f1;
359 atom1Ptr->
force() += f2;
362 atom2Ptr->
force() -= f2;
370 template <
class Interaction>
384 double rsq1, rsq2, cosTheta;
386 double localEnergy = 0.0;
388 double third = 1.0/3.0;
393 int type, isLocal0, isLocal1, isLocal2;
396 for ( ; iter.
notEnd(); ++iter) {
397 type = iter->typeId();
398 atom0Ptr = iter->atomPtr(0);
399 atom1Ptr = iter->atomPtr(1);
400 atom2Ptr = iter->atomPtr(2);
401 isLocal0 = !(atom0Ptr->
isGhost());
402 isLocal1 = !(atom1Ptr->
isGhost());
403 isLocal2 = !(atom2Ptr->
isGhost());
409 cosTheta = dr1.
dot(dr2) / sqrt(rsq1 * rsq2);
410 angleEnergy =
interaction().energy(cosTheta, type);
411 fraction = (isLocal0 + isLocal1 + isLocal2)*third;
422 template <
class Interaction>
436 double prefactor = -1.0/3.0;
442 int isLocal0, isLocal1, isLocal2;
447 for ( ; iter.
notEnd(); ++iter) {
448 atom0Ptr = iter->atomPtr(0);
449 atom1Ptr = iter->atomPtr(1);
450 atom2Ptr = iter->atomPtr(2);
451 type = iter->typeId();
460 isLocal0 = !(atom0Ptr->
isGhost());
461 isLocal1 = !(atom1Ptr->
isGhost());
462 isLocal2 = !(atom2Ptr->
isGhost());
463 factor = prefactor*(isLocal0 + isLocal1 + isLocal2);
virtual void readParameters(std::istream &in)
Read potential energy parameters.
Implementation template for a AnglePotential.
A Vector is a Cartesian vector.
Abstract base class for computation of angle force and energies.
virtual ~AnglePotentialImpl()
Destructor.
virtual void computeEnergy(MPI::Intracomm &communicator)
Compute the total angle energy for all processors.
double distanceSq(const Vector &r1, const Vector &r2) const
Return square distance between positions r1 and r2.
bool isStressSet() const
Is the stress set (known)?
void reduceStress(Tensor &localStress, MPI::Intracomm &communicator)
Add local stresses from all processors, set total on master.
double volume() const
Return unit cell volume.
double dot(const Vector &v) const
Return dot product of this vector and vector v.
Vector & position()
Get position Vector by reference.
GroupStorage< 3 > & storage() const
Return bond storage by reference.
Tensor & zero()
Set all elements of this tensor to zero.
File containing preprocessor macros for error handling.
A point particle in an MD simulation.
Parallel domain decomposition (DD) MD simulation.
Classes used by all simpatico molecular simulations.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Main object for a domain-decomposition MD simulation.
A Tensor represents a Cartesian tensor.
double angleEnergy(double cosTheta, int type) const
Returns potential energy for one angle.
virtual void computeForces()
Compute angle forces for atoms.
Saving / output archive for binary ostream.
bool isGhost() const
Is this atom a ghost?
Iterator for all Group < N > objects owned by a GroupStorage< N >.
const Interaction & interaction() const
Return angle interaction by const reference.
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
void begin(GroupIterator< N > &iterator)
Set iterator to beginning of the set of groups.
virtual void setNAngleType(int nAtomType)
Set the maximum number of atom types.
void incrementPairStress(const Vector &f, const Vector &dr, Tensor &stress) const
Add a pair contribution to the stress tensor.
Boundary & boundary() const
Return boundary by reference.
virtual std::string interactionClassName() const
Return pair interaction class name (e.g., "CosineAngle").
Saving archive for binary istream.
Vector & force()
Get force Vector by reference.
void addParamComposite(ParamComposite &child, bool next=true)
Add a child ParamComposite object to the format array.
void reduceEnergy(double localEnergy, MPI::Intracomm &communicator)
Add local energies from all processors, set energy on master.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
virtual void computeStress(MPI::Intracomm &communicator)
Compute the covalent bond stress.
AnglePotentialImpl()
Default constructor.
int nAngleType()
Get maximum number of angle types.
void angleForce(const Vector &R1, const Vector &R2, Vector &F1, Vector &F2, int type) const
Returns forces along two bonds at the angle, for use in MD and stress calculation.
bool isEnergySet() const
Is the energy set (known)?
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.