openPSTD  2.0
Open source simulation for sound propagation in urban environments
WisdomCache.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: 29-9-15
22 //
23 //
24 // Authors: Omar Richardson, Louis van Harten
25 //
26 //
28 #ifndef OPENPSTD_WISDOMCACHE_H
29 #define OPENPSTD_WISDOMCACHE_H
30 
31 #include <map>
32 #include <math.h>
33 #include <fftw3.h>
34 #include <complex>
35 #include <memory>
36 #include <iostream>
37 #include <Eigen/Dense>
38 
39 namespace OpenPSTD {
40  namespace Kernel {
41 
49  class WisdomCache {
50  public:
51 
55  struct Discretization {
56  Eigen::ArrayXf wave_numbers;
57  Eigen::ArrayXcf complex_factors;
58  Eigen::ArrayXcf pressure_deriv_factors;
59  Eigen::ArrayXcf velocity_deriv_factors;
60  };
61 
65  struct Planset_FFTW {
66  fftwf_plan plan;
67  fftwf_plan plan_inv;
68  };
69 
77  Discretization get_discretization(float dx, int N); //Todo: should we include dx here?
78 
85  Planset_FFTW get_fftw_planset(int fft_length, int fft_batch_size);
86 
90  WisdomCache();
91 
92  std::map<int, Discretization> computed_discretization; // Should be private! public for debugging purposes
93  std::map<std::string, Planset_FFTW> cached_fftw_plans; // Should be private! public for debugging purposes
94 
95  private:
96 
103  Discretization discretize_wave_numbers(float dx, int N); //Todo: Needs a better name
104 
110  Planset_FFTW create_fftw_planset(int fft_length, int fft_batch_size);
111 
119  int match_number(int n);
120  };
121 
122  std::ostream &operator<<(std::ostream &str, WisdomCache const &v);
123  }
124 }
125 
126 #endif //OPENPSTD_WISDOMCACHE_H
This is the general namespace of the OpenPSTD application.
Definition: Boundary.cpp:33
Storage of the accumulated wisdom in the simulation.
Definition: WisdomCache.h:49
Planset_FFTW get_fftw_planset(int fft_length, int fft_batch_size)
Obtain an FFTW plan for the given fft length and batch size.
Definition: WisdomCache.cpp:77
Discretization get_discretization(float dx, int N)
Obtain the discretization for the given grid size and number of grid points.
Definition: WisdomCache.cpp:39
WisdomCache()
Initializer for the cache.
Definition: WisdomCache.cpp:36
Storage of the plans used in the Fast Fourier Transform.
Definition: WisdomCache.h:65
Storage of the wave number discretizations.
Definition: WisdomCache.h:55