From 56607839297a48b2668bbb1560ccac09d63259cd Mon Sep 17 00:00:00 2001 From: nebmit <76664673+nebmit@users.noreply.github.com> Date: Fri, 1 Dec 2023 14:14:56 +0100 Subject: [PATCH] test: added FTCS testcase with large timestep [skip ci] --- julia/tests/cpp_bench/FTCS_500_500_300.cpp | 50 +++++++++++++++++++++ julia/tests/julia_bench/FTCS_500_500_300.jl | 39 ++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 julia/tests/cpp_bench/FTCS_500_500_300.cpp create mode 100644 julia/tests/julia_bench/FTCS_500_500_300.jl diff --git a/julia/tests/cpp_bench/FTCS_500_500_300.cpp b/julia/tests/cpp_bench/FTCS_500_500_300.cpp new file mode 100644 index 0000000..443800a --- /dev/null +++ b/julia/tests/cpp_bench/FTCS_500_500_300.cpp @@ -0,0 +1,50 @@ +#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/FTCS_500_500_300.jl b/julia/tests/julia_bench/FTCS_500_500_300.jl new file mode 100644 index 0000000..61eada4 --- /dev/null +++ b/julia/tests/julia_bench/FTCS_500_500_300.jl @@ -0,0 +1,39 @@ +include("../../tug/Simulation.jl") + +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 run(simulation)) * 1e9 + println("Simulation Time (nanoseconds): ", elapsed_time_ns) +end + +main()