openPSTD  2.0
Open source simulation for sound propagation in urban environments
Classes | Typedefs | Enumerations | Functions | Variables
OpenPSTD::Kernel Namespace Reference

The Kernel is responsible for the scientific computions in openPSTD. More...

Classes

class  Boundary
 Models a boundary between two domains. More...
 
class  Domain
 A representation of one rectangular scene unit. More...
 
class  DomainConf
 Interface representation of the domain. More...
 
class  DomainConfEdge
 Interface values for boundaries of domains. More...
 
struct  EdgeParameters
 The impedance parameter and locally reaction switch for a boundary. More...
 
struct  FieldLValues
 The spatial derivatives of the pressure and velocity in x and y direction. More...
 
struct  FieldValues
 The observed state variables. More...
 
class  GPUMultiThreadSolver
 Solver that both utilized multiple cores and the GPU. More...
 
class  GPUSingleThreadSolver
 Solver that performs the computational intensive parts on a GPU. More...
 
class  KernelCallback
 Callback interface for communication with the CLI or the GUI. More...
 
class  KernelInterface
 The kernel API. More...
 
class  MockKernel
 Fake kernel useful for testing the interaction between kernel and CLI or GUI. More...
 
class  MultiThreadSolver
 Solver that exploits the multiple CPU cores of a machine. More...
 
struct  PMLArrays
 The arrays used for attenuating the pressure and velocities at the boundaries of the domain. More...
 
class  Point
 The points of the grid, represented by 2D integer vectors. More...
 
class  PSTDConfiguration
 Representation of the scene configuration. More...
 
class  PSTDKernel
 The API with methods that run the simulation from a PSTDFile. More...
 
class  PSTDKernelNotConfiguredException
 
class  PSTDSettings
 A collection of parameters and settings for the simulation. More...
 
class  Receiver
 Measure pressure values on a fixed location in the scene. More...
 
struct  RhoArray
 Struct with arrays containing the reflection and transmission coefficients of the pressure and the velocity. More...
 
class  Scene
 Collection of the rectangular domains. More...
 
class  SimulationMetadata
 Data not obtained in running openPSTD but necessary for representing the information. More...
 
class  SingleThreadSolver
 Default singlethreaded solver. More...
 
class  Solver
 Component that computes the state variables of the scene for consecutive time steps. More...
 
class  Speaker
 Locations and amplitude of initial sound pressure. More...
 
class  WisdomCache
 Storage of the accumulated wisdom in the simulation. More...
 

Typedefs

using PSTD_FRAME_UNIT = float
 
using PSTD_FRAME = std::vector< PSTD_FRAME_UNIT >
 
using PSTD_FRAME_PTR = std::shared_ptr< PSTD_FRAME >
 

Enumerations

enum  CalcDirection { X = 0, Y = 1 }
 Helper enums - used to distinguish horizontal boundaries from vertical boundaries.
 
enum  CalculationType { PRESSURE, VELOCITY }
 Helper enums - used to distinguish pressure computations from velocity computations.
 
enum  Direction { LEFT, RIGHT, TOP, BOTTOM }
 Enum representing directions among domains.
 
enum  CALLBACKSTATUS { STARTING, RUNNING, FINISHED }
 The status of the kernel when the callback is called.
 
enum  PSTD_DOMAIN_SIDE {
  PSTD_DOMAIN_SIDE_TOP = 1, PSTD_DOMAIN_SIDE_BOTTOM = 2, PSTD_DOMAIN_SIDE_LEFT = 4, PSTD_DOMAIN_SIDE_RIGHT = 8,
  PSTD_DOMAIN_SIDE_ALL = 8 + 4 + 2 + 1, PSTD_DOMAIN_SIDE_NONE = 0
}
 Enums for the domain boundary representation in the interface.
 

Functions

ostream & operator<< (ostream &str, Domain const &v)
 
std::ostream & operator<< (std::ostream &str, Domain const &v)
 
Point operator+ (Point a, Point b)
 
Point operator- (Point a, Point b)
 
