Simpatico  v1.10
ddMd/analyzers/trajectory/TrajectoryWriter.h
1 #ifndef DDMD_TRAJECTORY_WRITER_H
2 #define DDMD_TRAJECTORY_WRITER_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <ddMd/analyzers/Analyzer.h> // base class
12 #include <ddMd/storage/AtomStorage.h>
13 #ifdef SIMP_BOND
14 #include <ddMd/storage/BondStorage.h>
15 #endif
16 #ifdef SIMP_ANGLE
17 #include <ddMd/storage/AngleStorage.h>
18 #endif
19 #ifdef SIMP_DIHEDRAL
20 #include <ddMd/storage/DihedralStorage.h>
21 #endif
22 #include <simp/boundary/Boundary.h> // typedef
23 
24 namespace DdMd
25 {
26 
27  class Simulation;
28  class Domain;
29  class AtomCollector;
30  template <int N> class GroupCollector;
31 
32  using namespace Util;
33  using namespace Simp;
34 
40  class TrajectoryWriter : public Analyzer
41  {
42 
43  public:
44 
51  TrajectoryWriter(Simulation& simulation, bool isBinary = false);
52 
57  {}
58 
64  virtual void readParameters(std::istream& in);
65 
71  virtual void loadParameters(Serializable::IArchive &ar);
72 
78  virtual void save(Serializable::OArchive &ar);
79 
83  virtual void setup();
84 
90  virtual void sample(long iStep);
91 
95  virtual void clear();
96 
100  virtual void output();
101 
102  protected:
103 
107  bool isBinary() const;
108 
116  virtual void writeHeader(std::ofstream& out)
117  {};
118 
125  virtual void writeFrame(std::ofstream& out, long iStep) = 0;
126 
130  Domain& domain();
131 
135  Boundary& boundary();
136 
140  AtomStorage& atomStorage();
141 
145  AtomCollector& atomCollector();
146 
147  #ifdef SIMP_BOND
148 
151  BondStorage& bondStorage();
152 
156  GroupCollector<2>& bondCollector();
157  #endif
158 
159  #ifdef SIMP_ANGLE
160 
163  AngleStorage& angleStorage();
164 
168  GroupCollector<3>& angleCollector();
169  #endif
170 
171  #ifdef SIMP_DIHEDRAL
172 
175  DihedralStorage& dihedralStorage();
176 
180  GroupCollector<4>& dihedralCollector();
181  #endif
182 
183  private:
184 
185  // Output file stream
186  std::ofstream outputFile_;
187 
189  long isInitialized_;
190 
192  bool isBinary_;
193 
194  // Pointers to associated Domain.
195  Domain* domainPtr_;
196 
197  // Pointers to associated Boundary.
198  Boundary* boundaryPtr_;
199 
200  // Pointers to storage objects.
201  AtomStorage* atomStoragePtr_;
202  #ifdef SIMP_BOND
203  BondStorage* bondStoragePtr_;
204  #endif
205  #ifdef SIMP_ANGLE
206  AngleStorage* angleStoragePtr_;
207  #endif
208  #ifdef SIMP_DIHEDRAL
209  DihedralStorage* dihedralStoragePtr_;
210  #endif
211 
212  };
213 
214  // Inline method definitions
215 
219  inline bool TrajectoryWriter::isBinary() const
220  { return isBinary_; }
221 
223  { return *domainPtr_; }
224 
226  { return *boundaryPtr_; }
227 
229  { return *atomStoragePtr_; }
230 
232  { return atomStoragePtr_->collector(); }
233 
234  #ifdef SIMP_BOND
236  { return *bondStoragePtr_; }
237 
239  { return bondStoragePtr_->collector(); }
240  #endif
241 
242  #ifdef SIMP_ANGLE
244  { return *angleStoragePtr_; }
245 
247  { return angleStoragePtr_->collector(); }
248  #endif
249 
250  #ifdef SIMP_DIHEDRAL
252  { return *dihedralStoragePtr_; }
253 
255  { return dihedralStoragePtr_->collector(); }
256  #endif
257 
258 }
259 #endif
Base class to write a trajectory to a single file.
Abstract base for periodic output and/or analysis actions.
Domain & domain()
Get the Domain by reference.
GroupCollector< 2 > & bondCollector()
Get the bond collector by reference.
An orthorhombic periodic unit cell.
GroupCollector< 3 > & angleCollector()
Get the angle collector by reference.
Parallel domain decomposition (DD) MD simulation.
Classes used by all simpatico molecular simulations.
Main object for a domain-decomposition MD simulation.
Saving / output archive for binary ostream.
Class for collecting Atoms from processors to master processor.
Definition: AtomCollector.h:57
bool isBinary() const
Is the file format binary (true) or text (false)?
Class for collecting Groups from processors to master processor.
Utility classes for scientific computation.
Definition: accumulators.mod:1
BondStorage & bondStorage()
Get BondStorage by reference.
DihedralStorage & dihedralStorage()
Get DihedralStorage by reference.
A container for all the atoms and ghost atoms on this processor.
Decomposition of the system into domains associated with processors.
Definition: Domain.h:31
AtomCollector & atomCollector()
Get the AtomCollector by reference.
Saving archive for binary istream.
Container for Group<3> (angle) objects.
Definition: AngleStorage.h:25
AngleStorage & angleStorage()
Get AngleStorage by reference.
Boundary & boundary()
Get Boundary by reference.
virtual void writeHeader(std::ofstream &out)
Write data that should appear once, at beginning of the file.
Container for Group<4> (dihedral) objects.
GroupCollector< 4 > & dihedralCollector()
Get the dihedral collector by reference.
AtomStorage & atomStorage()
Get AtomStorage by reference.
Container for for Group<2> (bond) objects.
Definition: BondStorage.h:25