fftpack.h 6.82 KB
Newer Older
1
/*
2
3
4
5
6
7
8
9
10
11
12
13
14
15
* This file contains a Fortran to C translation of the 1D transformations
* based on the original FFTPACK, written by paul n swarztrauber
* at the national center for atmospheric research and available
* at www.netlib.org. FFTPACK is in the public domain.
*
* Higher-dimension transforms written by Erik Lindahl, 2008-2009.
* Just as FFTPACK, this file may be redistributed freely, and can be
* considered to be in the public domain. 
*
* Any errors in this (threadsafe, but not threaded) C version
* are probably due to the f2c translator, or hacks by Erik Lindahl,
* rather than FFTPACK. If you find a bug, it would be great if you could
* drop a line to lindahl@cbr.su.se and let me know about it!
*/
16

17
18
19
20
21
22
23
24
#include "../SimTKUtilities/SimTKOpenMMCommon.h"

#ifndef _FFTPACK_H_
#define _FFTPACK_H_


#include <stdio.h>

25
#include "openmm/internal/windowsExport.h"
26
27
28
29
30
31
32
33
34

#ifdef __cplusplus
extern "C" {
#endif
#if 0
} /* fixes auto-indentation problems */
#endif


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class t_complex {
public:
    RealOpenMM re;
    RealOpenMM im;
    t_complex() : re(0.0), im(0.0) {
    }
    t_complex(RealOpenMM re, RealOpenMM im) : re(re), im(im) {
    }
    t_complex(const t_complex& c) : re(c.re), im(c.im) {
    }
    t_complex operator*(RealOpenMM r) {
        return t_complex(re*r, im*r);
    }
    t_complex operator+(const t_complex& c) const {
        return t_complex(re+c.re, im+c.im);
    }
    t_complex operator-(const t_complex& c) const {
        return t_complex(re-c.re, im-c.im);
    }
54
    t_complex& operator+=(const t_complex& c) {
55
56
        re += c.re;
        im += c.im;
57
        return *this;
58
    }
59
    t_complex& operator-=(const t_complex& c) {
60
61
        re -= c.re;
        im -= c.im;
62
        return *this;
63
64
    }
};
65
66


67
/*! \brief Datatype for FFT setup
68
69
 *
 *  The fftpack_t type contains all the setup information, e.g. twiddle
70
 *  factors, necessary to perform an FFT. Internally it is mapped to
71
72
73
74
75
76
77
78
79
 *  whatever FFT library we are using, or the built-in FFTPACK if no fast
 *  external library is available.
 */
typedef struct fftpack *
fftpack_t;




80
/*! \brief Specifier for FFT direction.
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
 *
 *  The definition of the 1D forward transform from input x[] to output y[] is
 *  \f[
 *  y_{k} = \sum_{j=0}^{N-1} x_{j} \exp{-i 2 \pi j k /N}
 *  \f]
 *
 *  while the corresponding backward transform is
 *
 *  \f[
 *  y_{k} = \sum_{j=0}^{N-1} x_{j} \exp{i 2 \pi j k /N}
 *  \f]
 *
 *  A forward-backward transform pair will this result in data scaled by N.
 *
 */
typedef enum fftpack_direction
{
    FFTPACK_FORWARD,         /*!< Forward complex-to-complex transform  */
    FFTPACK_BACKWARD,        /*!< Backward complex-to-complex transform */
} fftpack_direction;



104
/*! \brief Setup a 1-dimensional complex-to-complex transform
105
106
 *
 *  \param fft    Pointer to opaque Gromacs FFT datatype
107
 *  \param nx     Length of transform
108
109
110
111
 *
 *  \return status - 0 or a standard error message.
 */
int
112
OPENMM_EXPORT
113
114
115
116
117
fftpack_init_1d        (fftpack_t *       fft,
                        int               nx);



118
/*! \brief Setup a 2-dimensional complex-to-complex transform
119
120
121
122
123
124
 *
 *  \param fft    Pointer to opaque Gromacs FFT datatype
 *  \param nx     Length of transform in first dimension
 *  \param ny     Length of transform in second dimension
 *
 *  \return status - 0 or a standard error message.
125
 *
126
127
 */
