Simpatico  v1.10
ddMd/configIos/ConfigIo.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "ConfigIo.h"
9 
10 #include <ddMd/simulation/Simulation.h>
11 #include <ddMd/communicate/Domain.h>
12 #include <ddMd/communicate/GroupDistributor.tpp>
13 #include <ddMd/communicate/GroupCollector.tpp>
14 
15 #include <ddMd/storage/AtomStorage.h>
16 #ifdef SIMP_BOND
17 #include <ddMd/storage/BondStorage.h>
18 //#include <ddMd/chemistry/Bond.h>
19 #endif
20 #ifdef SIMP_ANGLE
21 #include <ddMd/storage/AngleStorage.h>
22 #endif
23 #ifdef SIMP_DIHEDRAL
24 #include <ddMd/storage/DihedralStorage.h>
25 #endif
26 
27 #include <ddMd/communicate/Buffer.h>
28 #include <ddMd/communicate/GroupCollector.tpp>
29 #include <ddMd/communicate/GroupDistributor.tpp>
30 #include <ddMd/chemistry/Atom.h>
31 #include <ddMd/chemistry/MaskPolicy.h>
32 #include <util/space/Vector.h>
33 #include <util/mpi/MpiSendRecv.h>
34 #include <util/mpi/MpiLoader.h>
35 #include <util/format/Int.h>
36 #include <util/format/Dbl.h>
37 
38 namespace DdMd
39 {
40 
41  using namespace Util;
42 
43  /*
44  * Constructor.
45  */
47  : domainPtr_(0),
48  boundaryPtr_(0),
49  atomStoragePtr_(0)
50  #ifdef SIMP_BOND
51  , bondStoragePtr_(0)
52  #endif
53  #ifdef SIMP_ANGLE
54  , angleStoragePtr_(0)
55  #endif
56  #ifdef SIMP_DIHEDRAL
57  , dihedralStoragePtr_(0)
58  #endif
59  { setClassName("ConfigIo"); }
60 
61  /*
62  * Constructor.
63  */
65  : domainPtr_(0),
66  boundaryPtr_(0),
67  atomStoragePtr_(0)
68  #ifdef SIMP_BOND
69  , bondStoragePtr_(0)
70  #endif
71  #ifdef SIMP_ANGLE
72  , angleStoragePtr_(0)
73  #endif
74  #ifdef SIMP_DIHEDRAL
75  , dihedralStoragePtr_(0)
76  #endif
77  {
78  setClassName("ConfigIo");
79  associate(simulation.domain(),
80  simulation.boundary(),
81  simulation.atomStorage(),
82  #ifdef SIMP_BOND
83  simulation.bondStorage(),
84  #endif
85  #ifdef SIMP_ANGLE
86  simulation.angleStorage(),
87  #endif
88  #ifdef SIMP_DIHEDRAL
89  simulation.dihedralStorage(),
90  #endif
91  simulation.buffer()
92  );
93  }
94 
95  /*
96  * Destructor.
97  */
99  {}
100 
101  /*
102  * Associate with required domain, boundary, storage, and buffer objects.
103  */
106  #ifdef SIMP_BOND
108  #endif
109  #ifdef SIMP_ANGLE
111  #endif
112  #ifdef SIMP_DIHEDRAL
114  #endif
115  Buffer& buffer)
116  {
117  domainPtr_ = &domain;
118  boundaryPtr_ = &boundary;
119 
120  atomStoragePtr_ = &atomStorage;
121  #ifdef SIMP_BOND
122  bondStoragePtr_ = &bondStorage;
123  #endif
124  #ifdef SIMP_ANGLE
125  angleStoragePtr_ = &angleStorage;
126  #endif
127  #ifdef SIMP_DIHEDRAL
128  dihedralStoragePtr_ = &dihedralStorage;
129  #endif
130 
131  }
132 
133 
134  /*
135  * Private method to read Group<N> objects.
136  */
137  template <int N>
138  int ConfigIo::readGroups(std::ifstream& file,
139  const char* sectionLabel,
140  const char* nGroupLabel,
141  GroupDistributor<N>& distributor)
142  {
143  int nGroup; // Total number of groups in file
144  if (domain().isMaster()) {
145  file >> Label(sectionLabel);
146  file >> Label(nGroupLabel) >> nGroup;
147  Group<N>* groupPtr;
148  int i, j, k;
149  distributor.setup();
150  for (i = 0; i < nGroup; ++i) {
151  groupPtr = distributor.newPtr();
152  file >> *groupPtr;
153  for (j = 0; j < 2; ++j) {
154  k = groupPtr->atomId(j);
155  }
156  distributor.add();
157  }
158  // Send any groups not sent previously.
159  distributor.send();
160  } else { // If I am not the master processor
161  // Receive all groups into BondStorage
162  distributor.receive();
163  }
164  return nGroup;
165  }
166 
167  /*
168  * Private method to write Group<N> objects.
169  */
170  template <int N>
171  int ConfigIo::writeGroups(std::ofstream& file,
172  const char* sectionLabel,
173  const char* nGroupLabel,
174  GroupStorage<N>& storage,
175  GroupCollector<N>& collector)
176  {
177  Group<N>* groupPtr;
178  int nGroup;
179  storage.computeNTotal(domain().communicator());
180  nGroup = storage.nTotal();
181  if (domain().isMaster()) {
182  file << std::endl;
183  file << sectionLabel << std::endl;
184  file << nGroupLabel << Int(nGroup, 10) << std::endl;
185  collector.setup();
186  groupPtr = collector.nextPtr();
187  while (groupPtr) {
188  file << *groupPtr << std::endl;
189  groupPtr = collector.nextPtr();
190  }
191  } else {
192  collector.send();
193  }
194  return nGroup;
195  }
196 
197  /*
198  * Set Mask (exclusion list) for all atoms, based on bond data.
199  */
201  {
202 
203  AtomIterator atomIter;
204  atomStorage().begin(atomIter);
205  for ( ; atomIter.notEnd(); ++atomIter) {
206  atomIter->mask().clear();
207  }
208 
209  #ifdef SIMP_BOND
210  int atomId0, atomId1;
211  Atom* atomPtr0;
212  Atom* atomPtr1;
213  GroupIterator<2> bondIter;
214  const AtomMap& atomMap = atomStorage().map();
215  bondStorage().begin(bondIter);
216  for ( ; bondIter.notEnd(); ++bondIter) {
217  atomId0 = bondIter->atomId(0);
218  atomId1 = bondIter->atomId(1);
219  atomPtr0 = atomMap.find(atomId0);
220  atomPtr1 = atomMap.find(atomId1);
221  if (atomPtr0) {
222  atomPtr0->mask().append(atomId1);
223  }
224  if (atomPtr1) {
225  atomPtr1->mask().append(atomId0);
226  }
227  }
228  #endif
229  }
230 
231 }
void computeNTotal(MPI::Intracomm &communicator)
Compute and store the number of distinct groups on all processors.
void setup()
Setup master processor for receiving.
AtomStorage & atomStorage()
Get AtomStorage by reference.
void add()
Add a group to the cache for sending, send if necessary.
AtomStorage & atomStorage()
Get the AtomStorage by reference.
Group< N > * nextPtr()
Return a pointer to the next available atom, or null.
BondStorage & bondStorage()
Get BondStorage by reference.
DihedralStorage & dihedralStorage()
Get the DihedralStorage by reference.
Domain & domain()
Get the Domain by reference.
An orthorhombic periodic unit cell.
void associate(Domain &domain, Boundary &boundary, AtomStorage &atomStorage, BondStorage &bondStorage, AngleStorage &angleStorage, DihedralStorage &dihedralStorage, Buffer &buffer)
Associate with related objects.
void append(int id)
Add an Atom to the masked set.
Associative container for finding atoms identified by integer id.
Definition: AtomMap.h:36
BondStorage & bondStorage()
Get the BondStorage by reference.
A point particle in an MD simulation.
Parallel domain decomposition (DD) MD simulation.
Main object for a domain-decomposition MD simulation.
Class for collecting Groups from processors to master processor.
Iterator for all Group < N > objects owned by a GroupStorage< N >.
Definition: GroupIterator.h:25
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
Definition: accumulators.mod:1
void setAtomMasks()
Set Mask data on all atoms.
const AtomMap & map() const
Return the AtomMap by const reference.
Wrapper for an int, for formatted ostream output.
Definition: Int.h:36
Group< N > * newPtr()
Returns pointer an address available for a new Group<N>.
Boundary & boundary()
Get Boundary by reference.
A container for all the Group<N> objects on this processor.
Atom * find(int atomId) const
Return pointer to Atom with specified id.
Definition: AtomMap.h:230
void send()
Send all atoms that have not be sent previously.
A container for all the atoms and ghost atoms on this processor.
void begin(GroupIterator< N > &iterator)
Set iterator to beginning of the set of groups.
ConfigIo()
Default constructor.
Buffer for interprocessor communication.
Definition: Buffer.h:217
A label string in a file format.
Definition: Label.h:36
Decomposition of the system into domains associated with processors.
Definition: Domain.h:31
int nTotal() const
Return total number of distinct groups on all processors.
void send()
Send all groups on this processor to the master processor.
Container for Group<3> (angle) objects.
Definition: AngleStorage.h:25
void setup()
Initialize Buffer for sending.
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.
Buffer & buffer()
Get the Buffer by reference.
Boundary & boundary()
Get the Boundary by reference.
Container for Group<4> (dihedral) objects.
DihedralStorage & dihedralStorage()
Get DihedralStorage by reference.
Domain & domain()
Get the Domain by reference.
Iterator for all atoms owned by an AtomStorage.
Definition: AtomIterator.h:24
int atomId(int i) const
Get the id for a specific atom in the Group.
void begin(AtomIterator &iterator)
Set iterator to beginning of the set of atoms.
Mask & mask()
Get the associated Mask by reference.
AngleStorage & angleStorage()
Get the AngleStorage by reference.
virtual ~ConfigIo()
Destructor.
Container for for Group<2> (bond) objects.
Definition: BondStorage.h:25
Class template for distributing Group<N> objects among processors.