1#ifndef RPG_W_FIELD_CONTAINER_TPP
2#define RPG_W_FIELD_CONTAINER_TPP
11#include "WFieldContainer.h"
12#include <rpg/field/FieldIo.h>
13#include <prdc/cuda/VecOp.h>
35 isAllocatedRGrid_(false),
36 isAllocatedBasis_(false),
53 { fieldIoPtr_ = &fieldIo; }
76 if (isAllocatedRGrid_) {
81 meshDimensions_ = meshDimensions;
83 for (
int i = 0; i < D; ++i) {
85 meshSize_ *= meshDimensions[i];
89 rgrid_.allocate(nMonomer_);
90 for (
int i = 0; i < nMonomer_; ++i) {
91 rgrid_[i].allocate(meshDimensions);
93 isAllocatedRGrid_ =
true;
105 for (
int i = 0; i < nMonomer_; ++i) {
106 rgrid_[i].deallocate();
111 isAllocatedRGrid_ =
false;
124 if (isAllocatedBasis_) {
130 basis_.allocate(nMonomer_);
131 for (
int i = 0; i < nMonomer_; ++i) {
132 basis_[i].allocate(nBasis);
134 isAllocatedBasis_ =
true;
146 for (
int i = 0; i < nMonomer_; ++i) {
147 basis_[i].deallocate();
151 isAllocatedBasis_ =
false;
161 setNMonomer(nMonomer);
162 allocateRGrid(meshDimensions);
163 allocateBasis(nBasis);
177 for (
int i = 0; i < nMonomer_; ++i) {
182 for (
int j = 0; j < nBasis_; ++j) {
188 fieldIoPtr_->convertBasisToRGrid(basis_, rgrid_);
205 for (
int i = 0; i < nMonomer_; ++i) {
206 UTIL_CHECK(fields[i].capacity() == meshSize_);
211 fieldIoPtr_->convertRGridToBasis(rgrid_, basis_);
215 isSymmetric_ = isSymmetric;
227 for (
int i = 0; i < nMonomer_; i++) {
229 tmp.associate(fields, i * meshSize_, meshDimensions_);
234 isSymmetric_ =
false;
250 fieldIoPtr_->readFieldsBasis(in, basis_, unitCell);
253 fieldIoPtr_->convertBasisToRGrid(basis_, rgrid_);
272 fieldIoPtr_->readFieldsBasis(filename, basis_, unitCell);
275 fieldIoPtr_->convertBasisToRGrid(basis_, rgrid_);
299 fieldIoPtr_->readFieldsRGrid(in, rgrid_, unitCell);
302 fieldIoPtr_->convertRGridToBasis(rgrid_, basis_);
306 isSymmetric_ = isSymmetric;
327 fieldIoPtr_->readFieldsRGrid(filename, rgrid_, unitCell);
330 fieldIoPtr_->convertRGridToBasis(rgrid_, basis_);
334 isSymmetric_ = isSymmetric;
344 fieldIoPtr_->convertRGridToBasis(rgrid_, basis_);
345 fieldIoPtr_->convertBasisToRGrid(basis_, rgrid_);
Dynamic array on the GPU device with aligned data.
int capacity() const
Return allocated capacity.
An IntVec<D, T> is a D-component vector of elements of integer type T.
Field of real double precision values on an FFT mesh.
Base template for UnitCell<D> classes, D=1, 2 or 3.
File input/output operations and format conversions for fields.
void setNMonomer(int nMonomer)
Set stored value of nMonomer.
void deallocateBasis()
De-allocate fields in basis format.
void allocateBasis(int nBasis)
Allocate or re-allocate memory for fields in basis format.
void setFieldIo(FieldIo< D > const &fieldIo)
Create association with FieldIo (store pointer).
void allocate(int nMonomer, int nBasis, IntVec< D > const &dimensions)
Allocate memory for all fields.
void readRGrid(std::istream &in, UnitCell< D > &unitCell, bool isSymmetric=false)
Reads fields from an input stream in real-space (r-grid) format.
void symmetrize()
Symmetrize r-grid fields, compute corresponding basis components.
void readBasis(std::istream &in, UnitCell< D > &unitCell)
Read field component values from input stream, in symmetrized Fourier format.
WFieldContainer()
Constructor.
void setBasis(DArray< DArray< double > > const &fields)
Set field component values, in symmetrized Fourier format.
void allocateRGrid(IntVec< D > const &dimensions)
Allocate or re-allocate memory for fields in rgrid format.
void setRGrid(DArray< RField< D > > const &fields, bool isSymmetric=false)
Set fields values in real-space (r-grid) format.
void deallocateRGrid()
De-allocate fields in rgrid format.
~WFieldContainer()
Destructor.
int capacity() const
Return allocated size.
Dynamically allocatable contiguous array template.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
void eqV(DeviceArray< cudaReal > &a, DeviceArray< cudaReal > const &b, const int beginIdA, const int beginIdB, const int n)
Vector assignment, a[i] = b[i], 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.