Skip to content

Commit

Permalink
Merge pull request #3 from Amazingkivas/new_branch
Browse files Browse the repository at this point in the history
Some fixes
  • Loading branch information
Amazingkivas authored Feb 6, 2024
2 parents 348ffb4 + 3253ada commit 659ae86
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 226 deletions.
6 changes: 3 additions & 3 deletions PlotScript/convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ def update_sources():
if not (select_update == 0 or select_update == 1):
print("Invalid input")
exit(1)

if (select_update):
elif (select_update == 1):
with open("Source.txt", "w") as file:
for component in input_list:
file.write(input(component + ": ") + "\n")


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]
Expand Down Expand Up @@ -92,7 +92,7 @@ def analyze_convergence(numbers, mult_2, iterations, shifts):
if __name__ == '__main__':
update_sources()
loaded_numbers = save_source_into_reserve()
nums, convergence = analyze_convergence(loaded_numbers, 4, 4, False)
nums, convergence = analyze_convergence(loaded_numbers, 4, 5, False)
reload_source()

print(convergence)
Expand Down
102 changes: 0 additions & 102 deletions PlotScript/legacy.py

This file was deleted.

Binary file modified PlotScript/src/Release/sample.exe
Binary file not shown.
2 changes: 2 additions & 0 deletions include/FDTD.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#include <vector>
#include <cmath>
#include <iostream>
Expand Down
71 changes: 71 additions & 0 deletions include/Writer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#pragma once

#include <fstream>

#include "FDTD.h"

void write_x(Field& this_field, std::ofstream& fout)
{
for (int j = 0; j < this_field.get_Nj(); ++j)
{
for (int i = 0; i < this_field.get_Ni(); ++i)
{
fout << this_field(i, j);
if (i == this_field.get_Ni() - 1)
{
fout << std::endl;
}
else
{
fout << ";";
}
}
}
fout << std::endl << std::endl;
}
void write_y(Field& this_field, std::ofstream& fout)
{
for (int i = 0; i < this_field.get_Ni(); ++i)
{
for (int j = 0; j < this_field.get_Nj(); ++j)
{
fout << this_field(i, j);
if (j == this_field.get_Nj() - 1)
{
fout << std::endl;
}
else
{
fout << ";";
}
}
}
fout << std::endl << std::endl;
}

void write_all(FDTD& test, char axis, char* file_path)
{
std::ofstream test_fout;
test_fout.open(file_path);

if (!test_fout.is_open())
{
std::cout << "ERROR: Failed to open OutFile.csv" << std::endl;
exit(1);
}
for (int i = static_cast<int>(Component::EX); i <= static_cast<int>(Component::BZ); ++i)
{
if (axis == 'x')
{
write_x(test.get_field(static_cast<Component>(i)), test_fout);
}
else write_y(test.get_field(static_cast<Component>(i)), test_fout);
}
test_fout.close();
}

//#ifndef __DEBUG__
//test_fout.open("OutFile.csv");
//#else
//test_fout.open("../../PlotScript/OutFile.csv");
//#endif
33 changes: 28 additions & 5 deletions include/test_FDTD.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@

enum class Axis {X, Y};

struct SelectedFields {
Component selected_1;
Component selected_2;

Component calculated;
};

struct Parameters {
double ax;
double bx;

double ay;
double by;

double dx;
double dy;

double time;
int iterations;
};

struct Functions {
std::function<double(double, double[2])>& init_function;
std::function<double(double, double, double[2])>& true_function;
};

class Test_FDTD
{
private:
Expand All @@ -17,7 +43,7 @@ class Test_FDTD
bool shifted;
double max_abs_error = 0.0;

void initial_filling(FDTD& _test, Component fields[2], double size_d, double size_wave[2],
void initial_filling(FDTD& _test, SelectedFields, double size_d, double size_wave[2],
std::function<double(double, double[2])>& _init_function);

void start_test(FDTD& _test, int _t);
Expand All @@ -28,10 +54,7 @@ class Test_FDTD
std::function<double(double, double, double[2])>& _true_function, double _t);

public:
Test_FDTD(FDTD& test, Component fields[2], Component field_3,
double size_x[2], double size_y[2], double size_d[2], double time, int iters,
std::function<double(double, double[2])>& init_function,
std::function<double(double, double, double[2])>& true_function, bool _shifted);
Test_FDTD(FDTD& test, SelectedFields, Parameters, Functions, bool _shifted);

double get_max_abs_error() { return max_abs_error; }
};
Loading

0 comments on commit 659ae86

Please sign in to comment.