PSCF v1.5.0
cuda/RFieldDft.tpp
1#ifndef PSCF_R_FIELD_DFT_CU_TPP
2#define PSCF_R_FIELD_DFT_CU_TPP
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "RFieldDft.h"
12#include "FFT.h"
13#include <pscf/backend/cuda/HostSendArray.h>
14
15namespace Pscf {
16
17 using namespace Util;
18
19 /*
20 * Default constructor.
21 */
22 template <int D>
26
27 /*
28 * Allocating constructor (calls allocate).
29 */
30 template <int D>
34
35 /*
36 * Destructor.
37 */
38 template <int D>
41
42 /*
43 * Copy constructor.
44 */
45 template <int D>
48 {
49 meshDimensions_ = other.meshDimensions_;
50 dftDimensions_ = other.dftDimensions_;
51 }
52
53 /*
54 * Allocate underlying BackendArray<cudaComplex,CUT> for the DFT mesh.
55 */
56 template <int D>
58 {
59 // Copy and validate dimensions of real space grid
60 for (int i = 0; i < D; ++i) {
62 meshDimensions_[i] = meshDimensions[i];
63 }
64
65 // Compute dimensions and size of Fourier space mesh
66 int size;
67 FFT<D,CUT>::computeKMesh(meshDimensions, dftDimensions_, size);
68
69 // Allocate complex array on the GPU with size of DFT mesh
71 }
72
73 /*
74 * Deallocate the underlying C array and zero grid dimensions.
75 */
76 template <int D>
78 {
80 for (int i = 0; i < D; ++i) {
81 meshDimensions_[i] = 0;
82 }
83 }
84
85 /*
86 * Associate this with a slice of a BackendArray<cudaComplex,CUT>.
87 */
88 template <int D>
91 int beginId,
93 {
94 // Copy and validate dimensions of real space grid
95 for (int i = 0; i < D; ++i) {
97 meshDimensions_[i] = meshDimensions[i];
98 }
99
100 // Compute dimensions and size of Fourier space mesh
101 int size;
102 FFT<D,CUT>::computeKMesh(meshDimensions, dftDimensions_, size);
103
104 // Associate data with a slice of input array arr
106 }
107
108 /*
109 * Assignment from another RFieldDft.
110 */
111 template <int D>
114 {
115 // Assign data and size of underlying array
117
118 // Assign more specialized data members
119 meshDimensions_ = other.meshDimensions_;
120 dftDimensions_ = other.dftDimensions_;
121
122 return *this;
123 }
124
125 /*
126 * Assignment from RHS HostSendArray<cudaComplex,CUT>.
127 */
128 template <int D>
131 {
132 // Preconditions: Both arrays must be allocated with equal capacities
133 UTIL_CHECK(other.isAllocated());
134 UTIL_CHECK(isAllocated());
135 UTIL_CHECK(capacity() == other.capacity());
136
137 // Use base class assignment operator to copy elements
139
140 return *this;
141 }
142
143} // namespace Pscf
144#endif
Backend identifier class for the GPU-enabled CUDA backend.
Definition CUT.h:31
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
void allocate(IntVec< D > const &meshDimensions)
Allocate the underlying C array for an FFT grid.
RFieldDft()
Default constructor.
IntVec< D > const & meshDimensions() const
Return vector of real-space mesh dimensions by constant reference.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
PSCF package top-level namespace.
cufftDoubleComplex cudaComplex
Complex number type used in CPU code that uses FFTW.
Definition cudaTypes.h:22