Typedefs | Functions
test_FftwReal2dDftData.cxx File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include "dunecore/DuneInterface/Data/FftwReal2dDftData.h"
#include <cassert>

Go to the source code of this file.

Typedefs

using DftData = FftwDouble2dDftData
 
using Index = DftData::Index
 
using IndexArray = DftData::IndexArray
 
using IndexArrayVector = DftData::IndexArrayVector
 
using Complex = DftData::Complex
 
using Float = DftData::Float
 

Functions

Index realval (Index idat)
 
Index imagval (Index idat)
 
int test_FftwReal2dDftData (Index nsam0, Index nsam1)
 
int main (int argc, char *argv[])
 

Typedef Documentation

Definition at line 28 of file test_FftwReal2dDftData.cxx.

Definition at line 24 of file test_FftwReal2dDftData.cxx.

Definition at line 29 of file test_FftwReal2dDftData.cxx.

Definition at line 25 of file test_FftwReal2dDftData.cxx.

Definition at line 26 of file test_FftwReal2dDftData.cxx.

Definition at line 27 of file test_FftwReal2dDftData.cxx.

Function Documentation

Index imagval ( Index  idat)

Definition at line 32 of file test_FftwReal2dDftData.cxx.

32 { return 2*idat + 2; }
int main ( int  argc,
char *  argv[] 
)

Definition at line 155 of file test_FftwReal2dDftData.cxx.

155  {
156  if ( argc > 1 ) {
157  cout << "Usage: " << argv[0] << " [ARG]" << endl;
158  return 0;
159  }
160  Index stat = 0;
161  stat += test_FftwReal2dDftData(3, 4);
162  stat += test_FftwReal2dDftData(4, 3);
163  return stat;
164 }
int test_FftwReal2dDftData(Index nsam0, Index nsam1)
unsigned int Index
QTextStream & endl(QTextStream &s)
Index realval ( Index  idat)

Definition at line 31 of file test_FftwReal2dDftData.cxx.

31 { return 2*idat + 1; }
int test_FftwReal2dDftData ( Index  nsam0,
Index  nsam1 
)

Definition at line 36 of file test_FftwReal2dDftData.cxx.

