Skip to content

Commit

Permalink
Merge pull request #10 from Amazingkivas/update_fdtd
Browse files Browse the repository at this point in the history
Added launch in the console
  • Loading branch information
Amazingkivas authored May 14, 2024
2 parents 66f78ca + 17f3940 commit 121d8a4
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 268 deletions.
11 changes: 0 additions & 11 deletions PlotScript/Reserve.txt

This file was deleted.

11 changes: 0 additions & 11 deletions PlotScript/Source.txt

This file was deleted.

98 changes: 0 additions & 98 deletions PlotScript/convergence.py

This file was deleted.

100 changes: 0 additions & 100 deletions PlotScript/main.py

This file was deleted.

Binary file removed PlotScript/src/Release/sample.exe
Binary file not shown.
61 changes: 48 additions & 13 deletions PlotScript/visualization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os
import glob
import subprocess
import platform
import argparse
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
Expand All @@ -9,21 +12,21 @@
def get_animation(component):
folder_path = f'OutFiles_{components_num[component]}'
file_names_base = sorted(glob.glob(folder_path + '/*.csv'))
file_names = sorted(file_names_base, key=lambda x: int(x.split('\\')[-1].split('.')[0]))
file_names = sorted(file_names_base, key=lambda x: int(x.split(os.path.sep)[-1].split('.')[0]))

fig, ax = plt.subplots()

def update(frame):
mut = 0
ax.clear()
data = pd.read_csv(file_names[frame], sep=';')
data = data.apply(lambda x: x.str.replace(',', '.').astype(float) if x.dtype == 'object' else x)
ax.imshow(data, cmap='viridis', vmin=-0.07, vmax=0.07, interpolation='none') # RdBu
ax.set_title('Frame {}'.format(frame + 1))


if not os.path.exists('animations'):
os.makedirs('animations')

ani = FuncAnimation(fig, update, frames=len(file_names), interval=50)

plt.show()
ani.save(f'animations/animation_{component}.gif', writer='imagemagick')


Expand All @@ -32,22 +35,54 @@ def get_heatmap(component, iteration):

data = data.applymap(lambda x: float(x.replace(',', '.')) if isinstance(x, str) else x)

plt.imshow(data, cmap='viridis', interpolation='nearest')
plt.imshow(data, cmap='viridis', vmin=-0.07, vmax=0.07, interpolation='none')
plt.colorbar()
plt.show()

if not os.path.exists('heatmap'):
os.makedirs('heatmap')

heatmap_path = os.path.join('heatmap', f'heatmap_iteration_{iteration}_component_{component}.png')
plt.savefig(heatmap_path)


def execute_cpp(grid_size, iters_num):

system = platform.system()

def execute_cpp(grid_size, iters_num, single_iteration_flag=True):
cpp_executable = 'src/Release/sample.exe'
args = [cpp_executable, str(grid_size), str(iters_num), str(int(single_iteration_flag))]
if system == 'Windows':
cpp_executable = 'src/Release/sample.exe'
else:
cpp_executable = 'src/Release/sample'

args = [cpp_executable, str(grid_size), str(iters_num), str(int(True))]
try:
subprocess.run(args, check=True)
except subprocess.CalledProcessError:
print('Error when starting a C++ project')
except FileNotFoundError:
print('sample.exe not found')
print(f'{cpp_executable} not found')


if __name__ == '__main__':
execute_cpp(75, 410, False)
get_animation("Ex")
parser = argparse.ArgumentParser()

parser.add_argument('--run_cpp', action='store_true', help="Run C++ application before generating data")
parser.add_argument('--function', choices=['heatmap', 'animation'], help="Select function to execute")
parser.add_argument('--iteration', type=int, default=0, help="Iteration number for heatmap")
parser.add_argument('component', type=str, help="Component for analysis")

group = parser.add_argument_group('conditional arguments')
group.add_argument('--grid_size', type=int, help="Grid size")
group.add_argument('--iters_num', type=int, help="Number of iterations")

args = parser.parse_args()

if args.run_cpp:
if not (args.grid_size and args.iters_num):
parser.error("The --run_cpp flag requires --grid_size and --iters_num arguments")
execute_cpp(args.grid_size, args.iters_num)

if args.function == 'heatmap':
get_heatmap(args.component, args.iteration)
elif args.function == 'animation':
get_animation(args.component)
1 change: 1 addition & 0 deletions include/Structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace FDTDconst
const double EPS0 = 1.0;
const double MU0 = EPS0;
const double N = 4.0;
const double PI = 3.14159265358;
}

namespace FDTDstruct
Expand Down
7 changes: 7 additions & 0 deletions sln/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ project(FDTD)

include_directories(../include ../gtest ../test)

find_package(OpenMP REQUIRED)

if(OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()

# BUILD
add_subdirectory(FDTD)
Expand Down
12 changes: 11 additions & 1 deletion sln/sample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@ file(GLOB hdrs "*.h*" "../../include/*.h")
file(GLOB srcs "*.cpp" "../../src/*.cpp" "../../samples/*.cpp")

add_executable(sample ${srcs} ${hdrs})
set_target_properties(sample PROPERTIES RUNTIME_OUTPUT_DIRECTORY "../../PlotScript/src")

if(WIN32)
set(output_dir "../../PlotScript/src")
else()
set(output_dir "../../PlotScript/src/Release")
endif()

set_target_properties(sample PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${output_dir})

if(NOT EXISTS ${output_dir})
file(MAKE_DIRECTORY ${output_dir})
endif()
Loading

0 comments on commit 121d8a4

Please sign in to comment.