Skip to content

Commit

Permalink
Waves simulation optimisation - part 3 (#87)
Browse files Browse the repository at this point in the history
* Waves: optimise current amplitude calculation for FFT wave simulation

- Investigate optimisation options for the current amplitude calculation.
- vectorised assignment to fft worlspace is not faster than a single loop.
- pre-calculate the fourier amplitude coefficients (reduce index lookup) - marginal gain?

Signed-off-by: Rhys Mainwaring <[email protected]>

* Waves: label indices in ocean tile to distinguish between vertex indices and wave indices

- Vertex array index: v_idx_cm: v - vertex, cm - column major
- Wave array index: w_idx_cm: v - vertex, cm - column major
- Wave array index: w_idx_rm: v - vertex, rm - row major

Signed-off-by: Rhys Mainwaring <[email protected]>

* CI: only run macOS workflow on PR

Signed-off-by: Rhys Mainwaring <[email protected]>

* Waves: rename FFT wave simulation class

Signed-off-by: Rhys Mainwaring <[email protected]>

* Waves: duplicate FFT wave simulation class to factor out reference version

Signed-off-by: Rhys Mainwaring <[email protected]>

* Waves: duplicate FFT wave simulation class to factor out reference version

- Complete split of reference implementation into separate class.
- Remove unused code from the separated FFT wave simulation classes.

Signed-off-by: Rhys Mainwaring <[email protected]>

* Waves: remove commented code

- Remove code referring to reference versions of the spectrum calculations.

Signed-off-by: Rhys Mainwaring <[email protected]>

* Waves: add performance checks for spectrum and FFT amplitude calculations

- Initial performance tests. Contain debugging and timing info.
- Eigen component-wise array versions are not performant...

Signed-off-by: Rhys Mainwaring <[email protected]>

* Waves: replace slow array versions of spectrum calcs.

- Eigen component-wise array versions are not performant - replace with calls using std::transform on unary / binary versions.

Signed-off-by: Rhys Mainwaring <[email protected]>

* Waves: refactor wave simulation and spectrum test names

- Functions are not truly vectorised - use Eigen array type to label tests instead.

Signed-off-by: Rhys Mainwaring <[email protected]>

* Waves: satisfy Eigen check that range iterators in STL algorithms are from the same expression.

Signed-off-by: Rhys Mainwaring <[email protected]>
  • Loading branch information
srmainwaring authored Nov 23, 2022
1 parent ce5dac9 commit e5617dd
Show file tree
Hide file tree
Showing 22 changed files with 1,987 additions and 929 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/macos-monterey-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: macOS Monterey CI

on: [push, pull_request]
on: [pull_request]

jobs:
macos-monterey-ci:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#ifndef GZ_WAVES_WAVESIMULATIONFFT2_HH_
#define GZ_WAVES_WAVESIMULATIONFFT2_HH_
#ifndef GZ_WAVES_WAVESIMULATIONFFT_HH_
#define GZ_WAVES_WAVESIMULATIONFFT_HH_

#include <memory>

Expand All @@ -26,14 +26,14 @@ namespace gz
{
namespace waves
{
class WaveSimulationFFT2Impl;
class WaveSimulationFFTImpl;

class WaveSimulationFFT2 : public WaveSimulation
class WaveSimulationFFT : public WaveSimulation
{
public:
virtual ~WaveSimulationFFT2();
virtual ~WaveSimulationFFT();

WaveSimulationFFT2(double lx, double ly, int nx, int ny);
WaveSimulationFFT(double lx, double ly, int nx, int ny);

void SetUseVectorised(bool value);

Expand Down Expand Up @@ -71,7 +71,7 @@ namespace waves
Eigen::Ref<Eigen::MatrixXd> dsxdy) override;

private:
std::unique_ptr<WaveSimulationFFT2Impl> impl_;
std::unique_ptr<WaveSimulationFFTImpl> impl_;
};
}
}
Expand Down
76 changes: 76 additions & 0 deletions gz-waves/include/gz/waves/WaveSimulationFFTRef.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (C) 2022 Rhys Mainwaring
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#ifndef GZ_WAVES_WAVESIMULATIONFFT_HH_
#define GZ_WAVES_WAVESIMULATIONFFT_HH_

#include <memory>

#include "WaveSimulation.hh"

using Eigen::MatrixXd;

namespace gz
{
namespace waves
{
class WaveSimulationFFTRefImpl;

class WaveSimulationFFTRef : public WaveSimulation
{
public:
virtual ~WaveSimulationFFTRef();

WaveSimulationFFTRef(double lx, double ly, int nx, int ny);

void SetLambda(double lambda);

virtual void SetWindVelocity(double ux, double uy) override;

virtual void SetTime(double value) override;

virtual void ComputeElevation(
Eigen::Ref<Eigen::MatrixXd> h) override;

virtual void ComputeElevationDerivatives(
Eigen::Ref<Eigen::MatrixXd> dhdx,
Eigen::Ref<Eigen::MatrixXd> dhdy) override;

virtual void ComputeDisplacements(
Eigen::Ref<Eigen::MatrixXd> sx,
Eigen::Ref<Eigen::MatrixXd> sy) override;

virtual void ComputeDisplacementsDerivatives(
Eigen::Ref<Eigen::MatrixXd> dsxdx,
Eigen::Ref<Eigen::MatrixXd> dsydy,
Eigen::Ref<Eigen::MatrixXd> dsxdy) override;

virtual void ComputeDisplacementsAndDerivatives(
Eigen::Ref<Eigen::MatrixXd> h,
Eigen::Ref<Eigen::MatrixXd> sx,
Eigen::Ref<Eigen::MatrixXd> sy,
Eigen::Ref<Eigen::MatrixXd> dhdx,
Eigen::Ref<Eigen::MatrixXd> dhdy,
Eigen::Ref<Eigen::MatrixXd> dsxdx,
Eigen::Ref<Eigen::MatrixXd> dsydy,
Eigen::Ref<Eigen::MatrixXd> dsxdy) override;

private:
std::unique_ptr<WaveSimulationFFTRefImpl> impl_;
};
}
}

#endif
5 changes: 3 additions & 2 deletions gz-waves/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ set(sources
WavefieldSampler.cc
WaveParameters.cc
WaveSimulation.cc
WaveSimulationFFT2.cc
WaveSimulationFFT.cc
WaveSimulationFFTRef.cc
WaveSimulationSinusoid.cc
WaveSimulationTrochoid.cc
WaveSpectrum.cc
Expand All @@ -42,7 +43,7 @@ set(gtest_sources
TriangulatedGrid_TEST.cc
Wavefield_TEST.cc
WaveSimulation_TEST.cc
WaveSimulationFFT2_TEST.cc
WaveSimulationFFT_TEST.cc
WaveSpectrum_TEST.cc
WaveSpreadingFunction_TEST.cc
)
Expand Down
Loading

0 comments on commit e5617dd

Please sign in to comment.