Simulating the Schrödinger wave equation using the Crank-Nicolson method in 2+1 dimensions
Simulating the Schrödinger wave equation using the Crank-Nicolson method in 2+1 dimensions
Loading...
Searching...
No Matches
WaveSimulation.hpp
Go to the documentation of this file.
1
12#ifndef __WAVE_SIMULATION__
13#define __WAVE_SIMULATION__
14
15#include "constants.hpp"
16#include "literals.hpp"
17
18#include <armadillo>
19#include <cstdint>
20
23private:
24 int32_t M;
25 int32_t N;
26 arma::cx_mat V;
27 arma::cx_mat U;
28 arma::sp_cx_mat B;
29 arma::sp_cx_mat A;
30 double h;
31 double dt;
32 double T;
33
44 void initialize_U(double x_c, double y_c, double sigma_x, double sigma_y,
45 double p_x, double p_y);
46
55 void initialize_V(double thickness, double pos_x,
56 double aperture_separation, double aperture,
57 uint32_t slits);
58
62
66
70
75 void write_U(std::ofstream &ofile);
76public:
94 WaveSimulation(double h, double dt, double T, double x_c, double y_c,
95 double sigma_x, double sigma_y, double p_x, double p_y,
96 double thickness, double pos_x, double ap_sep, double ap,
97 uint32_t slits);
98
111 WaveSimulation(double h, double dt, double T, double x_c, double y_c,
112 double sigma_x, double sigma_y, double p_x, double p_y);
113
116 void step();
117
125 void simulate(std::string outfile, bool write_each_step = false);
126
133 void simulate(std::string outfile, std::vector<double> &steps);
134
139 void probability_deviation(std::string outfile,
140 bool write_each_step = false);
141};
142
143#endif
Simulate the evolution of a wave packet in 2 + 1 domensions.
arma::cx_mat U
The particle wave matrix.
double dt
The step size int the time direction.
arma::sp_cx_mat A
The A matrix.
void initialize_B()
Initialize the B matrix according to the Crank-Nicolson method.
int32_t M
The size.
int32_t N
The size of the inner part.
arma::sp_cx_mat B
The B matrix.
void initialize_V(double thickness, double pos_x, double aperture_separation, double aperture, uint32_t slits)
Initialize the V matrix.
double h
The step size in both x and y direction.
void initialize_A()
Initialize the A matrix according to the Crank-Nicolson method.
void simulate(std::string outfile, bool write_each_step=false)
Evolve the wave packet until the time T has been reached and write U to file.
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)
Constructor for the WaveSimulation class with no wall.
void initialize_V()
Initialize the V matrix with no wall.
void simulate(std::string outfile, std::vector< double > &steps)
Evolve the wave packet and write U to fileto file at each time step in the vector given.
arma::cx_mat V
The potential matrix.
void write_U(std::ofstream &ofile)
Write the U matrix in a single line to the file buffer given.
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)
Constructor for the WaveSimulation class.
double T
The end time.
void initialize_U(double x_c, double y_c, double sigma_x, double sigma_y, double p_x, double p_y)
Initialize the U matrix using an unormalized Gaussian wave packet.
void probability_deviation(std::string outfile, bool write_each_step=false)
Write the deviation of the sum of the probability of U from 1.
void step()
Evolve a step forward in time.
Library of constants.
Useful literals.