Simpatico  v1.10
DdMdTrajectoryWriter.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 "DdMdTrajectoryWriter.h"
9 #include <ddMd/simulation/Simulation.h>
10 #include <ddMd/communicate/AtomCollector.h>
11 #include <ddMd/chemistry/Atom.h>
12 #include <util/archives/BinaryFileOArchive.h>
13 #include <util/space/Vector.h>
14 
15 #include <climits>
16 
17 namespace DdMd
18 {
19 
20  using namespace Util;
21 
22  /*
23  * Constructor.
24  */
26  : TrajectoryWriter(simulation, true)
27  { setClassName("DdMdTrajectoryWriter"); }
28 
29  /*
30  * Destructor.
31  */
33  {}
34 
35  void DdMdTrajectoryWriter::writeHeader(std::ofstream &file)
36  {
37  BinaryFileOArchive ar(file);
38 
39  // Compute and write total number of atoms
40  atomStorage().computeNAtomTotal(domain().communicator());
41  if (domain().isMaster()) {
42  nAtom_ = atomStorage().nAtomTotal();
43  ar << nAtom_;
44  }
45 
46  }
47 
48  void DdMdTrajectoryWriter::writeFrame(std::ofstream &file, long iStep)
49  {
50  BinaryFileOArchive ar(file);
51 
52  if (domain().isMaster()) {
53 
54  ar << iStep;
55  ar << boundary();
56 
57  Vector r;
58  int id, j;
59  unsigned int ir;
60  bool isCartesian = atomStorage().isCartesian();
61 
62  atomCollector().setup();
63  Atom* atomPtr = atomCollector().nextPtr();
64  while (atomPtr) {
65  id = atomPtr->id();
66  ar << id;
67  if (isCartesian) {
68  boundary().transformCartToGen(atomPtr->position(), r);
69  } else {
70  r = atomPtr->position();
71  }
72  for (j = 0; j < Dimension; ++j) {
73  if (r[j] >= 1.0) r[j] -= 1.0;
74  if (r[j] < 0.0) r[j] += 1.0;
75  ir = floor( UINT_MAX*r[j] + r[j] + 0.5 );
76  ar << ir;
77  }
78  // ar << atomPtr->velocity();
79  atomPtr = atomCollector().nextPtr();
80  }
81 
82  } else {
83  atomCollector().send();
84  }
85 
86  }
87 
88 }
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
int nAtomTotal() const
Get total number of atoms on all processors.
Vector & position()
Get position Vector by reference.
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.
void writeFrame(std::ofstream &file, long iStep)
Write a single frame.
Saving / output archive for binary ostream.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Atom * nextPtr()
Return a pointer to the next available atom, or null.
void computeNAtomTotal(MPI::Intracomm &communicator)
Compute the total number of local atoms on all processors.
AtomCollector & atomCollector()
Get the AtomCollector by reference.
virtual ~DdMdTrajectoryWriter()
Destructor.
bool isCartesian() const
Are atom coordinates Cartesian (true) or generalized (false)?
void writeHeader(std::ofstream &file)
Write trajectory file header.
void setClassName(const char *className)
Set class name string.
void setup()
Setup master processor for receiving.
Boundary & boundary()
Get Boundary by reference.
AtomStorage & atomStorage()
Get AtomStorage by reference.
DdMdTrajectoryWriter(Simulation &simulation)
Constructor.
void transformCartToGen(const Vector &Rc, Vector &Rg) const
Transform Cartesian Vector to scaled / generalized coordinates.