std::ostream & operator<< (std::ostream &str, Point const &v)
 String representation for points. More...
 
RhoArray get_rho_array (const float rho1, const float rho_self, const float rho2)
 Computes and return reflection and transmission matrices for pressure and velocity based on density of a domain and 2 opposite neighbours in any direction. More...
 
int next_2_power (float n)
 Computes the smallest power of 2 larger or equal to n if n positive, and 1 otherwise. More...
 
int next_2_power (int n)
 
float get_grid_spacing (PSTDSettings cnf)
 Computes the largest grid spacing possible based on the speed of the medium and the maximum frequency Throws an exception if no compatible grid size can be found. More...
 
Direction get_opposite (Direction direction)
 Return the opposite direction of the provided direction. More...
 
CalcDirection get_orthogonal (CalcDirection direction)
 Get the direction orthogonal to the provided calculation direction. More...
 
CalcDirection direction_to_calc_direction (Direction direction)
 Obtain corresponding Calculation Direction Axis from direction. More...
 
Eigen::ArrayXXf spatderp3 (Eigen::ArrayXXf p1, Eigen::ArrayXXf p2, Eigen::ArrayXXf p3, Eigen::ArrayXcf derfact, RhoArray rho_array, Eigen::ArrayXf window, int wlen, CalculationType ct, CalcDirection direct, fftwf_plan plan, fftwf_plan plan_inv)
 Version of spatderp3 that takes cached plans as input. More...
 
Eigen::ArrayXXf spatderp3 (Eigen::ArrayXXf p1, Eigen::ArrayXXf p2, Eigen::ArrayXXf p3, Eigen::ArrayXcf derfact, RhoArray rho_array, Eigen::ArrayXf window, int wlen, CalculationType ct, CalcDirection direct)
 Function computing the spatial derivatives of the domains. More...
 
Eigen::ArrayXf get_window_coefficients (int window_size, int patch_error)
 Gives a two-sided array of window coefficients for a given window size and patch error. More...
 
void debug (std::string msg)
 
bool is_approx (float a, float b)
 Perform a numerical check whether a approximately equals b. More...
 
template<typename T >
std::vector< T > arange (T start, T stop, T step=1)
 Helper function equivalent to numpy.arange()
 
ostream & operator<< (ostream &str, Scene const &v)
 
std::ostream & operator<< (std::ostream &str, Scene const &v)
 
ostream & operator<< (ostream &str, WisdomCache const &v)
 
std::ostream & operator<< (std::ostream &str, WisdomCache const &v)
 

Variables

const float EPSILON = 1E-5
 Small positive number to facilitate division and other numerical computations.
 
const std::vector< Directionall_directions
 Convenience vectors. More...
 
const std::vector< CalcDirectionall_calc_directions = {CalcDirection::X, CalcDirection::Y}
 
const std::vector< CalculationTypeall_calculation_types
 
const std::vector< float > rk_coefficients
 Coefficients for a six stage RK time integration. More...
 

Detailed Description

The Kernel is responsible for the scientific computions in openPSTD.

The Kernel consists of the functions used in the PSTD method, as well as the representations of the computational domain.

Function Documentation

CalcDirection OpenPSTD::Kernel::direction_to_calc_direction ( Direction  direction)

Obtain corresponding Calculation Direction Axis from direction.

Parameters
directionDirection Enum
Returns
Calculation direction with axis corresponding to direction
float OpenPSTD::Kernel::get_grid_spacing ( PSTDSettings  cnf)

Computes the largest grid spacing possible based on the speed of the medium and the maximum frequency Throws an exception if no compatible grid size can be found.

Parameters
cnfconfig object containing the properties of the geometry
Returns
float corresponding to the grid size
Direction OpenPSTD::Kernel::get_opposite ( Direction  direction)

Return the opposite direction of the provided direction.

Parameters
directionDirection enum
Returns
: opposite direction
CalcDirection OpenPSTD::Kernel::get_orthogonal ( CalcDirection  direction)

Get the direction orthogonal to the provided calculation direction.

