8 #include "DdMdConfigIo.h" 10 #include <ddMd/simulation/Simulation.h> 11 #include <ddMd/communicate/Domain.h> 13 #include <ddMd/storage/AtomStorage.h> 15 #include <ddMd/storage/BondStorage.h> 18 #include <ddMd/storage/AngleStorage.h> 21 #include <ddMd/storage/DihedralStorage.h> 24 #include <ddMd/communicate/GroupCollector.tpp> 25 #include <ddMd/communicate/GroupDistributor.tpp> 27 #include <ddMd/communicate/Buffer.h> 28 #include <ddMd/chemistry/Atom.h> 29 #include <ddMd/chemistry/Bond.h> 30 #include <ddMd/chemistry/MaskPolicy.h> 31 #include <util/space/Vector.h> 33 #include <util/format/Int.h> 34 #include <util/format/Dbl.h> 46 hasMolecules_(hasMolecules)
54 hasMolecules_(hasMolecules)
61 void DdMdConfigIo::readGroups(std::ifstream& file,
62 const char* sectionLabel,
63 const char* nGroupLabel,
68 file >>
Label(sectionLabel);
69 file >> Label(nGroupLabel) >> nGroup;
72 for (
int i = 0; i < nGroup; ++i) {
73 groupPtr = distributor.
newPtr();
92 UTIL_THROW(
"Atom storage is not empty (has local atoms)");
95 UTIL_THROW(
"Atom storage is not empty (has ghost atoms)");
98 UTIL_THROW(
"Error: Atom storage is set for Cartesian coordinates");
100 if (
domain().isMaster() && !file.is_open()) {
101 UTIL_THROW(
"Error: File is not open on master");
104 hasMolecules_ =
false;
108 if (
domain().isMaster()) {
109 file >>
Label(
"BOUNDARY");
118 if (
domain().isMaster()) {
121 file >>
Label(
"ATOMS");
124 file >> Label(
"nAtom") >> nAtom;
143 for (
int i = 0; i < nAtom; ++i) {
148 file >>
id >> typeId;
149 if (id < 0 || id >= totalAtomCapacity) {
155 file >> sId >> mId >> aId;
189 if (
domain().isMaster()) {
190 if (nAtomAll != nAtom) {
191 UTIL_THROW(
"nAtomAll != nAtom after distribution");
196 bool hasGhosts =
false;
202 if (maskPolicy == MaskBonded) {
227 int DdMdConfigIo::writeGroups(std::ofstream& file,
228 const char* sectionLabel,
229 const char* nGroupLabel,
236 nGroup = storage.
nTotal();
237 if (
domain().isMaster()) {
239 file << sectionLabel << std::endl;
240 file << nGroupLabel <<
Int(nGroup, 10) << std::endl;
242 groupPtr = collector.
nextPtr();
244 file << *groupPtr << std::endl;
245 groupPtr = collector.
nextPtr();
259 if (
domain().isMaster() && !file.is_open()) {
260 UTIL_THROW(
"Error: File is not open on master");
263 hasMolecules_ =
false;
267 if (
domain().isMaster()) {
268 file <<
"BOUNDARY" << std::endl << std::endl;
275 if (
domain().isMaster()) {
277 file <<
"ATOMS" << std::endl;
278 file <<
"nAtom" <<
Int(
atomStorage().nAtomTotal(), 10) << std::endl;
286 file <<
Int(atomPtr->
id(), 10)
299 <<
"\n" << atomPtr->
velocity() <<
"\n";
void computeNTotal(MPI::Intracomm &communicator)
Compute and store the number of distinct groups on all processors.
DdMdConfigIo(bool hasMolecules=false)
Default constructor.
void setup()
Setup master processor for receiving.
GroupDistributor< 2 > & bondDistributor()
Get the bondDistributor by reference.
int typeId() const
Get atom type index.
GroupCollector< 4 > & dihedralCollector()
Get the dihedral collector by reference.
A Vector is a Cartesian vector.
AtomStorage & atomStorage()
Get AtomStorage by reference.
Atom * newAtomPtr()
Returns pointer an address available for a new Atom.
void add()
Add a group to the cache for sending, send if necessary.
int moleculeId
Index of molecule within its molecular species.
Group< N > * nextPtr()
Return a pointer to the next available atom, or null.
BondStorage & bondStorage()
Get BondStorage by reference.
void setTypeId(int Id)
Set the atom type index.
void setId(int Id)
Set unique global id for this Atom.
Domain & domain()
Get the Domain by reference.
Vector & position()
Get position Vector by reference.
AtomCollector & atomCollector()
Get the AtomCollector by reference.
void send()
Send all atoms to the master.
GroupDistributor< 3 > & angleDistributor()
Get the angle distributor by reference.
A point particle in an MD simulation.
Parallel domain decomposition (DD) MD simulation.
Main object for a domain-decomposition MD simulation.
int id() const
Get unique global index for this atom.
int capacity() const
Return capacity for groups on this processor.
virtual void writeConfig(std::ofstream &file)
Write configuration file.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
AtomDistributor & atomDistributor()
Get the AtomDistributor by reference.
void bcast(MPI::Intracomm &comm, T &data, int root)
Broadcast a single T value.
int addAtom()
Process the active atom for sending.
Class for collecting Groups from processors to master processor.
int speciesId
Index of the species of molecule.
Utility classes for scientific computation.
void setAtomMasks()
Set Mask data on all atoms.
Atom * nextPtr()
Return a pointer to the next available atom, or null.
GroupDistributor< 4 > & dihedralDistributor()
Get the dihedral distributor by reference.
MaskPolicy
Enumeration of policies for suppressing ("masking") some pair interactions.
virtual bool isValid(AtomStorage &atomStorage, MPI::Intracomm &communicator, bool hasGhosts)
Return true if the container is valid, or throw an Exception.
static bool hasAtomContext()
Is AtomContext data enabled?
Wrapper for an int, for formatted ostream output.
Group< N > * newPtr()
Returns pointer an address available for a new Group<N>.
Boundary & boundary()
Get Boundary by reference.
void receive()
Receive all atoms sent by master processor.
A container for all the Group<N> objects on this processor.
void send()
Send all atoms that have not be sent previously.
void transformGenToCart(const Vector &Rg, Vector &Rc) const
Transform Vector of generalized coordinates to Cartesian Vector.
GroupCollector< 2 > & bondCollector()
Get the bond collector by reference.
void computeNAtomTotal(MPI::Intracomm &communicator)
Compute the total number of local atoms on all processors.
int totalAtomCapacity() const
Return maximum number of atoms on all processors.
void setup()
Initialization before the loop over atoms on master processor.
A label string in a file format.
int nTotal() const
Return total number of distinct groups on all processors.
AtomContext & context()
Get the AtomContext struct by non-const reference.
int validate()
Validate distribution of atoms after completion.
Abstract reader/writer for configuration files.
Vector & velocity()
Get velocity Vector by reference.
void send()
Send all groups on this processor to the master processor.
void setup()
Initialize Buffer for sending.
bool isCartesian() const
Are atom coordinates Cartesian (true) or generalized (false)?
This file contains templates for global functions send<T>, recv<T> and bcast<T>.
void receive()
Receive all atoms sent by master processor.
AngleStorage & angleStorage()
Get AngleStorage by reference.
void setClassName(const char *className)
Set class name string.
virtual void readConfig(std::ifstream &file, MaskPolicy maskPolicy)
Read configuration file.
A group of covalently interacting atoms.
void setup()
Setup master processor for receiving.
int atomId
Index of atom within its parent molecule.
GroupCollector< 3 > & angleCollector()
Get the angle collector by reference.
DihedralStorage & dihedralStorage()
Get DihedralStorage by reference.
void send()
Send all atoms that have not be sent previously.
void transformCartToGen(const Vector &Rc, Vector &Rg) const
Transform Cartesian Vector to scaled / generalized coordinates.
Class template for distributing Group<N> objects among processors.