Skip to content

Commit

Permalink
convergence study
Browse files Browse the repository at this point in the history
  • Loading branch information
Amazingkivas committed Nov 28, 2023
1 parent f9582b6 commit 60f96a8
Show file tree
Hide file tree
Showing 8 changed files with 1,018 additions and 628 deletions.
1,152 changes: 768 additions & 384 deletions PlotScript/OutFile.csv

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions PlotScript/Reserve.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
4.0
4.0
0.0
1.0
0.0
1.0
2e-13
1e-11
8 changes: 4 additions & 4 deletions PlotScript/Source.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
64
64
4.0
4.0
0.0
1.0
0.0
1.0
2.5e-17
5e-14
2e-13
1e-11
55 changes: 39 additions & 16 deletions PlotScript/convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

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"
input_list = ["Ni", "Nj", "ax", "bx", "ay", "by", "dt", "t"]


def execute_cpp(field_1, field_2, field_to_plot):
def execute_cpp(field_1, field_2, field_to_plot, shift_flag):
num_field_1 = nums_com[field_1]
num_field_2 = nums_com[field_2]
num_field_to_plot = nums_com[field_to_plot]
Expand All @@ -27,12 +27,10 @@ def execute_cpp(field_1, field_2, field_to_plot):
print("sample.exe not found")


if __name__ == '__main__':
input_list = ["Ni", "Nj", "ax", "bx", "ay", "by", "dt", "t"]

def update_sources():
print("Update parameters? \n \
1 - Yes \n \
2 - No")
1 - Yes \n \
2 - No")
select_update = int(input("Number: ")) * (-1) + 2
if not (select_update == 0 or select_update == 1):
print("Invalid input")
Expand All @@ -50,15 +48,30 @@ def execute_cpp(field_1, field_2, field_to_plot):
file.writelines(lines)
file.truncate()

with open('Source.txt', 'r') as file:
numbers = [float(line.strip()) for line in file]

def save_source_into_reserve():
with open('Source.txt', 'r') as file1, open('Reserve.txt', 'w') as file2:
numbers = [float(line.strip()) for line in file1]
for num in numbers:
file2.write(str(num) + "\n")

return numbers


def reload_source():
with open('Source.txt', 'w') as file2, open('Reserve.txt', 'r') as file1:
numbers = [float(line.strip()) for line in file1]
for num in numbers:
file2.write(str(num) + "\n")


def analyze_convergence(numbers, mult_2, iterations, shifts):
convergences = []
nums = []
for n in range(0, 5):
flag = str(int(shifts))
for n in range(0, iterations):
with open("Source.txt", "w") as file:
mult_1 = 2
mult_2 = 4

tmp_n_0 = numbers[0] * (mult_1 ** n)
file.write(str(tmp_n_0) + "\n")
Expand All @@ -76,13 +89,23 @@ def execute_cpp(field_1, field_2, field_to_plot):

file.write(str(numbers[7]) + "\n")

convergences.append(float(execute_cpp("Ex", "Bz", "Ex")))
convergences.append(float(execute_cpp("Ex", "Bz", "Ex", flag)))

convers = []
for n in range(0, 4):
convers.append(convergences[n] / convergences[n+1])
for n in range(0, iterations - 1):
convers.append(convergences[n] / convergences[n + 1])
nums.append(n)
print(convers)
plt.plot(nums, convers)
return nums, convers


if __name__ == '__main__':
update_sources()
loaded_numbers = save_source_into_reserve()
nums, convergence = analyze_convergence(loaded_numbers, 2, 6, True)
reload_source()

print(convergence)
plt.plot(nums, convergence)
plt.xlabel('n')
plt.ylabel('E/mult')
plt.title("Plot")
Expand Down
Binary file modified PlotScript/src/Release/sample.exe
Binary file not shown.
5 changes: 5 additions & 0 deletions include/FDTD.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class FDTD

Field& get_field(Component);

void periodical_boundary_conditions_E();
void periodical_boundary_conditions_B();
void periodical_boundary_conditions_shiftedE();
void periodical_boundary_conditions_shiftedB();

void update_field(const double&);
void shifted_update_field(const double&);

Expand Down
Loading

0 comments on commit 60f96a8

Please sign in to comment.