PSCF v1.4.0
FftwDArray.h
1#ifndef PRDC_CPU_FFTW_D_ARRAY_H
2#define PRDC_CPU_FFTW_D_ARRAY_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2025, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/containers/Array.h>
12#include <util/global.h>
13
14#include <fftw3.h>
15
16namespace Pscf {
17namespace Prdc {
18namespace Cpu {
19
20 using namespace Util;
21
31 template <typename Data>
32 class FftwDArray : public Array<Data>
33 {
34
35 public:
36
40 using ValueType = Data;
41
45 FftwDArray();
46
52 virtual ~FftwDArray();
53
61 void allocate(int capacity);
62
68 virtual void deallocate();
69
73 bool isAllocated() const;
74
81 template <class Archive>
82 void serialize(Archive& ar, const unsigned int version);
83
84 protected:
85
86 using Array<Data>:: data_;
87 using Array<Data>:: capacity_;
88
89 private:
90
94 FftwDArray(FftwDArray<Data> const & other);
95
99 FftwDArray<Data>& operator = (FftwDArray<Data> const & other);
100
101 };
102
103 /*
104 * Return true if the FftwDArray has been allocated, false otherwise.
105 */
106 template <typename Data>
108 { return (bool) data_; }
109
110 /*
111 * Serialize a FftwDArray to/from an Archive.
112 */
113 template <typename Data>
114 template <class Archive>
115 void FftwDArray<Data>::serialize(Archive& ar, const unsigned int version)
116 {
117 int capacity;
118 if (Archive::is_saving()) {
120 }
121 ar & capacity;
122 if (Archive::is_loading()) {
123 if (!isAllocated()) {
124 if (capacity > 0) {
126 }
127 } else {
128 if (capacity != capacity_) {
129 UTIL_THROW("Inconsistent FftwDArray capacities");
130 }
131 }
132 }
133 if (isAllocated()) {
134 for (int i = 0; i < capacity_; ++i) {
135 ar & data_[i];
136 }
137 }
138 }
139
140}
141}
142}
143#include "FftwDArray.tpp"
144#endif
void serialize(Archive &ar, const unsigned int version)
Serialize a FftwDArray to/from an Archive.
Definition FftwDArray.h:115
void allocate(int capacity)
Allocate the underlying C array.
virtual ~FftwDArray()
Destructor.
FftwDArray()
Default constructor.
virtual void deallocate()
Dellocate the underlying C array.
Data ValueType
Data type of each array element.
Definition FftwDArray.h:40
bool isAllocated() const
Return true if the FftwDArray has been allocated, false otherwise.
Definition FftwDArray.h:107
Data * data_
Pointer to an array of Data elements.
Definition Array.h:107
int capacity() const
Return allocated size.
Definition Array.h:144
int capacity_
Allocated size of the data_ array.
Definition Array.h:110
File containing preprocessor macros for error handling.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition global.h:49
Fields and FFTs for periodic boundary conditions (CPU)
Definition complex.cpp:12
Periodic fields and crystallography.
Definition complex.cpp:11
PSCF package top-level namespace.