1#ifndef RPG_FIELD_IO_TPP
2#define RPG_FIELD_IO_TPP
13#include <rpg/field/HostDArrayComplex.h>
15#include <pscf/math/complex.h>
17#include <prdc/field/FieldIoReal.tpp>
18#include <prdc/field/fieldIoUtil.h>
19#include <prdc/field/fieldArrayUtil.h>
20#include <prdc/crystal/fieldHeader.h>
21#include <prdc/crystal/Basis.h>
22#include <prdc/crystal/UnitCell.h>
23#include <prdc/cuda/types.h>
24#include <prdc/cuda/complex.h>
25#include <prdc/cuda/resources.h>
27#include <pscf/mesh/Mesh.h>
28#include <pscf/math/IntVec.h>
29#include <pscf/cuda/HostDArray.h>
73 allocateArrays(hostFields, nMonomer, mesh().size());
79 copyArrays(fields, hostFields);
95 allocateArrays(hostFields, nMonomer, mesh().size());
101 copyArrays(fields, hostFields);
143 bool writeMeshSize)
const
160 allocateArrays(hostFields, nMonomer, mesh().size());
161 copyArrays(hostFields, fields);
176 bool isSymmetric)
const
210 IntVec<D> dftDimensions = fields[0].dftDimensions();
211 int capacity = fields[0].capacity();
215 allocateArrays(hostFields, nMonomer, capacity);
221 copyArrays(fields, hostFields);
232 bool isSymmetric)
const
238 IntVec<D> dftDimensions = fields[0].dftDimensions();
239 int capacity = fields[0].capacity();
247 allocateArrays(hostFields, nMonomer, capacity);
248 copyArrays(hostFields, fields);
282 double epsilon)
const
292 checkSymmetry, epsilon);
323 for (
int i = 0; i < n; ++i) {
354 int capacity = fields[0].capacity();
358 allocateArrays(hostFields, nMonomer, capacity);
359 copyArrays(hostFields, fields);
380 int capacity = fields[0].capacity();
384 allocateArrays(hostFields, nMonomer, capacity);
385 copyArrays(hostFields, fields);
388 unitCell, d, newGridDimensions);
Template for dynamic array stored in host CPU memory.
An IntVec<D, T> is a D-component vector of elements of integer type T.
Fourier transform wrapper.
Fourier transform of a real field on an FFT mesh.
IntVec< D > const & dftDimensions() const
Return vector of dft (Fourier) grid dimensions by constant reference.
Field of real double precision values on an FFT mesh.
const IntVec< D > & meshDimensions() const
Return mesh dimensions by constant reference.
File input/output operations and format conversions for fields.
Base template for UnitCell<D> classes, D=1, 2 or 3.
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.
HostDArray containing cudaComplex elements.
int capacity() const
Return allocated size.
Dynamically allocatable contiguous array template.
void allocate(int capacity)
Allocate the underlying C array.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
void writeFieldHeader(std::ostream &out, int ver1, int ver2, UnitCell< D > const &cell, std::string const &groupName, int nMonomer)
Write common part of field header (fortran PSCF format).
void readFieldHeader(std::istream &in, int &ver1, int &ver2, UnitCell< D > &cell, std::string &groupName, int &nMonomer)
Read common part of field header (fortran PSCF format).
void replicateUnitCell(std::ostream &out, DArray< AT > const &fields, IntVec< D > const &meshDimensions, UnitCell< D > const &unitCell, IntVec< D > const &replicas)
Write r-grid fields in a replicated unit cell to std::ostream.
void writeKGridData(std::ostream &out, DArray< AT > const &fields, int nMonomer, IntVec< D > const &dftDimensions)
Write data for array of k-grid fields, with no header section.
bool hasSymmetry(AT const &in, Basis< D > const &basis, IntVec< D > const &dftDimensions, double epsilon=1.0e-8, bool verbose=true)
Check if a k-grid field has the declared space group symmetry.
void inspectFields(DArray< FT > const &fields, int &nMonomer, IntVec< D > &dimensions)
Inspect dimensions of a DArray of fields, each of type FT.
void readKGridData(std::istream &in, DArray< AT > &fields, int nMonomer, IntVec< D > const &dftDimensions)
Read data for array of k-grid fields, with no header section.
void convertBasisToKGrid(DArray< double > const &components, AT &dft, Basis< D > const &basis, IntVec< D > const &dftDimensions)
Convert a real field from symmetrized basis to Fourier grid.
void writeMeshDimensions(std::ostream &out, IntVec< D > const &meshDimensions)
Write mesh dimensions to a field file header.
void expandRGridDimension(std::ostream &out, DArray< AT > const &fields, IntVec< D > const &meshDimensions, UnitCell< D > const &unitCell, int d, DArray< int > newGridDimensions)
Expand the dimensionality of space from D to d.
void writeRGridData(std::ostream &out, DArray< AT > const &fields, int nMonomer, IntVec< D > const &dimensions)
Write data for array of r-grid fields, with no header section.
void convertKGridToBasis(AT const &in, DArray< double > &out, Basis< D > const &basis, IntVec< D > const &dftDimensions, bool checkSymmetry=true, double epsilon=1.0e-8)
Convert a real field from Fourier grid to symmetrized basis.
void readRGridData(std::istream &in, DArray< AT > &fields, int nMonomer, IntVec< D > const &dimensions)
Read data for array of r-grid fields, with no header section.
void readMeshDimensions(std::istream &in, IntVec< D > const &meshDimensions)
Read mesh dimensions from a field file header.
void checkAllocateFields(DArray< FT > &fields, int nMonomer, IntVec< D > const &dimensions)
Check allocation of an array of fields, allocate if necessary.
void checkAllocateField(FT &field, IntVec< D > const &dimensions)
Check allocation of a single field, allocate if necessary.
void mulEqS(DeviceArray< cudaReal > &a, cudaReal const b, const int beginIdA, const int n)
Vector multiplication in-place, a[i] *= b, kernel wrapper (cudaReal).
Fields, FFTs, and utilities for periodic boundary conditions (CUDA)
Periodic fields and crystallography.
PSCF package top-level namespace.
Utility classes for scientific computation.