Parameters
directionCalculation direction enum
Returns
: Axis orthogonal to calculation direction
RhoArray OpenPSTD::Kernel::get_rho_array ( const float  rho1,
const float  rho_self,
const float  rho2 
)

Computes and return reflection and transmission matrices for pressure and velocity based on density of a domain and 2 opposite neighbours in any direction.

Parameters
rho1density of first neighbour
rho2density of domain
rhodensity of opposite neighbour return struct containing pressure and velocity matrix (4x2)
Eigen::ArrayXf OpenPSTD::Kernel::get_window_coefficients ( int  window_size,
int  patch_error 
)

Gives a two-sided array of window coefficients for a given window size and patch error.

Parameters
window_sizelength of the window
patch_errorgiven patch error
Returns
Eigen::ArrayXf Eigen array of length window_size*2 containing window coefficients
bool OpenPSTD::Kernel::is_approx ( float  a,
float  b 
)

Perform a numerical check whether a approximately equals b.

Returns

See also
EPSILON
Parameters
afloat
bfloat
Returns
True if relative or absolute difference is smaller than the specified EPSILON, False otherwise
int OpenPSTD::Kernel::next_2_power ( float  n)

Computes the smallest power of 2 larger or equal to n if n positive, and 1 otherwise.

Parameters
n
Returns
2^k >= n
Point OpenPSTD::Kernel::operator- ( Point  a,
Point  b 
)

Points with negative entries are well defined.

std::ostream & OpenPSTD::Kernel::operator<< ( std::ostream &  str,
Point const &  v 
)

String representation for points.

Eigen::ArrayXXf OpenPSTD::Kernel::spatderp3 ( Eigen::ArrayXXf  p1,
Eigen::ArrayXXf  p2,
Eigen::ArrayXXf  p3,
Eigen::ArrayXcf  derfact,
RhoArray  rho_array,
Eigen::ArrayXf  window,
int  wlen,
CalculationType  ct,
CalcDirection  direct,
fftwf_plan  plan,
fftwf_plan  plan_inv 
)

Version of spatderp3 that takes cached plans as input.

See also
spatderp3(9)
Eigen::ArrayXXf OpenPSTD::Kernel::spatderp3 ( Eigen::ArrayXXf  p1,
Eigen::ArrayXXf  p2,
Eigen::ArrayXXf  p3,
Eigen::ArrayXcf  derfact,
RhoArray  rho_array,
Eigen::ArrayXf  window,
int  wlen,
CalculationType  ct,
CalcDirection  direct 
)

Function computing the spatial derivatives of the domains.

The domain for which the derivative is being computed is p2. p1 and p3 are its neighbours. *

//TODO (remove the warning on the next line when everything is ported) WARNING - order in Python code: (p2,derfact,Wlength,A,Ns2,N1,N2,Rmatrix,p1,p3,var,direct) order in the C++ code: (p1,p2,p3,derfact,Rmatrix,window,wlen,var_index,direct) var_index=var and N1, N2 and Ns2 are derived from other inputs

Parameters
p1variable matrix subdomain 1
p2variable matrix subdomain 2
p3variable matrix subdomain 3
fft_length
derfactfactor to compute derivative in wavenumber domain
Rmatrixmatrix of reflection coefficients
var_indexvariable index: 0 for pressure, 1,2,3, for respectively x, z and y (in 3rd dimension) velocity
directdirection for computation of derivative
Returns
a 2d array containing the derivative of p2

Variable Documentation

const std::vector<CalculationType> OpenPSTD::Kernel::all_calculation_types
Initial value:
= {CalculationType::PRESSURE,
CalculationType::VELOCITY}
const std::vector<Direction> OpenPSTD::Kernel::all_directions
Initial value:
= {Direction::LEFT, Direction::RIGHT, Direction::TOP,
Direction::BOTTOM}

Convenience vectors.

const std::vector<float> OpenPSTD::Kernel::rk_coefficients
Initial value:
= {8.91421261e-4f, 7555704391e-3f, 4.0919732041e-2f,
1.65919771368e-1f, 5e-1, 1.f}

Coefficients for a six stage RK time integration.