int
128
OPENMM_EXPORT
129
fftpack_init_2d        (fftpack_t *         fft,
130
                        int                 nx,
131
132
133
134
135
                        int                 ny);




136
/*! \brief Setup a 3-dimensional complex-to-complex transform
137
138
139
140
141
142
143
 *
 *  \param fft    Pointer to opaque Gromacs FFT datatype
 *  \param nx     Length of transform in first dimension
 *  \param ny     Length of transform in second dimension
 *  \param nz     Length of transform in third dimension
 *
 *  \return status - 0 or a standard error message.
144
 *
145
146
 */
int
147
OPENMM_EXPORT
148
fftpack_init_3d        (fftpack_t *         fft,
149
                        int                 nx,
150
151
152
153
154
155
156
157
158
159
160
161
                        int                 ny,
                        int                 nz);




/*! \brief Perform a 1-dimensional complex-to-complex transform
 *
 *  Performs an instance of a transform previously initiated.
 *
 *  \param setup     Setup returned from fftpack_init_1d()
 *  \param dir       Forward or Backward
162
163
 *  \param in_data   Input grid data.
 *  \param out_data  Output grid data.
164
165
166
167
168
 *                   You can provide the same pointer for in_data and out_data
 *                   to perform an in-place transform.
 *
 * \return 0 on success, or an error code.
 *
169
 * \note Data pointers are declared as void, to avoid casting pointers
170
171
 *       depending on your grid type.
 */
172
int
173
OPENMM_EXPORT
174
175
176
177
178
179
180
181
182
183
184
fftpack_exec_1d          (fftpack_t                  setup,
                          enum fftpack_direction     dir,
                          t_complex *                in_data,
                          t_complex *                out_data);

/*! \brief Perform a 2-dimensional complex-to-complex transform
 *
 *  Performs an instance of a transform previously initiated.
 *
 *  \param setup     Setup returned from fftpack_init_1d()
 *  \param dir       Forward or Backward
185
186
 *  \param in_data   Input grid data.
 *  \param out_data  Output grid data.
187
188
189
190
191
 *                   You can provide the same pointer for in_data and out_data
 *                   to perform an in-place transform.
 *
 * \return 0 on success, or an error code.
 *
192
 * \note Data pointers are declared as void, to avoid casting pointers
193
194
 *       depending on your grid type.
 */
195
int
196
OPENMM_EXPORT
197
198
199
200
201
202
203
204
205
206
207
208
fftpack_exec_2d          (fftpack_t                  setup,
                          enum fftpack_direction     dir,
                          t_complex *                in_data,
                          t_complex *                out_data);


/*! \brief Perform a 3-dimensional complex-to-complex transform
 *
 *  Performs an instance of a transform previously initiated.
 *
 *  \param setup     Setup returned from fftpack_init_1d()
 *  \param dir       Forward or Backward
209
210
 *  \param in_data   Input grid data.
 *  \param out_data  Output grid data.
211
212
213
214
215
 *                   You can provide the same pointer for in_data and out_data
 *                   to perform an in-place transform.
 *
 * \return 0 on success, or an error code.
 *
216
 * \note Data pointers are declared as void, to avoid casting pointers
217
218
 *       depending on your grid type.
 */
219
int
220
OPENMM_EXPORT
221
222
223
224
225
226
fftpack_exec_3d          (fftpack_t                  setup,
                          enum fftpack_direction     dir,
                          t_complex *                in_data,
                          t_complex *                out_data);


227
/*! \brief Release an FFT setup structure
228
229
230
231
232
233
234
235
 *
 *  Destroy setup and release all allocated memory.
 *
 *  \param setup Setup returned from fftpack_init_1d(), or one
 *		 of the other initializers.
 *
 */
void
236
OPENMM_EXPORT
237
238
239
240
241
242
243
244
245
fftpack_destroy          (fftpack_t                 setup);



#ifdef __cplusplus
}
#endif

#endif /* _FFTPACK_H_ */