PSCF v1.3.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/solvers/Mixture.h>
14#include <rpg/field/Domain.h>
15#include <rpg/fts/simulator/Simulator.h>
16#include <util/misc/FileMaster.h>
17#include <util/misc/ioUtil.h>
18#include <sstream>
19
20
21namespace Pscf {
22namespace Rpg
23{
24
25 using namespace Util;
26
27 /*
28 * Constructor.
29 */
30 template <int D>
39
40 /*
41 * Read interval and outputFileName.
42 */
43 template <int D>
45 {
47 isInitialized_ = true;
48 }
49
50
51 #if 0
52 /*
53 * Load state from an archive.
54 */
55 template <int D>
57 {
59 ar & nSample_;
60 isInitialized_ = true;
61 }
62 #endif
63
64 /*
65 * Save state to archive.
66 */
67 template <int D>
70
71 /*
72 * Read interval and outputFileName.
73 */
74 template <int D>
76 {
77 nSample_ = 0;
78 std::string filename;
79 filename_ = outputFileName();
80 system().fileMaster().openOutputFile(filename_ , outputFile_);
81 writeHeader(outputFile_);
82 }
83
84 template <int D>
85 void TrajectoryWriter<D>::writeFrame(std::ofstream& out, long iStep)
86 {
87 out << "i = " << iStep << "\n";
88 bool writeHeader = false;
89 bool isSymmetric = false;
90 Domain<D> const & domain = system().domain();
91 FieldIo<D> const & fieldIo = domain.fieldIo();
92 UnitCell<D> const & unitCell = domain.unitCell();
93 fieldIo.writeFieldsRGrid(out, system().w().rgrid(), unitCell,
94 writeHeader, isSymmetric);
95 out << "\n";
96 }
97
98
99 template <int D>
100 void TrajectoryWriter<D>::writeHeader(std::ofstream& out)
101 {
102 bool hasSymmetry = false;
103 int nMonomer = system().mixture().nMonomer();
104 FieldIo<D> const & fieldIo = system().domain().fieldIo();
105 fieldIo.writeFieldHeader(out, nMonomer, system().domain().unitCell(),
107 out << "\n";
108
109 }
110
111
112 /*
113 * Dump configuration to file
114 */
115 template <int D>
117 {
118 if (isAtInterval(iStep)) {
119 writeFrame(outputFile_, iStep);
120 ++nSample_;
121 }
122 }
123
124 /*
125 * Read interval and outputFileName.
126 */
127 template <int D>
129 { outputFile_.close(); }
130
131}
132}
133#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.
UnitCell< D > & unitCell()
Get the UnitCell by non-const reference.
FieldIo< D > & fieldIo()
Get the FieldIo 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 a complete physical 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.