CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Running, Solving & CFD (
-   -   Problems with fft (

ivan_cozza November 14, 2008 09:57

Hi Foamers! I'm trying to imp
Hi Foamers!
I'm trying to implement some analytical solutions of the Linearized Euler Equations and I need to evaluate a spatioal convolution product:

p(x,y,t) = f(x,y)@dG(x,y,t)/dt

where G is the free space green function.
To solve this convolution I apply this property:

FourierTransform(a(x,y)@b(x,y))=FourierTransform(a (x,y)) FourierTransform(b(x,y))

then I come back to physical space with the inverse fft.

My code is:

Kmesh K(mesh);
volScalarField f = eps*exp(-Foam::log(2.0)/2*(sqr(x-x_mon/lRef)+sqr(y-y_mon/lRef)));

Info << "\nEvaluating FFT" << endl;

complexField fFour = fft::forwardTransform(ReComplexField(f), K.nn());

etc etc....

but when I execute it I have:

Create time

Create mesh for time = 0

Reading parameters

Reading field U

(1.99 1.99 0.2)
3(200 200 1)

Evaluating FFT
#0 Foam::error::printStack(Foam: in "/opt/OpenFOAM/OpenFOAM-1.5/lib/linux64GccDPOpt/"
#1 Foam::sigSegv::sigSegvHandler(int) in "/opt/OpenFOAM/OpenFOAM-1.5/lib/linux64GccDPOpt/"
#2 ?? in "/lib64/"
#3 Foam::fft::transform(Foam::Field<foam::complex>&, Foam::List<int> const&, Foam::fft::transformDirection) in "/opt/OpenFOAM/OpenFOAM-1.5/lib/linux64GccDPOpt/"
#4 Foam::fft::forwardTransform(Foam::tmp<foam::field< foam::complex> > const&, Foam::List<int> const&) in "/opt/OpenFOAM/OpenFOAM-1.5/lib/linux64GccDPOpt/"
#5 main in "/home/ivan/OpenFOAM/ivan-1.5/applications/bin/linux64GccDPOpt/monopolo"
#6 __libc_start_main in "/lib64/"
#7 Foam::regIOobject::readIfModified() in "/home/ivan/OpenFOAM/ivan-1.5/applications/bin/linux64GccDPOpt/monopolo"
Segmentation fault

I have a square bidimensional mesh.
What does it means this segmentation fault?

mattijs November 16, 2008 07:43

Segmentation fault means that
Segmentation fault means that it accesses outside the allocated memory. See e.g.

ivan_cozza November 16, 2008 16:38

Ok, the correct question is:
Ok, the correct question is:
I'm doing something wrong in my setup, something like the use of fft::forwardTransform is incorrect or it works only with 3D meshes, or there are any best-practise for the use of fft?

Pascal_doran November 15, 2010 19:08

basic info with fft in OF
Hi Yvan,

Did you find a solution? I'm trying to implement 1D fft with the velocities in my solver and I'm not able to compile the solver...
kMesh, fft and complexField have not been declared the error message said.
How can I use the kMesh and fft class in OF 1.6.x. Would it be easier if create a utility for the fft?

Any advice would be great!

Thank you,


elisabet May 11, 2011 06:52

Hi all,

I've tried to implement a post-process in order to evaluate the FFT in a 3D mesh.

What I've done is:

1. To include the required header files (and modify accordingly the 'options' file):
#include "fft.H"
#include "Kmesh.H"
#include "complexFields.H"
2. To calculate the FFT of the x velocity component (this can be discussed)
Kmesh K(mesh);
scalarField Ufft=mag(fft::forwardTransform(ReComplexField( mponent(0)),K.nn()));
where Ufft is a scalarField of the same dimensions as the mesh.

I guess that Ufft is the y-axis of a typical FFT diagram but, what should be the x-axis?

Sorry if this is a very basic question, I'm familiar with FFT in time but I've never dealt with FFT in space.



Pascal_doran May 11, 2011 11:10

Fftw 2.1.5
Hi Elisabet,

The simplest solution I found was to link the public code FFTW 2.1.5 with OpenFOAM 1.6.x. All you need to do is modify your solver: option file and add a few line of code in order to calculate your FFT. You will have great flexibility using FFTW.

Note: Also, you can all do that as an post-process utility.


elisabet May 12, 2011 07:07

Thanks Pascal for the answer.

First of all, now I know what the final output should be (correct me if I'm wrong): a volScalarField in order to the see the peaks on my mesh (with paraview for example)

I've been looking to use FFTW properly. I've found the place:

but, as fas as I understand, my 'in' (of fft_complex type) would be a ReComplexField of size K.sizeOfBox(), as well as my 'out' variable. Afterwords, I would convert the 'out' to a scalarField. However, I still have the same question:

how to convert a scalarField to a volScalarField in order to visualize the resulting FFT in the physical space?

Any suggestion? Or other ways to handle it?


Pascal_doran May 12, 2011 10:55

1 Attachment(s)
Hi Elisabet,

When I use FFTW I need 1D array (standard C++) and volVectorField (I'm using 1D FFT on velocity vector):

            for (int nzi = 0; nzi < nz; nzi++) // Écriture du nouveau champ vectoriel
                champModeX[nxy + nzi*nLim].component(0) = inWx[nzi]/nz;
                champModeX[nxy + nzi*nLim].component(1) = inWy[nzi]/nz;
                champModeX[nxy + nzi*nLim].component(2) = inWz[nzi]/nz;

where inWx[nzi] is the nzi element of the array inWx created by FFTW. nz is the number of cell in the 'z' direction required for normalization. And champModeX is a new volVectorField. At the end I can observe the mode 0, 1, 2, etc. of the velocity field (called champModeX).

Entire code of this utility is attached to the post.

Hope this help.

elisabet May 12, 2011 12:14

Thank you very much Pascal! it was very useful!

If I understand it well, you call 'mode' a given xy plane (defined by z). Is it correct?

Thus, it's reasonable to just look the FFT at a given xy plane, but I don't see the reason why you are interested in looking all xy planes except one.


Pascal_doran May 12, 2011 13:30

Hi Elisabet,

I'm doing FFT along 'z' axis (1D) and I calculate the most interesting mode (n) from 0 to nz/2-1 or wavenumber (k = 2*pi*n/Lz). I have also the possibility to observe all the modes except one. For example, I could be interested by all the modes except mode 0 (which is the base flow or 2D field) Doing that it will allow me to visualize the perturbed field which is very interesting depending what you are looking for. The calculation is applied to the entire domain of simulation.


All times are GMT -4. The time now is 07:47.