test: added FTCS julia/cpp tests
[skip ci]
This commit is contained in:
parent
2b478c1dd4
commit
fe7f5c9b4a
53
julia/tests/cpp_bench/FTCS_1024_1000_100.cpp
Normal file
53
julia/tests/cpp_bench/FTCS_1024_1000_100.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
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<double, tug::FTCS_APPROACH>(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<nanoseconds>(stop - start);
|
||||
std::cout << duration.count() << std::endl;
|
||||
}
|
||||
42
julia/tests/cpp_bench/FTCS_1_20_7000.cpp
Normal file
42
julia/tests/cpp_bench/FTCS_1_20_7000.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
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<double, tug::FTCS_APPROACH>(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<seconds>(stop - start);
|
||||
std::cout << duration.count() << std::endl;
|
||||
}
|
||||
66
julia/tests/cpp_bench/FTCS_2027_1999_200.cpp
Normal file
66
julia/tests/cpp_bench/FTCS_2027_1999_200.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
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<double>(i * j) / 1e6;
|
||||
}
|
||||
}
|
||||
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 / 100.0) * std::cos(j / 100.0);
|
||||
alphay(i, j) = std::cos(i / 100.0) * std::sin(j / 100.0);
|
||||
}
|
||||
}
|
||||
grid.setAlpha(alphax, alphay);
|
||||
|
||||
// **** BOUNDARY ****
|
||||
Boundary bc = Boundary(grid);
|
||||
bc.setBoundarySideConstant(BC_SIDE_LEFT, 1.5);
|
||||
bc.setBoundarySideConstant(BC_SIDE_RIGHT, 1.5);
|
||||
bc.setBoundarySideConstant(BC_SIDE_TOP, 0.75);
|
||||
bc.setBoundarySideConstant(BC_SIDE_BOTTOM, 0.75);
|
||||
|
||||
// **** SIMULATION ****
|
||||
Simulation simulation = Simulation<double, tug::FTCS_APPROACH>(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<nanoseconds>(stop - start);
|
||||
std::cout << duration.count() << std::endl;
|
||||
}
|
||||
46
julia/tests/cpp_bench/FTCS_20_20_500.cpp
Normal file
46
julia/tests/cpp_bench/FTCS_20_20_500.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
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<double, tug::FTCS_APPROACH>(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<nanoseconds>(stop - start);
|
||||
std::cout << duration.count() << std::endl;
|
||||
}
|
||||
54
julia/tests/cpp_bench/FTCS_450_670_750.cpp
Normal file
54
julia/tests/cpp_bench/FTCS_450_670_750.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
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<double, tug::FTCS_APPROACH>(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<nanoseconds>(stop - start);
|
||||
std::cout << duration.count() << std::endl;
|
||||
}
|
||||
41
julia/tests/julia_bench/FTCS_1024_1000_100.jl
Normal file
41
julia/tests/julia_bench/FTCS_1024_1000_100.jl
Normal file
@ -0,0 +1,41 @@
|
||||
include("../../tug/Simulation.jl")
|
||||
|
||||
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 run(simulation)) * 1e9)
|
||||
end
|
||||
|
||||
main()
|
||||
30
julia/tests/julia_bench/FTCS_1_20_7000.jl
Normal file
30
julia/tests/julia_bench/FTCS_1_20_7000.jl
Normal file
@ -0,0 +1,30 @@
|
||||
include("../../tug/Simulation.jl")
|
||||
|
||||
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 run(simulation)) * 1e9)
|
||||
end
|
||||
|
||||
main()
|
||||
38
julia/tests/julia_bench/FTCS_2027_1999_200.jl
Normal file
38
julia/tests/julia_bench/FTCS_2027_1999_200.jl
Normal file
@ -0,0 +1,38 @@
|
||||
include("../../tug/Simulation.jl")
|
||||
|
||||
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 / 1e6 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, FTCS)
|
||||
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 run(simulation)) * 1e9)
|
||||
end
|
||||
|
||||
main()
|
||||
34
julia/tests/julia_bench/FTCS_20_20_500.jl
Normal file
34
julia/tests/julia_bench/FTCS_20_20_500.jl
Normal file
@ -0,0 +1,34 @@
|
||||
include("../../tug/Simulation.jl")
|
||||
|
||||
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 run(simulation)) * 1e9)
|
||||
end
|
||||
|
||||
main()
|
||||
42
julia/tests/julia_bench/FTCS_450_670_750.jl
Normal file
42
julia/tests/julia_bench/FTCS_450_670_750.jl
Normal file
@ -0,0 +1,42 @@
|
||||
include("../../tug/Simulation.jl")
|
||||
|
||||
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 run(simulation)) * 1e9)
|
||||
end
|
||||
|
||||
main()
|
||||
@ -33,7 +33,7 @@ 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
|
||||
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:
|
||||
@ -46,7 +46,8 @@ def run_benchmark(command, runs, precompile=False):
|
||||
output = subprocess.run(command, capture_output=True, text=True)
|
||||
elapsed = time.perf_counter() - start_time
|
||||
if precompile:
|
||||
times.append(float(output.stdout)*1e-9) # Convert from ns to s
|
||||
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)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user