1 #ifndef DDMD_DIHEDRAL_POTENTIAL_IMPL_H 2 #define DDMD_DIHEDRAL_POTENTIAL_IMPL_H 12 #include "DihedralPotential.h" 26 template <
int N>
class GroupStorage;
33 template <
class Interaction>
70 virtual void setNDihedralType(
int nAtomType);
81 virtual void readParameters(std::istream& in);
111 void set(std::string name,
int type,
double value);
119 double get(std::string name,
int type)
const;
158 virtual std::string interactionClassName()
const;
163 Interaction& interaction();
168 const Interaction& interaction()
const;
177 virtual void computeForces();
185 virtual void computeEnergy(MPI::Intracomm& communicator);
187 virtual void computeEnergy();
196 virtual void computeStress(MPI::Intracomm& communicator);
198 virtual void computeStress();
208 Interaction* interactionPtr_;
219 #include "DihedralPotential.h" 220 #include <ddMd/simulation/Simulation.h> 221 #include <ddMd/storage/GroupStorage.h> 222 #include <ddMd/storage/GroupIterator.h> 223 #include <simp/boundary/Boundary.h> 224 #include <util/space/Vector.h> 225 #include <util/space/Dimension.h> 226 #include <util/space/Vector.h> 227 #include <util/space/Tensor.h> 236 using namespace Util;
237 using namespace Simp;
242 template <
class Interaction>
246 isInitialized_(false)
248 interactionPtr_ =
new Interaction();
255 template <
class Interaction>
259 isInitialized_(false)
260 { interactionPtr_ =
new Interaction(); }
265 template <
class Interaction>
268 if (interactionPtr_) {
269 delete interactionPtr_;
276 template <
class Interaction>
283 template <
class Interaction>
287 bool nextIndent =
false;
290 isInitialized_ =
true;
296 template <
class Interaction>
301 bool nextIndent =
false;
304 isInitialized_ =
true;
310 template <
class Interaction>
317 template <
class Interaction>
319 set(std::string name,
int type,
double value)
320 { interactionPtr_->set(name, type, value); }
325 template <
class Interaction>
327 get(std::string name,
int type)
const 328 {
return interactionPtr_->get(name, type); }
333 template <
class Interaction>
337 {
return interaction().energy(R1, R2, R3, typeId); }
342 template <
class Interaction>
346 {
interaction().force(R1, R2, R3, F1, F2, F3, typeId); }
351 template <
class Interaction>
358 template <
class Interaction>
360 {
return *interactionPtr_; }
365 template <
class Interaction>
367 {
return *interactionPtr_; }
372 template <
class Interaction>
390 type = iter->typeId();
391 atom0Ptr = iter->atomPtr(0);
392 atom1Ptr = iter->atomPtr(1);
393 atom2Ptr = iter->atomPtr(2);
394 atom3Ptr = iter->atomPtr(3);
404 interaction().force(dr1, dr2, dr3, f1, f2, f3, type);
407 atom0Ptr->
force() += f1;
410 atom1Ptr->
force() -= f1;
411 atom1Ptr->
force() += f2;
414 atom2Ptr->
force() -= f2;
415 atom2Ptr->
force() += f3;
418 atom3Ptr->
force() -= f3;
426 template <
class Interaction>
450 int type, isLocal0, isLocal1, isLocal2, isLocal3;
455 type = iter->typeId();
456 atom0Ptr = iter->atomPtr(0);
457 atom1Ptr = iter->atomPtr(1);
458 atom2Ptr = iter->atomPtr(2);
459 atom3Ptr = iter->atomPtr(3);
470 dihedralEnergy =
interaction().energy(dr1, dr2, dr3, type);
472 isLocal0 = !(atom0Ptr->
isGhost());
473 isLocal1 = !(atom1Ptr->
isGhost());
474 isLocal2 = !(atom2Ptr->
isGhost());
475 isLocal3 = !(atom3Ptr->
isGhost());
476 fraction = (isLocal0 + isLocal1 + isLocal2 + isLocal3)*0.25;
487 template <
class Interaction>
502 double prefactor = -0.25;
509 int isLocal0, isLocal1, isLocal2, isLocal3;
514 type = iter->typeId();
515 atom0Ptr = iter->atomPtr(0);
516 atom1Ptr = iter->atomPtr(1);
517 atom2Ptr = iter->atomPtr(2);
518 atom3Ptr = iter->atomPtr(3);
529 interaction().force(dr1, dr2, dr2, f1, f2, f3, type);
531 isLocal0 = !(atom0Ptr->
isGhost());
532 isLocal1 = !(atom1Ptr->
isGhost());
533 isLocal2 = !(atom2Ptr->
isGhost());
534 isLocal3 = !(atom3Ptr->
isGhost());
535 factor = prefactor*(isLocal0 + isLocal1 + isLocal2 + isLocal3);
void set(std::string name, int type, double value)
Modify an dihedral parameter, identified by a string.
Boundary & boundary() const
Return boundary by reference.
A Vector is a Cartesian vector.
virtual void dihedralForce(const Vector &R1, const Vector &R2, const Vector &R3, Vector &F1, Vector &F2, Vector &F3, int type) const
Returns derivatives of energy with respect to bond vectors forming the dihedral group.
virtual void setNDihedralType(int nAtomType)
Set the maximum number of atom types.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
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)?
GroupStorage< 4 > & storage() const
Return bond storage by reference.
void reduceStress(Tensor &localStress, MPI::Intracomm &communicator)
Add local stresses from all processors, set total on master.
double volume() const
Return unit cell volume.
virtual void readParameters(std::istream &in)
Read potential energy parameters.
Vector & position()
Get position Vector by reference.
virtual void computeForces()
Add the dihedral forces for all atoms.
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.
Main object for a domain-decomposition MD simulation.
A Tensor represents a Cartesian tensor.
Saving / output archive for binary ostream.
int nDihedralType()
Get maximum number of dihedral types.
Interaction & interaction()
Return dihedral interaction by reference.
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?
virtual double dihedralEnergy(const Vector &R1, const Vector &R2, const Vector &R3, int type) const
Returns potential energy for one dihedral.
Utility classes for scientific computation.
virtual ~DihedralPotentialImpl()
Destructor.
Abstract base class for computing dihedral forces and energies.
void incrementPairStress(const Vector &f, const Vector &dr, Tensor &stress) const
Add a pair contribution to the stress tensor.
virtual std::string interactionClassName() const
Return pair interaction class name (e.g., "CosineDihedral").
virtual void computeEnergy(MPI::Intracomm &communicator)
Compute the total dihedral energy for all processors.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Saving archive for binary istream.
Vector & force()
Get force Vector by reference.
Implementation template for a DihedralPotential.
void addParamComposite(ParamComposite &child, bool next=true)
Add a child ParamComposite object to the format array.
DihedralPotentialImpl()
Default constructor.
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.
double get(std::string name, int type) const
Get a parameter value, identified by a string.
bool isEnergySet() const
Is the energy set (known)?
virtual void computeStress(MPI::Intracomm &communicator)
Compute the covalent dihedral stress.