-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bffb27f
commit 27b0fc3
Showing
55 changed files
with
2,253 additions
and
403 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
32 | ||
32 | ||
0 | ||
1 | ||
0 | ||
1 | ||
5e-16 | ||
64 | ||
64 | ||
0.0 | ||
1.0 | ||
0.0 | ||
1.0 | ||
2.5e-17 | ||
5e-14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import matplotlib.pyplot as plt | ||
import csv | ||
import subprocess | ||
|
||
components = {1: "Ex", 2: "Ey", 3: "Ez", 4: "Bx", 5: "By", 6: "Bz"} | ||
nums_com = {"Ex": 0, "Ey": 1, "Ez": 2, "Bx": 3, "By": 4, "Bz": 5} | ||
shift_flag = "0" | ||
|
||
|
||
def execute_cpp(field_1, field_2, field_to_plot): | ||
num_field_1 = nums_com[field_1] | ||
num_field_2 = nums_com[field_2] | ||
num_field_to_plot = nums_com[field_to_plot] | ||
|
||
print("\n" + field_to_plot + ":\n") | ||
|
||
cpp_executable = "src/Release/sample.exe" | ||
args = [cpp_executable, str(num_field_1), str(num_field_2), str(num_field_to_plot), shift_flag] | ||
try: | ||
completed_process = subprocess.run(args, check=True, stdout=subprocess.PIPE) | ||
output = completed_process.stdout.decode("utf-8").strip() | ||
print(output) | ||
return output | ||
except subprocess.CalledProcessError: | ||
print("Error when starting a C++ project") | ||
except FileNotFoundError: | ||
print("sample.exe not found") | ||
|
||
|
||
if __name__ == '__main__': | ||
input_list = ["Ni", "Nj", "ax", "bx", "ay", "by", "dt", "t"] | ||
|
||
print("Update parameters? \n \ | ||
1 - Yes \n \ | ||
2 - No") | ||
select_update = int(input("Number: ")) * (-1) + 2 | ||
if not (select_update == 0 or select_update == 1): | ||
print("Invalid input") | ||
exit(1) | ||
|
||
if (select_update): | ||
with open("Source.txt", "w") as file: | ||
for component in input_list: | ||
file.write(input(component + ": ") + "\n") | ||
else: | ||
with open("Source.txt", "r+") as file: | ||
lines = file.readlines() | ||
lines[-1] = input("t : ") + "\n" | ||
file.seek(0) | ||
file.writelines(lines) | ||
file.truncate() | ||
|
||
with open('Source.txt', 'r') as file: | ||
numbers = [float(line.strip()) for line in file] | ||
|
||
convergences = [] | ||
for n in range(0, 10): | ||
with open("Source.txt", "w") as file: | ||
tmp_n_0 = numbers[0] * (1.5 ** n) | ||
file.write(str(tmp_n_0) + "\n") | ||
|
||
tmp_n_1 = numbers[1] * (1.5 ** n) | ||
file.write(str(tmp_n_1) + "\n") | ||
|
||
file.write(str(numbers[2]) + "\n") | ||
file.write(str(numbers[3]) + "\n") | ||
file.write(str(numbers[4]) + "\n") | ||
file.write(str(numbers[5]) + "\n") | ||
|
||
tmp_n_6 = numbers[6] / (1.5 ** n) | ||
file.write(str(tmp_n_6) + "\n") | ||
|
||
file.write(str(numbers[7]) + "\n") | ||
|
||
convergences.append(execute_cpp("Ex", "Bz", "Ex")) |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
#pragma once | ||
#define _USE_MATH_DEFINES | ||
|
||
#include <iostream> | ||
#include <iomanip> | ||
#include <fstream> | ||
#include <functional> | ||
|
||
#include "FDTD.h" | ||
|
||
//sin(2.0 * M_PI * (x - size_wave[0]) / (size_wave[1] - size_wave[0])) | ||
//sin(2.0 * M_PI * (x - size_wave[0] - FDTD_Const::C * _t) / (size_wave[1] - size_wave[0]))) | ||
|
||
enum class Axis {X, Y}; | ||
|
||
class Test_FDTD | ||
{ | ||
private: | ||
double sign = 0.0; | ||
Axis axis; | ||
bool shifted; | ||
double max_abs_error = 0.0; | ||
|
||
void initial_filling(FDTD& _test, Component field_1, Component field_2, double size_d, double size_wave[2], | ||
std::function<double(double, double[2])>& _init_function) | ||
{ | ||
if (axis == Axis::X) | ||
{ | ||
double x = 0.0; | ||
double x_b = 0.0; | ||
for (int i = 0; i < _test.get_Ni(); x += size_d, ++i) | ||
{ | ||
for (int j = 0; j < _test.get_Nj(); ++j) | ||
{ | ||
_test.get_field(field_1)(i, j) = sign * _init_function(x, size_wave); | ||
if (shifted) | ||
{ | ||
x_b = x + size_d / 2.0; | ||
} | ||
else x_b = x; | ||
_test.get_field(field_2)(i, j) = _init_function(x_b, size_wave); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
double y = 0.0; | ||
double y_b = 0.0; | ||
for (int j = 0; j < _test.get_Nj(); y += size_d, ++j) | ||
{ | ||
for (int i = 0; i < _test.get_Ni(); ++i) | ||
{ | ||
_test.get_field(field_1)(i, j) = sign * _init_function(y, size_wave); | ||
if (shifted) | ||
{ | ||
y_b = y + size_d / 2.0; | ||
} | ||
else y_b = y; | ||
_test.get_field(field_2)(i, j) = _init_function(y_b, size_wave); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void start(FDTD& _test, double _t) | ||
{ | ||
if (shifted) | ||
{ | ||
_test.shifted_update_field(_t); | ||
} | ||
else _test.update_field(_t); | ||
} | ||
double get_shift(Component _field, double step) | ||
{ | ||
if (static_cast<int>(_field) > static_cast<int>(Component::EZ)) | ||
{ | ||
sign = 1.0; | ||
return step / 2; | ||
} | ||
} | ||
|
||
void get_max_abs_error(Field& this_field, Component field, double _size_d[2], double size_wave[2], | ||
std::function<double(double, double, double[2])>& _true_function, double _t) | ||
{ | ||
double shift = 0.0; | ||
if (axis == Axis::X) | ||
{ | ||
shift = get_shift(field, _size_d[0]); | ||
double extr_n = 0.0; | ||
double x = (shifted) ? shift : 0.0; | ||
int j = 0; | ||
for (int i = 0; i < this_field.get_Ni(); ++i, x += _size_d[0]) | ||
{ | ||
double this_n = fabs(sign * this_field(i, j) - _true_function(x, _t, size_wave)); | ||
if (this_n > extr_n) | ||
extr_n = this_n; | ||
} | ||
max_abs_error = extr_n; | ||
} | ||
else | ||
{ | ||
shift = get_shift(field, _size_d[1]); | ||
double extr_n = 0.0; | ||
double y = (shifted) ? shift : 0.0; | ||
int i = 0; | ||
for (int j = 0; j < this_field.get_Nj(); ++j, y += _size_d[1]) | ||
{ | ||
double this_n = fabs(sign * this_field(i, j) - _true_function(y, _t, size_wave)); | ||
if (this_n > extr_n) | ||
extr_n = this_n; | ||
} | ||
max_abs_error = extr_n; | ||
} | ||
} | ||
|
||
public: | ||
Test_FDTD(FDTD& test, Component field_1, Component field_2, Component field_3, | ||
double size_x[2], double size_y[2], double size_d[2], double t, | ||
std::function<double(double, double[2])>& init_function, | ||
std::function<double(double, double, double[2])>& true_function, bool _shifted) : shifted(_shifted) | ||
{ | ||
if (field_1 == Component::EY && field_2 == Component::BZ || field_1 == Component::EZ && field_2 == Component::BX) | ||
{ | ||
sign = 1.0; | ||
} | ||
else if (field_1 == Component::EX && field_2 == Component::BZ || field_1 == Component::EZ && field_2 == Component::BY) | ||
{ | ||
sign = -1.0; | ||
} | ||
|
||
if (field_1 == Component::EY && field_2 == Component::BZ || field_1 == Component::EZ && field_2 == Component::BY) | ||
{ | ||
axis = Axis::X; | ||
initial_filling(test, field_1, field_2, size_d[0], size_x, init_function); | ||
|
||
start(test, t); | ||
|
||
get_max_abs_error(test.get_field(field_3), field_3, size_d, size_x, true_function, t); | ||
} | ||
else if (field_1 == Component::EX && field_2 == Component::BZ || field_1 == Component::EZ && field_2 == Component::BX) | ||
{ | ||
axis = Axis::Y; | ||
initial_filling(test, field_1, field_2, size_d[1], size_y, init_function); | ||
|
||
start(test, t); | ||
|
||
get_max_abs_error(test.get_field(field_3), field_3, size_d, size_y, true_function, t); | ||
} | ||
else | ||
{ | ||
throw std::exception("ERROR: invalid selected fields"); | ||
} | ||
} | ||
|
||
double get_max_abs_error() | ||
{ | ||
return max_abs_error; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.