PSCF v1.2
FieldIoReal.h
1#ifndef RPC_FIELD_IO_REAL_H
2#define RPC_FIELD_IO_REAL_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/crystal/UnitCell.h> // nested LatticeSystem enum
12#include <pscf/math/IntVec.h> // template with default
13
14// Forward declarations for classes used in interfaces
15namespace Util {
16 class FileMaster;
17 template <typename T> class DArray;
18}
19namespace Pscf {
20 template <int D> class Mesh;
21 namespace Prdc {
22 template <int D> class Basis;
23 template <int D> class SpaceGroup;
24 namespace Cpu {
25 template <int D> class FFT;
26 template <int D> class RField;
27 }
28 }
29}
30
31namespace Pscf {
32namespace Prdc {
33
34 using namespace Util;
35 using namespace Pscf;
36 using namespace Pscf::Prdc;
37
66 template <int D, class RFRT, class RFKT, class FFTT>
68 {
69
70 public:
71
74
79
83 virtual ~FieldIoReal();
84
96 void associate(Mesh<D> const & mesh,
97 FFTT const & fft,
98 typename UnitCell<D>::LatticeSystem const & lattice,
99 bool const & hasGroup,
100 std::string const & groupName,
101 SpaceGroup<D> const & group,
102 Basis<D> & basis);
103
109 void setFileMaster(FileMaster const & fileMaster);
110
114
133 void
134 readFieldsBasis(std::istream& in, DArray< DArray<double> > & fields,
135 UnitCell<D> & unitCell) const;
136
150 void readFieldsBasis(std::string filename,
151 DArray< DArray<double> > & fields,
152 UnitCell<D> & unitCell) const;
153
165 void readFieldBasis(std::istream& in, DArray<double>& field,
166 UnitCell<D> & unitCell) const;
167
180 void readFieldBasis(std::string filename, DArray<double>& field,
181 UnitCell<D> & unitCell) const;
182
194 void writeFieldBasis(std::string filename,
195 DArray<double> const & field,
196 UnitCell<D> const & unitCell) const;
197
208 void writeFieldsBasis(std::ostream& out,
209 DArray< DArray<double> > const & fields,
210 UnitCell<D> const & unitCell) const;
211
223 void writeFieldsBasis(std::string filename,
224 DArray< DArray<double> > const & fields,
225 UnitCell<D> const & unitCell) const;
226
236 void writeFieldBasis(std::ostream& out,
237 DArray<double> const & field,
238 UnitCell<D> const & unitCell) const;
239
243
257 virtual
258 void readFieldsRGrid(std::istream& in,
259 DArray<RFRT>& fields,
260 UnitCell<D> & unitCell) const;
261
276 void readFieldsRGrid(std::string filename,
277 DArray<RFRT>& fields,
278 UnitCell<D> & unitCell) const;
279
293 virtual
294 void readFieldsRGridData(std::istream& in,
295 DArray<RFRT>& fields,
296 int nMonomer) const;
297
308 virtual
309 void readFieldRGrid(std::istream &in,
310 RFRT & field,
311 UnitCell<D>& unitCell) const;
312
324 void readFieldRGrid(std::string filename,
325 RFRT & field,
326 UnitCell<D>& unitCell) const;
327
341 virtual
342 void writeFieldsRGrid(std::ostream& out,
343 DArray<RFRT> const & fields,
344 UnitCell<D> const & unitCell,
345 bool writeHeader = true,
346 bool isSymmetric = true,
347 bool writeMeshSize = true) const;
348
361 void writeFieldsRGrid(std::string filename,
362 DArray<RFRT> const & fields,
363 UnitCell<D> const & unitCell,
364 bool isSymmetric = true) const;
365
378 virtual
379 void writeFieldRGrid(std::ostream &out,
380 RFRT const & field,
381 UnitCell<D> const & unitCell,
382 bool writeHeader = true,
383 bool isSymmetric = true) const;
384
397 void writeFieldRGrid(std::string filename,
398 RFRT const & field,
399 UnitCell<D> const & unitCell,
400 bool isSymmetric = true) const;
401
405
420 virtual
421 void readFieldsKGrid(std::istream& in,
422 DArray<RFKT>& fields,
423 UnitCell<D> & unitCell) const;
424
440 void readFieldsKGrid(std::string filename,
441 DArray<RFKT>& fields,
442 UnitCell<D> & unitCell) const;
443
459 virtual
460 void writeFieldsKGrid(std::ostream& out,
461 DArray<RFKT> const & fields,
462 UnitCell<D> const & unitCell,
463 bool isSymmetric = true) const;
464
477 void writeFieldsKGrid(std::string filename,
478 DArray<RFKT> const & fields,
479 UnitCell<D> const & unitCell,
480 bool isSymmetric = true) const;
481
485
495 virtual
496 void convertBasisToKGrid(DArray<double> const & components,
497 RFKT& dft) const;
498
508 void convertBasisToKGrid(DArray< DArray<double> > const & in,
509 DArray<RFKT>& out) const;
510
527 virtual
528 void convertKGridToBasis(RFKT const & in,
529 DArray<double> & out,
530 bool checkSymmetry = true,
531 double epsilon = 1.0e-8) const;
532
549 void convertKGridToBasis(DArray<RFKT> const & in,
550 DArray< DArray<double> > & out,
551 bool checkSymmetry = true,
552 double epsilon = 1.0e-8) const;
553
560 void convertBasisToRGrid(DArray<double> const & in,
561 RFRT & out) const;
562
569 void convertBasisToRGrid(DArray< DArray<double> > const & in,
570 DArray<RFRT> & out) const ;
571
586 void convertRGridToBasis(RFRT const & in,
587 DArray<double> & out,
588 bool checkSymmetry = true,
589 double epsilon = 1.0e-8) const;
590
605 void convertRGridToBasis(DArray<RFRT> const & in,
606 DArray< DArray<double> > & out,
607 bool checkSymmetry = true,
608 double epsilon = 1.0e-8) const;
609
621 void convertKGridToRGrid(DArray<RFKT> const & in,
622 DArray<RFRT> & out) const;
623
634 void convertKGridToRGrid(RFKT const & in,
635 RFRT & out) const;
636
643 void convertRGridToKGrid(DArray<RFRT> const & in,
644 DArray<RFKT> & out) const;
645
652 void convertRGridToKGrid(RFRT const & in,
653 RFKT & out) const;
654
658
676 virtual
677 bool hasSymmetry(RFKT const & in, double epsilon = 1.0e-8,
678 bool verbose = true) const;
679
694 bool hasSymmetry(RFRT const & in, double epsilon = 1.0e-8,
695 bool verbose = true) const;
696
700
711 virtual
712 void scaleFieldBasis(DArray<double>& field, double factor) const;
713
724 void scaleFieldsBasis(DArray< DArray<double> >& fields, double factor)
725 const;
726
737 virtual
738 void scaleFieldRGrid(RFRT& field, double factor) const;
739
750 void scaleFieldsRGrid(DArray<RFRT> & fields, double factor) const;
751
755
775 virtual
776 void replicateUnitCell(std::ostream& out,
777 DArray<RFRT> const & fields,
778 UnitCell<D> const & unitCell,
779 IntVec<D> const & replicas) const;
780
794 void replicateUnitCell(std::string filename,
795 DArray<RFRT> const & fields,
796 UnitCell<D> const & unitCell,
797 IntVec<D> const & replicas) const;
798
818 virtual
819 void expandRGridDimension(std::ostream &out,
820 DArray<RFRT > const & fields,
821 UnitCell<D> const & unitCell,
822 int d,
823 DArray<int> const& newGridDimensions)
824 const;
825
840 void expandRGridDimension(std::string filename,
841 DArray<RFRT > const & fields,
842 UnitCell<D> const & unitCell,
843 int d,
844 DArray<int> newGridDimensions) const;
845
846
850
889 void readFieldHeader(std::istream& in, int& nMonomer,
890 UnitCell<D> & unitCell,
891 bool & isSymmetric) const;
892
901 void writeFieldHeader(std::ostream& out, int nMonomer,
902 UnitCell<D> const & unitCell,
903 bool isSymmetric = true) const;
904
906
907 private:
908
909 // DFT work array for conversions basis <-> kgrid <-> r-grid
910 mutable RFKT workDft_;
911
912 // Pointers to associated external data
913
915 Mesh<D> const * meshPtr_;
916
918 FFTT const * fftPtr_;
919
921 typename UnitCell<D>::LatticeSystem const * latticePtr_;
922
924 bool const * hasGroupPtr_;
925
927 std::string const * groupNamePtr_;
928
930 SpaceGroup<D> const * groupPtr_;
931
933 Basis<D> * basisPtr_;
934
936 FileMaster const * fileMasterPtr_;
937
938 protected:
939
940 // Private accessor functions for associated external data
941
943 Mesh<D> const & mesh() const
944 {
945 UTIL_ASSERT(meshPtr_);
946 return *meshPtr_;
947 }
948
950 FFTT const & fft() const
951 {
952 UTIL_ASSERT(fftPtr_);
953 return *fftPtr_;
954 }
955
957 typename UnitCell<D>::LatticeSystem const & lattice() const
958 {
959 UTIL_ASSERT(latticePtr_);
960 return *latticePtr_;
961 }
962
964 bool hasGroup() const
965 {
966 UTIL_ASSERT(hasGroupPtr_);
967 return *hasGroupPtr_;
968 }
969
971 std::string const & groupName() const
972 {
973 UTIL_ASSERT(groupNamePtr_);
974 return *groupNamePtr_;
975 }
976
978 SpaceGroup<D> const & group() const
979 {
980 UTIL_ASSERT(groupPtr_);
981 return *groupPtr_;
982 }
983
985 Basis<D> const & basis() const
986 {
987 UTIL_ASSERT(basisPtr_);
988 return *basisPtr_;
989 }
990
992 FileMaster const & fileMaster() const
993 {
994 UTIL_ASSERT(fileMasterPtr_);
995 return *fileMasterPtr_;
996 }
997
998 };
999
1000} // namespace Prdc
1001} // namespace Pscf
1002#endif
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
Description of a regular grid of points in a periodic domain.
Symmetry-adapted Fourier basis for pseudo-spectral scft.
Definition fieldIoUtil.h:21
Fourier transform wrapper.
Field of real double precision values on an FFT mesh.
File input/output operations and format conversions for fields.
Definition FieldIoReal.h:68
FieldIoReal()
Constructor.
virtual void readFieldsRGridData(std::istream &in, DArray< RFRT > &fields, int nMonomer) const
Read data for array of r-grid fields, with no header section.
bool hasGroup() const
Has a space group been declared externally ?
virtual void scaleFieldBasis(DArray< double > &field, double factor) const
Multiply a single field in basis format by a real scalar.
FFTT const & fft() const
Get FFT object by const reference.
void scaleFieldsRGrid(DArray< RFRT > &fields, double factor) const
Scale an array of r-grid fields by a real scalar.
void writeFieldHeader(std::ostream &out, int nMonomer, UnitCell< D > const &unitCell, bool isSymmetric=true) const
Write header for field file (fortran pscf format)
virtual bool hasSymmetry(RFKT const &in, double epsilon=1.0e-8, bool verbose=true) const
Check if a k-grid field has the declared space group symmetry.
virtual void expandRGridDimension(std::ostream &out, DArray< RFRT > const &fields, UnitCell< D > const &unitCell, int d, DArray< int > const &newGridDimensions) const
Expand dimension of an array of r-grid fields, write to ostream.
virtual void writeFieldsRGrid(std::ostream &out, DArray< RFRT > 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 ostream.
virtual void replicateUnitCell(std::ostream &out, DArray< RFRT > const &fields, UnitCell< D > const &unitCell, IntVec< D > const &replicas) const
Write r-grid fields in a replicated unit cell to std::ostream.
virtual void convertBasisToKGrid(DArray< double > const &components, RFKT &dft) const
Convert a field from symmetrized basis to Fourier grid (k-grid).
virtual void convertKGridToBasis(RFKT 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.
std::string const & groupName() const
Get associated group name string by const reference.
SpaceGroup< D > const & group() const
Get associated SpaceGroup<D> by const reference.
virtual void scaleFieldRGrid(RFRT &field, double factor) const
Multiply a single field in r-grid format by a real scalar.
void convertBasisToRGrid(DArray< double > const &in, RFRT &out) const
Convert a field from symmetrized basis to spatial grid (r-grid).
virtual void readFieldRGrid(std::istream &in, RFRT &field, UnitCell< D > &unitCell) const
Read single RField (field on an r-space grid) from an istream.
virtual ~FieldIoReal()
Destructor.
virtual void writeFieldsKGrid(std::ostream &out, DArray< RFKT > const &fields, UnitCell< D > const &unitCell, bool isSymmetric=true) const
Write array of RFieldDft objects (k-space fields) to file.
void convertRGridToKGrid(DArray< RFRT > const &in, DArray< RFKT > &out) const
Convert fields from spatial grid (r-grid) to k-grid format.
virtual void writeFieldRGrid(std::ostream &out, RFRT const &field, UnitCell< D > const &unitCell, bool writeHeader=true, bool isSymmetric=true) const
Write a single RField (field on an r-space grid) to ostream.
void readFieldHeader(std::istream &in, int &nMonomer, UnitCell< D > &unitCell, bool &isSymmetric) const
Reader header of field file (fortran pscf format)
Mesh< D > const & mesh() const
Get spatial discretization mesh by const reference.
UnitCell< D >::LatticeSystem const & lattice() const
Get the lattice type enum value by const reference.
void setFileMaster(FileMaster const &fileMaster)
Create an association with a FileMaster.
void convertRGridToBasis(RFRT const &in, DArray< double > &out, bool checkSymmetry=true, double epsilon=1.0e-8) const
Convert a field from spatial grid (r-grid) to symmetrized basis.
void readFieldBasis(std::istream &in, DArray< double > &field, UnitCell< D > &unitCell) const
Read single concentration or chemical potential field from file.
void readFieldsBasis(std::istream &in, DArray< DArray< double > > &fields, UnitCell< D > &unitCell) const
Read concentration or chemical potential fields from file.
FileMaster const & fileMaster() const
Get associated FileMaster by const reference.
virtual void readFieldsRGrid(std::istream &in, DArray< RFRT > &fields, UnitCell< D > &unitCell) const
Read array of RField objects (r-grid fields) from an istream.
void scaleFieldsBasis(DArray< DArray< double > > &fields, double factor) const
Scale an array of fields in basis format by a real scalar.
void convertKGridToRGrid(DArray< RFKT > const &in, DArray< RFRT > &out) const
Convert fields from k-grid (DFT) to real space (r-grid) format.
void associate(Mesh< D > const &mesh, FFTT const &fft, typename UnitCell< D >::LatticeSystem const &lattice, bool const &hasGroup, std::string const &groupName, SpaceGroup< D > const &group, Basis< D > &basis)
Create association with other objects in parent Domain.
virtual void readFieldsKGrid(std::istream &in, DArray< RFKT > &fields, UnitCell< D > &unitCell) const
Read array of RFieldDft objects (k-space fields) from istream.
void writeFieldsBasis(std::ostream &out, DArray< DArray< double > > const &fields, UnitCell< D > const &unitCell) const
Write concentration or chemical potential field components to file.
Basis< D > const & basis() const
Get the associated Basis by const reference.
void writeFieldBasis(std::string filename, DArray< double > const &field, UnitCell< D > const &unitCell) const
Write single concentration or chemical potential field to file.
Crystallographic space group.
Definition FieldIoReal.h:23
Base template for UnitCell<D> classes, D=1, 2 or 3.
Definition rpg/System.h:34
Dynamically allocatable contiguous array template.
A FileMaster manages input and output files for a simulation.
Definition FileMaster.h:143
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition global.h:75
Periodic fields and crystallography.
Definition CField.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.