PSCF v1.2
rpg/fts/analyzer/TrajectoryWriter.tpp
1#ifndef RPG_TRAJECTORY_WRITER_TPP
2#define RPG_TRAJECTORY_WRITER_TPP
3/*
4* PSCF - Polymer Self-Consistent Field Theory
5*
6* Copyright 2016 - 2022, The Regents of the University of Minnesota
7* Distributed under the terms of the GNU General Public License.
8*/
9
10#include "TrajectoryWriter.h"
11#include "Analyzer.h"
12#include <rpg/System.h>
13#include <rpg/fts/simulator/Simulator.h>
14#include <util/misc/FileMaster.h>
15//#include <util/archives/Serializable_includes.h>
16#include <util/misc/ioUtil.h>
17#include <sstream>
18
19
20namespace Pscf {
21namespace Rpg
22{
23
24 using namespace Util;
25
26 /*
27 * Constructor.
28 */
29 template <int D>
31 System<D>& system)
32 : Analyzer<D>(),
33 nSample_(0),
34 isInitialized_(false),
35 simulatorPtr_(&simulator),
36 systemPtr_(&(simulator.system()))
37 { setClassName("TrajectoryWriter"); }
38
39 /*
40 * Read interval and outputFileName.
41 */
42 template <int D>
44 {
46 isInitialized_ = true;
47 }
48
49
50 #if 0
51 /*
52 * Load state from an archive.
53 */
54 template <int D>
56 {
58 ar & nSample_;
59 isInitialized_ = true;
60 }
61 #endif
62
63 /*
64 * Save state to archive.
65 */
66 template <int D>
69
70 /*
71 * Read interval and outputFileName.
72 */
73 template <int D>
75 {
76 nSample_ = 0;
77 std::string filename;
78 filename_ = outputFileName();
79 system().fileMaster().openOutputFile(filename_ , outputFile_);
80 writeHeader(outputFile_);
81 }
82
83 template <int D>
84 void TrajectoryWriter<D>::writeFrame(std::ofstream& out, long iStep)
85 {
86 out << "i = " << iStep << "\n";
87 bool writeHeader = false;
88 bool isSymmetric = false;
89 Domain<D> const & domain = system().domain();
90 FieldIo<D> const & fieldIo = domain.fieldIo();
91 UnitCell<D> const & unitCell = domain.unitCell();
92 fieldIo.writeFieldsRGrid(out, system().w().rgrid(), unitCell,
93 writeHeader, isSymmetric);
94 out << "\n";
95 }
96
97
98 template <int D>
99 void TrajectoryWriter<D>::writeHeader(std::ofstream& out)
100 {
101 bool hasSymmetry = false;
102 int nMonomer = system().mixture().nMonomer();
103 FieldIo<D> const & fieldIo = system().domain().fieldIo();
104 fieldIo.writeFieldHeader(out, nMonomer, system().domain().unitCell(),
106 out << "\n";
107
108 }
109
110
111 /*
112 * Dump configuration to file
113 */
114 template <int D>
116 {
117 if (isAtInterval(iStep)) {
118 writeFrame(outputFile_, iStep);
119 ++nSample_;
120 }
121 }
122
123 /*
124 * Read interval and outputFileName.
125 */
126 template <int D>
128 { outputFile_.close(); }
129
130}
131}
132#endif
void writeFieldHeader(std::ostream &out, int nMonomer, UnitCell< D > const &unitCell, bool isSymmetric=true) const
Write header for field file (fortran pscf format)
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition rpg/System.h:34
Abstract base for periodic output and/or analysis actions.
virtual void readParameters(std::istream &in)
Read parameters from archive.
Spatial domain and spatial discretization for a periodic structure.
UnitCell< D > & unitCell()
Get UnitCell by reference.
FieldIo< D > & fieldIo()
Get associated FieldIo object.
File input/output operations and format conversions for fields.
void writeFieldsRGrid(std::ostream &out, DArray< RField< D > > const &fields, UnitCell< D > const &unitCell, bool writeHeader=true, bool isSymmetric=true, bool writeMeshSize=true) const
Write array of RField objects (fields on r-space grid) to a stream.
Field theoretic simulator (base class).
Definition rpg/System.h:41
Main class for calculations that represent one system.
Definition rpg/System.h:107
void writeHeader(std::ofstream &out)
Write data that should appear once, at beginning of the file.
virtual void save(Serializable::OArchive &ar)
Save state to archive.
void setClassName(const char *className)
Set class name string.
virtual void readParameters(std::istream &in)
Read interval and output file name.
virtual void setup()
Clear nSample counter.
TrajectoryWriter(Simulator< D > &simulator, System< D > &system)
Constructor.
void writeFrame(std::ofstream &out, long iStep)
Write data that should appear in every frame.
virtual void output()
Close trajectory file after run.
virtual void sample(long iStep)
Write a frame/snapshot to trajectory file.
Loading (input) archive for binary istream.
Saving / output archive for binary ostream.
virtual void loadParameters(Serializable::IArchive &ar)
Load state from archive, without adding Begin and End lines.
bool hasSymmetry(AT const &in, Basis< D > const &basis, IntVec< D > const &dftDimensions, double epsilon=1.0e-8, bool verbose=true)
Check if a k-grid field has the declared space group symmetry.
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.