PSCF v1.2
rpg/field/FieldIo.h
1#ifndef RPG_FIELD_IO_H
2#define RPG_FIELD_IO_H
3
4/*
5* PSCF - Polymer Self-Consistent Field Theory
6*
7* Copyright 2016 - 2025, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <prdc/field/FieldIoReal.h> // base class template
12#include <prdc/cuda/RField.h> // template parameter
13#include <prdc/cuda/RFieldDft.h> // template parameter
14#include <prdc/cuda/FFT.h> // template parameter
15
16// Forward declarations for classes used only via references or pointers
17namespace Util {
18 class FileMaster;
19 template <typename T> class DArray;
20}
21namespace Pscf {
22 namespace Prdc {
23 template <int D> class UnitCell;
24 }
25}
26
27namespace Pscf {
28namespace Rpg {
29
30 using namespace Util;
31 using namespace Pscf::Prdc;
32 using namespace Pscf::Prdc::Cuda;
33
60 template <int D>
61 class FieldIo
62 : public FieldIoReal< D, RField<D>, RFieldDft<D>, FFT<D> >
63 {
64
65 public:
66
68
69 // Inherited public member functions
70 using Base::associate;
96
100 FieldIo();
101
105 ~FieldIo();
106
116 void readFieldsRGrid(std::istream& in,
117 DArray< RField<D> >& fields,
118 UnitCell<D> & unitCell) const;
119
129 void readFieldsRGridData(std::istream& in,
130 DArray< RField<D> >& fields,
131 int nMonomer) const;
132
142 void readFieldRGrid(std::istream &in,
143 RField<D> & field,
144 UnitCell<D>& unitCell) const;
145
158 void writeFieldsRGrid(std::ostream& out,
159 DArray< RField<D> > const & fields,
160 UnitCell<D> const & unitCell,
161 bool writeHeader = true,
162 bool isSymmetric = true,
163 bool writeMeshSize = true) const;
164
176 void writeFieldRGrid(std::ostream &out,
177 RField<D> const & field,
178 UnitCell<D> const & unitCell,
179 bool writeHeader = true,
180 bool isSymmetric = true) const;
181
191 void readFieldsKGrid(std::istream& in,
192 DArray< RFieldDft<D> >& fields,
193 UnitCell<D> & unitCell) const;
194
205 void writeFieldsKGrid(std::ostream& out,
206 DArray< RFieldDft<D> > const & fields,
207 UnitCell<D> const & unitCell,
208 bool isSymmetric = true) const;
209
218 void convertBasisToKGrid(DArray<double> const & components,
219 RFieldDft<D>& dft) const;
220
231 void convertKGridToBasis(RFieldDft<D> const & in,
232 DArray<double> & out,
233 bool checkSymmetry = true,
234 double epsilon = 1.0e-8) const;
235
246 bool hasSymmetry(RFieldDft<D> const & in,
247 double epsilon = 1.0e-8,
248 bool verbose = true) const;
249
259 void scaleFieldBasis(DArray<double>& field, double factor) const;
260
270 void scaleFieldRGrid(RField<D>& field, double factor) const;
271
284 std::ostream &out,
285 DArray<RField<D> > const & fields,
286 UnitCell<D> const & unitCell,
287 int d,
288 DArray<int> const& newGridDimensions) const;
289
301 std::ostream& out,
302 DArray< RField<D> > const & fields,
303 UnitCell<D> const & unitCell,
304 IntVec<D> const & replicas) const;
305
306 protected:
307
308 using Base::mesh;
309 using Base::fft;
310 using Base::lattice;
311 using Base::hasGroup;
312 using Base::groupName;
313 using Base::group;
314 using Base::basis;
315 using Base::fileMaster;
316
317 };
318
319 #ifndef RPG_FIELD_IO_TPP
320 extern template class FieldIo<1>;
321 extern template class FieldIo<2>;
322 extern template class FieldIo<3>;
323 #endif
324
325} // namespace Rpg
326
327#ifndef RPG_FIELD_IO_TPP
328namespace Prdc {
329 using namespace Pscf::Prdc::Cuda;
330 extern template class FieldIoReal<1, RField<1>, RFieldDft<1>, FFT<1>>;
331 extern template class FieldIoReal<2, RField<2>, RFieldDft<2>, FFT<2>>;
332 extern template class FieldIoReal<3, RField<3>, RFieldDft<3>, FFT<3>>;
333}
334#endif
335
336} // namespace Pscf
337#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 writeFieldsKGrid(std::ostream &out, DArray< RFieldDft< D > > const &fields, UnitCell< D > const &unitCell, bool isSymmetric=true) const
Write array of RFieldDft objects (k-space fields) to file.
FieldIo()
Default constructor.
void expandRGridDimension(std::ostream &out, DArray< RField< D > > const &fields, UnitCell< D > const &unitCell, int d, DArray< int > const &newGridDimensions) const
Expand spatial dimension of an array of r-grid fields.
void readFieldsKGrid(std::istream &in, DArray< RFieldDft< D > > &fields, UnitCell< D > &unitCell) const
Read array of RFieldDft objects (k-space fields) from a stream.
void replicateUnitCell(std::ostream &out, DArray< RField< D > > const &fields, UnitCell< D > const &unitCell, IntVec< D > const &replicas) const
Write r-grid fields in a replicated unit cell to std::ostream.
void scaleFieldBasis(DArray< double > &field, double factor) const
Rescale a single field in basis format by a scalar factor.
void scaleFieldRGrid(RField< D > &field, double factor) const
Rescale a single r-grid field by a scalar factor.
bool hasSymmetry(RFieldDft< D > const &in, double epsilon=1.0e-8, bool verbose=true) const
Check if a k-grid field has the declared space group symmetry.
void readFieldsRGridData(std::istream &in, DArray< RField< D > > &fields, int nMonomer) const
Read data for an array of r-grid fields, with no header section.
void writeFieldRGrid(std::ostream &out, RField< D > const &field, UnitCell< D > const &unitCell, bool writeHeader=true, bool isSymmetric=true) const
Write a single RField (field on an r-space grid) to a stream.
void convertKGridToBasis(RFieldDft< D > const &in, DArray< double > &out, bool checkSymmetry=true, double epsilon=1.0e-8) const
Convert a field from Fourier (k-grid) to symmetrized basis form.
void readFieldRGrid(std::istream &in, RField< D > &field, UnitCell< D > &unitCell) const
Read a single RField (field on an r-space grid) from a stream.
void writeFieldsRGrid(std::ostream &out, DArray< RField< D > > const &fields, UnitCell< D > const &unitCell, bool writeHeader=true, bool isSymmetric=true, bool writeMeshSize=true) const
Write array of RField objects (fields on r-space grid) to a stream.
void convertBasisToKGrid(DArray< double > const &components, RFieldDft< D > &dft) const
Convert a field from symmetrized basis to Fourier grid (k-grid).
void readFieldsRGrid(std::istream &in, DArray< RField< D > > &fields, UnitCell< D > &unitCell) const
Read array of RField objects (r-grid fields) from a stream.
Dynamically allocatable contiguous array template.
A FileMaster manages input and output files for a simulation.
Definition FileMaster.h:143
Fields, FFTs, and utilities for periodic boundary conditions (CUDA)
Definition CField.cu:12
Periodic fields and crystallography.
Definition CField.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.