srmainwaring / asv_wave_sim

This package contains plugins that support the simulation of waves and surface vessels in Gazebo.
GNU General Public License v3.0
122 stars 34 forks source link

Waves simulation optimisation - part 5 #89

Closed srmainwaring closed 1 year ago

srmainwaring commented 1 year ago

This PR is part 5 in a series of updates to the wave simulation.

The main change is converting the FFT wave simulation to use the complex to real FFTW planner. This is faster and reduces the storage and copying required in the simulation by a factor of 2.

Details

  1. Add example using the fftw_plan_dft_c2r_1d to EigenFFTW_Test.
  2. Change the FFT wave simulation to use fftw_plan_dft_c2r_2d which has nx * ny/2 + 1 complex inputs and nx * ny real outputs. Re-dimension data as required and update amplitude calculations to fill the arrays correctly.
  3. Move the allocation of the FFT storage into the function to create the plan and initialise post plan creation. This is because FFTW may overwrite the storage when creating the plan (although not for FFTW_ESTIMATE).
  4. The loop populating the amplitudes now ranges to < ny/2+1 in the inner most loop.
  5. Disable the Hermitian tests on the optimised wave sim (as this is now assumed in the c2r FFTW plan).
  6. Temporarily disable the Parseval's Identity test - the loops need to be redesigned to count elements in the re-dimensioned arrays correctly.

Notes

  1. This change has uncovered a couple of issues regarding the FFT derivative calculations that are used in the shading. The derivative amplitudes in the reference version are not Hermitian - possibly because of the Nyquist terms being imaginary, when they must be real. The new calculation forces these terms to be Hermitian. A couple of cross-check tests against the reference version have been disabled until this is resolved.