PSCF v1.3
rpg/fts/analyzer/TrajectoryWriter.tpp
1#ifndef RPG_TRAJECTORY_WRITER_TPP
2#define RPG_TRAJECTORY_WRITER_TPP
3/*
4* PSCF - Polymer Self-Consistent Field
5*
6* Copyright 2015 - 2025, 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/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>
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
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition UnitCell.h:56
virtual void readParameters(std::istream &in)
Read parameters from archive.
const std::string & outputFileName() const
Return outputFileName string.
Analyzer()
Default constructor.
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
Spatial domain for a periodic structure with real fields, on a GPU.
FieldIo< D > & fieldIo()
Get the FieldIo by non-const reference.
UnitCell< D > & unitCell()
Get the UnitCell by non-const reference.
File input/output operations and format conversions for fields.
void writeFieldHeader(std::ostream &out, int nMonomer, UnitCell< D > const &unitCell, bool isSymmetric=true) const
Write header for field file (fortran pscf format).
void writeFieldsRGrid(std::ostream &out, DArray< RField< D > > const &fields, UnitCell< D > const &unitCell, bool writeHeader=true, bool isSymmetric=true, bool writeMeshSize=true) const override
Write array of RField objects (fields on r-space grid) to a stream.
Field theoretic simulator (base class).
Main class, representing one complete system.
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.
long nSample_
Number of configurations dumped thus far (first dump is zero).
Simulator< D > & simulator()
Return reference to parent Simulator.
TrajectoryWriter(Simulator< D > &simulator, System< D > &system)
Constructor.
void writeFrame(std::ofstream &out, long iStep)
Write data that should appear in every frame.
Simulator< D > * simulatorPtr_
Pointer to parent Simulator.
System< D > & system()
Return reference to parent system.
virtual void output()
Close trajectory file after run.
long isInitialized_
Has readParam been called?
System< D > * systemPtr_
Pointer to the parent system.
virtual void sample(long iStep)
Write a frame/snapshot to trajectory file.
virtual void loadParameters(Serializable::IArchive &ar)
Load state from archive, without adding Begin and End lines.
BinaryFileIArchive IArchive
Type of input archive used by load method.
BinaryFileOArchive OArchive
Type of output archive used by save method.
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.
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.
Definition param_pc.dox:1