Compare commits
No commits in common. "b0ce8ef73057db0c57bb48af011ff8a59ce23a43" and "4458ff2d126114cfb1f2193d5d889b9d198bde20" have entirely different histories.
b0ce8ef730
...
4458ff2d12
2
.clangd
2
.clangd
@ -1,2 +1,2 @@
|
||||
CompileFlags:
|
||||
Add: [-I../include, -std=c++11]
|
||||
Add: [-I../include]
|
||||
|
||||
45
Makefile
45
Makefile
@ -1,5 +1,5 @@
|
||||
# The compiler
|
||||
CC=g++
|
||||
CC=mpicxx
|
||||
|
||||
# Flags
|
||||
CFLAGS=-Wall -larmadillo -std=c++11 -O3 -fopenmp
|
||||
@ -26,26 +26,19 @@ LATEXDIR=./latex
|
||||
|
||||
# Source directories
|
||||
SRC=./src
|
||||
LIB=./lib
|
||||
INCLUDE=./include
|
||||
|
||||
# Source files and object file locations
|
||||
#SRCFILES=utils.cpp testlib.cpp
|
||||
#SRCS=$(addprefix $(SRC)/, $(SRCS))
|
||||
#BINOBJS=$(addprefix $(BINOBJDIR)/, $(SRCFILES:.cpp=.o))
|
||||
#PROFOBJS=$(addprefix $(PROFOBJDIR)/, $(SRCFILES:.cpp=.o))
|
||||
#DEBUGOBJS=$(addprefix $(DEBUGOBJDIR)/, $(SRCFILES:.cpp=.o))
|
||||
|
||||
# Lib files
|
||||
LIBSRCS=$(notdir $(shell find $(LIB) -type f))
|
||||
LIBBINOBJS=$(addprefix $(BINOBJDIR)/, $(LIBSRCS:.cpp=.o))
|
||||
LIBPROFOBJS=$(addprefix $(PROFOBJDIR)/, $(LIBSRCS:.cpp=.o))
|
||||
LIBDEBUGOBJS=$(addprefix $(DEBUGOBJDIR)/, $(LIBSRCS:.cpp=.o))
|
||||
SRCFILES=utils.cpp testlib.cpp
|
||||
SRCS=$(addprefix $(SRC)/, $(SRCS))
|
||||
BINOBJS=$(addprefix $(BINOBJDIR)/, $(SRCFILES:.cpp=.o))
|
||||
PROFOBJS=$(addprefix $(PROFOBJDIR)/, $(SRCFILES:.cpp=.o))
|
||||
DEBUGOBJS=$(addprefix $(DEBUGOBJDIR)/, $(SRCFILES:.cpp=.o))
|
||||
|
||||
# Location for Binaries
|
||||
EXEC=$(basename $(notdir $(shell find $(SRC) -type f)))
|
||||
EXEC=main test_suite
|
||||
BINS=$(addprefix $(BINDIR)/, $(EXEC))
|
||||
PROFBINS=$(addprefix $(PROFDIR)/, $(EXEC))
|
||||
PROFBINS=$(PROFDIR)/phase_transition_mpi
|
||||
DEBUGBINS=$(addprefix $(DEBUGDIR)/, $(EXEC))
|
||||
|
||||
# List phony targets
|
||||
@ -63,24 +56,23 @@ latex:
|
||||
$(MAKE) -C $(LATEXDIR)
|
||||
|
||||
# Rule for binaries
|
||||
$(BINDIR)/%: $(BINOBJDIR)/%.o $(LIBBINOBJS)
|
||||
$(BINDIR)/%: $(BINOBJDIR)/%.o $(BINOBJS)
|
||||
$(MKDIR) $(BINDIR)
|
||||
$(CC) $^ -o $@ $(CFLAGS) -I$(INCLUDE)
|
||||
|
||||
# Rule for profiling binaries
|
||||
$(PROFDIR)/%: $(PROFOBJDIR)/%.o $(LIBPROFOBJS)
|
||||
$(PROFDIR)/%: $(PROFOBJDIR)/%.o $(PROFOBJS)
|
||||
$(MKDIR) $(PROFDIR)
|
||||
$(INSTRUMENT) $(CC) $^ -o $@ $(CFLAGS) $(PROFFLAGS) -I$(INCLUDE)
|
||||
|
||||
# Rule for debug binaries
|
||||
$(DEBUGDIR)/%: $(DEBUGOBJDIR)/%.o $(LIBDEBUGOBJS)
|
||||
$(DEBUGDIR)/%: $(DEBUGOBJDIR)/%.o $(DEBUGOBJS)
|
||||
$(MKDIR) $(DEBUGDIR)
|
||||
$(CC) $^ -o $@ $(CFLAGS) $(DBGFLAGS) -I$(INCLUDE)
|
||||
|
||||
# Rule for object files
|
||||
$(BINOBJDIR)/%.o: $(SRC)/%.cpp
|
||||
$(MKDIR) $(BINOBJDIR)
|
||||
echo $(LIBBINOBJS)
|
||||
$(CC) -c $^ -o $@ $(CFLAGS) -I$(INCLUDE)
|
||||
|
||||
# Rule for instrumented object files
|
||||
@ -93,21 +85,6 @@ $(DEBUGOBJDIR)/%.o: $(SRC)/%.cpp
|
||||
$(MKDIR) $(DEBUGOBJDIR)
|
||||
$(CC) -c $^ -o $@ $(CFLAGS) $(DBGFLAGS) -I$(INCLUDE)
|
||||
|
||||
# Rule for object files
|
||||
$(BINOBJDIR)/%.o: $(LIB)/%.cpp
|
||||
$(MKDIR) $(BINOBJDIR)
|
||||
$(CC) -c $^ -o $@ $(CFLAGS) -I$(INCLUDE)
|
||||
|
||||
# Rule for instrumented object files
|
||||
$(PROFOBJDIR)/%.o: $(LIB)/%.cpp
|
||||
$(MKDIR) $(PROFOBJDIR)
|
||||
$(INSTRUMENT) $(CC) -c $^ -o $@ $(CFLAGS) $(PROFFLAGS) -I$(INCLUDE)
|
||||
|
||||
# Rule for debug object files
|
||||
$(DEBUGOBJDIR)/%.o: $(LIB)/%.cpp
|
||||
$(MKDIR) $(DEBUGOBJDIR)
|
||||
$(CC) -c $^ -o $@ $(CFLAGS) $(DBGFLAGS) -I$(INCLUDE)
|
||||
|
||||
# Cleaning
|
||||
clean: objclean binclean latexclean
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -1,320 +0,0 @@
|
||||
0,1,1
|
||||
1,1,1
|
||||
2,1,1
|
||||
3,1,1
|
||||
4,1,1
|
||||
5,1,1
|
||||
6,1,1
|
||||
7,1,1
|
||||
8,1,1
|
||||
9,1,1
|
||||
10,1,1
|
||||
11,1,1
|
||||
12,1,1
|
||||
13,1,1
|
||||
14,1,1
|
||||
15,1,1
|
||||
16,1,1
|
||||
17,1,1
|
||||
18,1,1
|
||||
19,1,1
|
||||
20,1,1
|
||||
21,1,1
|
||||
22,1,1
|
||||
23,1,1
|
||||
24,1,1
|
||||
25,1,1
|
||||
26,1,1
|
||||
27,1,1
|
||||
28,1,1
|
||||
29,1,1
|
||||
30,1,1
|
||||
31,1,1
|
||||
32,1,1
|
||||
33,1,1
|
||||
34,1,1
|
||||
35,1,1
|
||||
36,1,1
|
||||
37,1,1
|
||||
38,1,1
|
||||
39,1,1
|
||||
40,1,1
|
||||
41,1,1
|
||||
42,1,1
|
||||
43,1,1
|
||||
44,1,1
|
||||
45,1,1
|
||||
46,1,1
|
||||
47,1,1
|
||||
48,1,1
|
||||
49,1,1
|
||||
50,1,1
|
||||
51,1,1
|
||||
52,1,1
|
||||
53,1,1
|
||||
54,1,1
|
||||
55,1,1
|
||||
56,1,1
|
||||
57,1,1
|
||||
58,1,1
|
||||
59,1,1
|
||||
60,1,1
|
||||
61,1,1
|
||||
62,1,1
|
||||
63,1,1
|
||||
64,1,1
|
||||
65,1,1
|
||||
66,1,1
|
||||
67,1,1
|
||||
68,1,1
|
||||
69,1,1
|
||||
70,1,1
|
||||
71,1,1
|
||||
72,1,1
|
||||
73,1,1
|
||||
74,1,1
|
||||
75,1,1
|
||||
76,1,1
|
||||
77,1,1
|
||||
78,1,1
|
||||
79,1,1
|
||||
80,1,1
|
||||
81,1,1
|
||||
82,1,1
|
||||
83,1,1
|
||||
84,1,1
|
||||
85,1,1
|
||||
86,1,1
|
||||
87,1,1
|
||||
88,1,1
|
||||
89,1,1
|
||||
90,1,1
|
||||
91,1,1
|
||||
92,1,1
|
||||
93,1,1
|
||||
94,1,1
|
||||
95,1,1
|
||||
96,1,1
|
||||
97,1,1
|
||||
98,1,1
|
||||
99,1,1
|
||||
100,1,1
|
||||
101,1,1
|
||||
102,1,1
|
||||
103,1,1
|
||||
104,1,1
|
||||
105,1,1
|
||||
106,1,1
|
||||
107,1,1
|
||||
108,1,1
|
||||
109,1,1
|
||||
110,1,1
|
||||
111,1,1
|
||||
112,1,1
|
||||
113,1,1
|
||||
114,1,1
|
||||
115,1,1
|
||||
116,1,1
|
||||
117,1,1
|
||||
118,1,1
|
||||
119,1,1
|
||||
120,1,1
|
||||
121,1,1
|
||||
122,1,1
|
||||
123,1,1
|
||||
124,1,1
|
||||
125,1,1
|
||||
126,1,1
|
||||
127,1,1
|
||||
128,1,1
|
||||
129,1,1
|
||||
130,1,1
|
||||
131,1,1
|
||||
132,1,1
|
||||
133,1,1
|
||||
134,1,1
|
||||
135,1,1
|
||||
136,1,1
|
||||
137,1,1
|
||||
138,1,1
|
||||
139,1,1
|
||||
140,1,1
|
||||
141,1,1
|
||||
142,1,1
|
||||
143,1,1
|
||||
144,1,1
|
||||
145,1,1
|
||||
146,1,1
|
||||
147,1,1
|
||||
148,1,1
|
||||
149,1,1
|
||||
150,1,1
|
||||
151,1,1
|
||||
152,1,1
|
||||
153,1,1
|
||||
154,1,1
|
||||
155,1,1
|
||||
156,1,1
|
||||
157,1,1
|
||||
158,1,1
|
||||
159,1,1
|
||||
160,1,1
|
||||
161,1,1
|
||||
162,1,1
|
||||
163,1,1
|
||||
164,1,1
|
||||
165,1,1
|
||||
166,1,1
|
||||
167,1,1
|
||||
168,1,1
|
||||
169,1,1
|
||||
170,1,1
|
||||
171,1,1
|
||||
172,1,1
|
||||
173,1,1
|
||||
174,1,1
|
||||
175,1,1
|
||||
176,1,1
|
||||
177,1,1
|
||||
178,1,1
|
||||
179,1,1
|
||||
180,1,1
|
||||
181,1,1
|
||||
182,1,1
|
||||
183,1,1
|
||||
184,1,1
|
||||
185,1,1
|
||||
186,1,1
|
||||
187,1,1
|
||||
188,1,1
|
||||
189,1,1
|
||||
190,1,1
|
||||
191,1,1
|
||||
192,1,1
|
||||
193,1,1
|
||||
194,1,1
|
||||
195,1,1
|
||||
196,1,1
|
||||
197,1,1
|
||||
198,1,1
|
||||
199,1,1
|
||||
200,1,1
|
||||
201,1,1
|
||||
202,1,1
|
||||
203,1,1
|
||||
204,1,1
|
||||
205,1,1
|
||||
206,1,1
|
||||
207,1,1
|
||||
208,1,1
|
||||
209,1,1
|
||||
210,1,1
|
||||
211,1,1
|
||||
212,1,1
|
||||
213,1,1
|
||||
214,1,1
|
||||
215,1,1
|
||||
216,1,1
|
||||
217,1,1
|
||||
218,1,1
|
||||
219,1,1
|
||||
220,1,1
|
||||
221,1,1
|
||||
222,1,1
|
||||
223,1,1
|
||||
224,1,1
|
||||
225,1,1
|
||||
226,1,1
|
||||
227,1,1
|
||||
228,1,1
|
||||
229,1,1
|
||||
230,1,1
|
||||
231,1,1
|
||||
232,1,1
|
||||
233,1,1
|
||||
234,1,1
|
||||
235,1,1
|
||||
236,1,1
|
||||
237,1,1
|
||||
238,1,1
|
||||
239,1,1
|
||||
240,1,1
|
||||
241,1,1
|
||||
242,1,1
|
||||
243,1,1
|
||||
244,1,1
|
||||
245,1,1
|
||||
246,1,1
|
||||
247,1,1
|
||||
248,1,1
|
||||
249,1,1
|
||||
250,1,1
|
||||
251,1,1
|
||||
252,1,1
|
||||
253,1,1
|
||||
254,1,1
|
||||
255,1,1
|
||||
256,1,1
|
||||
257,1,1
|
||||
258,1,1
|
||||
259,1,1
|
||||
260,1,1
|
||||
261,1,1
|
||||
262,1,1
|
||||
263,1,1
|
||||
264,1,1
|
||||
265,1,1
|
||||
266,1,1
|
||||
267,1,1
|
||||
268,1,1
|
||||
269,1,1
|
||||
270,1,1
|
||||
271,1,1
|
||||
272,1,1
|
||||
273,1,1
|
||||
274,1,1
|
||||
275,1,1
|
||||
276,1,1
|
||||
277,1,1
|
||||
278,1,1
|
||||
279,1,1
|
||||
280,1,1
|
||||
281,1,1
|
||||
282,1,1
|
||||
283,1,1
|
||||
284,1,1
|
||||
285,1,1
|
||||
286,1,1
|
||||
287,1,1
|
||||
288,1,1
|
||||
289,1,1
|
||||
290,1,1
|
||||
291,1,1
|
||||
292,1,1
|
||||
293,1,1
|
||||
294,1,1
|
||||
295,1,1
|
||||
296,1,1
|
||||
297,1,1
|
||||
298,1,1
|
||||
299,1,1
|
||||
300,1,1
|
||||
301,1,1
|
||||
302,1,1
|
||||
303,1,1
|
||||
304,1,1
|
||||
305,1,1
|
||||
306,1,1
|
||||
307,1,1
|
||||
308,1,1
|
||||
309,1,1
|
||||
310,1,1
|
||||
311,1,1
|
||||
312,1,1
|
||||
313,1,1
|
||||
314,1,1
|
||||
315,1,1
|
||||
316,1,1
|
||||
317,1,1
|
||||
318,1,1
|
||||
319,1,1
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -12,34 +12,21 @@
|
||||
#ifndef __WAVE_SIMULATION__
|
||||
#define __WAVE_SIMULATION__
|
||||
|
||||
#include "constants.hpp"
|
||||
#include "literals.hpp"
|
||||
|
||||
#include <armadillo>
|
||||
#include <cstdint>
|
||||
|
||||
class WaveSimulation {
|
||||
protected:
|
||||
uint32_t M;
|
||||
arma::sp_cx_mat B;
|
||||
int M;
|
||||
arma::cx_mat U;
|
||||
arma::cx_mat V;
|
||||
arma::cx_mat A;
|
||||
arma::cx_mat B;
|
||||
double h;
|
||||
double dt;
|
||||
double T;
|
||||
|
||||
public:
|
||||
int32_t N;
|
||||
arma::cx_mat V;
|
||||
arma::cx_mat U;
|
||||
arma::sp_cx_mat A;
|
||||
WaveSimulation(double h, double dt, double T);
|
||||
virtual void solve(std::ofstream& ofile);
|
||||
void build_A();
|
||||
void build_B();
|
||||
void initialize_U(double x_c, double y_c, double sigma_x, double sigma_y,
|
||||
double p_x, double p_y);
|
||||
void write_U(std::ofstream &ofile);
|
||||
void step();
|
||||
void build_V(double thickness, double pos_x, double aperture_sparation, double aperture, uint32_t slits);
|
||||
virtual void solve() = 0;
|
||||
void build_A(arma::cx_vec A_vec);
|
||||
void build_B(arma::cx_vec B_vec);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
/** @file constants.hpp
|
||||
*
|
||||
* @author Cory Alexander Balaton (coryab)
|
||||
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
||||
*
|
||||
* @version 1.0
|
||||
*
|
||||
* @brief Library of constants
|
||||
*
|
||||
* @bug No known bugs
|
||||
* */
|
||||
#ifndef __CONST__
|
||||
#define __CONST__
|
||||
|
||||
#define I std::complex<double>{0., 1.}
|
||||
|
||||
#endif
|
||||
@ -1,19 +0,0 @@
|
||||
/** @file literals.hpp
|
||||
*
|
||||
* @author Cory Alexander Balaton (coryab)
|
||||
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
||||
*
|
||||
* @version 1.0
|
||||
*
|
||||
* @brief Useful literals
|
||||
*
|
||||
* @bug No known bugs
|
||||
* */
|
||||
#ifndef __LITERALS__
|
||||
#define __LITERALS__
|
||||
|
||||
#include <complex>
|
||||
|
||||
std::complex<double> operator ""_i(long double magnitude);
|
||||
|
||||
#endif
|
||||
@ -117,10 +117,10 @@ std::string dirname(const std::string &path);
|
||||
/** @brief Take 2 strings and concatenate them and make sure there is a
|
||||
* directory separator (/) between them.
|
||||
*
|
||||
* @details This function doesn't care whether or not the values given as
|
||||
* parameters are valid path strings. It is the responsibility of the user to
|
||||
* make sure that the values given are valid path strings. The function only
|
||||
* guarantees that the output string is a valid path string.
|
||||
* @details This function doesn't care whether or not the values given as
|
||||
* parameters are valid path strings. It is the responsibility of the user to make
|
||||
* sure that the values given are valid path strings.
|
||||
* The function only guarantees that the output string is a valid path string.
|
||||
*
|
||||
* @param left The left hand side of the result string
|
||||
* @param right The right hand side of the result string
|
||||
@ -129,8 +129,6 @@ std::string dirname(const std::string &path);
|
||||
* */
|
||||
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);
|
||||
} // namespace utils
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,180 +0,0 @@
|
||||
/** @file WaveSimulation.cpp
|
||||
*
|
||||
* @author Cory Alexander Balaton (coryab)
|
||||
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
||||
*
|
||||
* @version 0.1
|
||||
*
|
||||
* @brief Implementation of the WaveSimulation class.
|
||||
*
|
||||
* @bug No known bugs
|
||||
* */
|
||||
#include "WaveSimulation.hpp"
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <complex>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
WaveSimulation::WaveSimulation(double h, double dt, double T)
|
||||
{
|
||||
this->dt = dt;
|
||||
this->h = h;
|
||||
this->T = T;
|
||||
this->M = 1. / h;
|
||||
this->N = M - 2;
|
||||
this->V.set_size(this->N, this->N);
|
||||
this->V.fill(0.);
|
||||
this->U.set_size(this->N, this->N);
|
||||
this->U.fill(0.);
|
||||
}
|
||||
|
||||
void WaveSimulation::solve(std::ofstream &ofile)
|
||||
{
|
||||
ofile << this->N << '\n';
|
||||
uint32_t iterations = this->T / this->dt;
|
||||
for (size_t i = 0; i < iterations; i++) {
|
||||
this->write_U(ofile);
|
||||
this->step();
|
||||
}
|
||||
}
|
||||
|
||||
void WaveSimulation::step()
|
||||
{
|
||||
DEBUG("Inside step");
|
||||
arma::cx_vec tmp = this->B * this->U.as_col();
|
||||
arma::spsolve(this->U, this->A, tmp);
|
||||
}
|
||||
|
||||
void WaveSimulation::build_A()
|
||||
{
|
||||
// Create the diagonal
|
||||
arma::cx_vec diagonal(this->N * this->N);
|
||||
|
||||
// Set diagonal values
|
||||
std::complex<double> r = (1._i * this->dt) / (2 * h * h);
|
||||
for (size_t i = 0; i < diagonal.size(); i++) {
|
||||
diagonal(i) = 1. + 4. * r + (1._i * this->dt / 2.) * this->V(i);
|
||||
}
|
||||
|
||||
// Create the submatrix
|
||||
arma::cx_mat sub_matrix(this->N, this->N, arma::fill::zeros);
|
||||
sub_matrix.diag(-1).fill(-r);
|
||||
sub_matrix.diag(1).fill(-r);
|
||||
|
||||
// Set the size of A
|
||||
this->A.set_size(this->N * this->N, this->N * this->N);
|
||||
|
||||
// Fill in the values in the submatrix diagonal
|
||||
for (size_t i = 0; i < this->A.n_cols; i += this->N) {
|
||||
this->A.submat(i, i, i + this->N - 1, i + this->N - 1) = sub_matrix;
|
||||
}
|
||||
|
||||
// Fill the last sub/sup-diagonals
|
||||
this->A.diag() = diagonal;
|
||||
this->A.diag(-this->N).fill(-r);
|
||||
this->A.diag(this->N).fill(-r);
|
||||
}
|
||||
|
||||
void WaveSimulation::build_B()
|
||||
{
|
||||
std::complex<double> r = (1._i * this->dt) / (2 * h * h);
|
||||
|
||||
// Create the diagonal
|
||||
arma::cx_vec diagonal(this->N * this->N);
|
||||
|
||||
for (size_t i = 0; i < diagonal.size(); i++) {
|
||||
diagonal(i) = 1. - 4. * r - (1._i * this->dt / 2.) * this->V(i);
|
||||
}
|
||||
|
||||
// Create the submatrix
|
||||
arma::cx_mat sub_matrix(this->N, this->N, arma::fill::zeros);
|
||||
sub_matrix.diag(-1).fill(r);
|
||||
sub_matrix.diag(1).fill(r);
|
||||
|
||||
// Set the size of B
|
||||
this->B.set_size(this->N * this->N, this->N * this->N);
|
||||
|
||||
// Fill in the values in the submatrix diagonal
|
||||
for (size_t i = 0; i < this->B.n_cols; i += this->N) {
|
||||
this->B.submat(i, i, i + this->N - 1, i + this->N - 1) = sub_matrix;
|
||||
}
|
||||
|
||||
// Fill the last sub/sup-diagonals
|
||||
this->B.diag() = diagonal;
|
||||
this->B.diag(-this->N).fill(r);
|
||||
this->B.diag(this->N).fill(r);
|
||||
}
|
||||
|
||||
void WaveSimulation::initialize_U(double x_c, double y_c, double sigma_x,
|
||||
double sigma_y, double p_x, double p_y)
|
||||
{
|
||||
double x, y, diff_x, diff_y;
|
||||
std::complex<double> sum = 0.;
|
||||
for (size_t j = 0; j < this->U.n_cols; j++) {
|
||||
x = j * h;
|
||||
diff_x = x - x_c;
|
||||
for (size_t i = 0; i < this->U.n_rows; i++) {
|
||||
y = i * h;
|
||||
diff_y = y - y_c;
|
||||
this->U(i, j) =
|
||||
std::exp(-(diff_x * diff_x) / (2. * sigma_x * sigma_x)
|
||||
- (diff_y * diff_y) / (2. * sigma_y * sigma_y)
|
||||
+ p_x * x * 1._i + p_y * y * 1._i);
|
||||
sum += this->U(i, j) * std::conj(this->U(i, j));
|
||||
}
|
||||
}
|
||||
if (std::abs(sum.imag()) > 1e-7) {
|
||||
abort();
|
||||
}
|
||||
double norm = 1. / std::sqrt(sum.real());
|
||||
|
||||
this->U.for_each([norm](std::complex<double> &el) { el *= norm; });
|
||||
}
|
||||
|
||||
void WaveSimulation::write_U(std::ofstream &ofile)
|
||||
{
|
||||
this->U.for_each(
|
||||
[&ofile](std::complex<double> el) { ofile << el << '\t'; });
|
||||
ofile << '\n';
|
||||
}
|
||||
|
||||
void WaveSimulation::build_V(double thickness, double pos_x,
|
||||
double aperture_separation, double aperture,
|
||||
uint32_t slits)
|
||||
{
|
||||
uint32_t mid_y = this->N / 2 - (this->N % 2 == 0);
|
||||
arma::cx_vec res;
|
||||
|
||||
if (slits % 2 == 0) {
|
||||
res = arma::cx_vec(aperture_separation/this->h,arma::fill::value(1e10));
|
||||
for (size_t i=0; i < slits; i+=2) {
|
||||
res = arma::join_cols(res, arma::cx_vec(aperture/this->h,arma::fill::zeros));
|
||||
res = arma::join_cols(arma::cx_vec(aperture/this->h,arma::fill::zeros), res);
|
||||
res = arma::join_cols(res, arma::cx_vec(aperture_separation/this->h,arma::fill::value(1e10)));
|
||||
res = arma::join_cols(arma::cx_vec(aperture_separation/this->h,arma::fill::value(1e10)), res);
|
||||
}
|
||||
}
|
||||
else {
|
||||
res = arma::cx_vec(aperture/this->h,arma::fill::value(0));
|
||||
for (size_t i=0; i < slits-1; i+=2) {
|
||||
res = arma::join_cols(res, arma::cx_vec(aperture_separation/this->h,arma::fill::value(1e10)));
|
||||
res = arma::join_cols(arma::cx_vec(aperture_separation/this->h,arma::fill::value(1e10)), res);
|
||||
res = arma::join_cols(res, arma::cx_vec(aperture/this->h,arma::fill::zeros));
|
||||
res = arma::join_cols(arma::cx_vec(aperture/this->h,arma::fill::zeros), res);
|
||||
}
|
||||
}
|
||||
if (res.size() > this->N) {
|
||||
abort();
|
||||
}
|
||||
uint32_t fill = (this->N - res.size()) / 2;
|
||||
res = arma::join_cols(arma::cx_vec(fill, arma::fill::value(1e10)), res);
|
||||
res = arma::join_cols(res, arma::cx_vec(fill + ((this->N - res.size()) % 2), arma::fill::value(1e10)));
|
||||
|
||||
uint32_t start = pos_x/this->h - thickness/this->h/2;
|
||||
for (size_t i=0; i < thickness/this->h; i++) {
|
||||
this->V.col(start+i) = res;
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
/** @file literals.cpp
|
||||
*
|
||||
* @author Cory Alexander Balaton (coryab)
|
||||
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
||||
*
|
||||
* @version 1.0
|
||||
*
|
||||
* @brief The implementation of the literals.
|
||||
*
|
||||
* @bug No known bugs
|
||||
* */
|
||||
#include "literals.hpp"
|
||||
|
||||
std::complex<double> operator""_i(long double magnitude)
|
||||
{
|
||||
return std::complex<double>(0.,magnitude);
|
||||
}
|
||||
@ -70,47 +70,4 @@ std::string concatpath(const std::string &left, const std::string &right)
|
||||
}
|
||||
}
|
||||
|
||||
void print_sp_matrix_structure(const arma::sp_cx_mat &A)
|
||||
{
|
||||
using namespace std;
|
||||
using namespace arma;
|
||||
|
||||
// Declare a C-style 2D array of strings.
|
||||
string S[A.n_rows][A.n_cols];
|
||||
|
||||
// Initialise all the strings to " ".
|
||||
for (int i = 0; i < A.n_rows; i++) {
|
||||
for (int j = 0; j < A.n_cols; j++) {
|
||||
S[i][j] = " ";
|
||||
}
|
||||
}
|
||||
|
||||
// Next, we want to set the string to a dot at each non-zero element.
|
||||
// To do this we use the special loop iterator from the sp_cx_mat class
|
||||
// to help us loop over only the non-zero matrix elements.
|
||||
sp_cx_mat::const_iterator it = A.begin();
|
||||
sp_cx_mat::const_iterator it_end = A.end();
|
||||
|
||||
int nnz = 0;
|
||||
for (; it != it_end; ++it) {
|
||||
S[it.row()][it.col()] = "•";
|
||||
nnz++;
|
||||
}
|
||||
|
||||
// Finally, print the matrix to screen.
|
||||
cout << endl;
|
||||
for (int i = 0; i < A.n_rows; i++) {
|
||||
cout << "| ";
|
||||
for (int j = 0; j < A.n_cols; j++) {
|
||||
cout << S[i][j] << " ";
|
||||
}
|
||||
cout << "|\n";
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
cout << "matrix size: " << A.n_rows << "x" << A.n_cols << endl;
|
||||
cout << "non-zero elements: " << nnz << endl;
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib
|
||||
from matplotlib.animation import FuncAnimation
|
||||
import ast
|
||||
|
||||
wave_arr = []
|
||||
fig = plt.figure()
|
||||
ax = plt.gca()
|
||||
img = ax.imshow([[]])
|
||||
|
||||
def plot():
|
||||
with open("test.txt") as f:
|
||||
lines = f.readlines();
|
||||
size = int(lines[0])
|
||||
for line in lines[1:]:
|
||||
arr = line.strip().split("\t")
|
||||
arr = np.asarray(list(map(lambda x: ((a := complex(*ast.literal_eval(x)))*a.conjugate()).real, arr)))
|
||||
|
||||
# print(sum(arr))
|
||||
arr = arr.reshape(size,size)
|
||||
wave_arr.append(arr.T)
|
||||
# print(arr)
|
||||
|
||||
# plt.imshow(arr, cmap="hot", interpolation="nearest")
|
||||
# plt.show()
|
||||
|
||||
|
||||
def animation(i):
|
||||
norm = matplotlib.cm.colors.Normalize(vmin=0, vmax=np.max(wave_arr[i]))
|
||||
img.set_norm(norm)
|
||||
img.set_data(wave_arr[i])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
plot()
|
||||
|
||||
norm = matplotlib.cm.colors.Normalize(vmin=0, vmax=np.max(wave_arr[0]))
|
||||
img = ax.imshow(wave_arr[0], extent=[0,1,0,1], cmap=plt.get_cmap("viridis"), norm=norm)
|
||||
anim = FuncAnimation(fig, animation, interval=1, frames=np.arange(0,len(wave_arr)), repeat=True, blit=0)
|
||||
# plt.show()
|
||||
|
||||
anim.save("./animation.mp4", writer="ffmpeg", bitrate=10000, fps=15)
|
||||
@ -1,27 +0,0 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib
|
||||
from matplotlib.animation import FuncAnimation
|
||||
import ast
|
||||
|
||||
|
||||
def plot():
|
||||
with open("v.txt") as f:
|
||||
lines = f.readlines();
|
||||
size = int(lines[0])
|
||||
for line in lines[1:]:
|
||||
arr = line.strip().split("\t")
|
||||
arr = np.asarray(list(map(lambda x: ((a := complex(*ast.literal_eval(x)))*a.conjugate()).real, arr)))
|
||||
|
||||
# print(sum(arr))
|
||||
arr = arr.reshape(size,size)
|
||||
# print(arr)
|
||||
|
||||
plt.imshow(arr.T, cmap="hot", interpolation="nearest")
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
plot()
|
||||
121
src/main.cpp
121
src/main.cpp
@ -1,121 +0,0 @@
|
||||
/** @file main.cpp
|
||||
*
|
||||
* @author Cory Alexander Balaton (coryab)
|
||||
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
||||
*
|
||||
* @version 1.0
|
||||
*
|
||||
* @brief Implementation of the testing library
|
||||
*
|
||||
* @bug No known bugs
|
||||
* */
|
||||
#include "WaveSimulation.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
void probability_deviation()
|
||||
{
|
||||
WaveSimulation sim_narrow(.005, 2.5e-5, .008);
|
||||
sim_narrow.initialize_U(.25, .5, .05, .05, 200., 0.);
|
||||
sim_narrow.build_A();
|
||||
sim_narrow.build_B();
|
||||
|
||||
WaveSimulation sim_wide(.005, 2.5e-5, .008);
|
||||
sim_wide.build_V(.02, .5, .05, .05, 2);
|
||||
sim_wide.initialize_U(.25, .5, .05, .10, 200., 0.);
|
||||
sim_wide.build_A();
|
||||
sim_wide.build_B();
|
||||
|
||||
std::ofstream ofile;
|
||||
utils::mkpath("data");
|
||||
ofile.open("data/probability_deviation.txt");
|
||||
|
||||
double sum_narrow, sum_wide;
|
||||
|
||||
for (size_t i = 0; i < 320; i++) {
|
||||
sum_narrow = 0;
|
||||
sum_wide = 0;
|
||||
for (size_t j = 0; j < sim_narrow.U.n_elem; j++) {
|
||||
sum_narrow += (sim_narrow.U(j) * std::conj(sim_narrow.U(j))).real();
|
||||
sum_wide += (sim_wide.U(j) * std::conj(sim_wide.U(j))).real();
|
||||
}
|
||||
|
||||
sim_narrow.step();
|
||||
sim_wide.step();
|
||||
ofile << i << ',' << sum_narrow << ',' << sum_wide << '\n';
|
||||
}
|
||||
|
||||
ofile.close();
|
||||
}
|
||||
|
||||
void color_map()
|
||||
{
|
||||
WaveSimulation sim(.005, 2.5e-5, .008);
|
||||
sim.build_V(.02, .5, .05, .05, 2);
|
||||
sim.initialize_U(.25, .5, .05, .10, 200., 0.);
|
||||
sim.build_A();
|
||||
sim.build_B();
|
||||
|
||||
std::ofstream ofile;
|
||||
ofile.open("data/color_map.txt");
|
||||
ofile << sim.N << '\n';
|
||||
sim.write_U(ofile);
|
||||
for (size_t i = 0; i < 40; i++) {
|
||||
sim.step();
|
||||
}
|
||||
sim.write_U(ofile);
|
||||
for (size_t i = 0; i < 40; i++) {
|
||||
sim.step();
|
||||
}
|
||||
sim.write_U(ofile);
|
||||
ofile.close();
|
||||
}
|
||||
|
||||
void detector_screen()
|
||||
{
|
||||
WaveSimulation sim(.005, 2.5e-5, .008);
|
||||
sim.build_V(.02, .5, .05, .05, 1);
|
||||
sim.initialize_U(.25, .5, .05, .10, 200., 0.);
|
||||
sim.build_A();
|
||||
sim.build_B();
|
||||
|
||||
std::ofstream ofile;
|
||||
utils::mkpath("data/screen");
|
||||
ofile.open("data/screen/single_slit.txt");
|
||||
ofile << sim.N << '\n';
|
||||
for (size_t i = 0; i < 80; i++) {
|
||||
sim.step();
|
||||
}
|
||||
sim.write_U(ofile);
|
||||
ofile.close();
|
||||
|
||||
sim.build_V(.02, .5, .05, .05, 2);
|
||||
sim.initialize_U(.25, .5, .05, .10, 200., 0.);
|
||||
|
||||
ofile.open("data/screen/double_slit.txt");
|
||||
ofile << sim.N << '\n';
|
||||
for (size_t i = 0; i < 80; i++) {
|
||||
sim.step();
|
||||
}
|
||||
sim.write_U(ofile);
|
||||
ofile.close();
|
||||
|
||||
sim.build_V(.02, .5, .05, .05, 3);
|
||||
sim.initialize_U(.25, .5, .05, .10, 200., 0.);
|
||||
|
||||
ofile.open("data/screen/triple_slit.txt");
|
||||
ofile << sim.N << '\n';
|
||||
for (size_t i = 0; i < 80; i++) {
|
||||
sim.step();
|
||||
}
|
||||
sim.write_U(ofile);
|
||||
ofile.close();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
probability_deviation();
|
||||
color_map();
|
||||
detector_screen();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user