WaveSimPP 1.0
A C library for solving the wave equation and reconstructing the wave field
All Classes Namespaces Functions Modules Pages
helper_func.hpp
1//
2// Created by Yan Cheng on 11/28/22.
3//
4
5#ifndef WAVESIMC_HELPER_FUNC_HPP
6#define WAVESIMC_HELPER_FUNC_HPP
7
8#include "CustomLibraries/np.hpp"
9
15namespace waveSimCore
16{
18 boost::multi_array<double, 2> dfdx(boost::multi_array<double, 2> f, double dx)
19 {
20 std::vector<boost::multi_array<double, 2>> grad_f = np::gradient(f, {dx, dx});
21 return grad_f[0];
22 }
23
25 boost::multi_array<double, 2> dfdz(boost::multi_array<double, 2> f, double dz)
26 {
27 std::vector<boost::multi_array<double, 2>> grad_f = np::gradient(f, {dz, dz});
28 return grad_f[1];
29 }
30
32 boost::multi_array<double, 2> d2fdx2(boost::multi_array<double, 2> f, double dx)
33 {
34 boost::multi_array<double, 2> df = dfdx(f, dx);
35 boost::multi_array<double, 2> df2 = dfdx(df, dx);
36 return df2;
37 }
38
40 boost::multi_array<double, 2> d2fdz2(boost::multi_array<double, 2> f, double dz)
41 {
42 boost::multi_array<double, 2> df = dfdz(f, dz);
43 boost::multi_array<double, 2> df2 = dfdz(df, dz);
44 return df2;
45 }
46
49 boost::multi_array<double, 2> divergence(boost::multi_array<double, 2> f1, boost::multi_array<double, 2> f2,
50 double dx, double dz)
51 {
52 boost::multi_array<double, 2> f_x = dfdx(f1, dx);
53 boost::multi_array<double, 2> f_z = dfdz(f2, dz);
54 boost::multi_array<double, 2> div = f_x + f_z;
55 return div;
56 }
57
58}
59#endif // WAVESIMC_HELPER_FUNC_HPP
boost::multi_array< double, 2 > dfdz(boost::multi_array< double, 2 > f, double dz)
Takes the partial derivative of a 2D matrix f with respect to z.
Definition: helper_func.hpp:25
boost::multi_array< double, 2 > dfdx(boost::multi_array< double, 2 > f, double dx)
Takes the partial derivative of a 2D matrix f with respect to x.
Definition: helper_func.hpp:18
boost::multi_array< double, 2 > d2fdx2(boost::multi_array< double, 2 > f, double dx)
Takes the second partial derivative of a 2D matrix f with respect to x.
Definition: helper_func.hpp:32
boost::multi_array< double, 2 > d2fdz2(boost::multi_array< double, 2 > f, double dz)
Takes the second partial derivative of a 2D matrix f with respect to z.
Definition: helper_func.hpp:40
boost::multi_array< double, 2 > divergence(boost::multi_array< double, 2 > f1, boost::multi_array< double, 2 > f2, double dx, double dz)
Definition: helper_func.hpp:49
::value constexpr std::vector< boost::multi_array< T, ND > > gradient(boost::multi_array< T, ND > inArray, std::initializer_list< T > args)
Definition: np.hpp:90