WaveSimPP 1.0
A C library for solving the wave equation and reconstructing the wave field
All Classes Namespaces Functions Modules Pages
Namespaces | Classes | Functions
WavePlotter

Namespaces

namespace  wavePlotter
 Custom plotter class.
 

Classes

class  wavePlotter::Plotter
 This class is used to plot the wave field TODO: make it multithreaded. More...
 

Functions

 wavePlotter::Plotter::Plotter (const boost::multi_array< double, 3 > &u, const matplot::vector_2d &Xp, const matplot::vector_2d &Zp, int num_levels, int nt)
 Constructor.
 
void wavePlotter::Plotter::renderFrame (int index)
 Renders a frame of the wave field to a image on disk.
 
void wavePlotter::Plotter::renderAllFrames (int begin_frame_index, int end_frame_index)
 Renders all frames of the wave field to form an animation to be saved on disk.
 
void wavePlotter::Plotter::animate (std::string output_file_name, int begin_frame_index, int end_frame_index, int frame_rate)
 Renders a complete video animation of the wave field.
 
void wavePlotter::Plotter::exportFrame (int index)
 Export a frame of the wave field to a .csv format for external use.
 
void wavePlotter::Plotter::exportAllFrames (int begin_frame_index, int end_frame_index)
 Export all frames of the wave field to a .csv format for external use.
 
void wavePlotter::Plotter::setSaveDirectory (std::string save_directory)
 Set the save directory for the rendered frames.
 

Detailed Description

Function Documentation

◆ animate()

void wavePlotter::Plotter::animate ( std::string  output_file_name,
int  begin_frame_index,
int  end_frame_index,
int  frame_rate 
)
inline

Renders a complete video animation of the wave field.

Definition at line 56 of file wavePlotter.hpp.

57 {
58 renderAllFrames(begin_frame_index, end_frame_index);
59 std::string ffmpeg_render_command = "ffmpeg -framerate " + std::to_string(frame_rate) + " -pattern_type glob -i '" + save_directory + "/*.png' -c:v libx264 -pix_fmt yuv420p " + output_file_name;
60 std::system(ffmpeg_render_command.c_str());
61 }
void renderAllFrames(int begin_frame_index, int end_frame_index)
Renders all frames of the wave field to form an animation to be saved on disk.
Definition: wavePlotter.hpp:47

◆ exportAllFrames()

void wavePlotter::Plotter::exportAllFrames ( int  begin_frame_index,
int  end_frame_index 
)
inline

Export all frames of the wave field to a .csv format for external use.

Definition at line 82 of file wavePlotter.hpp.

83 {
84 for (int i = begin_frame_index; i < end_frame_index; i++)
85 {
86 exportFrame(i);
87 }
88 }
void exportFrame(int index)
Export a frame of the wave field to a .csv format for external use.
Definition: wavePlotter.hpp:63

◆ exportFrame()

void wavePlotter::Plotter::exportFrame ( int  index)
inline

Export a frame of the wave field to a .csv format for external use.

Definition at line 63 of file wavePlotter.hpp.

64 {
65 matplot::vector_2d Up = np::convert_to_matplot(this->u[index]);
66 std::ofstream outfile;
67 outfile.open(save_directory + "/frame_" + format_num(index) + ".csv");
68 for (std::size_t i = 0; i < Up.size(); i++)
69 {
70 for (std::size_t j = 0; j < Up[i].size(); j++)
71 {
72 outfile << Up[i][j];
73 if (j != Up[i].size() - 1)
74 outfile << ",";
75 }
76 outfile << "\n";
77 }
78 outfile.close();
79 }
matplot::vector_2d convert_to_matplot(const boost::multi_array< double, 2 > &arr)
Convert a 2D boost::multi_array to a matplot::vector_2d.

◆ Plotter()

wavePlotter::Plotter::Plotter ( const boost::multi_array< double, 3 > &  u,
const matplot::vector_2d &  Xp,
const matplot::vector_2d &  Zp,
int  num_levels,
int  nt 
)
inline

Constructor.

Definition at line 25 of file wavePlotter.hpp.

26 {
27 this->u.resize(boost::extents[u.shape()[0]][u.shape()[1]][u.shape()[2]]);
28 this->u = u;
29 this->Xp = Xp;
30 this->Zp = Zp;
31 this->num_levels = num_levels;
32 this->nt = nt;
33 double min_u = np::min(u);
34 double max_u = np::max(u);
35 std::cout << "min_u = " << min_u << " max_u = " << max_u << "\n";
36 this->levels = matplot::linspace(min_u, max_u, num_levels);
37 }
::value constexpr T min(boost::multi_array< T, ND > const &input_array)
Implements the numpy min function for an n-dimensionl multi array.
Definition: np.hpp:419
::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

◆ renderAllFrames()

void wavePlotter::Plotter::renderAllFrames ( int  begin_frame_index,
int  end_frame_index 
)
inline

Renders all frames of the wave field to form an animation to be saved on disk.

Definition at line 47 of file wavePlotter.hpp.

48 {
49 for (int i = begin_frame_index; i < end_frame_index; i++)
50 {
51 renderFrame(i);
52 }
53 }
void renderFrame(int index)
Renders a frame of the wave field to a image on disk.
Definition: wavePlotter.hpp:39

◆ renderFrame()

void wavePlotter::Plotter::renderFrame ( int  index)
inline

Renders a frame of the wave field to a image on disk.

Definition at line 39 of file wavePlotter.hpp.

40 {
41 matplot::vector_2d Up = np::convert_to_matplot(this->u[index]);
42 matplot::contourf(this->Xp, this->Zp, Up, this->levels);
43 matplot::save(save_directory + "/contourf_" + format_num(index) + ".png");
44 }

◆ setSaveDirectory()

void wavePlotter::Plotter::setSaveDirectory ( std::string  save_directory)
inline

Set the save directory for the rendered frames.

Definition at line 91 of file wavePlotter.hpp.

92 {
93 this->save_directory = save_directory;
94 }