PSCF v1.1
RFieldDft.tpp
1#ifndef PSPC_R_FIELD_DFT_TPP
2#define PSPC_R_FIELD_DFT_TPP
3
4/*
5* PSCF Package
6*
7* Copyright 2016 - 2022, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "RFieldDft.h"
12
13namespace Pscf {
14namespace Pspc {
15
16 using namespace Util;
17
21 template <int D>
23 : Field<fftw_complex>()
24 {}
25
26 /*
27 * Destructor.
28 */
29 template <int D>
31 {}
32
33 /*
34 * Copy constructor.
35 *
36 * Allocates new memory and copies all elements by value.
37 *
38 *\param other the RField<D> to be copied.
39 */
40 template <int D>
42 : Field<fftw_complex>()
43 {
44 if (!other.isAllocated()) {
45 UTIL_THROW("Other Field must be allocated.");
46 }
47 data_ = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*other.capacity_);
48 capacity_ = other.capacity_;
49 for (int i = 0; i < capacity_; ++i) {
50 data_[i][0] = other.data_[i][0];
51 data_[i][1] = other.data_[i][1];
52 }
53 meshDimensions_ = other.meshDimensions_;
54 dftDimensions_ = other.dftDimensions_;
55 }
56
57 /*
58 * Assignment, element-by-element.
59 *
60 * This operator will allocate memory if not allocated previously.
61 *
62 * \throw Exception if other Field is not allocated.
63 * \throw Exception if both Fields are allocated with unequal capacities.
64 *
65 * \param other the rhs Field
66 */
67 template <int D>
69 {
70 // Check for self assignment
71 if (this == &other) return *this;
72
73 // Precondition
74 if (!other.isAllocated()) {
75 UTIL_THROW("Other Field must be allocated.");
76 }
77
78 if (!isAllocated()) {
79 allocate(other.capacity());
80 } else if (capacity_ != other.capacity_) {
81 UTIL_THROW("Cannot assign Fields of unequal capacity");
82 }
83
84 // Copy elements
85 for (int i = 0; i < capacity_; ++i) {
86 data_[i][0] = other.data_[i][0];
87 data_[i][1] = other.data_[i][1];
88 }
89 meshDimensions_ = other.meshDimensions_;
90 dftDimensions_ = other.dftDimensions_;
91
92 return *this;
93 }
94
95}
96}
97#endif
Base class template for a field defined on a spatial grid.
Fourier transform of a real field on an FFT mesh.
Definition: RFieldDft.h:31
virtual ~RFieldDft()
Destructor.
Definition: RFieldDft.tpp:30
RFieldDft< D > & operator=(RFieldDft< D > const &other)
Assignment operator.
Definition: RFieldDft.tpp:68
RFieldDft()
Default constructor.
Definition: RFieldDft.tpp:22
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
bool isAllocated() const
Return true if this DArray has been allocated, false otherwise.
Definition: DArray.h:247
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
Definition: accumulators.mod:1