]> git.treefish.org Git - seamulator.git/blob - include/sea.h
Added gpl license
[seamulator.git] / include / sea.h
1 /**
2  * Copyright (C) 2016  Alexander Schmidt
3  *
4  * This file is part of Seamulator.
5  *
6  * Seamulator is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Seamulator is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #pragma once
21
22 #include <chrono>
23 #include <complex>
24 #include <random>
25
26 #include <fftw3.h>
27
28 #include "seafwd.h"
29
30 #include "watersurfacefwd.h"
31
32 class Sea
33 {
34  public:
35   Sea(WaterSurfacePtr surface, double windSpeed, double magicConstant);
36   ~Sea();
37   Sea(const Sea&) = delete;
38   Sea& operator=(const Sea&) = delete;
39   void update();
40
41  private:
42   static const double GRAVITATIONAL_CONSTANT;
43
44   WaterSurfacePtr m_surface;
45   double m_windDirection[2];
46   double m_windSpeed;
47   double m_magicConstant;
48   std::random_device m_randomDevice;
49   std::mt19937 m_randomGenerator;
50   std::normal_distribution<> m_normalDistribution;
51   std::vector<std::complex<double>> m_fourierAmplitudes;
52   fftw_complex *m_fftwIn, *m_fftwOut;
53   fftw_plan m_fftwPlan;
54   std::chrono::time_point<std::chrono::system_clock> m_startTime;
55
56   double phillipsSpectrum(double k_x, double k_y) const;
57   std::complex<double>& fourierAmplitudeAt(int n, int m);
58   void generateFourierAmplitudes();
59   double spatialFrequencyForIndex(int n) const;
60   double getRuntime() const;
61 };