8 #include "DdMdOrderedConfigIo.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 DdMdOrderedConfigIo::readGroups(std::ifstream& file,
62 const char* sectionLabel,
63 const char* nGroupLabel,
68 file >>
Label(sectionLabel);
69 file >> Label(nGroupLabel) >> nGroup;
73 for (
int i = 0; i < nGroup; ++i) {
74 groupPtr = distributor.
newPtr();
94 UTIL_THROW(
"Atom storage is not empty (has local atoms)");
97 UTIL_THROW(
"Atom storage is not empty (has ghost atoms)");
100 UTIL_THROW(
"Atom storage is set for Cartesian coordinates");
102 if (
domain().isMaster() && !file.is_open()) {
103 UTIL_THROW(
"Error: File is not open on master");
106 hasMolecules_ =
false;
110 if (
domain().isMaster()) {
111 file >>
Label(
"BOUNDARY");
120 if (
domain().isMaster()) {
123 file >>
Label(
"ATOMS");
126 file >> Label(
"nAtom") >> nAtom;
145 for (
int i = 0; i < nAtom; ++i) {
150 file >>
id >> typeId;
151 if (id < 0 || id >= totalAtomCapacity) {
158 file >> sId >> mId >> aId;
193 if (
domain().isMaster()) {
194 if (nAtomAll != nAtom) {
195 UTIL_THROW(
"nAtomAll != nAtom after distribution");
201 bool hasGhosts =
false;
207 if (maskPolicy == MaskBonded) {
233 int DdMdOrderedConfigIo::writeGroups(std::ofstream& file,
234 const char* sectionLabel,
235 const char* nGroupLabel,
242 nGroup = storage.
nTotal();
243 if (
domain().isMaster()) {
245 file << sectionLabel << std::endl;
246 file << nGroupLabel <<
Int(nGroup, 10) << std::endl;
249 std::vector<IoGroup <N> > groups;
250 groups.reserve(nGroup);
252 groups.insert(groups.end(), nGroup, ioGroup);
255 groupPtr = collector.
nextPtr();
261 groups[id].group = *groupPtr;
262 groupPtr = collector.
nextPtr();
268 for (
id = 0;
id < nGroup; ++id) {
269 if (
id != groups[
id].
id) {
272 file << groups[id].group << std::endl;
287 if (
domain().isMaster() && !file.is_open()) {
288 UTIL_THROW(
"Error: File is not open on master");
291 hasMolecules_ =
false;
295 if (
domain().isMaster()) {
296 file <<
"BOUNDARY" << std::endl << std::endl;
303 if (
domain().isMaster()) {
307 file <<
"ATOMS" << std::endl;
308 file <<
"nAtom" <<
Int(nAtom, 10) << std::endl;
312 atoms_.reserve(nAtom);
314 atoms_.insert(atoms_.end(), nAtom, atom);
329 atoms_[id].position = r;
330 atoms_[id].velocity = atomPtr->
velocity();
331 atoms_[id].typeId = atomPtr->
typeId();
334 atoms_[id].context = atomPtr->
context();
344 for (
id = 0;
id < nAtom; ++id) {
345 if (
id != atoms_[
id].
id) {
348 file <<
Int(
id, 10) <<
Int(atoms_[
id].typeId, 6);
350 file << Int(atoms_[
id].context.speciesId, 6)
351 << Int(atoms_[
id].context.moleculeId, 6)
352 << Int(atoms_[
id].context.atomId, 6);
354 file <<
"\n" << atoms_[id].position
355 <<
"\n" << atoms_[id].velocity
void computeNTotal(MPI::Intracomm &communicator)
Compute and store the number of distinct groups on all processors.
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.
virtual void readConfig(std::ifstream &file, MaskPolicy maskPolicy)
Read configuration file.
int nAtomTotal() const
Get total number of atoms on all processors.
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.
#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.
DdMdOrderedConfigIo(bool hasMolecules)
Default constructor.
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.
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.
virtual void writeConfig(std::ofstream &file)
Write configuration file.
int id() const
Get the global id for this group.
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.