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 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 function getConcentrations(grid::Grid{T})::Matrix{T} where {T} grid.concentrations[] end function setConcentrations!(grid::Grid{T}, new_concentrations::Matrix{T}) where {T} grid.concentrations[] = new_concentrations end function getCols(grid::Grid{T})::Int where {T} grid.cols end function getRows(grid::Grid{T})::Int where {T} grid.rows end