Simpatico  v1.10
DdMdGroupTrajectoryWriter.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 "DdMdGroupTrajectoryWriter.h"
9 #include <ddMd/simulation/Simulation.h>
10 #include <ddMd/communicate/AtomCollector.h>
11 #include <ddMd/storage/AtomIterator.h>
12 #include <ddMd/chemistry/Atom.h>
13 #include <util/archives/BinaryFileOArchive.h>
14 #include <util/space/Vector.h>
15 #include <util/misc/Bit.h>
16 
17 #include <climits>
18 
19 namespace DdMd
20 {
21 
22  using namespace Util;
23 
24  /*
25  * Constructor.
26  */
28  : TrajectoryWriter(simulation, true)
29  {}
30 
31  /*
32  * Destructor.
33  */
35  {}
36 
37  /*
38  * Read parameter file block.
39  */
41  {
43  read<unsigned int>(in, "groupId", groupId_);
44  }
45 
46  /*
47  * Load internal state from an archive.
48  */
50  {
52  loadParameter<unsigned int>(ar, "groupId", groupId_);
53  }
54 
55  /*
56  * Save internal state to output archive.
57  */
59  {
61  ar << groupId_;
62  }
63 
64  void DdMdGroupTrajectoryWriter::writeHeader(std::ofstream &file)
65  {
66  if (domain().isMaster()) {
67  BinaryFileOArchive ar(file);
68  Bit bit(groupId_);
69 
70  atomCollector().setup();
71  Atom* atomPtr = atomCollector().nextPtr();
72  nAtom_ = 0;
73  while (atomPtr) {
74  if (bit.isSet(atomPtr->groups())) {
75  ++nAtom_;
76  }
77  atomPtr = atomCollector().nextPtr();
78  }
79  ar << nAtom_;
80  //file << nAtom_ << std::endl;
81  } else {
82  atomCollector().send();
83  }
84  }
85 
86  void DdMdGroupTrajectoryWriter::writeFrame(std::ofstream &file, long iStep)
87  {
88  if (domain().isMaster()) {
89  BinaryFileOArchive ar(file);
90  Bit bit(groupId_);
91 
92  ar << iStep;
93  ar << boundary();
94  //file << iStep << std::endl;
95  //file << boundary() << std::endl;
96 
97  Vector r;
98  int id, j;
99  unsigned int ir;
100  bool isCartesian = atomStorage().isCartesian();
101 
102  atomCollector().setup();
103  Atom* atomPtr = atomCollector().nextPtr();
104  while (atomPtr) {
105  if (bit.isSet(atomPtr->groups())) {
106  id = atomPtr->id();
107  ar << id;
108  //file << id << std::endl;
109  if (isCartesian) {
110  boundary().transformCartToGen(atomPtr->position(), r);
111  } else {
112  r = atomPtr->position();
113  }
114  for (j = 0; j < Dimension; ++j) {
115  if (r[j] >= 1.0) r[j] -= 1.0;
116  if (r[j] < 0.0) r[j] += 1.0;
117  ir = floor( UINT_MAX*r[j] + r[j] + 0.5 );
118  ar << ir;
119  //file << ir;
120  }
121  // ar << atomPtr->velocity();
122  }
123  atomPtr = atomCollector().nextPtr();
124  }
125  } else {
126  atomCollector().send();
127  }
128  }
129 
130 }
Base class to write a trajectory to a single file.
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
Domain & domain()
Get the Domain by reference.
A Vector is a Cartesian vector.
Definition: Vector.h:75
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Vector & position()
Get position Vector by reference.
virtual void readParameters(std::istream &in)
Read parameters and initialize.
void send()
Send all atoms to the master.
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.
Saving / output archive for binary ostream.
bool isSet(unsigned int flags) const
Is this bit set in the flags integer?
Definition: Bit.h:92
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an input archive.
unsigned int & groups()
Get groups bit field by non-const reference.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Atom * nextPtr()
Return a pointer to the next available atom, or null.
DdMdGroupTrajectoryWriter(Simulation &simulation)
Constructor.
void writeHeader(std::ofstream &file)
Write trajectory file header.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
AtomCollector & atomCollector()
Get the AtomCollector by reference.
virtual void save(Serializable::OArchive &ar)
Save internal state to an output archive.
Saving archive for binary istream.
bool isCartesian() const
Are atom coordinates Cartesian (true) or generalized (false)?
void setup()
Setup master processor for receiving.
Boundary & boundary()
Get Boundary by reference.
Represents a specific bit location within an unsigned int.
Definition: Bit.h:21
void writeFrame(std::ofstream &file, long iStep)
Write a single frame.
virtual void readParameters(std::istream &in)
Read parameter file block.
AtomStorage & atomStorage()
Get AtomStorage by reference.
void transformCartToGen(const Vector &Rc, Vector &Rg) const
Transform Cartesian Vector to scaled / generalized coordinates.