PSCF v1.2
rpc/field/FieldIo.h
1#ifndef RPC_FIELD_IO_H
2#define RPC_FIELD_IO_H
3
4/*
5* PSCF - Polymer Self-Consistent Field Theory
6*
7* Copyright 2016 - 2022, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <prdc/cpu/types.h>
12#include <prdc/cpu/complex.h>
13
14#include <prdc/field/FieldIoReal.h> // base class template
15#include <prdc/cpu/RField.h> // template parameter
16#include <prdc/cpu/RFieldDft.h> // template parameter
17#include <prdc/cpu/FFT.h> // template parameter
18
19// Forward declarations for classes used only via references or pointers
20namespace Util {
21 class FileMaster;
22 template <typename T> class DArray;
23}
24namespace Pscf {
25 namespace Prdc {
26 template <int D> class UnitCell;
27 }
28}
29
30namespace Pscf {
31namespace Rpc {
32
33 using namespace Util;
34 using namespace Pscf::Prdc;
35 using namespace Pscf::Prdc::Cpu;
36
63 template <int D>
64 class FieldIo
65 : public FieldIoReal< D, RField<D>, RFieldDft<D>, FFT<D> >
66 {
67
68 public:
69
71
75 FieldIo();
76
80 ~FieldIo();
81
91 void readFieldsRGrid(std::istream& in,
92 DArray< RField<D> >& fields,
93 UnitCell<D> & unitCell) const override;
94
104 void readFieldsRGridData(std::istream& in,
105 DArray< RField<D> >& fields,
106 int nMonomer) const override;
107
117 void readFieldRGrid(std::istream &in,
118 RField<D> & field,
119 UnitCell<D>& unitCell) const override;
120
133 void writeFieldsRGrid(std::ostream& out,
134 DArray< RField<D> > const & fields,
135 UnitCell<D> const & unitCell,
136 bool writeHeader = true,
137 bool isSymmetric = true,
138 bool writeMeshSize = true) const override;
139
151 void writeFieldRGrid(std::ostream &out,
152 RField<D> const & field,
153 UnitCell<D> const & unitCell,
154 bool writeHeader = true,
155 bool isSymmetric = true)
156 const override;
157
167 void readFieldsKGrid(std::istream& in,
168 DArray< RFieldDft<D> >& fields,
169 UnitCell<D> & unitCell)
170 const override;
171
182 void writeFieldsKGrid(std::ostream& out,
183 DArray< RFieldDft<D> > const & fields,
184 UnitCell<D> const & unitCell,
185 bool isSymmetric = true)
186 const override;
187
196 void convertBasisToKGrid(DArray<double> const & components,
197 RFieldDft<D>& dft)
198 const override;
199
210 void convertKGridToBasis(RFieldDft<D> const & in,
211 DArray<double> & out,
212 bool checkSymmetry = true,
213 double epsilon = 1.0e-8)
214 const override;
215
226 bool hasSymmetry(RFieldDft<D> const & in,
227 double epsilon = 1.0e-8,
228 bool verbose = true)
229 const override;
230
240 void scaleFieldBasis(DArray<double>& field, double factor)
241 const override;
242
252 void scaleFieldRGrid(RField<D>& field, double factor)
253 const override;
254
267 std::ostream &out,
268 DArray<RField<D> > const & fields,
269 UnitCell<D> const & unitCell,
270 int d,
271 DArray<int> const& newGridDimensions)
272 const override;
273
285 std::ostream& out,
286 DArray< RField<D> > const & fields,
287 UnitCell<D> const & unitCell,
288 IntVec<D> const & replicas) const override;
289
290 // Inherited public member functions
291 using Base::associate;
310 using Base::hasSymmetry;
317
318 protected:
319
320 // Inherited protected member functions
321 using Base::mesh;
322 using Base::fft;
323 using Base::lattice;
324 using Base::hasGroup;
325 using Base::groupName;
326 using Base::group;
327 using Base::basis;
328 using Base::fileMaster;
329
330 };
331
332 #ifndef RPC_FIELD_IO_TPP
333 extern template class FieldIo<1>;
334 extern template class FieldIo<2>;
335 extern template class FieldIo<3>;
336 #endif
337
338} // namespace Rpc
339
340#ifndef RPC_FIELD_IO_TPP
341namespace Prdc {
342 using namespace Pscf::Prdc::Cpu;
343 extern template class FieldIoReal<1, RField<1>, RFieldDft<1>, FFT<1>>;
344 extern template class FieldIoReal<2, RField<2>, RFieldDft<2>, FFT<2>>;
345 extern template class FieldIoReal<3, RField<3>, RFieldDft<3>, FFT<3>>;
346}
347#endif
348
349} // namespace Pscf
350#endif
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
Fourier transform wrapper.
Fourier transform of a real field on an FFT mesh.
Field of real double precision values on an FFT mesh.
File input/output operations and format conversions for fields.
Definition FieldIoReal.h:68
virtual void readFieldsRGridData(std::istream &in, DArray< RField< D > > &fields, int nMonomer) const
void scaleFieldsRGrid(DArray< RField< D > > &fields, double factor) const
void writeFieldHeader(std::ostream &out, int nMonomer, UnitCell< D > const &unitCell, bool isSymmetric=true) const
virtual bool hasSymmetry(RFieldDft< D > const &in, double epsilon=1.0e-8, bool verbose=true) const
virtual void expandRGridDimension(std::ostream &out, DArray< RField< D > > const &fields, UnitCell< D > const &unitCell, int d, DArray< int > const &newGridDimensions) const
virtual void writeFieldsRGrid(std::ostream &out, DArray< RField< D > > const &fields, UnitCell< D > const &unitCell, bool writeHeader=true, bool isSymmetric=true, bool writeMeshSize=true) const
virtual void replicateUnitCell(std::ostream &out, DArray< RField< D > > const &fields, UnitCell< D > const &unitCell, IntVec< D > const &replicas) const
virtual void convertBasisToKGrid(DArray< double > const &components, RFieldDft< D > &dft) const
virtual void convertKGridToBasis(RFieldDft< D > const &in, DArray< double > &out, bool checkSymmetry=true, double epsilon=1.0e-8) const
void convertBasisToRGrid(DArray< double > const &in, RField< D > &out) const
virtual void readFieldRGrid(std::istream &in, RField< D > &field, UnitCell< D > &unitCell) const
virtual void writeFieldsKGrid(std::ostream &out, DArray< RFieldDft< D > > const &fields, UnitCell< D > const &unitCell, bool isSymmetric=true) const
void convertRGridToKGrid(DArray< RField< D > > const &in, DArray< RFieldDft< D > > &out) const
virtual void writeFieldRGrid(std::ostream &out, RField< D > const &field, UnitCell< D > const &unitCell, bool writeHeader=true, bool isSymmetric=true) const
void readFieldHeader(std::istream &in, int &nMonomer, UnitCell< D > &unitCell, bool &isSymmetric) const
UnitCell< D >::LatticeSystem const & lattice() const
void convertRGridToBasis(RField< D > const &in, DArray< double > &out, bool checkSymmetry=true, double epsilon=1.0e-8) const
void readFieldBasis(std::istream &in, DArray< double > &field, UnitCell< D > &unitCell) const
void readFieldsBasis(std::istream &in, DArray< DArray< double > > &fields, UnitCell< D > &unitCell) const
virtual void readFieldsRGrid(std::istream &in, DArray< RField< D > > &fields, UnitCell< D > &unitCell) const
void scaleFieldsBasis(DArray< DArray< double > > &fields, double factor) const
void convertKGridToRGrid(DArray< RFieldDft< D > > const &in, DArray< RField< D > > &out) const
void associate(Mesh< D > const &mesh, FFT< D > const &fft, typename UnitCell< D >::LatticeSystem const &lattice, bool const &hasGroup, std::string const &groupName, SpaceGroup< D > const &group, Basis< D > &basis)
virtual void readFieldsKGrid(std::istream &in, DArray< RFieldDft< D > > &fields, UnitCell< D > &unitCell) const
void writeFieldsBasis(std::ostream &out, DArray< DArray< double > > const &fields, UnitCell< D > const &unitCell) const
void writeFieldBasis(std::string filename, DArray< double > const &field, UnitCell< D > const &unitCell) const
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition rpg/System.h:34
void expandRGridDimension(std::ostream &out, DArray< RField< D > > const &fields, UnitCell< D > const &unitCell, int d, DArray< int > const &newGridDimensions) const override
Expand spatial dimension of an array of r-grid fields.
void replicateUnitCell(std::ostream &out, DArray< RField< D > > const &fields, UnitCell< D > const &unitCell, IntVec< D > const &replicas) const override
Write r-grid fields in a replicated unit cell to std::ostream.
bool hasSymmetry(RFieldDft< D > const &in, double epsilon=1.0e-8, bool verbose=true) const override
Check if a k-grid field has the declared space group symmetry.
void scaleFieldRGrid(RField< D > &field, double factor) const override
Rescale a single r-grid field by a scalar factor.
void writeFieldsKGrid(std::ostream &out, DArray< RFieldDft< D > > const &fields, UnitCell< D > const &unitCell, bool isSymmetric=true) const override
Write array of RFieldDft objects (k-space fields) to file.
void readFieldsRGrid(std::istream &in, DArray< RField< D > > &fields, UnitCell< D > &unitCell) const override
Read array of RField objects (r-grid fields) from a stream.
void convertBasisToKGrid(DArray< double > const &components, RFieldDft< D > &dft) const override
Convert a field from symmetrized basis to Fourier grid (k-grid).
void readFieldsRGridData(std::istream &in, DArray< RField< D > > &fields, int nMonomer) const override
Read data for an array of r-grid fields, with no header section.
void readFieldsKGrid(std::istream &in, DArray< RFieldDft< D > > &fields, UnitCell< D > &unitCell) const override
Read array of RFieldDft objects (k-space fields) from a stream.
void convertKGridToBasis(RFieldDft< D > const &in, DArray< double > &out, bool checkSymmetry=true, double epsilon=1.0e-8) const override
Convert a field from Fourier (k-grid) to symmetrized basis form.
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.
void scaleFieldBasis(DArray< double > &field, double factor) const override
Rescale a single field in basis format by a scalar factor.
void readFieldRGrid(std::istream &in, RField< D > &field, UnitCell< D > &unitCell) const override
Read a single RField (field on an r-space grid) from a stream.
FieldIo()
Default constructor.
void writeFieldRGrid(std::ostream &out, RField< D > const &field, UnitCell< D > const &unitCell, bool writeHeader=true, bool isSymmetric=true) const override
Write a single RField (field on an r-space grid) to a stream.
Dynamically allocatable contiguous array template.
A FileMaster manages input and output files for a simulation.
Definition FileMaster.h:143
Fields and FFTs for periodic boundary conditions (CPU)
Definition CField.cpp:12
Periodic fields and crystallography.
Definition CField.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.