Make changes
This commit is contained in:
parent
bb602a56c8
commit
e020fccf58
@ -18,19 +18,20 @@
|
|||||||
#include <armadillo>
|
#include <armadillo>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
/** @brief Simulate the evolution of a wave packet in 2 + 1 domensions.*/
|
||||||
class WaveSimulation {
|
class WaveSimulation {
|
||||||
protected:
|
private:
|
||||||
uint32_t M;
|
int32_t M; ///< The size
|
||||||
int32_t N;
|
int32_t N; ///< The size of the inner part
|
||||||
arma::cx_mat V;
|
arma::cx_mat V; ///< The potential matrix
|
||||||
arma::cx_mat U;
|
arma::cx_mat U; ///< The particle wave matrix
|
||||||
arma::sp_cx_mat B;
|
arma::sp_cx_mat B; ///< The B matrix
|
||||||
arma::sp_cx_mat A;
|
arma::sp_cx_mat A; ///< The A matrix
|
||||||
double h;
|
double h; ///< The step size in both x and y direction
|
||||||
double dt;
|
double dt; ///< The step size int the time direction
|
||||||
double T;
|
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.
|
* packet.
|
||||||
*
|
*
|
||||||
* @param x_c The center of the packet in the x direction.
|
* @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 sigma_y The The initial width in the y direction.
|
||||||
* @param p_x The wave packet momentum in the x direction.
|
* @param p_x The wave packet momentum in the x direction.
|
||||||
* @param p_y The wave packet momentum in the y 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,
|
void initialize_U(double x_c, double y_c, double sigma_x, double sigma_y,
|
||||||
double p_x, double p_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 thickness The thickness of the wall in the x direction.
|
||||||
* @param pos_x The center 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_sep The separation between each aperture.
|
||||||
* @param ap The aperture width.
|
* @param ap The aperture width.
|
||||||
* @param slits The number of slits.
|
* @param slits The number of slits.
|
||||||
* **/
|
* */
|
||||||
void initialize_V(double thickness, double pos_x,
|
void initialize_V(double thickness, double pos_x,
|
||||||
double aperture_separation, double aperture,
|
double aperture_separation, double aperture,
|
||||||
uint32_t slits);
|
uint32_t slits);
|
||||||
|
|
||||||
/* @brief Initialize the V matrix with no wall.
|
/** @brief Initialize the V matrix with no wall.
|
||||||
* **/
|
* */
|
||||||
void initialize_V();
|
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();
|
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();
|
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:
|
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 h The step size in the x and y direction.
|
||||||
* @param dt The step size in the temporal dimension.
|
* @param dt The step size in the temporal dimension.
|
||||||
@ -84,13 +90,13 @@ public:
|
|||||||
* @param ap_sep The separation between each aperture.
|
* @param ap_sep The separation between each aperture.
|
||||||
* @param ap The aperture width.
|
* @param ap The aperture width.
|
||||||
* @param slits The number of slits.
|
* @param slits The number of slits.
|
||||||
* **/
|
* */
|
||||||
WaveSimulation(double h, double dt, double T, double x_c, double y_c,
|
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 sigma_x, double sigma_y, double p_x, double p_y,
|
||||||
double thickness, double pos_x, double ap_sep, double ap,
|
double thickness, double pos_x, double ap_sep, double ap,
|
||||||
uint32_t slits);
|
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 h The step size in the x and y direction.
|
||||||
* @param dt The step size in the temporal dimension.
|
* @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 sigma_y The The initial width in the y direction.
|
||||||
* @param p_x The wave packet momentum in the x direction.
|
* @param p_x The wave packet momentum in the x direction.
|
||||||
* @param p_y The wave packet momentum in the y 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,
|
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 sigma_x, double sigma_y, double p_x, double p_y);
|
||||||
|
|
||||||
|
/** @brief Evolve a step forward in time
|
||||||
|
* */
|
||||||
void step();
|
void step();
|
||||||
void solve(std::string outfile, bool write_each_step = false);
|
|
||||||
void solve(std::string outfile, std::vector<double> &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<double> &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,
|
void probability_deviation(std::string outfile,
|
||||||
bool write_each_step = false);
|
bool write_each_step = false);
|
||||||
void write_U(std::ofstream &ofile);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -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.
|
// A function that prints the structure of a sparse matrix to screen.
|
||||||
void print_sp_matrix_structure(const arma::sp_cx_mat &A);
|
void print_sp_matrix_structure(const arma::sp_cx_mat &A);
|
||||||
|
|
||||||
|
// A function that splits a string using a delimiter
|
||||||
|
std::vector<std::string> 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
|
} // namespace utils
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user