5#ifndef CORETESTS_CPP_SOLVER2_HPP
6#define CORETESTS_CPP_SOLVER2_HPP
8#include "CustomLibraries/np.hpp"
27 boost::multi_array<double, 3>
wave_solver(boost::multi_array<double, 2> c,
28 double dt,
double dx,
double dz,
int nt,
int nx,
int nz,
29 boost::multi_array<double, 3> f)
32 const boost::multi_array<double, 2> CX =
np::pow(c * dt / dx, 2.0);
33 const boost::multi_array<double, 2> CZ =
np::pow(c * dt / dz, 2.0);
34 const double Cf =
np::pow(dt, 2.0);
36 int dimensions_1[] = {nt, nx, nz};
37 boost::multi_array<double, 3> u = np::zeros<double>(dimensions_1);
38 int dimensions_4[] = {nx, nz};
39 boost::multi_array<double, 2> u_xx = np::zeros<double>(dimensions_4);
40 int dimensions_5[] = {nx, nz};
41 boost::multi_array<double, 2> u_zz = np::zeros<double>(dimensions_5);
43 for (
int n = 1; n < nt - 1; n++)
45 for (
int i = 1; i < nx - 1; i++)
47 for (
int j = 1; j < nz - 1; j++)
49 u_xx[i][j] = u[n][i + 1][j] + u[n][i - 1][j] - 2.0 * u[n][i][j];
50 u_zz[i][j] = u[n][i][j + 1] + u[n][i][j - 1] - 2.0 * u[n][i][j];
55 for (
int i = 0; i < nx; i++)
57 for (
int j = 0; j < nz; j++)
59 u[n + 1][i][j] = 2.0 * u[n][i][j] + CX[i][j] * u_xx[i][j] + CZ[i][j] * u_zz[i][j] + Cf * f[n][i][j] - u[n - 1][i][j];
64 for (
int i = 0; i < nx; i++)
67 u[n + 1][i][nz - 1] = 0.0;
69 for (
int j = 0; j < nz; j++)
72 u[n + 1][nx - 1][j] = 0.0;
boost::multi_array< double, 3 > wave_solver(boost::multi_array< double, 2 > c, double dt, double dx, double dz, int nt, int nx, int nz, boost::multi_array< double, 3 > f)
::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.