TugJulia/julia/tug/Grid.jl
nebmit 957f73bb83
refactor!: structural changes
Improved julia structs and removed redundant calculations

[skip ci]
2023-11-20 12:16:15 +01:00

64 lines
1.8 KiB
Julia

using LinearAlgebra
struct Grid{T}
cols::Int
rows::Int
dim::Int
domainCol::T
domainRow::T
deltaCol::T
deltaRow::T
concentrations::Ref{Matrix{T}}
alphaX::Matrix{T}
alphaY::Union{Matrix{T},Nothing}
alphaX_t::Union{Matrix{T},Nothing}
alphaY_t::Union{Matrix{T},Nothing}
# Constructor for 1D-Grid
function Grid{T}(length::Int, alpha::Matrix{T}) where {T}
if length <= 3
throw(ArgumentError("Given grid length too small. Must be greater than 3."))
end
if size(alpha, 1) != 1 || size(alpha, 2) != length
error("Given matrix of alpha coefficients mismatch with Grid dimensions!")
end
new{T}(length, 1, 1, T(length), 0, T(1), 0, Ref(fill(T(0), 1, length)), alpha, nothing, nothing, nothing)
end
# Constructor for 2D-Grid
function Grid{T}(rows::Int, cols::Int, alphaX::Matrix{T}, alphaY::Matrix{T}) where {T}
if rows <= 3 || cols <= 3
throw(ArgumentError("Given grid dimensions too small. Must each be greater than 3."))
end
if size(alphaX) != (rows, cols) || size(alphaY) != (rows, cols)
error("Given matrices of alpha coefficients mismatch with Grid dimensions!")
end
alphaX_t = alphaX'
alphaY_t = alphaY'
new{T}(cols, rows, 2, T(cols), T(rows), T(1), T(1), Ref(fill(T(0), rows, cols)), alphaX, alphaY, alphaX_t, alphaY_t)
end
end
function setConcentrations!(grid::Grid{T}, new_concentrations::Matrix{T}) where {T}
grid.concentrations[] = new_concentrations
end
function getAlphaX(grid::Grid{T})::Matrix{T} where {T}
grid.alphaX
end
function getAlphaY(grid::Grid{T})::Matrix{T} where {T}
grid.alphaY
end
function getAlphaX_t(grid::Grid{T})::Matrix{T} where {T}
grid.alphaX_t
end
function getAlphaY_t(grid::Grid{T})::Matrix{T} where {T}
grid.alphaY_t
end