PSCF v1.3
rpc/fts/analyzer/ConcentrationWriter.tpp
1#ifndef RPC_CONCENTRATION_WRITER_TPP
2#define RPC_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
13#include <rpc/system/System.h>
14#include <rpc/fts/simulator/Simulator.h>
15#include <rpc/solvers/Mixture.h>
16#include <rpc/field/Domain.h>
17
18#include <util/misc/FileMaster.h>
19#include <util/misc/ioUtil.h>
20
21#include <string>
22#include <iostream>
23//#include <sstream>
24
25namespace Pscf {
26namespace Rpc
27{
28
29 using namespace Util;
30
31 /*
32 * Constructor.
33 */
34 template <int D>
43
44 /*
45 * Read interval and outputFileName.
46 */
47 template <int D>
49 {
51 isInitialized_ = true;
52 }
53
54 /*
55 * Read interval and outputFileName.
56 */
57 template <int D>
59 {
60 nSample_ = 0;
61 std::string filename;
62 filename_ = outputFileName();
63 system().fileMaster().openOutputFile(filename_ , outputFile_);
64 writeHeader(outputFile_);
65 }
66
67 template <int D>
68 void ConcentrationWriter<D>::writeFrame(std::ofstream& out, long iStep)
69 {
70 UTIL_CHECK(system().w().hasData());
71 if (!system().c().hasData()){
72 system().compute();
73 }
74 out << "i = " << iStep << "\n";
75 bool writeHeader = false;
76 bool isSymmetric = false;
77 Domain<D> const & domain = system().domain();
78 FieldIo<D> const & fieldIo = domain.fieldIo();
79 fieldIo.writeFieldsRGrid(out, system().c().rgrid(),
80 domain.unitCell(),
81 writeHeader, isSymmetric);
82 out << "\n";
83 }
84
85
86 template <int D>
87 void ConcentrationWriter<D>::writeHeader(std::ofstream& out)
88 {
89 int nMonomer = system().mixture().nMonomer();
90 bool isSymmetric = false;
91 Domain<D> const & domain = system().domain();
92 FieldIo<D> const & fieldIo = domain.fieldIo();
93 fieldIo.writeFieldHeader(out, nMonomer,
94 domain.unitCell(), isSymmetric);
95 out << "\n";
96 }
97
98
99 /*
100 * Periodically write a frame to file
101 */
102 template <int D>
104 {
105 if (isAtInterval(iStep)) {
106 writeFrame(outputFile_, iStep);
107 ++nSample_;
108 }
109 }
110
111 /*
112 * Close output file at end of simulation.
113 */
114 template <int D>
116 { outputFile_.close(); }
117
118}
119}
120#endif
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
virtual void readParameters(std::istream &in)
Read parameters from archive.
const std::string & outputFileName() const
Return outputFileName string.
Analyzer()
Default constructor.
void writeHeader(std::ofstream &out)
Write data that should appear once, at beginning of the file.
void setClassName(const char *className)
Set class name string.
void writeFrame(std::ofstream &out, long iStep)
Write data that should appear in every frame.
Simulator< D > * simulatorPtr_
Pointer to parent Simulator.
System< D > * systemPtr_
Pointer to the parent system.
ConcentrationWriter(Simulator< D > &simulator, System< D > &system)
Constructor.
long nSample_
Number of configurations dumped thus far (first dump is zero).
System< D > & system()
Return reference to parent system.
Simulator< D > & simulator()
Return reference to parent Simulator.
virtual void sample(long iStep)
Write a frame/snapshot to trajectory file.
virtual void readParameters(std::istream &in)
Read interval and output file name.
virtual void output()
Close trajectory file after run.
Spatial domain for a periodic structure with real fields, on a CPU.
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
Real periodic fields, SCFT and PS-FTS (CPU).
Definition param_pc.dox:2
PSCF package top-level namespace.
Definition param_pc.dox:1