From e020fccf58c7e937622bff6aca017e4e8fb82e31 Mon Sep 17 00:00:00 2001 From: Cory Date: Mon, 1 Jan 2024 15:57:40 +0100 Subject: [PATCH] Make changes --- include/WaveSimulation.hpp | 81 +++++++++++++++++++++++++------------- include/utils.hpp | 20 ++++++++++ 2 files changed, 74 insertions(+), 27 deletions(-) diff --git a/include/WaveSimulation.hpp b/include/WaveSimulation.hpp index 7e6a0c2..b1b3b20 100644 --- a/include/WaveSimulation.hpp +++ b/include/WaveSimulation.hpp @@ -18,19 +18,20 @@ #include #include +/** @brief Simulate the evolution of a wave packet in 2 + 1 domensions.*/ class WaveSimulation { -protected: - uint32_t M; - int32_t N; - arma::cx_mat V; - arma::cx_mat U; - arma::sp_cx_mat B; - arma::sp_cx_mat A; - double h; - double dt; - double T; +private: + int32_t M; ///< The size + int32_t N; ///< The size of the inner part + arma::cx_mat V; ///< The potential matrix + arma::cx_mat U; ///< The particle wave matrix + arma::sp_cx_mat B; ///< The B matrix + arma::sp_cx_mat A; ///< The A matrix + double h; ///< The step size in both x and y direction + double dt; ///< The step size int the time direction + double T; ///< The end time - /* @brief Initialize the U matrix using an unormalized Gaussian wave + /** @brief Initialize the U matrix using an unormalized Gaussian wave * packet. * * @param x_c The center of the packet in the x direction. @@ -39,36 +40,41 @@ protected: * @param sigma_y The The initial width in the y direction. * @param p_x The wave packet momentum in the x direction. * @param p_y The wave packet momentum in the y direction. - * **/ + * */ void initialize_U(double x_c, double y_c, double sigma_x, double sigma_y, double p_x, double p_y); - /* @brief Initialize the V matrix. + /** @brief Initialize the V matrix. * * @param thickness The thickness of the wall in the x direction. * @param pos_x The center of the wall in the x direction. * @param ap_sep The separation between each aperture. * @param ap The aperture width. * @param slits The number of slits. - * **/ + * */ void initialize_V(double thickness, double pos_x, double aperture_separation, double aperture, uint32_t slits); - /* @brief Initialize the V matrix with no wall. - * **/ + /** @brief Initialize the V matrix with no wall. + * */ void initialize_V(); - /* @brief Initialize the A matrix according to the Crank-Nicolson method - * **/ + /** @brief Initialize the A matrix according to the Crank-Nicolson method + * */ void initialize_A(); - /* @brief Initialize the B matrix according to the Crank-Nicolson method - * **/ + /** @brief Initialize the B matrix according to the Crank-Nicolson method + * */ void initialize_B(); + /** @brief Write the U matrix in a single line to the file buffer given + * + * @param ofile The file buffer to write to + * */ + void write_U(std::ofstream &ofile); public: - /* @brief Constructor for the WaveSimulation class. + /** @brief Constructor for the WaveSimulation class. * * @param h The step size in the x and y direction. * @param dt The step size in the temporal dimension. @@ -84,13 +90,13 @@ public: * @param ap_sep The separation between each aperture. * @param ap The aperture width. * @param slits The number of slits. - * **/ + * */ WaveSimulation(double h, double dt, double T, double x_c, double y_c, double sigma_x, double sigma_y, double p_x, double p_y, double thickness, double pos_x, double ap_sep, double ap, uint32_t slits); - /* @brief Constructor for the WaveSimulation class with no wall. + /** @brief Constructor for the WaveSimulation class with no wall. * * @param h The step size in the x and y direction. * @param dt The step size in the temporal dimension. @@ -101,16 +107,37 @@ public: * @param sigma_y The The initial width in the y direction. * @param p_x The wave packet momentum in the x direction. * @param p_y The wave packet momentum in the y direction. - * **/ + * */ WaveSimulation(double h, double dt, double T, double x_c, double y_c, double sigma_x, double sigma_y, double p_x, double p_y); + /** @brief Evolve a step forward in time + * */ void step(); - void solve(std::string outfile, bool write_each_step = false); - void solve(std::string outfile, std::vector &steps); + + /** @brief Evolve the wave packet until the time T has been reached and + * write U to file. + * + * @param outfile The name of the file to write to + * @param write_each_step Boolean for deciding to write each step to file + * or just the last step + * */ + void simulate(std::string outfile, bool write_each_step = false); + + /** @brief Evolve the wave packet and write U to fileto file at each time step in + * the vector given. + * + * @param outfile The name of the file to write to + * @param steps What time steps to write U to file. + * */ + void simulate(std::string outfile, std::vector &steps); + + /** @brief Write the deviation of the sum of the probability of U from 1 + * + * @param outfile The name of the file to write to + * to file*/ void probability_deviation(std::string outfile, bool write_each_step = false); - void write_U(std::ofstream &ofile); }; #endif diff --git a/include/utils.hpp b/include/utils.hpp index 83f98a8..24c7004 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -131,6 +131,26 @@ std::string concatpath(const std::string &left, const std::string &right); // A function that prints the structure of a sparse matrix to screen. void print_sp_matrix_structure(const arma::sp_cx_mat &A); + +// A function that splits a string using a delimiter +std::vector split(const std::string &s, char delim); + +// trim from left +std::string <rim(std::string &s, const char *t = " \t\n\r\f\v"); + +// trim from right +std::string &rtrim(std::string &s, const char *t = " \t\n\r\f\v"); + +// trim from left & right +std::string &trim(std::string &s, const char *t = " \t\n\r\f\v"); + +// copying versions + +std::string ltrim_copy(std::string s, const char *t = " \t\n\r\f\v"); + +std::string rtrim_copy(std::string s, const char *t = " \t\n\r\f\v"); + +std::string trim_copy(std::string s, const char *t = " \t\n\r\f\v"); } // namespace utils #endif