1 #ifndef DDMD_BOND_POTENTIAL_IMPL_H 2 #define DDMD_BOND_POTENTIAL_IMPL_H 12 #include "BondPotential.h" 20 template <
int N>
class GroupStorage;
27 template <
class Interaction>
66 virtual void setNBondType(
int nAtomType);
77 virtual void readParameters(std::istream& in);
102 virtual double bondEnergy(
double rsq,
int bondTypeId)
const;
107 virtual double bondForceOverR(
double rsq,
int bondTypeId)
const;
113 double randomBondLength(
Random* random,
double beta,
int bondTypeId)
123 void set(std::string name,
int bondTypeId,
double value);
131 double get(std::string name,
int bondTypeId)
const;
136 virtual std::string interactionClassName()
const;
141 const Interaction& interaction()
const;
146 Interaction& interaction();
155 virtual void computeForces();
163 virtual void computeEnergy(MPI::Intracomm& communicator);
165 virtual void computeEnergy();
174 virtual void computeStress(MPI::Intracomm& communicator);
176 virtual void computeStress();
185 virtual void computeForcesAndStress(MPI::Intracomm& communicator);
187 virtual void computeForcesAndStress();
202 Interaction* interactionPtr_;
213 #include "BondPotential.h" 214 #include <ddMd/simulation/Simulation.h> 215 #include <ddMd/storage/GroupStorage.h> 216 #include <ddMd/storage/GroupIterator.h> 217 #include <simp/boundary/Boundary.h> 218 #include <util/space/Vector.h> 219 #include <util/space/Dimension.h> 220 #include <util/space/Vector.h> 221 #include <util/space/Tensor.h> 230 using namespace Util;
231 using namespace Simp;
236 template <
class Interaction>
240 isInitialized_(false)
242 interactionPtr_ =
new Interaction();
249 template <
class Interaction>
253 isInitialized_(false)
254 { interactionPtr_ =
new Interaction(); }
259 template <
class Interaction>
262 if (interactionPtr_) {
263 delete interactionPtr_;
270 template <
class Interaction>
277 template <
class Interaction>
281 bool nextIndent =
false;
284 isInitialized_ =
true;
290 template <
class Interaction>
295 bool nextIndent =
false;
298 isInitialized_ =
true;
304 template <
class Interaction>
311 template <
class Interaction>
319 template <
class Interaction>
323 {
return interaction().forceOverR(rsq, bondTypeId); }
328 template <
class Interaction>
double 331 {
return interaction().randomBondLength(random, beta, bondTypeId); }
336 template <
class Interaction>
343 template <
class Interaction>
347 { interactionPtr_->set(name, bondTypeId, value); }
352 template <
class Interaction>
355 {
return interactionPtr_->get(name, bondTypeId); }
360 template <
class Interaction>
362 {
return *interactionPtr_; }
367 template <
class Interaction>
369 {
return *interactionPtr_; }
374 template <
class Interaction>
382 int type, isLocal0, isLocal1;
385 for ( ; iter.
notEnd(); ++iter) {
386 type = iter->typeId();
387 atom0Ptr = iter->atomPtr(0);
388 atom1Ptr = iter->atomPtr(1);
389 isLocal0 = !(atom0Ptr->
isGhost());
390 isLocal1 = !(atom1Ptr->
isGhost());
395 f *= interactionPtr_->forceOverR(rsq, type);
397 atom0Ptr->
force() += f;
400 atom1Ptr->
force() -= f;
408 template <
class Interaction>
423 double localEnergy = 0.0;
427 int type, isLocal0, isLocal1;
431 for ( ; iter.
notEnd(); ++iter) {
432 type = iter->typeId();
433 atom0Ptr = iter->atomPtr(0);
434 atom1Ptr = iter->atomPtr(1);
439 bondEnergy = interactionPtr_->energy(rsq, type);
441 isLocal0 = !(atom0Ptr->
isGhost());
442 isLocal1 = !(atom1Ptr->
isGhost());
443 if (isLocal0 && isLocal1) {
446 assert(isLocal0 || isLocal1);
458 template <
class Interaction>
471 double rsq, forceOverR;
476 int isLocal0, isLocal1;
482 for ( ; iter.
notEnd(); ++iter) {
483 type = iter->typeId();
484 atom0Ptr = iter->atomPtr(0);
485 atom1Ptr = iter->atomPtr(1);
486 isLocal0 = !(atom0Ptr->
isGhost());
487 isLocal1 = !(atom1Ptr->
isGhost());
491 assert(isLocal0 || isLocal1);
492 if (isLocal0 && isLocal1) {
493 forceOverR = interactionPtr_->forceOverR(rsq, type);
495 forceOverR = 0.5*interactionPtr_->forceOverR(rsq, type);
513 template <
class Interaction>
534 int isLocal0, isLocal1;
540 for ( ; iter.
notEnd(); ++iter) {
541 type = iter->typeId();
542 atom0Ptr = iter->atomPtr(0);
543 atom1Ptr = iter->atomPtr(1);
547 f *= interactionPtr_->forceOverR(rsq, type);
548 isLocal0 = !(atom0Ptr->
isGhost());
549 isLocal1 = !(atom1Ptr->
isGhost());
550 assert(isLocal0 || isLocal1);
552 atom0Ptr->
force() += f;
555 atom1Ptr->
force() -= f;
557 if (!(isLocal0 && isLocal1)) {
A Vector is a Cartesian vector.
double distanceSq(const Vector &r1, const Vector &r2) const
Return square distance between positions r1 and r2.
Implementation template for a BondPotential.
bool isStressSet() const
Is the stress set (known)?
BondPotentialImpl()
Default constructor.
void reduceStress(Tensor &localStress, MPI::Intracomm &communicator)
Add local stresses from all processors, set total on master.
double volume() const
Return unit cell volume.
Vector & position()
Get position Vector by reference.
virtual ~BondPotentialImpl()
Destructor.
Tensor & zero()
Set all elements of this tensor to zero.
virtual double randomBondLength(Random *random, double beta, int bondTypeId) const
Return force / separation for a single pair.
Abstract base class for computing bond forces and energies.
virtual void computeStress(MPI::Intracomm &communicator)
Compute the covalent bond stress.
virtual void computeEnergy(MPI::Intracomm &communicator)
Compute the total bond energy for all processors.
File containing preprocessor macros for error handling.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
const Interaction & interaction() const
Return bond interaction by const reference.
int nBondType()
Get maximum number of bond types.
A point particle in an MD simulation.
Parallel domain decomposition (DD) MD simulation.
Classes used by all simpatico molecular simulations.
virtual void computeForces()
Add the bond forces for all atoms.
virtual void readParameters(std::istream &in)
Read potential energy parameters.
Main object for a domain-decomposition MD simulation.
A Tensor represents a Cartesian tensor.
virtual double bondEnergy(double rsq, int bondTypeId) const
Return pair energy for a single pair.
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 >.
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
void set(std::string name, int bondTypeId, double value)
Modify a bond parameter, identified by a string.
double get(std::string name, int bondTypeId) const
Get a parameter value, identified by a string.
virtual void setNBondType(int nAtomType)
Set the maximum number of atom types.
void begin(GroupIterator< N > &iterator)
Set iterator to beginning of the set of groups.
void incrementPairStress(const Vector &f, const Vector &dr, Tensor &stress) const
Add a pair contribution to the stress tensor.
virtual double bondForceOverR(double rsq, int bondTypeId) const
Return force / separation for a single pair.
GroupStorage< 2 > & storage() const
Return bond storage by reference.
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.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
virtual void computeForcesAndStress(MPI::Intracomm &communicator)
Compute bond forces and stress.
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 std::string interactionClassName() const
Return pair interaction class name (e.g., "HarmonicBond").
Boundary & boundary() const
Return boundary by reference.
bool isEnergySet() const
Is the energy set (known)?