36  {
37  const string myname = "test_FftwReal2dDftData: ";
38 #ifdef NDEBUG
39  cout << myname << "NDEBUG must be off." << endl;
40  abort();
41 #endif
42  string line = myname + "-----------------------------";
43 
44  cout << line << endl;
45  cout << myname << "Sample sizes: " << nsam0 << ", " << nsam1 << endl;
46 
47  cout << line << endl;
48  cout << myname << "Checking index array." << endl;
49  IndexArray nsams({nsam0, nsam1});
50  assert( nsams[0] == nsam0 );
51  assert( nsams[1] == nsam1 );
52  Index nComplexExp = nsam0*(nsam1/2 + 1);
53  Index ndftComplex = DftData::dftComplexDataSize(nsams);
54  cout << myname << " Complex size: " << ndftComplex << endl;
55  Index ndftFloat = DftData::dftFloatDataSize(nsams);
56  cout << myname << " Float size: " << ndftFloat << endl;
57  assert( ndftComplex == nComplexExp );
58  assert( ndftFloat == 2*nComplexExp );
59 
60  cout << line << endl;
61  cout << myname << "Construct DFT object." << endl;
62  DftData::Norm norm(22);
63  DftData dft(norm, nsams);
64  assert( dft.rank() == 2 );
65  assert( dft.normalization() == norm );
66  assert( dft.size() == ndftComplex );
67  assert( dft.nSamples(0) == nsam0 );
68  assert( dft.size(0) == nsam0 );
69  assert( dft.nSamples(1) == nsam1 );
70  assert( dft.size(1) == nsam1 );
71 
72  cout << myname << "Check indexing." << endl;
73  Index cntij = 0;
74  for ( Index idat=0; idat<nComplexExp; ++idat ) {
75  IndexArrayVector idxas = dft.indexArrays(idat);
76  cout << myname << setw(3) << idat << ": ";
77  Index nerr = idxas.size() == 0;
78  bool first = true;
79  for ( IndexArray idxa : idxas ) {
80  Index jdat = dft.globalIndex(idxa);
81  if ( first ) first = false;
82  else cout << ", ";
83  cout << "[" << setw(3) << idxa[0] << "," << setw(3) << idxa[1] << "]";
84  if ( jdat != idat ) cout << " --> " << jdat << " (!)";
85  if ( jdat != idat ) ++nerr;
86  ++cntij;
87  }
88  cout << endl;
89  assert( nerr == 0 );
90  }
91  assert( cntij == nsam0*nsam1 );
92 
93  cout << line << endl;
94  cout << myname << "Create test data." << endl;
95  vector<Complex> datc(nComplexExp);
96  vector<Float> datf(2*nComplexExp);
97  Index iflt = 0;
98  Index idat;
99  for ( idat=0; idat<nComplexExp; ++idat ) {
100  IndexArrayVector arrs = dft.indexArrays(idat);
101  Float re = realval(idat);
102  Float im = imagval(idat);
103  datf[iflt++] = re;
104  datf[iflt++] = im;
105  Complex cval(re, im);
106  datc[idat] = cval;
107  }
108  assert( idat == datc.size() );
109  assert( iflt == datf.size() );
110 
111  cout << line << endl;
112  cout << myname << "Copy data in." << endl;
113  assert( dft.copyIn(nsams, datc) == 0 );
114  for ( Index idat=0; idat<nComplexExp; ++idat ) {
115  IndexArrayVector idxas = dft.indexArrays(idat);
116  assert( idxas.size() );
117  Complex cval = dft.value(idat);
118  Index ire = cval.real() + 0.1;
119  Index iim = cval.imag() + 0.1;
120  cout << myname << setw(3) << idat << ": ["
121  << setw(3) << idxas[0][0] << "," << setw(3) << idxas[0][1] << "]: "
122  << "(" << setw(3) << ire << "," << setw(3) << iim << ")"
123  << endl;
124  }
125 
126  cout << line << endl;
127  cout << myname << "Copy object." << endl;
128  DftData dft2(dft);
129  assert( dft2.rank() == 2 );
130  assert( dft2.normalization() == norm );
131  assert( dft2.size() == ndftComplex );
132  assert( dft2.nSamples(0) == nsam0 );
133  assert( dft2.size(0) == nsam0 );
134  assert( dft2.nSamples(1) == nsam1 );
135  assert( dft2.size(1) == nsam1 );
136  for ( Index idat=0; idat<nComplexExp; ++idat ) {
137  IndexArrayVector idxas = dft.indexArrays(idat);
138  assert( idxas.size() );
139  Complex cval = dft2.value(idat);
140  Index ire = cval.real() + 0.1;
141  Index iim = cval.imag() + 0.1;
142  cout << myname << setw(3) << idat << ": ["
143  << setw(3) << idxas[0][0] << "," << setw(3) << idxas[0][1] << "]: "
144  << "(" << setw(3) << ire << "," << setw(3) << iim << ")"
145  << endl;
146  }
147 
148  cout << line << endl;
149  cout << myname << "All tests passed." << endl;
150  return 0;
151 }
DftData::IndexArrayVector IndexArrayVector
Index imagval(Index idat)
Fw2dFFT::Complex Complex
DftData::IndexArray IndexArray
unsigned int Index
static Index dftComplexDataSize(const std::array< Index, N > &nsams)
Index realval(Index idat)
auto norm(Vector const &v)
Return norm of the specified vector.
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
static Index dftFloatDataSize(const std::array< Index, N > &nsams)
void line(double t, double *p, double &x, double &y, double &z)
DftData::Float Float
QTextStream & endl(QTextStream &s)