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
22 class WaveSimulation {
23 private:
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
61 void initialize_V();
62
65 void initialize_A();
66
69 void initialize_B();
70
75 void write_U(std::ofstream &ofile);
76 public:
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
WaveSimulation
Simulate the evolution of a wave packet in 2 + 1 domensions.
Definition: WaveSimulation.hpp:22
WaveSimulation::U
arma::cx_mat U
The particle wave matrix.
Definition: WaveSimulation.hpp:27
WaveSimulation::dt
double dt
The step size int the time direction.
Definition: WaveSimulation.hpp:31
WaveSimulation::A
arma::sp_cx_mat A
The A matrix.
Definition: WaveSimulation.hpp:29
WaveSimulation::initialize_B
void initialize_B()
Initialize the B matrix according to the Crank-Nicolson method.
WaveSimulation::M
int32_t M
The size.
Definition: WaveSimulation.hpp:24
WaveSimulation::N
int32_t N
The size of the inner part.
Definition: WaveSimulation.hpp:25
WaveSimulation::B
arma::sp_cx_mat B
The B matrix.
Definition: WaveSimulation.hpp:28
WaveSimulation::initialize_V
void initialize_V(double thickness, double pos_x, double aperture_separation, double aperture, uint32_t slits)
Initialize the V matrix.
WaveSimulation::h
double h
The step size in both x and y direction.
Definition: WaveSimulation.hpp:30
WaveSimulation::initialize_A
void initialize_A()
Initialize the A matrix according to the Crank-Nicolson method.
WaveSimulation::simulate
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::WaveSimulation
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.
WaveSimulation::initialize_V
void initialize_V()
Initialize the V matrix with no wall.
WaveSimulation::simulate
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.
WaveSimulation::V
arma::cx_mat V
The potential matrix.
Definition: WaveSimulation.hpp:26
WaveSimulation::write_U
void write_U(std::ofstream &ofile)
Write the U matrix in a single line to the file buffer given.
WaveSimulation::WaveSimulation
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.
WaveSimulation::T
double T
The end time.
Definition: WaveSimulation.hpp:32
WaveSimulation::initialize_U
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.
WaveSimulation::probability_deviation
void probability_deviation(std::string outfile, bool write_each_step=false)
Write the deviation of the sum of the probability of U from 1.
WaveSimulation::step
void step()
Evolve a step forward in time.
constants.hpp
Library of constants.
literals.hpp
Useful literals.