diff --git a/julia/tests/DistributedTest.jl b/julia/tests/DistributedTest.jl deleted file mode 100644 index b10daf9..0000000 --- a/julia/tests/DistributedTest.jl +++ /dev/null @@ -1,182 +0,0 @@ -using BenchmarkTools -using ClusterManagers -using CSV -using DataFrames -using Distributed -using Statistics - -include("../TUG/src/TUG.jl") -using .TUG - -# 1. Environment Setup -function setup_environment(num_procs::Int) - if num_procs > 0 - if haskey(ENV, "SLURM_JOB_ID") - # Add SLURM processes - added_procs = addprocs(SlurmManager(num_procs), exclusive="") - else - # Add local processes - added_procs = addprocs(num_procs) - end - - # Use remotecall to include TUG on each new worker - for proc in added_procs - remotecall_wait(include, proc, "../TUG/src/TUG.jl") - remotecall_wait(eval, proc, :(using .TUG)) - end - end -end - -# 2. Test Case Definitions -function testBTCS100()::Tuple{Grid,Boundary} - rows::Int = 1024 - cols::Int = 1000 - - alphaX = fill(1.25, rows, cols) - alphaY = fill(1.1, rows, cols) - alphaX[1:100, :] .= 0.5 - alphaX[101:200, :] .= 0.8 - alphaY[:, 1:200] .= 0.6 - alphaY[:, 201:400] .= 0.9 - grid::Grid = Grid{Float64}(rows, cols, alphaX, alphaY) - - concentrations = fill(0.5, rows, cols) - concentrations[11, 11] = 15000 - concentrations[1015, 991] = 7500 - concentrations[11, 991] = 7500 - concentrations[1015, 11] = 7500 - setConcentrations!(grid, concentrations) - - bc::Boundary = Boundary(grid) - setBoundarySideClosed!(bc, LEFT) - setBoundarySideClosed!(bc, RIGHT) - setBoundarySideClosed!(bc, TOP) - setBoundarySideClosed!(bc, BOTTOM) - - return grid, bc -end - -function testBTCS200()::Tuple{Grid,Boundary} - rows::Int = 2027 - cols::Int = 1999 - - alphaX = [sin(i / 100) * cos(j / 100) for i in 1:rows, j in 1:cols] - alphaY = [cos(i / 100) * sin(j / 100) for i in 1:rows, j in 1:cols] - - grid::Grid = Grid{Float64}(rows, cols, alphaX, alphaY) - - concentrations = [i * j / 1e2 for i in 1:rows, j in 1:cols] - concentrations[11, 11] = 15000 - concentrations[2021, 1995] = 7500 - concentrations[11, 1995] = 7500 - concentrations[2021, 11] = 7500 - setConcentrations!(grid, concentrations) - - bc::Boundary = Boundary(grid) - setBoundarySideClosed!(bc, LEFT) - setBoundarySideConstant!(bc, RIGHT, 1.5) - setBoundarySideClosed!(bc, TOP) - setBoundarySideConstant!(bc, BOTTOM, 0.75) - - return grid, bc -end - -function testFTCS500()::Tuple{Grid,Boundary} - rows::Int = 2000 - cols::Int = 2000 - - alphaX = [sin(i / 100) * cos(j / 100) + 1 for i in 1:rows, j in 1:cols] - alphaY = [cos(i / 100) * sin(j / 100) + 1 for i in 1:rows, j in 1:cols] - - grid::Grid = Grid{Float64}(rows, cols, alphaX, alphaY) - - concentrations = [(i * j) / 1e6 for i in 1:rows, j in 1:cols] - concentrations[1001, 1001] = 2000 - setConcentrations!(grid, concentrations) - - bc::Boundary = Boundary(grid) - setBoundarySideClosed!(bc, LEFT) - setBoundarySideClosed!(bc, RIGHT) - setBoundarySideClosed!(bc, TOP) - setBoundarySideConstant!(bc, BOTTOM, 0.75) - - return grid, bc -end - -# 3. Simulation Runners -function run_static_simulation(grid::Grid, bc::Boundary, method, steps::Int, dt::Float64) - simulation = Simulation(grid, bc, method, steps, dt, CONSOLE_OUTPUT_OFF, CSV_OUTPUT_OFF) - TUG.run(simulation) -end - -function run_dynamic_simulation(grid::Grid, bc::Boundary, method, steps::Int, dt::Float64, num_procs::Int) - setup_environment(num_procs) - - simulation = DynamicSimulation(grid, bc, method, dt) - createGrid(simulation) - for _ in 1:steps - next(simulation) - end - - if num_procs > 0 - rmprocs(workers()) - end -end - -# 4. Performance Metrics -function measure_performance(test_case_function, method, steps::Int, dt::Float64, num_procs::Int, dynamic::Bool=false) - grid, bc = test_case_function() - - if dynamic - simulation_run = @benchmark run_dynamic_simulation($grid, $bc, $method, $steps, $dt, $num_procs) - else - simulation_run = @benchmark run_static_simulation($grid, $bc, $method, $steps, $dt) - end - - time_measurement = mean(simulation_run).time / 1e9 - memory_measurement = mean(simulation_run).memory / 1e6 - - return (time=time_measurement, memory=memory_measurement) -end - -# 5. Benchmarking and Comparison -function benchmark_test_case(test_case_function, method, steps::Int, dt::Float64, is_distributed::Bool, num_procs::Int) - performance_metrics = measure_performance(test_case_function, method, steps, dt, num_procs, is_distributed) - return performance_metrics -end - -# 6. Reporting -function report_results(results) - for result in results - println("Test Case: $(result.test_case)$(result.is_distributed ? ", Procs: $(result.num_procs)" : ""), Time: $(result.time) s, Memory: $(result.memory) MB") - end -end - -# 7. Cleanup -function cleanup() - for filename in readdir() - if occursin(".csv", filename) - rm(filename, force=true) - end - end -end - -# Main Function -function main() - test_cases = [(testBTCS100, BTCS, 100, 0.01), (testBTCS200, BTCS, 200, 0.005), (testFTCS500, FTCS, 500, 0.005)] - configurations = [(false, 0), (true, 0), (true, 1), (true, 2)] # Non-distributed, distributed with 1 and 2 additional procs - - results = [] - - for (test_case, method, steps, dt) in test_cases - for (is_distributed, num_procs) in configurations - performance_metrics = benchmark_test_case(test_case, method, steps, dt, is_distributed, num_procs) - push!(results, (test_case=test_case, method=method, is_distributed=is_distributed, num_procs=num_procs, time=performance_metrics.time, memory=performance_metrics.memory)) - end - end - - cleanup() - report_results(results) -end - -main() diff --git a/julia/tests/compare_csv.py b/julia/tests/compare_csv.py deleted file mode 100644 index 4184d78..0000000 --- a/julia/tests/compare_csv.py +++ /dev/null @@ -1,82 +0,0 @@ -import argparse -import csv -import sys - - -def read_matrices_from_csv(file_path): - with open(file_path, newline='') as csvfile: - reader = csv.reader(csvfile, delimiter=' ', skipinitialspace=True) - matrices, matrix, line_numbers = [], [], [] - line_number = 0 - - for row in reader: - line_number += 1 - if row: - matrix.append([float(item) for item in row]) - line_numbers.append(line_number) - else: - if matrix: - matrices.append((matrix, line_numbers)) - matrix, line_numbers = [], [] - - if matrix: # Add the last matrix if there's no blank line at the end - matrices.append((matrix, line_numbers)) - - return matrices - -def compare_matrices(matrix_a_tuple, matrix_b_tuple, tolerance=0.01): - data_a, line_numbers_a = matrix_a_tuple - data_b, line_numbers_b = matrix_b_tuple - max_diff = 0 - - if len(data_a) != len(data_b): - return False, f"Matrix size mismatch: Matrix A has {len(data_a)} rows, Matrix B has {len(data_b)} rows.", None, None, max_diff - - for row_index, (row_a, row_b, line_num_a, line_num_b) in enumerate(zip(data_a, data_b, line_numbers_a, line_numbers_b)): - if len(row_a) != len(row_b): - return False, f"Row size mismatch at line {line_num_a} (File A) and line {line_num_b} (File B).", line_num_a, line_num_b, max_diff - - for col_index, (elem_a, elem_b) in enumerate(zip(row_a, row_b)): - if abs(elem_a - elem_b) > max_diff: - max_diff = abs(elem_a - elem_b) - if abs(elem_a - elem_b) > tolerance: - return False, f"Mismatch at line {line_num_a}, column {col_index+1} (File A) vs line {line_num_b}, column {col_index+1} (File B):\nA({elem_a}) vs B({elem_b}).", line_num_a, line_num_b, max_diff - - return True, "Matrices are equal.", None, None, max_diff - -def compare_csv_files(file_path1, file_path2, tolerance=0): - matrices1 = read_matrices_from_csv(file_path1) - matrices2 = read_matrices_from_csv(file_path2) - max_difference = 0 - - if len(matrices1) != len(matrices2): - return False, "Number of matrices in files do not match.", None, None, max_difference - - for index, (matrix_a_tuple, matrix_b_tuple) in enumerate(zip(matrices1, matrices2)): - equal, message, line_num_a, line_num_b, max_diff = compare_matrices(matrix_a_tuple, matrix_b_tuple, tolerance) - if max_diff > max_difference: - max_difference = max_diff - if not equal: - return False, f"In Matrix pair {index}: {message}", line_num_a, line_num_b, max_difference - - return True, "All matrices are equal.", None, None, max_difference - - -def main(): - parser = argparse.ArgumentParser(description='Compare two CSV files containing matrices.') - parser.add_argument('file_a', help='Path to File A') - parser.add_argument('file_b', help='Path to File B') - parser.add_argument('--tolerance', type=float, default=0, help='Tolerance for comparison (default: 0)') - parser.add_argument('--silent', action='store_true', help='Run in silent mode without printing details') - args = parser.parse_args() - - are_equal, message, line_num_a, line_num_b, max_difference = compare_csv_files(args.file_a, args.file_b, args.tolerance) - - if not args.silent: - print(message) - - if not are_equal: - sys.exit(1) - -if __name__ == "__main__": - main() diff --git a/julia/tests/cpp_bench/BTCS_100_100_1000.cpp b/julia/tests/cpp_bench/BTCS_100_100_1000.cpp deleted file mode 100644 index 22cbc53..0000000 --- a/julia/tests/cpp_bench/BTCS_100_100_1000.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include - -using namespace Eigen; -using namespace tug; -using namespace std::chrono; - -int main(int argc, char *argv[]) -{ - // **** GRID **** - int rows = 100; - int cols = 100; - Grid64 grid(rows, cols); - - MatrixXd concentrations = MatrixXd::Constant(rows, cols, 0); - concentrations(10, 10) = 2000; - concentrations(90, 90) = 2000; - grid.setConcentrations(concentrations); - - MatrixXd alphax = MatrixXd::Constant(rows, cols, 1); - MatrixXd alphay = MatrixXd::Constant(rows, cols, 1); - grid.setAlpha(alphax, alphay); - - // **** BOUNDARY **** - Boundary bc = Boundary(grid); - bc.setBoundarySideConstant(BC_SIDE_LEFT, 1); - bc.setBoundarySideConstant(BC_SIDE_RIGHT, 1); - bc.setBoundarySideConstant(BC_SIDE_TOP, 0); - bc.setBoundarySideConstant(BC_SIDE_BOTTOM, 2); - - // **** SIMULATION **** - Simulation simulation = Simulation(grid, bc); - simulation.setTimestep(0.05); - simulation.setIterations(1000); - simulation.setOutputCSV(CSV_OUTPUT_ON); - simulation.setOutputConsole(CONSOLE_OUTPUT_OFF); - - // **** RUN SIMULATION **** - auto start = high_resolution_clock::now(); - simulation.run(); - auto stop = high_resolution_clock::now(); - - auto duration = duration_cast(stop - start); - std::cout << duration.count() << std::endl; -} diff --git a/julia/tests/cpp_bench/BTCS_1024_1000_100.cpp b/julia/tests/cpp_bench/BTCS_1024_1000_100.cpp deleted file mode 100644 index 3c68535..0000000 --- a/julia/tests/cpp_bench/BTCS_1024_1000_100.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include -#include - -using namespace Eigen; -using namespace tug; -using namespace std::chrono; - -int main(int argc, char *argv[]) -{ - // **** GRID **** - int rows = 1024; - int cols = 1000; - Grid64 grid(rows, cols); - - MatrixXd concentrations = MatrixXd::Constant(rows, cols, 0.5); - concentrations(10, 10) = 15000; - concentrations(1014, 990) = 7500; - concentrations(10, 990) = 7500; - concentrations(1014, 10) = 7500; - grid.setConcentrations(concentrations); - - MatrixXd alphax = MatrixXd::Constant(rows, cols, 1.25); - MatrixXd alphay = MatrixXd::Constant(rows, cols, 1.1); - alphax.block(0, 0, 100, cols) = MatrixXd::Constant(100, cols, 0.5); - alphax.block(100, 0, 100, cols) = MatrixXd::Constant(100, cols, 0.8); - alphay.block(0, 0, rows, 200) = MatrixXd::Constant(rows, 200, 0.6); - alphay.block(0, 200, rows, 200) = MatrixXd::Constant(rows, 200, 0.9); - grid.setAlpha(alphax, alphay); - - // **** BOUNDARY **** - Boundary bc = Boundary(grid); - bc.setBoundarySideClosed(BC_SIDE_LEFT); - bc.setBoundarySideClosed(BC_SIDE_RIGHT); - bc.setBoundarySideClosed(BC_SIDE_TOP); - bc.setBoundarySideClosed(BC_SIDE_BOTTOM); - - // **** SIMULATION **** - Simulation simulation = Simulation(grid, bc); - simulation.setTimestep(0.01); - simulation.setIterations(100); - simulation.setOutputCSV(CSV_OUTPUT_ON); - simulation.setOutputConsole(CONSOLE_OUTPUT_OFF); - - // **** RUN SIMULATION **** - auto start = high_resolution_clock::now(); - simulation.run(); - auto stop = high_resolution_clock::now(); - - auto duration = duration_cast(stop - start); - std::cout << duration.count() << std::endl; -} diff --git a/julia/tests/cpp_bench/BTCS_1_20_100.cpp b/julia/tests/cpp_bench/BTCS_1_20_100.cpp deleted file mode 100644 index 33d1a07..0000000 --- a/julia/tests/cpp_bench/BTCS_1_20_100.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -#include -#include - -using namespace Eigen; -using namespace tug; -using namespace std::chrono; - -int main(int argc, char *argv[]) -{ - // **** GRID **** - int cells = 20; - Grid64 grid(cells); - - MatrixXd concentrations = MatrixXd::Constant(1, cells, 0); - concentrations(0, 0) = 2000; - grid.setConcentrations(concentrations); - - MatrixXd alpha = MatrixXd::Constant(1, cells, 1); - grid.setAlpha(alpha); - - // **** BOUNDARY **** - Boundary bc = Boundary(grid); - bc.setBoundarySideConstant(BC_SIDE_LEFT, 0); - bc.setBoundarySideConstant(BC_SIDE_RIGHT, 0); - - // **** SIMULATION **** - Simulation simulation = Simulation(grid, bc); - simulation.setTimestep(0.1); - simulation.setIterations(100); - simulation.setOutputCSV(CSV_OUTPUT_ON); - simulation.setOutputConsole(CONSOLE_OUTPUT_OFF); - - // **** RUN SIMULATION **** - auto start = high_resolution_clock::now(); - simulation.run(); - auto stop = high_resolution_clock::now(); - - auto duration = duration_cast(stop - start); - std::cout << duration.count() << std::endl; -} diff --git a/julia/tests/cpp_bench/BTCS_1_45_75000.cpp b/julia/tests/cpp_bench/BTCS_1_45_75000.cpp deleted file mode 100644 index 1657299..0000000 --- a/julia/tests/cpp_bench/BTCS_1_45_75000.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include -#include - -using namespace Eigen; -using namespace tug; -using namespace std::chrono; - -int main(int argc, char *argv[]) -{ - // **** GRID **** - int cells = 45; - Grid64 grid(cells); - - MatrixXd concentrations = MatrixXd::Constant(1, cells, 10); - concentrations(0, 5) = 2000; - grid.setConcentrations(concentrations); - - MatrixXd alpha = MatrixXd::Constant(1, cells, 1); - alpha.block(0, 0, 1, 15) = MatrixXd::Constant(1, 15, 0.5); - alpha.block(0, 30, 1, 15) = MatrixXd::Constant(1, 15, 1.5); - grid.setAlpha(alpha); - - // **** BOUNDARY **** - Boundary bc = Boundary(grid); - bc.setBoundarySideClosed(BC_SIDE_LEFT); - bc.setBoundarySideClosed(BC_SIDE_RIGHT); - - // **** SIMULATION **** - Simulation simulation = Simulation(grid, bc); - simulation.setTimestep(1.23); - simulation.setIterations(75000); - simulation.setOutputCSV(CSV_OUTPUT_ON); - simulation.setOutputConsole(CONSOLE_OUTPUT_OFF); - - // **** RUN SIMULATION **** - auto start = high_resolution_clock::now(); - simulation.run(); - auto stop = high_resolution_clock::now(); - - auto duration = duration_cast(stop - start); - std::cout << duration.count() << std::endl; -} diff --git a/julia/tests/cpp_bench/BTCS_2027_1999_200.cpp b/julia/tests/cpp_bench/BTCS_2027_1999_200.cpp deleted file mode 100644 index 34fb92e..0000000 --- a/julia/tests/cpp_bench/BTCS_2027_1999_200.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#include -#include -#include - -using namespace Eigen; -using namespace tug; -using namespace std::chrono; - -int main(int argc, char *argv[]) -{ - // **** GRID **** - int rows = 2027; - int cols = 1999; - Grid64 grid(rows, cols); - - MatrixXd concentrations(rows, cols); - for (int i = 0; i < rows; ++i) - { - for (int j = 0; j < cols; ++j) - { - concentrations(i, j) = static_cast((i + 1) * (j + 1)) / 1e2; - } - } - concentrations(10, 10) = 15000; - concentrations(2020, 1994) = 7500; - concentrations(10, 1994) = 7500; - concentrations(2020, 10) = 7500; - grid.setConcentrations(concentrations); - - // Complex alpha patterns - MatrixXd alphax = MatrixXd(rows, cols); - MatrixXd alphay = MatrixXd(rows, cols); - for (int i = 0; i < rows; ++i) - { - for (int j = 0; j < cols; ++j) - { - alphax(i, j) = std::sin((i + 1) / 100.0) * std::cos((j + 1) / 100.0); - alphay(i, j) = std::cos((i + 1) / 100.0) * std::sin((j + 1) / 100.0); - } - } - grid.setAlpha(alphax, alphay); - - // **** BOUNDARY **** - Boundary bc = Boundary(grid); - bc.setBoundarySideClosed(BC_SIDE_LEFT); - bc.setBoundarySideConstant(BC_SIDE_RIGHT, 1.5); - bc.setBoundarySideClosed(BC_SIDE_TOP); - bc.setBoundarySideConstant(BC_SIDE_BOTTOM, 0.75); - - // **** SIMULATION **** - Simulation simulation = Simulation(grid, bc); - simulation.setTimestep(0.005); - simulation.setIterations(200); - simulation.setOutputCSV(CSV_OUTPUT_ON); - simulation.setOutputConsole(CONSOLE_OUTPUT_OFF); - - // **** RUN SIMULATION **** - auto start = high_resolution_clock::now(); - simulation.run(); - auto stop = high_resolution_clock::now(); - - auto duration = duration_cast(stop - start); - std::cout << duration.count() << std::endl; -} diff --git a/julia/tests/cpp_bench/BTCS_20_20_500.cpp b/julia/tests/cpp_bench/BTCS_20_20_500.cpp deleted file mode 100644 index 9df10b8..0000000 --- a/julia/tests/cpp_bench/BTCS_20_20_500.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include -#include - -using namespace Eigen; -using namespace tug; -using namespace std::chrono; - -int main(int argc, char *argv[]) -{ - // **** GRID **** - int rows = 20; - int cols = 20; - Grid64 grid(rows, cols); - - MatrixXd concentrations = MatrixXd::Constant(rows, cols, 0); - concentrations(10, 10) = 2000; - grid.setConcentrations(concentrations); - - MatrixXd alphax = MatrixXd::Constant(rows, cols, 1); - MatrixXd alphay = MatrixXd::Constant(rows, cols, 1); - grid.setAlpha(alphax, alphay); - - // **** BOUNDARY **** - Boundary bc = Boundary(grid); - bc.setBoundarySideClosed(BC_SIDE_LEFT); - bc.setBoundarySideClosed(BC_SIDE_RIGHT); - bc.setBoundarySideClosed(BC_SIDE_TOP); - bc.setBoundarySideClosed(BC_SIDE_BOTTOM); - - // **** SIMULATION **** - Simulation simulation = Simulation(grid, bc); - simulation.setTimestep(0.1); - simulation.setIterations(500); - simulation.setOutputCSV(CSV_OUTPUT_ON); - simulation.setOutputConsole(CONSOLE_OUTPUT_OFF); - - // **** RUN SIMULATION **** - auto start = high_resolution_clock::now(); - simulation.run(); - auto stop = high_resolution_clock::now(); - - auto duration = duration_cast(stop - start); - std::cout << duration.count() << std::endl; -} diff --git a/julia/tests/cpp_bench/BTCS_450_670_750.cpp b/julia/tests/cpp_bench/BTCS_450_670_750.cpp deleted file mode 100644 index 2ffb814..0000000 --- a/julia/tests/cpp_bench/BTCS_450_670_750.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include -#include - -using namespace Eigen; -using namespace tug; -using namespace std::chrono; - -int main(int argc, char *argv[]) -{ - // **** GRID **** - int rows = 450; - int cols = 670; - Grid64 grid(rows, cols); - - MatrixXd concentrations = MatrixXd::Constant(rows, cols, 0); - concentrations(10, 10) = 1500; - concentrations(440, 660) = 750; - concentrations(440, 10) = 750; - concentrations(10, 660) = 750; - concentrations(220, 335) = 1500; - grid.setConcentrations(concentrations); - - MatrixXd alphax = MatrixXd::Constant(rows, cols, 1); - MatrixXd alphay = MatrixXd::Constant(rows, cols, 1); - alphax.block(0, 0, 100, cols) = MatrixXd::Constant(100, cols, 0.5); - alphax.block(100, 0, 100, cols) = MatrixXd::Constant(100, cols, 0.8); - alphay.block(0, 0, rows, 200) = MatrixXd::Constant(rows, 200, 0.6); - alphay.block(0, 200, rows, 200) = MatrixXd::Constant(rows, 200, 0.9); - grid.setAlpha(alphax, alphay); - - // **** BOUNDARY **** - Boundary bc = Boundary(grid); - bc.setBoundarySideClosed(BC_SIDE_LEFT); - bc.setBoundarySideClosed(BC_SIDE_RIGHT); - bc.setBoundarySideClosed(BC_SIDE_TOP); - bc.setBoundarySideClosed(BC_SIDE_BOTTOM); - - // **** SIMULATION **** - Simulation simulation = Simulation(grid, bc); - simulation.setTimestep(0.2); - simulation.setIterations(750); - simulation.setOutputCSV(CSV_OUTPUT_ON); - simulation.setOutputConsole(CONSOLE_OUTPUT_OFF); - - // **** RUN SIMULATION **** - auto start = high_resolution_clock::now(); - simulation.run(); - auto stop = high_resolution_clock::now(); - - auto duration = duration_cast(stop - start); - std::cout << duration.count() << std::endl; -} diff --git a/julia/tests/cpp_bench/FTCS_1024_1000_100.cpp b/julia/tests/cpp_bench/FTCS_1024_1000_100.cpp deleted file mode 100644 index dd7f14c..0000000 --- a/julia/tests/cpp_bench/FTCS_1024_1000_100.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include -#include - -using namespace Eigen; -using namespace tug; -using namespace std::chrono; - -int main(int argc, char *argv[]) -{ - // **** GRID **** - int rows = 1024; - int cols = 1000; - Grid64 grid(rows, cols); - - MatrixXd concentrations = MatrixXd::Constant(rows, cols, 0.5); - concentrations(10, 10) = 15000; - concentrations(1014, 990) = 7500; - concentrations(10, 990) = 7500; - concentrations(1014, 10) = 7500; - grid.setConcentrations(concentrations); - - MatrixXd alphax = MatrixXd::Constant(rows, cols, 1.25); - MatrixXd alphay = MatrixXd::Constant(rows, cols, 1.1); - alphax.block(0, 0, 100, cols) = MatrixXd::Constant(100, cols, 0.5); - alphax.block(100, 0, 100, cols) = MatrixXd::Constant(100, cols, 0.8); - alphay.block(0, 0, rows, 200) = MatrixXd::Constant(rows, 200, 0.6); - alphay.block(0, 200, rows, 200) = MatrixXd::Constant(rows, 200, 0.9); - grid.setAlpha(alphax, alphay); - - // **** BOUNDARY **** - Boundary bc = Boundary(grid); - bc.setBoundarySideClosed(BC_SIDE_LEFT); - bc.setBoundarySideClosed(BC_SIDE_RIGHT); - bc.setBoundarySideClosed(BC_SIDE_TOP); - bc.setBoundarySideClosed(BC_SIDE_BOTTOM); - - // **** SIMULATION **** - Simulation simulation = Simulation(grid, bc); - simulation.setTimestep(0.01); - simulation.setIterations(100); - simulation.setOutputCSV(CSV_OUTPUT_ON); - simulation.setOutputConsole(CONSOLE_OUTPUT_OFF); - - // **** RUN SIMULATION **** - auto start = high_resolution_clock::now(); - simulation.run(); - auto stop = high_resolution_clock::now(); - - auto duration = duration_cast(stop - start); - std::cout << duration.count() << std::endl; -} diff --git a/julia/tests/cpp_bench/FTCS_1_20_7000.cpp b/julia/tests/cpp_bench/FTCS_1_20_7000.cpp deleted file mode 100644 index 52b9951..0000000 --- a/julia/tests/cpp_bench/FTCS_1_20_7000.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -#include -#include - -using namespace Eigen; -using namespace tug; -using namespace std::chrono; - -int main(int argc, char *argv[]) -{ - // **** GRID **** - int cells = 20; - Grid64 grid(cells); - - MatrixXd concentrations = MatrixXd::Constant(1, cells, 0); - concentrations(0, 0) = 2000; - grid.setConcentrations(concentrations); - - MatrixXd alpha = MatrixXd::Constant(1, cells, 1); - grid.setAlpha(alpha); - - // **** BOUNDARY **** - Boundary bc = Boundary(grid); - bc.setBoundarySideConstant(BC_SIDE_LEFT, 0); - bc.setBoundarySideConstant(BC_SIDE_RIGHT, 0); - - // **** SIMULATION **** - Simulation simulation = Simulation(grid, bc); - simulation.setTimestep(0.001); - simulation.setIterations(7000); - simulation.setOutputCSV(CSV_OUTPUT_ON); - simulation.setOutputConsole(CONSOLE_OUTPUT_OFF); - - // **** RUN SIMULATION **** - auto start = high_resolution_clock::now(); - simulation.run(); - auto stop = high_resolution_clock::now(); - - auto duration = duration_cast(stop - start); - std::cout << duration.count() << std::endl; -} diff --git a/julia/tests/cpp_bench/FTCS_2000_2000_500.cpp b/julia/tests/cpp_bench/FTCS_2000_2000_500.cpp deleted file mode 100644 index cbae4e2..0000000 --- a/julia/tests/cpp_bench/FTCS_2000_2000_500.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include -#include -#include - -using namespace Eigen; -using namespace tug; -using namespace std::chrono; - -int main(int argc, char *argv[]) -{ - // **** GRID **** - int rows = 2000; - int cols = 2000; - Grid64 grid(rows, cols); - - MatrixXd concentrations(rows, cols); - for (int i = 0; i < rows; ++i) - { - for (int j = 0; j < cols; ++j) - { - concentrations(i, j) = static_cast(((i + 1) * (j + 1)) / 1e6); - } - } - concentrations(1000, 1000) = 2000; - grid.setConcentrations(concentrations); - - // Complex alpha patterns - MatrixXd alphax = MatrixXd(rows, cols); - MatrixXd alphay = MatrixXd(rows, cols); - for (int i = 0; i < rows; ++i) - { - for (int j = 0; j < cols; ++j) - { - alphax(i, j) = std::sin((i + 1) / 100.0) * std::cos((j + 1) / 100.0) + 1; - alphay(i, j) = std::cos((i + 1) / 100.0) * std::sin((j + 1) / 100.0) + 1; - } - } - grid.setAlpha(alphax, alphay); - - // **** BOUNDARY **** - Boundary bc = Boundary(grid); - bc.setBoundarySideClosed(BC_SIDE_LEFT); - bc.setBoundarySideClosed(BC_SIDE_RIGHT); - bc.setBoundarySideClosed(BC_SIDE_TOP); - bc.setBoundarySideConstant(BC_SIDE_BOTTOM, 0.75); - - // **** SIMULATION **** - Simulation simulation = Simulation(grid, bc); - simulation.setTimestep(0.005); - simulation.setIterations(500); - simulation.setOutputCSV(CSV_OUTPUT_ON); - simulation.setOutputConsole(CONSOLE_OUTPUT_OFF); - - // **** RUN SIMULATION **** - auto start = high_resolution_clock::now(); - simulation.run(); - auto stop = high_resolution_clock::now(); - - auto duration = duration_cast(stop - start); - std::cout << duration.count() << std::endl; -} diff --git a/julia/tests/cpp_bench/FTCS_20_20_500.cpp b/julia/tests/cpp_bench/FTCS_20_20_500.cpp deleted file mode 100644 index e766801..0000000 --- a/julia/tests/cpp_bench/FTCS_20_20_500.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include -#include - -using namespace Eigen; -using namespace tug; -using namespace std::chrono; - -int main(int argc, char *argv[]) -{ - // **** GRID **** - int rows = 20; - int cols = 20; - Grid64 grid(rows, cols); - - MatrixXd concentrations = MatrixXd::Constant(rows, cols, 0); - concentrations(10, 10) = 2000; - grid.setConcentrations(concentrations); - - MatrixXd alphax = MatrixXd::Constant(rows, cols, 1); - MatrixXd alphay = MatrixXd::Constant(rows, cols, 1); - grid.setAlpha(alphax, alphay); - - // **** BOUNDARY **** - Boundary bc = Boundary(grid); - bc.setBoundarySideClosed(BC_SIDE_LEFT); - bc.setBoundarySideClosed(BC_SIDE_RIGHT); - bc.setBoundarySideClosed(BC_SIDE_TOP); - bc.setBoundarySideClosed(BC_SIDE_BOTTOM); - - // **** SIMULATION **** - Simulation simulation = Simulation(grid, bc); - simulation.setTimestep(0.1); - simulation.setIterations(500); - simulation.setOutputCSV(CSV_OUTPUT_ON); - simulation.setOutputConsole(CONSOLE_OUTPUT_OFF); - - // **** RUN SIMULATION **** - auto start = high_resolution_clock::now(); - simulation.run(); - auto stop = high_resolution_clock::now(); - - auto duration = duration_cast(stop - start); - std::cout << duration.count() << std::endl; -} diff --git a/julia/tests/cpp_bench/FTCS_450_670_750.cpp b/julia/tests/cpp_bench/FTCS_450_670_750.cpp deleted file mode 100644 index 734268e..0000000 --- a/julia/tests/cpp_bench/FTCS_450_670_750.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include -#include - -using namespace Eigen; -using namespace tug; -using namespace std::chrono; - -int main(int argc, char *argv[]) -{ - // **** GRID **** - int rows = 450; - int cols = 670; - Grid64 grid(rows, cols); - - MatrixXd concentrations = MatrixXd::Constant(rows, cols, 0); - concentrations(10, 10) = 1500; - concentrations(440, 660) = 750; - concentrations(440, 10) = 750; - concentrations(10, 660) = 750; - concentrations(220, 335) = 1500; - grid.setConcentrations(concentrations); - - MatrixXd alphax = MatrixXd::Constant(rows, cols, 1); - MatrixXd alphay = MatrixXd::Constant(rows, cols, 1); - alphax.block(0, 0, 100, cols) = MatrixXd::Constant(100, cols, 0.5); - alphax.block(100, 0, 100, cols) = MatrixXd::Constant(100, cols, 0.8); - alphay.block(0, 0, rows, 200) = MatrixXd::Constant(rows, 200, 0.6); - alphay.block(0, 200, rows, 200) = MatrixXd::Constant(rows, 200, 0.9); - grid.setAlpha(alphax, alphay); - - // **** BOUNDARY **** - Boundary bc = Boundary(grid); - bc.setBoundarySideClosed(BC_SIDE_LEFT); - bc.setBoundarySideClosed(BC_SIDE_RIGHT); - bc.setBoundarySideClosed(BC_SIDE_TOP); - bc.setBoundarySideClosed(BC_SIDE_BOTTOM); - - // **** SIMULATION **** - Simulation simulation = Simulation(grid, bc); - simulation.setTimestep(0.2); - simulation.setIterations(750); - simulation.setOutputCSV(CSV_OUTPUT_ON); - simulation.setOutputConsole(CONSOLE_OUTPUT_OFF); - - // **** RUN SIMULATION **** - auto start = high_resolution_clock::now(); - simulation.run(); - auto stop = high_resolution_clock::now(); - - auto duration = duration_cast(stop - start); - std::cout << duration.count() << std::endl; -} diff --git a/julia/tests/cpp_bench/FTCS_500_500_300.cpp b/julia/tests/cpp_bench/FTCS_500_500_300.cpp deleted file mode 100644 index 443800a..0000000 --- a/julia/tests/cpp_bench/FTCS_500_500_300.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include -#include - -using namespace Eigen; -using namespace tug; -using namespace std::chrono; - -int main(int argc, char *argv[]) -{ - // **** GRID **** - int rows = 500; - int cols = 500; - Grid64 grid(rows, cols); - - MatrixXd concentrations = MatrixXd::Constant(rows, cols, 0); - concentrations.block(50, 50, 100, 100) = MatrixXd::Constant(100, 100, 1500); - concentrations.block(350, 350, 100, 100) = MatrixXd::Constant(100, 100, 1200); - concentrations(250, 250) = 2000; - grid.setConcentrations(concentrations); - - MatrixXd alphax = MatrixXd::Constant(rows, cols, 0.7); - MatrixXd alphay = MatrixXd::Constant(rows, cols, 0.7); - alphax.block(200, 200, 100, 100) = MatrixXd::Constant(100, 100, 0.4); - alphay.block(200, 200, 100, 100) = MatrixXd::Constant(100, 100, 0.4); - grid.setAlpha(alphax, alphay); - - // **** BOUNDARY **** - Boundary bc = Boundary(grid); - bc.setBoundarySideClosed(BC_SIDE_LEFT); - bc.setBoundarySideClosed(BC_SIDE_RIGHT); - bc.setBoundarySideClosed(BC_SIDE_TOP); - bc.setBoundarySideClosed(BC_SIDE_BOTTOM); - - // **** SIMULATION **** - Simulation simulation = Simulation(grid, bc); - simulation.setTimestep(2.5); - simulation.setIterations(300); - simulation.setOutputCSV(CSV_OUTPUT_ON); - simulation.setOutputConsole(CONSOLE_OUTPUT_OFF); - - // **** RUN SIMULATION **** - auto start = high_resolution_clock::now(); - simulation.run(); - auto stop = high_resolution_clock::now(); - - auto duration = duration_cast(stop - start); - std::cout << "Simulation Time (nanoseconds): " << duration.count() << std::endl; -} diff --git a/julia/tests/julia_bench/BTCS_100_100_1000.jl b/julia/tests/julia_bench/BTCS_100_100_1000.jl deleted file mode 100644 index 9bc9884..0000000 --- a/julia/tests/julia_bench/BTCS_100_100_1000.jl +++ /dev/null @@ -1,36 +0,0 @@ -include("../../TUG/src/TUG.jl") -using .TUG - -function main() - # **** GRID **** - rows::Int = 100 - cols::Int = 100 - - alphaX = fill(1.0, rows, cols) - alphaY = fill(1.0, rows, cols) - grid::Grid = Grid{Float64}(rows, cols, alphaX, alphaY) - - concentrations = fill(0.0, rows, cols) - concentrations[11, 11] = 2000 - concentrations[91, 91] = 2000 - setConcentrations!(grid, concentrations) - - # **** BOUNDARY **** - bc::Boundary = Boundary(grid) - setBoundarySideConstant!(bc, LEFT, 1.0) - setBoundarySideConstant!(bc, RIGHT, 1.0) - setBoundarySideConstant!(bc, TOP, 0.0) - setBoundarySideConstant!(bc, BOTTOM, 2.0) - - # **** SIMULATION **** - simulation::Simulation = Simulation(grid, bc) - simulation = setTimestep(simulation, 0.05) - simulation = setIterations(simulation, 1000) - simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF) - simulation = setOutputCSV(simulation, CSV_OUTPUT_ON) - - # **** RUN SIMULATION **** - print((@elapsed TUG.run(simulation)) * 1e9) -end - -main() diff --git a/julia/tests/julia_bench/BTCS_1024_1000_100.jl b/julia/tests/julia_bench/BTCS_1024_1000_100.jl deleted file mode 100644 index 2759526..0000000 --- a/julia/tests/julia_bench/BTCS_1024_1000_100.jl +++ /dev/null @@ -1,42 +0,0 @@ -include("../../TUG/src/TUG.jl") -using .TUG - -function main() - # **** GRID **** - rows::Int = 1024 - cols::Int = 1000 - - alphaX = fill(1.25, rows, cols) - alphaY = fill(1.1, rows, cols) - alphaX[1:100, :] .= 0.5 - alphaX[101:200, :] .= 0.8 - alphaY[:, 1:200] .= 0.6 - alphaY[:, 201:400] .= 0.9 - grid::Grid = Grid{Float64}(rows, cols, alphaX, alphaY) - - concentrations = fill(0.5, rows, cols) - concentrations[11, 11] = 15000 - concentrations[1015, 991] = 7500 - concentrations[11, 991] = 7500 - concentrations[1015, 11] = 7500 - setConcentrations!(grid, concentrations) - - # **** BOUNDARY **** - bc::Boundary = Boundary(grid) - setBoundarySideClosed!(bc, LEFT) - setBoundarySideClosed!(bc, RIGHT) - setBoundarySideClosed!(bc, TOP) - setBoundarySideClosed!(bc, BOTTOM) - - # **** SIMULATION **** - simulation::Simulation = Simulation(grid, bc) - simulation = setTimestep(simulation, 0.01) - simulation = setIterations(simulation, 100) - simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF) - simulation = setOutputCSV(simulation, CSV_OUTPUT_ON) - - # **** RUN SIMULATION **** - print((@elapsed TUG.run(simulation)) * 1e9) -end - -main() diff --git a/julia/tests/julia_bench/BTCS_1_20_100.jl b/julia/tests/julia_bench/BTCS_1_20_100.jl deleted file mode 100644 index 1036ad6..0000000 --- a/julia/tests/julia_bench/BTCS_1_20_100.jl +++ /dev/null @@ -1,31 +0,0 @@ -include("../../TUG/src/TUG.jl") -using .TUG - -function main() - # **** GRID **** - cells::Int = 20 - - alpha = fill(1.0, 1, cells) - grid::Grid = Grid{Float64}(cells, alpha) - - concentrations = fill(0.0, 1, cells) - concentrations[1] = 2000 - setConcentrations!(grid, concentrations) - - # **** BOUNDARY **** - bc::Boundary = Boundary(grid) - setBoundarySideConstant!(bc, LEFT, 0.0) - setBoundarySideConstant!(bc, RIGHT, 0.0) - - # **** SIMULATION **** - simulation::Simulation = Simulation(grid, bc) - simulation = setTimestep(simulation, 0.1) - simulation = setIterations(simulation, 100) - simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF) - simulation = setOutputCSV(simulation, CSV_OUTPUT_ON) - - # **** RUN SIMULATION **** - print((@elapsed TUG.run(simulation)) * 1e9) -end - -main() diff --git a/julia/tests/julia_bench/BTCS_1_45_75000.jl b/julia/tests/julia_bench/BTCS_1_45_75000.jl deleted file mode 100644 index 2981ad8..0000000 --- a/julia/tests/julia_bench/BTCS_1_45_75000.jl +++ /dev/null @@ -1,33 +0,0 @@ -include("../../TUG/src/TUG.jl") -using .TUG - -function main() - # **** GRID **** - cells::Int = 45 - - alpha = fill(1.0, 1, cells) - alpha[1:15] .= 0.5 - alpha[31:45] .= 1.5 - grid::Grid = Grid{Float64}(cells, alpha) - - concentrations = fill(10.0, 1, cells) - concentrations[6] = 2000 - setConcentrations!(grid, concentrations) - - # **** BOUNDARY **** - bc::Boundary = Boundary(grid) - setBoundarySideClosed!(bc, LEFT) - setBoundarySideClosed!(bc, RIGHT) - - # **** SIMULATION **** - simulation::Simulation = Simulation(grid, bc) - simulation = setTimestep(simulation, 1.23) - simulation = setIterations(simulation, 75000) - simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF) - simulation = setOutputCSV(simulation, CSV_OUTPUT_ON) - - # **** RUN SIMULATION **** - print((@elapsed TUG.run(simulation)) * 1e9) -end - -main() diff --git a/julia/tests/julia_bench/BTCS_2027_1999_200.jl b/julia/tests/julia_bench/BTCS_2027_1999_200.jl deleted file mode 100644 index 52a2cf7..0000000 --- a/julia/tests/julia_bench/BTCS_2027_1999_200.jl +++ /dev/null @@ -1,39 +0,0 @@ -include("../../TUG/src/TUG.jl") -using .TUG - -function main() - # **** GRID **** - rows::Int = 2027 - cols::Int = 1999 - - alphaX = [sin(i / 100) * cos(j / 100) for i in 1:rows, j in 1:cols] - alphaY = [cos(i / 100) * sin(j / 100) for i in 1:rows, j in 1:cols] - - grid::Grid = Grid{Float64}(rows, cols, alphaX, alphaY) - - concentrations = [i * j / 1e2 for i in 1:rows, j in 1:cols] - concentrations[11, 11] = 15000 - concentrations[2021, 1995] = 7500 - concentrations[11, 1995] = 7500 - concentrations[2021, 11] = 7500 - setConcentrations!(grid, concentrations) - - # **** BOUNDARY **** - bc::Boundary = Boundary(grid) - setBoundarySideClosed!(bc, LEFT) - setBoundarySideConstant!(bc, RIGHT, 1.5) - setBoundarySideClosed!(bc, TOP) - setBoundarySideConstant!(bc, BOTTOM, 0.75) - - # **** SIMULATION **** - simulation::Simulation = Simulation(grid, bc) - simulation = setTimestep(simulation, 0.005) - simulation = setIterations(simulation, 200) - simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF) - simulation = setOutputCSV(simulation, CSV_OUTPUT_ON) - - # **** RUN SIMULATION **** - print((@elapsed TUG.run(simulation)) * 1e9) -end - -main() diff --git a/julia/tests/julia_bench/BTCS_20_20_500.jl b/julia/tests/julia_bench/BTCS_20_20_500.jl deleted file mode 100644 index 248f9af..0000000 --- a/julia/tests/julia_bench/BTCS_20_20_500.jl +++ /dev/null @@ -1,35 +0,0 @@ -include("../../TUG/src/TUG.jl") -using .TUG - -function main() - # **** GRID **** - rows::Int = 20 - cols::Int = 20 - - alphaX = fill(1.0, rows, cols) - alphaY = fill(1.0, rows, cols) - grid::Grid = Grid{Float64}(rows, cols, alphaX, alphaY) - - concentrations = fill(0.0, rows, cols) - concentrations[11, 11] = 2000 - setConcentrations!(grid, concentrations) - - # **** BOUNDARY **** - bc::Boundary = Boundary(grid) - setBoundarySideClosed!(bc, LEFT) - setBoundarySideClosed!(bc, RIGHT) - setBoundarySideClosed!(bc, TOP) - setBoundarySideClosed!(bc, BOTTOM) - - # **** SIMULATION **** - simulation::Simulation = Simulation(grid, bc) - simulation = setTimestep(simulation, 0.1) - simulation = setIterations(simulation, 500) - simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF) - simulation = setOutputCSV(simulation, CSV_OUTPUT_ON) - - # **** RUN SIMULATION **** - print((@elapsed TUG.run(simulation)) * 1e9) -end - -main() diff --git a/julia/tests/julia_bench/BTCS_450_670_750.jl b/julia/tests/julia_bench/BTCS_450_670_750.jl deleted file mode 100644 index d6f58df..0000000 --- a/julia/tests/julia_bench/BTCS_450_670_750.jl +++ /dev/null @@ -1,43 +0,0 @@ -include("../../TUG/src/TUG.jl") -using .TUG - -function main() - # **** GRID **** - rows::Int = 450 - cols::Int = 670 - - alphaX = fill(1.0, rows, cols) - alphaY = fill(1.0, rows, cols) - alphaX[1:100, :] .= 0.5 - alphaX[101:200, :] .= 0.8 - alphaY[:, 1:200] .= 0.6 - alphaY[:, 201:400] .= 0.9 - grid::Grid = Grid{Float64}(rows, cols, alphaX, alphaY) - - concentrations = fill(0.0, rows, cols) - concentrations[11, 11] = 1500 - concentrations[441, 661] = 750 - concentrations[441, 11] = 750 - concentrations[11, 661] = 750 - concentrations[221, 336] = 1500 - setConcentrations!(grid, concentrations) - - # **** BOUNDARY **** - bc::Boundary = Boundary(grid) - setBoundarySideClosed!(bc, LEFT) - setBoundarySideClosed!(bc, RIGHT) - setBoundarySideClosed!(bc, TOP) - setBoundarySideClosed!(bc, BOTTOM) - - # **** SIMULATION **** - simulation::Simulation = Simulation(grid, bc) - simulation = setTimestep(simulation, 0.2) - simulation = setIterations(simulation, 750) - simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF) - simulation = setOutputCSV(simulation, CSV_OUTPUT_ON) - - # **** RUN SIMULATION **** - print((@elapsed TUG.run(simulation)) * 1e9) -end - -main() diff --git a/julia/tests/julia_bench/FTCS_1024_1000_100.jl b/julia/tests/julia_bench/FTCS_1024_1000_100.jl deleted file mode 100644 index 5d79d1a..0000000 --- a/julia/tests/julia_bench/FTCS_1024_1000_100.jl +++ /dev/null @@ -1,42 +0,0 @@ -include("../../TUG/src/TUG.jl") -using .TUG - -function main() - # **** GRID **** - rows::Int = 1024 - cols::Int = 1000 - - alphaX = fill(1.25, rows, cols) - alphaY = fill(1.1, rows, cols) - alphaX[1:100, :] .= 0.5 - alphaX[101:200, :] .= 0.8 - alphaY[:, 1:200] .= 0.6 - alphaY[:, 201:400] .= 0.9 - grid::Grid = Grid{Float64}(rows, cols, alphaX, alphaY) - - concentrations = fill(0.5, rows, cols) - concentrations[11, 11] = 15000 - concentrations[1015, 991] = 7500 - concentrations[11, 991] = 7500 - concentrations[1015, 11] = 7500 - setConcentrations!(grid, concentrations) - - # **** BOUNDARY **** - bc::Boundary = Boundary(grid) - setBoundarySideClosed!(bc, LEFT) - setBoundarySideClosed!(bc, RIGHT) - setBoundarySideClosed!(bc, TOP) - setBoundarySideClosed!(bc, BOTTOM) - - # **** SIMULATION **** - simulation::Simulation = Simulation(grid, bc, FTCS) - simulation = setTimestep(simulation, 0.01) - simulation = setIterations(simulation, 100) - simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF) - simulation = setOutputCSV(simulation, CSV_OUTPUT_ON) - - # **** RUN SIMULATION **** - print((@elapsed TUG.run(simulation)) * 1e9) -end - -main() diff --git a/julia/tests/julia_bench/FTCS_1_20_7000.jl b/julia/tests/julia_bench/FTCS_1_20_7000.jl deleted file mode 100644 index 298198a..0000000 --- a/julia/tests/julia_bench/FTCS_1_20_7000.jl +++ /dev/null @@ -1,31 +0,0 @@ -include("../../TUG/src/TUG.jl") -using .TUG - -function main() - # **** GRID **** - cells::Int = 20 - - alpha = fill(1.0, 1, cells) - grid::Grid = Grid{Float64}(cells, alpha) - - concentrations = fill(0.0, 1, cells) - concentrations[1] = 2000 - setConcentrations!(grid, concentrations) - - # **** BOUNDARY **** - bc::Boundary = Boundary(grid) - setBoundarySideConstant!(bc, LEFT, 0.0) - setBoundarySideConstant!(bc, RIGHT, 0.0) - - # **** SIMULATION **** - simulation::Simulation = Simulation(grid, bc, FTCS) - simulation = setTimestep(simulation, 0.001) - simulation = setIterations(simulation, 7000) - simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF) - simulation = setOutputCSV(simulation, CSV_OUTPUT_ON) - - # **** RUN SIMULATION **** - print((@elapsed TUG.run(simulation)) * 1e9) -end - -main() diff --git a/julia/tests/julia_bench/FTCS_2000_2000_500.jl b/julia/tests/julia_bench/FTCS_2000_2000_500.jl deleted file mode 100644 index df87811..0000000 --- a/julia/tests/julia_bench/FTCS_2000_2000_500.jl +++ /dev/null @@ -1,36 +0,0 @@ -include("../../TUG/src/TUG.jl") -using .TUG - -function main() - # **** GRID **** - rows::Int = 2000 - cols::Int = 2000 - - alphaX = [sin(i / 100) * cos(j / 100) + 1 for i in 1:rows, j in 1:cols] - alphaY = [cos(i / 100) * sin(j / 100) + 1 for i in 1:rows, j in 1:cols] - - grid::Grid = Grid{Float64}(rows, cols, alphaX, alphaY) - - concentrations = [(i * j) / 1e6 for i in 1:rows, j in 1:cols] - concentrations[1001, 1001] = 2000 - setConcentrations!(grid, concentrations) - - # **** BOUNDARY **** - bc::Boundary = Boundary(grid) - setBoundarySideClosed!(bc, LEFT) - setBoundarySideClosed!(bc, RIGHT) - setBoundarySideClosed!(bc, TOP) - setBoundarySideConstant!(bc, BOTTOM, 0.75) - - # **** SIMULATION **** - simulation::Simulation = Simulation(grid, bc, FTCS) - simulation = setTimestep(simulation, 0.005) - simulation = setIterations(simulation, 500) - simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF) - simulation = setOutputCSV(simulation, CSV_OUTPUT_ON) - - # **** RUN SIMULATION **** - print((@elapsed TUG.run(simulation)) * 1e9) -end - -main() diff --git a/julia/tests/julia_bench/FTCS_20_20_500.jl b/julia/tests/julia_bench/FTCS_20_20_500.jl deleted file mode 100644 index 5742d21..0000000 --- a/julia/tests/julia_bench/FTCS_20_20_500.jl +++ /dev/null @@ -1,35 +0,0 @@ -include("../../TUG/src/TUG.jl") -using .TUG - -function main() - # **** GRID **** - rows::Int = 20 - cols::Int = 20 - - alphaX = fill(1.0, rows, cols) - alphaY = fill(1.0, rows, cols) - grid::Grid = Grid{Float64}(rows, cols, alphaX, alphaY) - - concentrations = fill(0.0, rows, cols) - concentrations[11, 11] = 2000 - setConcentrations!(grid, concentrations) - - # **** BOUNDARY **** - bc::Boundary = Boundary(grid) - setBoundarySideClosed!(bc, LEFT) - setBoundarySideClosed!(bc, RIGHT) - setBoundarySideClosed!(bc, TOP) - setBoundarySideClosed!(bc, BOTTOM) - - # **** SIMULATION **** - simulation::Simulation = Simulation(grid, bc, FTCS) - simulation = setTimestep(simulation, 0.1) - simulation = setIterations(simulation, 500) - simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF) - simulation = setOutputCSV(simulation, CSV_OUTPUT_ON) - - # **** RUN SIMULATION **** - print((@elapsed TUG.run(simulation)) * 1e9) -end - -main() diff --git a/julia/tests/julia_bench/FTCS_450_670_750.jl b/julia/tests/julia_bench/FTCS_450_670_750.jl deleted file mode 100644 index c4cad82..0000000 --- a/julia/tests/julia_bench/FTCS_450_670_750.jl +++ /dev/null @@ -1,43 +0,0 @@ -include("../../TUG/src/TUG.jl") -using .TUG - -function main() - # **** GRID **** - rows::Int = 450 - cols::Int = 670 - - alphaX = fill(1.0, rows, cols) - alphaY = fill(1.0, rows, cols) - alphaX[1:100, :] .= 0.5 - alphaX[101:200, :] .= 0.8 - alphaY[:, 1:200] .= 0.6 - alphaY[:, 201:400] .= 0.9 - grid::Grid = Grid{Float64}(rows, cols, alphaX, alphaY) - - concentrations = fill(0.0, rows, cols) - concentrations[11, 11] = 1500 - concentrations[441, 661] = 750 - concentrations[441, 11] = 750 - concentrations[11, 661] = 750 - concentrations[221, 336] = 1500 - setConcentrations!(grid, concentrations) - - # **** BOUNDARY **** - bc::Boundary = Boundary(grid) - setBoundarySideClosed!(bc, LEFT) - setBoundarySideClosed!(bc, RIGHT) - setBoundarySideClosed!(bc, TOP) - setBoundarySideClosed!(bc, BOTTOM) - - # **** SIMULATION **** - simulation::Simulation = Simulation(grid, bc, FTCS) - simulation = setTimestep(simulation, 0.2) - simulation = setIterations(simulation, 750) - simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF) - simulation = setOutputCSV(simulation, CSV_OUTPUT_ON) - - # **** RUN SIMULATION **** - print((@elapsed TUG.run(simulation)) * 1e9) -end - -main() diff --git a/julia/tests/julia_bench/FTCS_500_500_300.jl b/julia/tests/julia_bench/FTCS_500_500_300.jl deleted file mode 100644 index 4e71343..0000000 --- a/julia/tests/julia_bench/FTCS_500_500_300.jl +++ /dev/null @@ -1,40 +0,0 @@ -include("../../TUG/src/TUG.jl") -using .TUG - -function main() - # **** GRID **** - rows::Int = 500 - cols::Int = 500 - - alphaX = fill(0.7, rows, cols) - alphaY = fill(0.7, rows, cols) - alphaX[201:300, 201:300] .= 0.4 - alphaY[201:300, 201:300] .= 0.4 - grid::Grid = Grid{Float64}(rows, cols, alphaX, alphaY) - - concentrations = fill(0.0, rows, cols) - concentrations[51:150, 51:150] .= 1500 - concentrations[351:450, 351:450] .= 1200 - concentrations[251, 251] = 2000 - setConcentrations!(grid, concentrations) - - # **** BOUNDARY **** - bc::Boundary = Boundary(grid) - setBoundarySideClosed!(bc, LEFT) - setBoundarySideClosed!(bc, RIGHT) - setBoundarySideClosed!(bc, TOP) - setBoundarySideClosed!(bc, BOTTOM) - - # **** SIMULATION **** - simulation::Simulation = Simulation(grid, bc, FTCS) - simulation = setTimestep(simulation, 2.5) - simulation = setIterations(simulation, 300) - simulation = setOutputConsole(simulation, CONSOLE_OUTPUT_OFF) - simulation = setOutputCSV(simulation, CSV_OUTPUT_ON) - - # **** RUN SIMULATION **** - elapsed_time_ns = (@elapsed TUG.run(simulation)) * 1e9 - println("Simulation Time (nanoseconds): ", elapsed_time_ns) -end - -main() diff --git a/julia/tests/test.py b/julia/tests/test.py deleted file mode 100644 index 9f1360c..0000000 --- a/julia/tests/test.py +++ /dev/null @@ -1,154 +0,0 @@ -import argparse -import os -import statistics -import subprocess -import time - -from compare_csv import compare_csv_files - -# ANSI color codes -RED = '\033[0;31m' -GREEN = '\033[0;32m' -NC = '\033[0m' # No Color - -def remove_non_empty_dir(path): - if os.path.exists(path): - for root, dirs, files in os.walk(path, topdown=False): - for name in files: - os.remove(os.path.join(root, name)) - for name in dirs: - os.rmdir(os.path.join(root, name)) - os.rmdir(path) - -def get_max_name_length(directory): - max_length = 0 - for file in os.listdir(directory): - if file.endswith('.csv'): - name_length = len(os.path.splitext(file)[0]) - if name_length > max_length: - max_length = name_length - return max_length - -def format_difference(diff): - threshold = 1e-5 - if diff != 0: - if abs(diff) < threshold: - return '{:.2e}'.format(diff).rjust(6) # Scientific notation for small values - else: - return '{:.3f}'.format(diff).rjust(6) # Fixed-point notation for larger values - else: - return '0'.rjust(6) - -def run_benchmark(command, runs, precompile=False): - times = [] - for _ in range(runs): - start_time = time.perf_counter() - output = subprocess.run(command, capture_output=True, text=True) - elapsed = time.perf_counter() - start_time - if precompile: - out = output.stdout.splitlines()[-1] # Take the second to last line if there are new line symbols - times.append(float(out)*1e-9) # Convert from nanoseconds to seconds - else: - times.append(elapsed) - - avg_time = sum(times) / len(times) - min_time = min(times) - max_time = max(times) - std_dev = statistics.stdev(times) if len(times) > 1 else 0 - - return avg_time, min_time, max_time, std_dev - -def main(tolerance, runs, silent, no_clean, precompile): - BENCHMARK_DIR = "./cpp_bench" - JULIA_DIR = "./julia_bench" - COMPILER = "g++" - CFLAGS = ["-O3", "-fopenmp", "-I", "../../include/", "-I", "/usr/include/eigen3"] - BIN_DIR = "./cpp_bin_temp" - OUTPUT_DIR = "./csv_temp" - - # Clean up and create directories - for dir_path in [BIN_DIR, OUTPUT_DIR]: - remove_non_empty_dir(dir_path) - os.makedirs(dir_path) - - for file in os.listdir('.'): - if file.endswith('.csv'): - os.remove(file) - - # Compile and run C++ benchmarks - if not silent: print("----- Running C++ Benchmarks -----") - cpp_times = {} - for benchmark in os.listdir(BENCHMARK_DIR): - if benchmark.endswith(".cpp"): - name = os.path.splitext(benchmark)[0] - if not silent: print(f"Compiling {name}...", end="", flush=True) - subprocess.run([COMPILER, *CFLAGS, "-o", f"{BIN_DIR}/{name}", f"{BENCHMARK_DIR}/{benchmark}"]) - if not silent: print(" Running...", end="", flush=True) - cpp_times[name] = run_benchmark([f"./{BIN_DIR}/{name}"], runs, precompile) - if not silent: print(" Done.", flush=True) - - # Move CSV files to output directory - for file in os.listdir('.'): - if file.endswith('.csv'): - os.rename(file, f"{OUTPUT_DIR}/{file}") - - max_name_length = get_max_name_length(OUTPUT_DIR) - - # Run Julia benchmarks and compare - if not silent: print("\n----- Running Julia Benchmarks -----") - results_dict = {} - pass_all = True - julia_times = {} - for csv_file in sorted(os.listdir(OUTPUT_DIR), key=lambda x: os.path.splitext(x)[0]): - name = os.path.splitext(csv_file)[0] - padded_name = name.ljust(max_name_length) - if os.path.exists(f"{JULIA_DIR}/{name}.jl"): - if not silent: print(f"Running {name}...", end="", flush=True) - julia_times[name] = run_benchmark(["julia", f"{JULIA_DIR}/{name}.jl"], runs, precompile) - - if os.path.exists(f"./{name}.csv"): - are_equal, _, _, _, max_diff = compare_csv_files(f"./{name}.csv", f"{OUTPUT_DIR}/{csv_file}", tolerance) - formatted_diff = format_difference(max_diff) - cpp_time = '{:.4f}s'.format(cpp_times[name][0]).rjust(8) - julia_time = '{:.4f}s'.format(julia_times[name][0]).rjust(8) - result = f"{padded_name}: {'Success' if are_equal else 'Failure'} (Max Diff: {formatted_diff}, C++: {cpp_time}, Julia: {julia_time})" - result_color = GREEN if are_equal else RED - results_dict[name] = f"{result_color}{result}{NC}" - if not are_equal: - pass_all = False - - else: - results_dict[name] = f"{RED}{padded_name}: No Julia output{NC}" - pass_all = False - if not silent: print(" Done.", flush=True) - - - # Clean up - if not no_clean: - remove_non_empty_dir(BIN_DIR) - remove_non_empty_dir(OUTPUT_DIR) - - for file in os.listdir('.'): - if file.endswith('.csv'): - os.remove(file) - - # Print results - if not silent: print("\n----- Benchmark Results -----") - print(f"Parameters: Tolerance = {tolerance}, Runs = {runs}, Precompile = {precompile}") - for name in sorted(results_dict): - print(results_dict[name]) - if pass_all: - print(f"\n{GREEN}All benchmarks and comparisons passed.{NC}") - else: - print(f"\n{RED}Some benchmarks or comparisons failed.{NC}") - exit(1) - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Benchmark and Compare Script') - parser.add_argument('--tolerance', type=float, default=0, help='Tolerance for CSV comparison') - parser.add_argument('--runs', type=int, default=1, help='Number of benchmark runs') - parser.add_argument('--silent', action='store_true', help='Run in silent mode without printing details') - parser.add_argument('--no-clean', action='store_true', help='Do not clean up temporary files') - parser.add_argument('--precompile', action='store_true', help='Use precompiling for Julia benchmarks and rely on benchmark script for timing') - args = parser.parse_args() - main(args.tolerance, args.runs, args.silent, args.no_clean, args.precompile)