WaveSimPP 1.0
A C library for solving the wave equation and reconstructing the wave field
All Classes Namespaces Functions Modules Pages
Benchmarks.cpp
1//
2// Created by Yan Cheng on 12/2/22.
3//
4
5#include <boost/multi_array.hpp>
6#include <boost/array.hpp>
7#include "CustomLibraries/np.hpp"
8#include "CustomLibraries/np_to_matplot.hpp"
9#include "CustomLibraries/wavePlotter.hpp"
10#include <matplot/matplot.h>
11#include <cassert>
12#include <iostream>
13#include <sstream>
14#include <chrono>
15
16#include "CoreAlgorithm/helper_func.hpp"
17#include "CoreAlgorithm/coeff.hpp"
18#include "CoreAlgorithm/source.hpp"
19#include "CoreAlgorithm/computational.hpp"
20#include "CoreAlgorithm/solver.hpp"
21
22void benchmark_solver()
23{
24 int nx = 101;
25 int nz = 101;
26 int nt = 750;
27
28 double dx = 10;
29 double dz = 10;
30 double dt = 0.001;
31
32 double xmin = 0.0;
33 double xmax = nx * dx;
34 double zmin = 0.0;
35 double zmax = nz * dz;
36 double tmin = 0.0;
37 double tmax = nt * dt;
38
39 double f_M = 10.0;
40 double amp = 1e0;
41 double shift = 0.1;
42
43 boost::multi_array<double, 3> f = waveSimCore::ricker(50, 50, f_M, amp, shift, tmin, tmax, nt, nx, nz);
44
45 double r = 150.0;
46 boost::multi_array<double, 2> vel = waveSimCore::get_profile(xmin, xmax, zmin, zmax, nx, nz, r);
47 auto start = std::chrono::high_resolution_clock::now();
48 boost::multi_array<double, 3> u = waveSimCore::wave_solver(vel, dt, dx, dz, nt, nx, nz, f);
49 auto stop = std::chrono::high_resolution_clock::now();
50 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
51 std::cout << "Time taken by the solving function: " << duration.count() << " microseconds" << std::endl;
52}
53
54void benchmark_gradient()
55{
56 int sizex = 100;
57 int sizey = 100;
58 int sizez = 100;
59 int sizet = 10;
60 double dx = 0.1;
61 double dy = 0.1;
62 double dz = 0.1;
63 double dt = 0.1;
64 int axis[4] = {sizex, sizey, sizez, sizet};
65 boost::multi_array<double, 4> nd_array = np::zeros<double>(axis);
66 auto start = std::chrono::high_resolution_clock::now();
67 auto grad = np::gradient(nd_array, {dx, dy, dz, dt});
68 auto stop = std::chrono::high_resolution_clock::now();
69 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
70 std::cout << "Time taken by the gradient function: " << duration.count() << " microseconds" << std::endl;
71}
72
73int main()
74{
75 benchmark_solver();
76 benchmark_gradient();
77}
boost::multi_array< double, 3 > ricker(int i_s, int j_s, double f, double amp, double shift, double tmin, double tmax, int nt, int nx, int nz)
Get the Ricker wavelet as a 3D Array.
Definition: source.hpp:14
boost::multi_array< double, 2 > get_profile(double xmin, double xmax, double zmin, double zmax, int nx, int nz, double r)
Get the velocity profile of the model as a 2D Array.
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)
Definition: solver.hpp:27
::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