|
PSCF v1.4.0
|
File input/output operations for fields. More...
#include <FieldIo.h>
Public Types | |
| using | Base = Cp::FieldIo< D, CField<D>, FFT<D> > |
| Alias for base class. | |
Public Member Functions | |
| void | associate (Mesh< D > const &mesh, FFT const &fft, typename UnitCell< D >::LatticeSystem const &lattice) |
| Create associations with other members of the parent Domain. | |
| void | setFileMaster (FileMaster const &fileMaster) |
| Create an association with a FileMaster. | |
| void | readFields (std::string filename, DArray< CField< D > > &fields, UnitCell< D > &unitCell) const |
| Read an array of complex fields from a named file. | |
| void | readField (std::string filename, CField< D > &field, UnitCell< D > &unitCell) const |
| Read a single field from a named file. | |
| void | writeFields (std::string filename, DArray< CField< D > > const &fields, UnitCell< D > const &unitCell) const |
| Write an array of complex fields to a named file. | |
| void | writeField (std::string filename, CField< D > const &field, UnitCell< D > const &unitCell) const |
| Write a single complex field to a named file. | |
| void | readFieldHeader (std::istream &in, int &nMonomer, UnitCell< D > &unitCell) const |
| Reader header of field file (fortran PSCF format) | |
| void | writeFieldHeader (std::ostream &out, int nMonomer, UnitCell< D > const &unitCell) const |
| Write header for field file (fortran pscf format). | |
| Mesh< D > const & | mesh () const |
| Get spatial discretization mesh by const reference. | |
| FileMaster const & | fileMaster () const |
| Get associated FileMaster by const reference. | |
Read fields from file | |
| void | readFields (std::istream &in, DArray< CField< D > > &fields, UnitCell< D > &unitCell) const override |
| Read multiple complex-valued fields from an input stream. | |
| void | readFieldsData (std::istream &in, DArray< CField< D > > &fields, int nMonomer) const override |
| Read data for multiple complex fields, with no header section. | |
| void | readField (std::istream &in, CField< D > &field, UnitCell< D > &unitCell) const override |
| Read a single CField (field on an r-space grid) from a stream. | |
| void | readFieldsRGrid (std::istream &in, DArray< CField< D > > &fields, UnitCell< D > &unitCell) const |
| Read multiple real value field in r-grid format. | |
Write fields to file | |
| void | writeFields (std::ostream &out, DArray< CField< D > > const &fields, UnitCell< D > const &unitCell, bool writeHeader=true, bool writeMeshSize=true) const override |
| Write array of CField objects (fields on r-space grid) to a stream. | |
| void | writeField (std::ostream &out, CField< D > const &field, UnitCell< D > const &unitCell, bool writeHeader=true) const override |
| Write a single CField (field on an r-space grid) to a stream. | |
| Public Member Functions inherited from Pscf::Cp::FieldIo< D, CField< D >, FFT< D > > | |
| FieldIo () | |
| Constructor. | |
| virtual | ~FieldIo () |
| Destructor. | |
| void | associate (Mesh< D > const &mesh, FFT const &fft, typename UnitCell< D >::LatticeSystem const &lattice) |
| Create associations with other members of the parent Domain. | |
| void | setFileMaster (FileMaster const &fileMaster) |
| Create an association with a FileMaster. | |
| void | setNMonomer (int nMonomer) |
| Set the number of monomer types. | |
| void | readFields (std::string filename, DArray< CField< D > > &fields, UnitCell< D > &unitCell) const |
| Read an array of complex fields from a named file. | |
| void | readField (std::string filename, CField< D > &field, UnitCell< D > &unitCell) const |
| Read a single field from a named file. | |
| void | writeFields (std::string filename, DArray< CField< D > > const &fields, UnitCell< D > const &unitCell) const |
| Write an array of complex fields to a named file. | |
| void | writeField (std::string filename, CField< D > const &field, UnitCell< D > const &unitCell) const |
| Write a single complex field to a named file. | |
| void | convertRGridToKGrid (DArray< CField< D > > const &in, DArray< CField< D > > &out) const |
| Fourier transform array of fields from r-grid to k-grid format. | |
| void | convertRGridToKGrid (std::string const &inFileName, std::string const &outFileName) const |
| Fourier transform a field file from r-grid to k-grid format. | |
| void | convertKGridToRGrid (DArray< CField< D > > const &in, DArray< CField< D > > &out) const |
| Fourier transform an array of fields from k-grid to r-grid format. | |
| void | convertKGridToRGrid (std::string const &inFileName, std::string const &outFileName) const |
| Transform a field file from Fourier (k-grid) to r-grid format. | |
| void | readFieldHeader (std::istream &in, int &nMonomer, UnitCell< D > &unitCell) const |
| Reader header of field file (fortran PSCF format) | |
| void | writeFieldHeader (std::ostream &out, int nMonomer, UnitCell< D > const &unitCell) const |
| Write header for field file (fortran pscf format). | |
| Mesh< D > const & | mesh () const |
| Get spatial discretization mesh by const reference. | |
| FileMaster const & | fileMaster () const |
| Get associated FileMaster by const reference. | |
Protected Member Functions | |
| UnitCell< D >::LatticeSystem const & | lattice () const |
| Get the lattice type enum value by const reference. | |
| FFT const & | fft () const |
| Get FFT object by const reference. | |
| Protected Member Functions inherited from Pscf::Cp::FieldIo< D, CField< D >, FFT< D > > | |
| UnitCell< D >::LatticeSystem const & | lattice () const |
| Get the lattice type enum value by const reference. | |
| FFT const & | fft () const |
| Get FFT object by const reference. | |
| void | checkAllocate () const |
| Check if r-grid workspace is allocated, allocate if necessary. | |
File input/output operations for fields.
Please refer to the documentation of the base class template Cp::FieldIo for complete API documentation. The public interface of this class is identical to that of the base class.
This class template is derived from a partial specialization of the template Cp::FieldIo<D, CFT, FFT> using classes CFT = CField<D> and FFT = FFT<D> that are all defined in the Prdc::Cpu subspace, and that all use conventional CPU hardware. An analogous class template named Rpg::FieldIo that is defined in the Pscf::Rpg namespace instead uses a GPU.
The member functions defined in this class are all implementations of pure virtual functions declared in the base class, Cp::FieldIo. These are all functions for which different implementations are required for the CPU and GPU variants, usually because the GPU implementation requires data transfer between host and device.
Definition at line 66 of file cpc/field/FieldIo.h.
| using Pscf::Cpc::FieldIo< D >::Base = Cp::FieldIo< D, CField<D>, FFT<D> > |
Alias for base class.
Definition at line 189 of file cpc/field/FieldIo.h.
|
overridevirtual |
Read multiple complex-valued fields from an input stream.
See documentation of analogous function in Cp::FieldIo.
| in | input file stream |
| fields | array of complex fields |
| unitCell | associated crystallographic unit cell |
Implements Pscf::Cp::FieldIo< D, CField< D >, FFT< D > >.
Definition at line 36 of file cpc/field/FieldIo.tpp.
References Pscf::Prdc::checkAllocateFields(), mesh(), Pscf::Prdc::readCFieldsData(), Pscf::Prdc::readFieldHeader(), and Pscf::Prdc::readMeshDimensions().
|
overridevirtual |
Read data for multiple complex fields, with no header section.
See documentation of analogous function in Cp::FieldIo.
| in | input file stream |
| fields | array of complex fields |
| nMonomer | number of monomer types |
Implements Pscf::Cp::FieldIo< D, CField< D >, FFT< D > >.
Definition at line 57 of file cpc/field/FieldIo.tpp.
References Pscf::Prdc::checkAllocateFields(), mesh(), and Pscf::Prdc::readCFieldsData().
|
overridevirtual |
Read a single CField (field on an r-space grid) from a stream.
See documentation of analogous function in Cp::FieldIo.
| in | input file stream |
| field | fields defined on r-space grid |
| unitCell | associated crystallographic unit cell |
Implements Pscf::Cp::FieldIo< D, CField< D >, FFT< D > >.
Definition at line 71 of file cpc/field/FieldIo.tpp.
References Pscf::Prdc::checkAllocateField(), mesh(), Pscf::Prdc::readCFieldData(), Pscf::Prdc::readFieldHeader(), Pscf::Prdc::readMeshDimensions(), and UTIL_CHECK.
| void Pscf::Cpc::FieldIo< D >::readFieldsRGrid | ( | std::istream & | in, |
| DArray< CField< D > > & | fields, | ||
| UnitCell< D > & | unitCell ) const |
Read multiple real value field in r-grid format.
This function is designed to read a real-valued field file written in the the r-grid file format used by the programs pscf_rpc and pscf_rpg, but stores data for each field in a CField<D> container designed for complex-valued fields. On return, each field value in this container is a complex number with a zero imaginary part and a real part equal to the value given in the field file for the specified monomer type and grid node.
| in | input file stream |
| fields | array of fields defined on grid (out) |
| unitCell | associated crystallographic unit cell (out) |
Definition at line 93 of file cpc/field/FieldIo.tpp.
References Pscf::Prdc::checkAllocateFields(), mesh(), Pscf::Prdc::readFieldHeader(), Pscf::Prdc::readMeshDimensions(), and Pscf::Prdc::readRGridData().
|
overridevirtual |
Write array of CField objects (fields on r-space grid) to a stream.
See documentation of analogous function in Cp::FieldIo.
| out | output stream (i.e., output file) |
| fields | array of CField objects (fields on r-space grid) |
| unitCell | associated crystallographic unit cell |
| writeHeader | flag to write file header if true |
| writeMeshSize | Should mesh size be written in header? |
Implements Pscf::Cp::FieldIo< D, CField< D >, FFT< D > >.
Definition at line 114 of file cpc/field/FieldIo.tpp.
References Pscf::Prdc::inspectFields(), Pscf::Prdc::writeCFieldsData(), Pscf::Prdc::writeFieldHeader(), and Pscf::Prdc::writeMeshDimensions().
|
overridevirtual |
Write a single CField (field on an r-space grid) to a stream.
See documentation of analogous function in Cp::FieldIo.
| out | output stream |
| field | field defined on r-space grid |
| unitCell | associated crystallographic unit cell |
| writeHeader | Should a file header be written? |
Implements Pscf::Cp::FieldIo< D, CField< D >, FFT< D > >.
Definition at line 147 of file cpc/field/FieldIo.tpp.
References Pscf::Prdc::Cpu::CField< D >::meshDimensions(), Pscf::Prdc::writeCFieldData(), Pscf::Prdc::writeFieldHeader(), and Pscf::Prdc::writeMeshDimensions().
| void Pscf::Cp::FieldIo< D, CField< D >, FFT >::associate | ( | Mesh< D > const & | mesh, |
| FFT const & | fft, | ||
| typename UnitCell< D >::LatticeSystem const & | lattice ) |
| void Pscf::Cp::FieldIo< D, CField< D >, FFT >::setFileMaster | ( | FileMaster const & | fileMaster | ) |
Create an association with a FileMaster.
The FileMaster is used to open and close files in all member functions that take file name arguments and that open and close files. This allows prefixes for input and output files (if any) to be automatically prepended to file names.
| fileMaster | associated FileMaster (for file paths) |
| void Pscf::Cp::FieldIo< D, CField< D >, FFT >::readFields | ( | std::string | filename, |
| DArray< CField< D > > & | fields, | ||
| UnitCell< D > & | unitCell ) const |
Read an array of complex fields from a named file.
This function opens an input file with the specified filename, reads fields in real-space grid format from that file, and then closes the file. The overloaded readFieldsRGrid member function that takes a std::istream& argument is called to read the file.
| filename | name of input file |
| fields | array of r-grid fields (instances of CFT) |
| unitCell | associated crystallographic unit cell |
| void Pscf::Cp::FieldIo< D, CField< D >, FFT >::readField | ( | std::string | filename, |
| CField< D > & | field, | ||
| UnitCell< D > & | unitCell ) const |
Read a single field from a named file.
This function opens an input file with the specified filename, reads a complex field from that file, and then closes the file. The overloaded readField member function that takes a std::istream& argument is called internally to read the file.
| filename | name of input file |
| field | single field defined on r-space grid |
| unitCell | associated crystallographic unit cell |
| void Pscf::Cp::FieldIo< D, CField< D >, FFT >::writeFields | ( | std::string | filename, |
| DArray< CField< D > > const & | fields, | ||
| UnitCell< D > const & | unitCell ) const |
Write an array of complex fields to a named file.
This function opens a file, writes field file header and data to the file, and closes the file. The overloaded writeFieldsGrid member function that takes a std::ostream& argument is called internally with writeHeader == true to write the data.
| filename | name of output file |
| fields | array of CFT objects (fields on a grid) |
| unitCell | associated crystallographic unit cell |
| void Pscf::Cp::FieldIo< D, CField< D >, FFT >::writeField | ( | std::string | filename, |
| CField< D > const & | field, | ||
| UnitCell< D > const & | unitCell ) const |
Write a single complex field to a named file.
This function opens a file, writes the header and data for a single field to the file, and closes that file. The overloaded writeFieldGrid member function that takes a std::ostream& argument is called internally with writeHeader == true to write the file.
| filename | name of output file |
| field | field defined on r-space grid |
| unitCell | associated crystallographic unit cell |
| void Pscf::Cp::FieldIo< D, CField< D >, FFT >::readFieldHeader | ( | std::istream & | in, |
| int & | nMonomer, | ||
| UnitCell< D > & | unitCell ) const |
Reader header of field file (fortran PSCF format)
This reads the common part of the header for all PSCF field file formats. This contains the dimension of space, the lattice system, a list of unit cell parameters, the space group name as an optional parameter, and the number of monomer types. The unit cell data is used to update a UnitCell<D> that is passed as a parameter by non-const reference.
On return, parameter nMonomer contains the number of monomer types declared in the field file header. This function does not require the number of monomers declared in the field file header to match the value of nMonomer set by the setNMonomer member function.
Consistency checks (Exceptions thrown on failure):
The value of "dim" in the header file must match the template parameter D. If the UnitCell<D> object passed to this function already contains a non-null lattice type, it must match the lattice system in the header file.
| in | input stream (i.e., file) |
| nMonomer | number of monomer types in the header (out) |
| unitCell | associated crystallographic unit cell (out) |
| void Pscf::Cp::FieldIo< D, CField< D >, FFT >::writeFieldHeader | ( | std::ostream & | out, |
| int | nMonomer, | ||
| UnitCell< D > const & | unitCell ) const |
Write header for field file (fortran pscf format).
| out | output stream (i.e., file) |
| nMonomer | number of monomer types or fields |
| unitCell | associated crystallographic unit cell |
|
inline |
Get spatial discretization mesh by const reference.
Definition at line 421 of file cp/field/FieldIo.h.
Referenced by readField(), readFields(), readFieldsData(), and readFieldsRGrid().
|
inline |
Get associated FileMaster by const reference.
Definition at line 430 of file cp/field/FieldIo.h.
|
inlineprotected |
Get the lattice type enum value by const reference.
Definition at line 443 of file cp/field/FieldIo.h.
|
inlineprotected |
Get FFT object by const reference.
Definition at line 452 of file cp/field/FieldIo.h.