openPSTD  2.0
Open source simulation for sound propagation in urban environments
KernelInterface.h
1 //
2 // Created by michiel on 24-1-2016.
3 //
4 
5 #ifndef OPENPSTD_KERNELINTERFACE_H
6 #define OPENPSTD_KERNELINTERFACE_H
7 
8 #include <string>
9 #include "GeneralTypes.h"
10 #include <QVector2D>
11 #include <QVector3D>
12 #include <Eigen/Core>
13 
14 
15 namespace OpenPSTD {
16  namespace Kernel {
20  enum class CALLBACKSTATUS {
21  STARTING,
22  RUNNING,
23  FINISHED
24  };
25 
30  PSTD_DOMAIN_SIDE_TOP = 1,
31  PSTD_DOMAIN_SIDE_BOTTOM = 2,
32  PSTD_DOMAIN_SIDE_LEFT = 4,
33  PSTD_DOMAIN_SIDE_RIGHT = 8,
34  PSTD_DOMAIN_SIDE_ALL = 8 + 4 + 2 + 1,
35  PSTD_DOMAIN_SIDE_NONE = 0
36  };
37 
44  class PSTDSettings {
45  private:
47  float calctime;
49  float c1;
51  float ampMax;
53  float freqMax;
55  float rho;
57  // Todo: What is this?
58  float patcherror;
60  float tfactRK;
62  float gridSpacing;
64  float band_width;
66  float wave_length;
68  std::vector<float> rk_coefficients;
71  bool spectral_interpolation;
73  int PMLCells;
75  int SaveNth;
77  bool gpu;
79  bool multithread;
81  Eigen::ArrayXf window;
82  public:
83  float GetGridSpacing();
84 
85  void SetGridSpacing(float value);
86 
87  float GetPatchError();
88 
89  void SetPatchError(float value);
90 
91  int GetWindowSize();
92 
93  float GetRenderTime();
94 
95  void SetRenderTime(float value);
96 
97  int GetPMLCells();
98 
99  void SetPMLCells(int value);
100 
101  float GetAttenuationOfPMLCells();
102 
103  void SetAttenuationOfPMLCells(float value);
104 
105  float GetDensityOfAir();
106 
107  void SetDensityOfAir(float value);
108 
109  float GetMaxFrequency();
110 
111  void SetMaxFrequency(float value);
112 
113  float GetSoundSpeed();
114 
115  void SetSoundSpeed(float value);
116 
117  float GetFactRK();
118 
119  void SetFactRK(float value);
120 
121  int GetSaveNth();
122 
123  void SetSaveNth(int value);
124 
125  float GetBandWidth();
126 
127  void SetBandWidth(float value);
128 
129  bool GetSpectralInterpolation();
130 
131  void SetSpectralInterpolation(bool value);
132 
133  float GetWaveLength();
134 
135  void SetWaveLength(float value);
136 
137  float GetTimeStep();
138 
139  bool GetGPUAccel();
140 
141  void SetGPUAccel(bool value);
142 
143  bool GetMultiThread();
144 
145  void SetMultiThread(bool value);
146 
147  std::vector<float> GetRKCoefficients();
148 
149  void SetRKCoefficients(std::vector<float> coef);
150  };
151 
156  public:
158  float Absorption;
160  bool LR;
161  };
162 
166  class DomainConf {
167  public:
168  //todo replace QVector2D
169  QVector2D TopLeft;
170  QVector2D Size;
171  DomainConfEdge T, L, B, R;
172 
173  float GetAbsorption(PSTD_DOMAIN_SIDE side);
174 
175  void SetAbsorption(PSTD_DOMAIN_SIDE sides, float absorption);
176 
177  bool GetLR(PSTD_DOMAIN_SIDE side);
178 
179  void SetLR(PSTD_DOMAIN_SIDE sides, bool LR);
180 
181 
182  };
183 
191  public:
192  PSTDSettings Settings;
193  //todo replace QVector3D
194  std::vector<QVector3D> Speakers;
195  std::vector<QVector3D> Receivers;
196  std::vector<DomainConf> Domains;
197 
203  static std::shared_ptr<PSTDConfiguration> CreateDefaultConf();
204  };
205 
213  public:
220  virtual void Callback(CALLBACKSTATUS status, std::string message, int frame) = 0;
221 
228  virtual void WriteFrame(int frame, int domain, PSTD_FRAME_PTR data) = 0;
229 
236  virtual void WriteSample(int startSample, int receiver, std::vector<float> data) = 0;
237  };
238 
243  public:
249  std::vector<std::vector<int>> DomainMetadata;
259  std::vector<std::vector<int>> DomainPositions;
260  };
261 
266  public:
270  virtual void initialize_kernel(std::shared_ptr<PSTDConfiguration> config) = 0;
271 
277  virtual void run(KernelCallback *callback) = 0;
278 
282  virtual SimulationMetadata get_metadata() = 0;
283  };
284 
285  class PSTDKernelNotConfiguredException : public std::exception {
286  public:
287  const char *what() const noexcept override;
288  };
289  }
290 }
291 
292 
293 #endif //OPENPSTD_KERNELINTERFACE_H
This is the general namespace of the OpenPSTD application.
Definition: Boundary.cpp:33
The kernel API.
Definition: KernelInterface.h:265
A collection of parameters and settings for the simulation.
Definition: KernelInterface.h:44
bool LR
Locally reacting flag.
Definition: KernelInterface.h:160
std::vector< std::vector< int > > DomainPositions
The discretization of the domain positions, in order they were passed to the kernel.
Definition: KernelInterface.h:259
int Framecount
Number of frames generated by the kernel.
Definition: KernelInterface.h:253
PSTD_DOMAIN_SIDE
Enums for the domain boundary representation in the interface.
Definition: KernelInterface.h:29
Interface representation of the domain.
Definition: KernelInterface.h:166
Data not obtained in running openPSTD but necessary for representing the information.
Definition: KernelInterface.h:242
Interface values for boundaries of domains.
Definition: KernelInterface.h:155
Representation of the scene configuration.
Definition: KernelInterface.h:190
std::vector< std::vector< int > > DomainMetadata
The discretization of the domain sizes, in order they were passed to the kernel.
Definition: KernelInterface.h:249
Callback interface for communication with the CLI or the GUI.
Definition: KernelInterface.h:212
const std::vector< float > rk_coefficients
Coefficients for a six stage RK time integration.
Definition: kernel_functions.h:102
CALLBACKSTATUS
The status of the kernel when the callback is called.
Definition: KernelInterface.h:20
float Absorption
Wall absorption coefficient.
Definition: KernelInterface.h:158