Efficient 3D Inverse Fourier Transform on FORTRAN Code with Chi Array

In summary, the conversation discusses the use of a FORTRAN code with an array called Chi and the desire to run an inverse FT on it. The individual has defined two spaces, X and K, consisting of 3 vectors each. They mention that their code is slow and inefficient and ask for the best way to do a 3D IFT computationally. The conversation then delves into the use of a standard library like FFTPACK and the benefits of manipulating arrays in bulk. Finally, the individual asks for guidance on which subroutine to use and how to implement it for a 3D complex to real transformation.
  • #1
Ben Wilson
90
16
Hi, I have a FORTRAN code with an array called Chi that I want to run an inverse FT on. I have defined two spaces X and K which each consist of 3 vectors running across my physical verse and inverse space.

My code (If it works??) is extremely slow and inefficient (see below). What is the best way of doing a 3D IFT computationally?

CODE

!Real & Inverse Spaces
do i1 = 1, 2*No_x +1
x_x(i1) = -L/2.d0 + dx*(i1-1)
x_y(i1) = -L/2.d0 + dx*(i1-1)
x_z(i1) = -L/2.d0 + dx*(i1-1)
xi_x(i1) = (i1-(No_k+1))*(2.d0*pi/L)
xi_y(i1) = (i1-(No_k+1))*(2.d0*pi/L)
xi_z(i1) = (i1-(No_k+1))*(2.d0*pi/L)
end do

chi = blablabla
!chi is a function of xi

!3d IFT
do r1 = 1,2*No_x +1
do r2 = 1,2*No_x +1
do r3 = 1,2*No_x +1
chi_ift(r1,r2,r3) = 0
do i1 = 1,2*No_k +1
do i2 = 1,2*No_k +1
do i3 = 1,2*No_k +1
chi_ift(r1,r2,r3) = chi_ift(r1,r2,r3) + chi(i1,i2,i3)*exp(imagi*xi_z(i3)*x_z(r3))
end do
chi_ift(r1,r2,r3) = chi_ift(r1,r2,r3) + chi(i1,i2,i3)*exp(imagi*xi_y(i2)*x_y(r2))
end do
chi_ift(r1,r2,r3) = chi_ift(r1,r2,r3) + chi(i1,i2,i3)*exp(imagi*xi_x(i1)*x_x(r1))
end do
end do
end do
end do
Reply Reply to All Forward More
Click to Reply, Reply all or Forward
 
Physics news on Phys.org
  • #2
Definitely you should use a standard library like FFTPACK. Unless it is a classroom exercise you should not be rewriting FFT algorithms.
 
  • #3
Well, for popular algorithms, what Dale said.

Other than that, you need to learn to manipulate arrays en masse, a-la-matlab, whenever possible. This tells the compiler that assignments can be done in any order and without having to carefully traverse one index at a time, or switching from evaluating one array and then another and loop again.

You initialization do-loop above, can be made at least 3 times faster by not having to repeat the calculations; an even faster if you forget the loop altogether:
Code:
n=2*No_x+1
iarr(1:n) = (/ (i1-1, i1=1,n) /)

x_x(1:n) = -L/2.0 + dx*iarr(1:n)
x_y(1:n) = x_x(1:n)
x_Z(1:n) = x_x(1:n)

xi_x(1:n) = ( iarr(1:n) - No_k )*2.0*pi/L
xi_y(1:n) = xi_x(1:n)
xi_z(1:n) = xi_x(1:n)
 
  • Like
Likes Ben Wilson
  • #4
gsal said:
Well, for popular algorithms, what Dale said.

Other than that, you need to learn to manipulate arrays en masse, a-la-matlab, whenever possible. This tells the compiler that assignments can be done in any order and without having to carefully traverse one index at a time, or switching from evaluating one array and then another and loop again.

You initialization do-loop above, can be made at least 3 times faster by not having to repeat the calculations; an even faster if you forget the loop altogether:
Code:
n=2*No_x+1
iarr(1:n) = (/ (i1-1, i1=1,n) /)

x_x(1:n) = -L/2.0 + dx*iarr(1:n)
x_y(1:n) = x_x(1:n)
x_Z(1:n) = x_x(1:n)

xi_x(1:n) = ( iarr(1:n) - No_k )*2.0*pi/L
xi_y(1:n) = xi_x(1:n)
xi_z(1:n) = xi_x(1:n)
i'll give this a whirl
 
  • #5
Dale said:
Definitely you should use a standard library like FFTPACK. Unless it is a classroom exercise you should not be rewriting FFT algorithms.
hey I'm a really crummy programmer. Which subroutine do I use and how do I implement it (given I'm doing a 3d complex to real transform)?
 

Related to Efficient 3D Inverse Fourier Transform on FORTRAN Code with Chi Array

What is a 3D Fourier Transform?

A 3D Fourier Transform is a mathematical tool used to transform a function or signal from its original 3-dimensional space to a different space, known as the frequency domain. This transformation allows us to analyze the frequency components of the function or signal, which can provide valuable insights for scientific research and applications.

What is the difference between a 3D Fourier Transform and a 2D Fourier Transform?

The main difference between a 3D Fourier Transform and a 2D Fourier Transform is the number of dimensions involved. A 3D Fourier Transform operates on a three-dimensional function or signal, while a 2D Fourier Transform operates on a two-dimensional function or signal. Additionally, a 3D Fourier Transform results in a 3D frequency spectrum, whereas a 2D Fourier Transform results in a 2D frequency spectrum.

What are the applications of 3D Fourier Transforms?

3D Fourier Transforms have various applications in fields such as physics, engineering, and medical imaging. They are used to analyze the frequency components of 3D signals and images, which can help in understanding the underlying physical processes and identifying anomalies or patterns in the data.

What is the inverse 3D Fourier Transform?

The inverse 3D Fourier Transform is the reverse process of a 3D Fourier Transform. It transforms a 3D function or signal from the frequency domain back to its original space. This is useful for reconstructing images or signals from their frequency components, and is an important tool in signal processing and image reconstruction.

What are the limitations of 3D Fourier Transforms?

One of the main limitations of 3D Fourier Transforms is that they assume the function or signal being transformed is stationary, meaning it does not change over time. This may not be applicable for some real-world signals or systems. Additionally, 3D Fourier Transforms can be computationally expensive for large datasets, which can limit their practical use in certain applications.

Similar threads

  • Programming and Computer Science
Replies
10
Views
2K
  • Introductory Physics Homework Help
Replies
18
Views
1K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
2
Replies
54
Views
4K
Replies
2
Views
5K
  • Introductory Physics Homework Help
Replies
12
Views
6K
  • Introductory Physics Homework Help
Replies
2
Views
17K
  • Introductory Physics Homework Help
Replies
2
Views
4K
  • Programming and Computer Science
Replies
1
Views
2K
Back
Top