PSCF v1.5.0
cuda/RField.tpp
1#ifndef PSCF_R_FIELD_CU_TPP
2#define PSCF_R_FIELD_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 "RField.h"
12#include <pscf/backend/cuda/HostSendArray.h>
13
14namespace Pscf {
15
16 using namespace Util;
17
21 template <int D>
25
29 template <int D>
33
34 /*
35 * Copy constructor.
36 */
37 template <int D>
39 : BackendArray<cudaReal,CUT>(other),
40 meshDimensions_(0)
41 { meshDimensions_ = other.meshDimensions_; }
42
43 /*
44 * Destructor.
45 */
46 template <int D>
49
50 /*
51 * Allocate the underlying C array for data on a regular mesh.
52 */
53 template <int D>
55 {
56 int size = 1;
57 for (int i = 0; i < D; ++i) {
59 meshDimensions_[i] = meshDimensions[i];
60 size *= meshDimensions[i];
61 }
63 }
64
65 /*
66 * Deallocate the underlying C array and zero grid dimensions.
67 */
68 template <int D>
70 {
72 for (int i = 0; i < D; ++i) {
73 meshDimensions_[i] = 0;
74 }
75 }
76
77 /*
78 * Associate this object with a slice of another BackendArray.
79 */
80 template <int D>
82 int beginId,
84 {
85 int size = 1;
86 for (int i = 0; i < D; ++i) {
88 meshDimensions_[i] = meshDimensions[i];
89 size *= meshDimensions[i];
90 }
91 BackendArray<cudaReal,CUT>::associate(arr, beginId, size);
92 }
93
94 /*
95 * Assignment from another RField.
96 */
97 template <int D>
100 {
102 meshDimensions_ = other.meshDimensions_;
103
104 return *this;
105 }
106
107 /*
108 * Assignment of this RField from RHS HostSendArray.
109 */
110 template <int D>
113 {
114 // Preconditions: both arrays must be allocated with equal capacities
115 UTIL_CHECK(other.isAllocated());
117 UTIL_CHECK((BackendArray<cudaReal,CUT>::capacity() == other.capacity()));
118
119 // Use base class assignment operator to copy elements
121
122 return *this;
123 }
124
125}
126#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
RField()
Default constructor.
void allocate(IntVec< D > const &meshDimensions)
Allocate the underlying array for data on a regular mesh.
IntVec< D > const & meshDimensions() const
Return 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.
cufftDoubleReal cudaReal
Real number type used in CPU code that uses FFTW.
Definition cudaTypes.h:35