PSCF v1.3.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 <rpg/solvers/Mixture.h>
15#include <rpg/field/Domain.h>
16#include <util/misc/FileMaster.h>
17#include <util/misc/ioUtil.h>
18#include <sstream>
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 * Read interval and outputFileName.
51 */
52 template <int D>
54 {
55 nSample_ = 0;
56 std::string filename;
57 filename_ = outputFileName();
58 system().fileMaster().openOutputFile(filename_ , outputFile_);
59 writeHeader(outputFile_);
60 }
61
62 template <int D>
63 void ConcentrationWriter<D>::writeFrame(std::ofstream& out, long iStep)
64 {
65 UTIL_CHECK(system().w().hasData());
66 if (!system().c().hasData()){
67 system().compute();
68 }
69 out << "i = " << iStep << "\n";
70 bool writeHeader = false;
71 bool isSymmetric = false;
72 Domain<D> const & domain = system().domain();
73 FieldIo<D> const & fieldIo = domain.fieldIo();
74 fieldIo.writeFieldsRGrid(out, system().c().rgrid(),
75 domain.unitCell(),
76 writeHeader, isSymmetric);
77 out << "\n";
78 }
79
80
81 template <int D>
82 void ConcentrationWriter<D>::writeHeader(std::ofstream& out)
83 {
84 int nMonomer = system().mixture().nMonomer();
85 bool isSymmetric = false;
86 Domain<D> const & domain = system().domain();
87 FieldIo<D> const & fieldIo = domain.fieldIo();
88 fieldIo.writeFieldHeader(out, nMonomer,
89 domain.unitCell(), isSymmetric);
90 out << "\n";
91 }
92
93
94 /*
95 * Periodically write a frame to file
96 */
97 template <int D>
99 {
100 if (isAtInterval(iStep)) {
101 writeFrame(outputFile_, iStep);
102 ++nSample_;
103 }
104 }
105
106 /*
107 * Close output file at end of simulation.
108 */
109 template <int D>
111 { outputFile_.close(); }
112
113}
114}
115#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.
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.
#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.