62 lines
3.9 KiB
Julia
62 lines
3.9 KiB
Julia
@testset "Simulation.jl" begin
|
|
@testset "Constructor" begin
|
|
grid = TUG.Grid{Float64}(5, ones(1, 5))
|
|
boundary = TUG.Boundary(grid)
|
|
simulation = TUG.Simulation(grid, boundary)
|
|
@test simulation.grid == grid
|
|
@test simulation.bc == boundary
|
|
@test simulation.approach == BTCS
|
|
@test simulation.iterations == 1
|
|
@test simulation.timestep == 0.1
|
|
@test simulation.consoleOutput == CONSOLE_OUTPUT_OFF
|
|
@test simulation.csvOutput == CSV_OUTPUT_OFF
|
|
|
|
grid = TUG.Grid{Float64}(5, ones(1, 5))
|
|
boundary = TUG.Boundary(grid)
|
|
simulation = TUG.Simulation(grid, boundary, FTCS, 2, 0.2, CONSOLE_OUTPUT_ON, CSV_OUTPUT_ON)
|
|
@test simulation.grid == grid
|
|
@test simulation.bc == boundary
|
|
@test simulation.approach == FTCS
|
|
@test simulation.iterations == 2
|
|
@test simulation.timestep == 0.2
|
|
@test simulation.consoleOutput == CONSOLE_OUTPUT_ON
|
|
@test simulation.csvOutput == CSV_OUTPUT_ON
|
|
end
|
|
@testset "1D-Run" begin
|
|
grid = TUG.Grid{Float64}(5, ones(1, 5))
|
|
TUG.setConcentrations!(grid, [1.0 1.0 20.0 1.0 1.0])
|
|
boundary = TUG.Boundary(grid)
|
|
simulation = TUG.Simulation(grid, boundary, BTCS, 20, 0.01)
|
|
TUG.run(simulation)
|
|
expected_concentrations = [1.281106278320615 3.5643693033301567 14.309048836698485 3.5643693033301598 1.281106278320616]
|
|
@test isapprox(TUG.getConcentrations(grid), expected_concentrations, atol=1e-6)
|
|
|
|
grid = TUG.Grid{Float64}(5, ones(1, 5))
|
|
TUG.setConcentrations!(grid, [1.0 1.0 20.0 1.0 1.0])
|
|
boundary = TUG.Boundary(grid)
|
|
TUG.setBoundarySideConstant!(boundary, LEFT, 5.0)
|
|
simulation = TUG.Simulation(grid, boundary, BTCS, 20, 0.01)
|
|
TUG.run(simulation)
|
|
expected_concentrations = [2.4416160635284823 3.6810808789967466 14.317333805802393 3.5648326408458035 1.2811288426376255]
|
|
@test isapprox(TUG.getConcentrations(grid), expected_concentrations, atol=1e-6)
|
|
end
|
|
@testset "2D-Run" begin
|
|
grid = TUG.Grid{Float64}(5, 5, ones(5, 5), ones(5, 5))
|
|
TUG.setConcentrations!(grid, [1.0 1.0 20.0 1.0 1.0; 1.0 1.0 20.0 1.0 1.0; 1.0 1.0 20.0 1.0 1.0; 1.0 1.0 20.0 1.0 1.0; 1.0 1.0 20.0 1.0 1.0])
|
|
boundary = TUG.Boundary(grid)
|
|
simulation = TUG.Simulation(grid, boundary, BTCS, 20, 0.01)
|
|
TUG.run(simulation)
|
|
expected_concentrations = [1.141904802011076 3.591390417498421 14.249599956958917 3.5913904174984217 1.1419048020110782; 1.1419048020110738 3.5913904174984173 14.2495999569589 3.5913904174984177 1.1419048020110767; 1.1419048020110725 3.591390417498413 14.249599956958875 3.5913904174984137 1.1419048020110751; 1.1419048020110738 3.5913904174984164 14.249599956958901 3.5913904174984173 1.141904802011077; 1.1419048020110774 3.5913904174984297 14.24959995695894 3.5913904174984297 1.1419048020110796]
|
|
@test isapprox(TUG.getConcentrations(grid), expected_concentrations, atol=1e-6)
|
|
|
|
grid = TUG.Grid{Float64}(5, 5, ones(5, 5), ones(5, 5))
|
|
TUG.setConcentrations!(grid, [1.0 1.0 20.0 1.0 1.0; 1.0 1.0 20.0 1.0 1.0; 1.0 1.0 20.0 1.0 1.0; 1.0 1.0 20.0 1.0 1.0; 1.0 1.0 20.0 1.0 1.0])
|
|
boundary = TUG.Boundary(grid)
|
|
TUG.setBoundarySideConstant!(boundary, LEFT, 5.0)
|
|
simulation = TUG.Simulation(grid, boundary, BTCS, 20, 0.01)
|
|
TUG.run(simulation)
|
|
expected_concentrations = [1.9866377371338924 3.67421468453773 14.255058363518529 3.5916629034159486 1.1419105589005596; 1.98663773713389 3.674214684537723 14.255058363518497 3.5916629034159406 1.1419105589005576; 1.9866377371338884 3.6742146845377186 14.255058363518481 3.591662903415937 1.1419105589005565; 1.9866377371338895 3.674214684537725 14.255058363518502 3.5916629034159424 1.1419105589005574; 1.9866377371338952 3.6742146845377377 14.255058363518547 3.591662903415955 1.141910558900562]
|
|
@test isapprox(TUG.getConcentrations(grid), expected_concentrations, atol=1e-6)
|
|
end
|
|
end
|