Added dynamic simulation for use with distributed systems and incremental simulations Added module based exports Added test for distributed systems [skip ci]
70 lines
2.4 KiB
Julia
70 lines
2.4 KiB
Julia
using Distributed
|
|
|
|
include("AbstractSimulation.jl")
|
|
include("Boundary.jl")
|
|
include("Core/BTCS.jl")
|
|
include("Core/FTCS.jl")
|
|
include("Grid.jl")
|
|
|
|
struct DynamicSimulation{T} <: AbstractSimulation{T}
|
|
grid::Grid{T}
|
|
grids::Vector{Grid{T}}
|
|
bc::Boundary{T}
|
|
|
|
approach::APPROACH
|
|
iterations::Int
|
|
timestep::T
|
|
|
|
# Constructor
|
|
function DynamicSimulation(grid::Grid{T}, bc::Boundary{T}, approach::APPROACH, timestep::T) where {T}
|
|
timestep, iterations = adjustTimestep(grid, approach, timestep, 1)
|
|
new{T}(grid, Vector{Grid{T}}(), bc, approach, iterations, timestep)
|
|
end
|
|
end
|
|
|
|
function createGrid(simulation::DynamicSimulation{T})::Int where {T}
|
|
new_grid = clone(simulation.grid)
|
|
push!(simulation.grids, new_grid)
|
|
return length(simulation.grids)
|
|
end
|
|
|
|
function next(simulation::DynamicSimulation{T}) where {T}
|
|
pmap(grid -> runSimulationForGrid(simulation, grid), simulation.grids)
|
|
end
|
|
|
|
function printConcentrations(simulation::DynamicSimulation{T}, gridIndex::Int) where {T}
|
|
writeConcentrationsToCLI(simulation, simulation.grids[gridIndex])
|
|
end
|
|
|
|
function printConcentrationsCSV(simulation::DynamicSimulation{T}, gridIndex::Int) where {T}
|
|
file = createCSVfile(simulation, simulation.grids[gridIndex])
|
|
writeConcentrationsToCSV(file, simulation, simulation.grids[gridIndex])
|
|
close(file)
|
|
end
|
|
|
|
function runSimulationForGrid(simulation::DynamicSimulation{T}, grid::Grid{T}) where {T}
|
|
if simulation.approach == BTCS
|
|
runBTCS(grid, simulation.bc, simulation.timestep, simulation.iterations, () -> nothing)
|
|
elseif simulation.approach == FTCS
|
|
runFTCS(grid, simulation.bc, simulation.timestep, simulation.iterations, () -> nothing)
|
|
else
|
|
error("Undefined approach!")
|
|
end
|
|
end
|
|
|
|
function getConcentrations(simulation::DynamicSimulation{T}, gridIndex::Int)::Matrix{T} where {T}
|
|
getConcentrations(simulation.grids[gridIndex])
|
|
end
|
|
|
|
function setConcentrations!(simulation::DynamicSimulation{T}, gridIndex::Int, concentrations::Matrix{T}) where {T}
|
|
setConcentrations!(simulation.grids[gridIndex], concentrations)
|
|
end
|
|
|
|
function setAlphaX!(simulation::DynamicSimulation{T}, gridIndex::Int, alphaX::Matrix{T}) where {T}
|
|
setAlphaX!(simulation.grids[gridIndex], alphaX)
|
|
end
|
|
|
|
function setAlphaY!(simulation::DynamicSimulation{T}, gridIndex::Int, alphaY::Matrix{T}) where {T}
|
|
setAlphaY!(simulation.grids[gridIndex], alphaY)
|
|
end
|