PSCF v1.3
rpg/fts/analyzer/ConcentrationWriter.tpp
1#ifndef RPG_CONCENTRATION_WRITER_TPP
2#define RPG_CONCENTRATION_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 "ConcentrationWriter.h"
11#include "Analyzer.h"
12#include <rpg/fts/simulator/Simulator.h>
13#include <rpg/system/System.h>
14#include <util/misc/FileMaster.h>
15#include <util/misc/ioUtil.h>
16#include <sstream>
17
18namespace Pscf {
19namespace Rpg
20{
21
22 using namespace Util;
23
24 /*
25 * Constructor.
26 */
27 template <int D>
36
37 /*
38 * Read interval and outputFileName.
39 */
40 template <int D>
42 {
44 isInitialized_ = true;
45 }
46
47 /*
48 * Read interval and outputFileName.
49 */
50 template <int D>
52 {
53 nSample_ = 0;
54 std::string filename;
55 filename_ = outputFileName();
56 system().fileMaster().openOutputFile(filename_ , outputFile_);
57 writeHeader(outputFile_);
58 }
59
60 template <int D>
61 void ConcentrationWriter<D>::writeFrame(std::ofstream& out, long iStep)
62 {
63 UTIL_CHECK(system().w().hasData());
64 if (!system().c().hasData()){
65 system().compute();
66 }
67 out << "i = " << iStep << "\n";
68 bool writeHeader = false;
69 bool isSymmetric = false;
70 Domain<D> const & domain = system().domain();
71 FieldIo<D> const & fieldIo = domain.fieldIo();
72 fieldIo.writeFieldsRGrid(out, system().c().rgrid(),
73 domain.unitCell(),
74 writeHeader, isSymmetric);
75 out << "\n";
76 }
77
78
79 template <int D>
80 void ConcentrationWriter<D>::writeHeader(std::ofstream& out)
81 {
82 int nMonomer = system().mixture().nMonomer();
83 bool isSymmetric = false;
84 Domain<D> const & domain = system().domain();
85 FieldIo<D> const & fieldIo = domain.fieldIo();
86 fieldIo.writeFieldHeader(out, nMonomer,
87 domain.unitCell(), isSymmetric);
88 out << "\n";
89 }
90
91
92 /*
93 * Periodically write a frame to file
94 */
95 template <int D>
97 {
98 if (isAtInterval(iStep)) {
99 writeFrame(outputFile_, iStep);
100 ++nSample_;
101 }
102 }
103
104 /*
105 * Close output file at end of simulation.
106 */
107 template <int D>
109 { outputFile_.close(); }
110
111}
112}
113#endif
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.
long nSample_
Number of configurations dumped thus far (first dump is zero).
ConcentrationWriter(Simulator< D > &simulator, System< D > &system)
Constructor.
void setClassName(const char *className)
Set class name string.
Simulator< D > * simulatorPtr_
Pointer to parent Simulator.
virtual void readParameters(std::istream &in)
Read interval and output file name.
virtual void sample(long iStep)
Write a frame/snapshot to trajectory file.
virtual void output()
Close trajectory file after run.
void writeFrame(std::ofstream &out, long iStep)
Write data that should appear in every frame.
Simulator< D > & simulator()
Return reference to parent Simulator.
System< D > & system()
Return reference to parent system.
System< D > * systemPtr_
Pointer to the parent system.
void writeHeader(std::ofstream &out)
Write data that should appear once, at beginning of the file.
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.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.
Definition param_pc.dox:1