FourierTransform.h 3.38 KB
Newer Older
Francois Gygi committed
1 2 3 4 5
////////////////////////////////////////////////////////////////////////////////
//
// FourierTransform.h
//
////////////////////////////////////////////////////////////////////////////////
6
// $Id: FourierTransform.h,v 1.11 2007-10-19 16:24:04 fgygi Exp $
Francois Gygi committed
7 8 9 10 11 12 13

#ifndef FOURIERTRANSFORM_H
#define FOURIERTRANSFORM_H

#include <complex>
#include <vector>

14
#if USE_FFTW
Francois Gygi committed
15 16 17
#include "fftw.h"
#endif

18 19
#include "Timer.h"

Francois Gygi committed
20 21 22 23 24 25 26 27
class Basis;
class Context;

class FourierTransform
{
  private:

  const Context& ctxt_;
28
  const Basis& basis_;
Francois Gygi committed
29 30 31
  int nprocs_, myproc_;

  int np0_,np1_,np2_;
32
  int ntrans0_,ntrans1_,ntrans2_;
33

Francois Gygi committed
34
  int nvec_;
35

36 37 38
  std::vector<int> np2_loc_; // np2_loc_[iproc], iproc=0, nprocs_-1
  std::vector<int> np2_first_; // np2_first_[iproc], iproc=0, nprocs_-1
  std::vector<std::complex<double> > zvec_;
39

40 41
  std::vector<int> scounts, sdispl, rcounts, rdispl;
  std::vector<std::complex<double> > sbuf, rbuf;
Francois Gygi committed
42

43 44
  std::vector<int> ifftp_, ifftm_;
  std::vector<int> ipack_, iunpack_;
45

Francois Gygi committed
46
  void init_lib(void);
47

48 49
#if USE_ESSL
#if USE_ESSL_2DFFT
50 51
  std::vector<double> aux1xyf;
  std::vector<double> aux1xyb;
Francois Gygi committed
52 53
  int naux1xy;
#else
54 55 56
  std::vector<double> aux1xf, aux1yf, aux1zf;
  std::vector<double> aux1xb, aux1yb, aux1zb;
  std::vector<double> aux2;
Francois Gygi committed
57 58
  int naux1x,naux1y,naux1z,naux2;
#endif
Francois Gygi committed
59
#elif USE_FFTW || USE_FFTW3
Francois Gygi committed
60 61 62 63 64
  fftw_plan fwplan0,fwplan1,fwplan2,bwplan0,bwplan1,bwplan2;
#else
  // no library
#endif

65 66 67 68 69 70 71
  void vector_to_zvec(const std::complex<double>* c);
  void zvec_to_vector(std::complex<double>* c);
  void doublevector_to_zvec(const std::complex<double>* c1,
       const std::complex<double> *c2);
  void zvec_to_doublevector(std::complex<double>* c1, std::complex<double>* c2);
  void fwd(std::complex<double>* val);
  void bwd(std::complex<double>* val);
72

Francois Gygi committed
73 74 75 76 77
  public:

  FourierTransform (const Basis &basis, int np0, int np1, int np2);
  ~FourierTransform ();
  const Context& context(void) const { return ctxt_; }
78

Francois Gygi committed
79 80 81 82
  // backward: Fourier synthesis, compute real-space function
  // forward:  Fourier analysis, compute Fourier coefficients
  // forward transform includes scaling by 1/np012
  // single transforms: c -> f, f -> c
83
  void backward (const std::complex<double>* c, std::complex<double>* f);
Francois Gygi committed
84
  // Note: forward transforms overwrite the array f
85
  void forward(std::complex<double>* f, std::complex<double>* c);
86

Francois Gygi committed
87
  // double transforms: c1 + i*c2 -> f, f -> c1 + i*c2
88
  void backward (const std::complex<double>* c1,
89
                 const std::complex<double>* c2, std::complex<double>* f);
Francois Gygi committed
90
  // Note: forward transforms overwrite the array f
91
  void forward(std::complex<double>* f,
92
               std::complex<double>* c1, std::complex<double>* c2);
93

Francois Gygi committed
94 95 96 97 98 99 100 101 102 103 104
  int np0() const { return np0_; }
  int np1() const { return np1_; }
  int np2() const { return np2_; }
  int np2_loc() const { return np2_loc_[myproc_]; }
  int np2_loc(int iproc) const { return np2_loc_[iproc]; }
  int np2_first() const { return np2_first_[myproc_]; }
  int np2_first(int iproc) const { return np2_first_[iproc]; }
  int np012() const { return np0_ * np1_ * np2_; }
  int np012loc(int iproc) const { return np0_ * np1_ * np2_loc_[iproc]; }
  int np012loc() const { return np0_ * np1_ * np2_loc_[myproc_]; }
  int index(int i, int j, int k) const
105
  { return i + np0_ * ( j +  np1_ * k ); }
Francois Gygi committed
106

107 108 109
  void reset_timers(void);
  Timer tm_f_map, tm_f_fft, tm_f_pack, tm_f_mpi, tm_f_zero, tm_f_unpack,
        tm_b_map, tm_b_fft, tm_b_pack, tm_b_mpi, tm_b_zero, tm_b_unpack;
Francois Gygi committed
110 111
};
#endif