openPSTD  2.0
Open source simulation for sound propagation in urban environments
Domain.h
1 // This file is part of openPSTD. //
3 // //
4 // openPSTD is free software: you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation, either version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // openPSTD is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with openPSTD. If not, see <http://www.gnu.org/licenses/>. //
16 // //
18 
20 //
21 // Date:
22 // 16-9-2015
23 //
24 // Authors:
25 // Louis van Harten, 0mar Richardson
26 //
27 // Purpose:
28 // Class containing a numerical representation of a domain as part of
29 // the Scene. Stores computed values for velocity/pressure.
30 //
32 
33 #ifndef OPENPSTD_KERNELDOMAIN_H
34 #define OPENPSTD_KERNELDOMAIN_H
35 
36 #include <Eigen/Dense>
37 #include <map>
38 #include <string>
39 #include <set>
40 #include <numeric>
41 #include <algorithm>
42 #include <iterator>
43 #include "kernel_functions.h"
44 #include "Geometry.h"
45 #include "../KernelInterface.h"
46 #include "Geometry.h"
47 #include "WisdomCache.h"
48 
49 namespace OpenPSTD {
50  namespace Kernel {
51 
57  struct FieldValues {
58  Eigen::ArrayXXf u0; //TODO (do we want to do this?): change float to T, derive a float and a double class
59  Eigen::ArrayXXf w0;
60  Eigen::ArrayXXf p0;
61  Eigen::ArrayXXf px0;
62  Eigen::ArrayXXf py0;
63  };
64 
68  struct FieldLValues { // Todo (0mar): Rename, these are spatial derivatives
69  Eigen::ArrayXXf Lpx;
70  Eigen::ArrayXXf Lpy;
71  Eigen::ArrayXXf Lvx;
72  Eigen::ArrayXXf Lvy;
73 
74  };
75 
82  struct PMLArrays {
83  Eigen::ArrayXXf px;
84  Eigen::ArrayXXf py;
85  Eigen::ArrayXXf u;
86  Eigen::ArrayXXf w;
87  };
88 
92  struct EdgeParameters {
93  bool locally_reacting;
94  float alpha;
95  };
96 
103  class Domain : public std::enable_shared_from_this<Domain> {
104  public:
106  std::shared_ptr<PSTDSettings> settings;
108  int id;
110  float alpha;
111  // Todo: What is the alpha coefficient?
113  float impedance;
115  float rho;
117  std::map<Direction, EdgeParameters> edge_param_map;
119  std::map<CalcDirection, bool> should_update;
127  bool is_pml;
129  //Todo: What is this local?
130  bool local;
138  std::shared_ptr<WisdomCache> wnd;
142  std::vector<std::shared_ptr<Domain>> pml_for_domain_list;
143 
144  private:
145  std::vector<std::shared_ptr<Domain>> left;
146  std::vector<std::shared_ptr<Domain>> right;
147  std::vector<std::shared_ptr<Domain>> top;
148  std::vector<std::shared_ptr<Domain>> bottom;
149  int num_neighbour_domains; // including pml_domains;
150  int num_pml_neighbour_domains;
151  bool has_horizontal_attenuation, is_corner_domain;
152  std::vector<bool> needs_reversed_attenuation;
153  PMLArrays pml_arrays;
154  public:
155 
167  Domain(std::shared_ptr<PSTDSettings> settings, int id, const float alpha,
168  Point top_left, Point size, const bool is_pml,
169  std::shared_ptr<WisdomCache> wnd, std::map<Direction, EdgeParameters> edge_param_map,
170  const std::shared_ptr<Domain> pml_for_domain);
171 
178  Domain(std::shared_ptr<PSTDSettings> settings, int id, const float alpha,
179  std::vector<float> top_left_vector, std::vector<float> size_vector, const bool is_pml,
180  std::shared_ptr<WisdomCache> wnd, std::map<Direction, EdgeParameters> edge_param_map,
181  const std::shared_ptr<Domain> pml_for_domain);
182 
187  void push_values();
188 
192  void clear_matrices();
193 
197  void compute_pml_matrices();
198 
202  void apply_pml_matrices();
203 
209  int number_of_neighbours(bool count_pml);
210 
216  bool contains_point(Point point);
217 
224  bool contains_location(std::vector<float> location);
225 
231  std::vector<std::shared_ptr<Domain>> get_neighbours_at(Direction direction);
232 
239  std::shared_ptr<Domain> get_neighbour_at(Direction direction, std::vector<float> location);
240 
241 
247  void add_neighbour_at(std::shared_ptr<Domain> domain, Direction direction);
248 
253  bool is_neighbour_of(std::shared_ptr<Domain> domain);
254 
258  bool is_pml_for(std::shared_ptr<Domain> domain);
259 
263  bool is_rigid();
264 
270  std::vector<int> get_range(CalcDirection cd);
271 
278  std::vector<int> get_intersection_with(std::shared_ptr<Domain> other_domain, Direction direction);
279 
287  Eigen::ArrayXXf calc(CalcDirection cd, CalculationType ct, Eigen::ArrayXcf dest);
288 
295  void calc(CalcDirection cd, CalculationType ct);
296 
301  void post_initialization();
302 
308  Eigen::ArrayXXi get_vacant_range(Direction direction);
309 
317  Eigen::ArrayXXf extended_zeros(int x, int y, int z = 0);
318 
319  private:
320  void initialize_domain(std::shared_ptr<PSTDSettings> settings, int id, const float alpha,
321  Point top_left, Point size, const bool is_pml,
322  std::shared_ptr<WisdomCache> wnd,
323  std::map<Direction, EdgeParameters> edge_param_map,
324  const std::shared_ptr<Domain> pml_for_domain);
325 
326  void clear_fields();
327 
328  void clear_pml_arrays();
329 
330  void find_update_directions();
331 
332  void compute_number_of_neighbours();
333 
334  int get_num_pmls_in_direction(Direction direction);
335 
336  void create_attenuation_array(CalcDirection calc_dir, bool ascending, Eigen::ArrayXXf &pml_pressure,
337  Eigen::ArrayXXf &pml_velocity);
338  };
339 
340  std::ostream &operator<<(std::ostream &str, Domain const &v);
341  }
342 }
343 
344 #endif //OPENPSTD_KERNELDOMAIN_H
This is the general namespace of the OpenPSTD application.
Definition: Boundary.cpp:33
float impedance
Impedance of the boundary.
Definition: Domain.h:113
int id
Domain identifier. Does not necessarily correspond to the GUI and CLI ids; no need for that...
Definition: Domain.h:108
FieldValues current_values
Collection of state variables in this time step (not thread-safe)
Definition: Domain.h:132
Point top_left
Start of the domain (top left)
Definition: Domain.h:121
The arrays used for attenuating the pressure and velocities at the boundaries of the domain...
Definition: Domain.h:82
Point bottom_right
End of the domain (bottom right)
Definition: Domain.h:123
float rho
Density of the domain interior. Defaults to air.
Definition: Domain.h:115
bool is_pml
Whether the domain is a perfectly matched layer.
Definition: Domain.h:127
CalcDirection
Helper enums - used to distinguish horizontal boundaries from vertical boundaries.
Definition: kernel_functions.h:71
FieldLValues l_values
Derivative approximations of the state variables.
Definition: Domain.h:136
The observed state variables.
Definition: Domain.h:57
Point size
Domain size.
Definition: Domain.h:125
The points of the grid, represented by 2D integer vectors.
Definition: Geometry.h:43
std::map< CalcDirection, bool > should_update
Map with update directions.
Definition: Domain.h:119
bool local
Another parameter (PML-related)
Definition: Domain.h:130
float alpha
Some coefficient...
Definition: Domain.h:110
std::shared_ptr< WisdomCache > wnd
Pointer to WisdomCache object.
Definition: Domain.h:138
std::vector< std::shared_ptr< Domain > > pml_for_domain_list
List of domains that this domain functions for as a PML.
Definition: Domain.h:142
std::map< Direction, EdgeParameters > edge_param_map
Map with boundary coefficients.
Definition: Domain.h:117
std::shared_ptr< PSTDSettings > settings
Settings from the PSTDKernel.
Definition: Domain.h:106
The spatial derivatives of the pressure and velocity in x and y direction.
Definition: Domain.h:68
Direction
Enum representing directions among domains.
Definition: kernel_functions.h:85
bool is_secondary_pml
Whether the domain is a PML domain for other PML domains.
Definition: Domain.h:140
A representation of one rectangular scene unit.
Definition: Domain.h:103
The impedance parameter and locally reaction switch for a boundary.
Definition: Domain.h:92
FieldValues previous_values
Collection of state variables in previous time step (should be thread-safe)
Definition: Domain.h:134
CalculationType
Helper enums - used to distinguish pressure computations from velocity computations.
Definition: kernel_functions.h:78