WaveSimPP 1.0
A C library for solving the wave equation and reconstructing the wave field
All Classes Namespaces Functions Modules Pages
coeff.hpp
1//
2// Created by Yan Cheng on 11/28/22.
3//
4
5#ifndef WAVESIMC_COEFF_HPP
6#define WAVESIMC_COEFF_HPP
7
8#include "CustomLibraries/np.hpp"
9#include <math.h>
10
16namespace waveSimCore
17{
21 boost::multi_array<double, 2> get_sigma_1(boost::multi_array<double, 1> x, double dx, int nx, int nz,
22 double c_max, int n = 15, double R = 1e-3, double m = 2.0)
23 {
24 boost::multi_array<double, 2> sigma_1(boost::extents[nx][nz]);
25 const double PML_width = n * dx;
26
27 const double sigma_max = -c_max * log(R) * (m + 1.0) / np::pow(PML_width, m + 1.0);
28
29 const double x_0 = np::max(x) - PML_width;
30
31 boost::multi_array<double, 1> polynomial(boost::extents[nx]);
32
33 for (int i = 0; i < nx; i++)
34 {
35 if (x[i] > x_0)
36 {
37 polynomial[i] = sigma_max * np::pow(np::abs(x[i] - x_0), m);
38 polynomial[nx - 1 - i] = polynomial[i];
39 }
40 else
41 {
42 polynomial[i] = 0;
43 }
44 }
45
46 for (int i = 0; i < nx; i++)
47 for (int j = 0; j < nz; j++)
48 sigma_1[i][j] = polynomial[i];
49
50 return sigma_1;
51 }
52
56 boost::multi_array<double, 2> get_sigma_2(boost::multi_array<double, 1> z, double dz, int nx, int nz,
57 double c_max, int n = 10, double R = 1e-3, double m = 2.0)
58 {
59 boost::multi_array<double, 2> sigma_2(boost::extents[nx][nz]);
60 const double PML_width = n * dz;
61 const double sigma_max = -c_max * log(R) * (m + 1.0) / np::pow(PML_width, m + 1.0);
62
63 const double z_0 = np::max(z) - PML_width;
64
65 boost::multi_array<double, 1> polynomial(boost::extents[nz]);
66 for (int j = 0; j < nz; j++)
67 {
68 if (z[j] > z_0)
69 {
70 polynomial[j] = sigma_max * np::pow(np::abs(z[j] - z_0), m);
71 polynomial[nz - 1 - j] = polynomial[j];
72 }
73 else
74 {
75 polynomial[j] = 0;
76 }
77 }
78
79 for (int i = 0; i < nx; i++)
80 for (int j = 0; j < nz; j++)
81 sigma_2[i][j] = polynomial[j];
82
83 return sigma_2;
84 }
85}
86#endif // WAVESIMC_COEFF_HPP
boost::multi_array< double, 2 > get_sigma_2(boost::multi_array< double, 1 > z, double dz, int nx, int nz, double c_max, int n=10, double R=1e-3, double m=2.0)
Definition: coeff.hpp:56
boost::multi_array< double, 2 > get_sigma_1(boost::multi_array< double, 1 > x, double dx, int nx, int nz, double c_max, int n=15, double R=1e-3, double m=2.0)
Definition: coeff.hpp:21
::value constexpr boost::multi_array< T, ND > pow(const boost::multi_array< T, ND > &input_array, const T exponent)
Implements the numpy pow function on multi arrays.
Definition: np.hpp:319
::value constexpr T abs(T input)
Implements the numpy abs function for a scalar.
Definition: np.hpp:463
::value constexpr T max(boost::multi_array< T, ND > const &input_array)
Implements the numpy max function for an n-dimensionl multi array.
Definition: np.hpp:384