PSCF v1.3
FftwDArray.tpp
1#ifndef PRDC_CPU_FFTW_D_ARRAY_TPP
2#define PRDC_CPU_FFTW_D_ARRAY_TPP
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 "FftwDArray.h"
12#include <fftw3.h>
13
14namespace Pscf {
15namespace Prdc {
16namespace Cpu {
17
18 using namespace Util;
19
20 /*
21 * Default constructor.
22 */
23 template <typename Data>
25 : Array<Data>()
26 {}
27
28 /*
29 * Destructor.
30 */
31 template <typename Data>
33 {
34 if (isAllocated()) {
35 fftw_free(data_);
36 capacity_ = 0;
37 }
38 }
39
40 /*
41 * Allocate the underlying C array.
42 *
43 * Throw an Exception if the FftwDArray has already been allocated.
44 *
45 * \param capacity number of elements to allocate.
46 */
47 template <typename Data>
49 {
50 if (isAllocated()) {
51 UTIL_THROW("Attempt to re-allocate a FftwDArray");
52 }
53 if (capacity <= 0) {
54 UTIL_THROW("Attempt to allocate FftwDArray with capacity <= 0");
55 }
57 data_ = (Data*) fftw_malloc(sizeof(Data)*capacity);
58 }
59
60 /*
61 * Deallocate the underlying C array.
62 *
63 * Throw an Exception if this FftwDArray is not allocated.
64 */
65 template <typename Data>
67 {
68 if (!isAllocated()) {
69 UTIL_THROW("Array is not allocated");
70 }
71 fftw_free(data_);
72 capacity_ = 0;
73 }
74
75}
76}
77}
78#endif
void allocate(int capacity)
Allocate the underlying C array.
virtual ~FftwDArray()
Destructor.
FftwDArray()
Default constructor.
virtual void deallocate()
Dellocate the underlying C array.
bool isAllocated() const
Return true if the FftwDArray has been allocated, false otherwise.
Definition FftwDArray.h:102
Data * data_
Pointer to an array of Data elements.
Definition Array.h:109
int capacity() const
Return allocated size.
Definition Array.h:159
int capacity_
Allocated size of the data_ array.
Definition Array.h:112
Array()
Default constructor.
Definition Array.h:143
#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 CField.cpp:12
Periodic fields and crystallography.
Definition CField.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1