feat(Grid): add domain values as optional arguments

[skip ci]
This commit is contained in:
nebmit 2024-03-12 15:04:38 +01:00
parent 65a16cac1c
commit 6a98a23439
No known key found for this signature in database

View File

@ -12,11 +12,11 @@ Represents a computational grid with concentration values and alpha coefficients
It can be either 1D or 2D and includes dimensions, domain sizes, delta values, and matrices for concentrations and alpha coefficients. It can be either 1D or 2D and includes dimensions, domain sizes, delta values, and matrices for concentrations and alpha coefficients.
# Fields # Fields
- `cols::Int`: Number of columns in the grid.
- `rows::Int`: Number of rows in the grid. - `rows::Int`: Number of rows in the grid.
- `cols::Int`: Number of columns in the grid.
- `dim::Int`: Dimension of the grid (1 for 1D, 2 for 2D). - `dim::Int`: Dimension of the grid (1 for 1D, 2 for 2D).
- `domainCol::T`, `domainRow::T`: Size of the grid's domain in column and row direction. - `domainRow::T`, `domainCol::T`: Size of the grid's domain in column and row direction.
- `deltaCol::T`, `deltaRow::T`: Delta values for columns and rows. - `deltaRow::T`, `deltaCol::T`: Delta values for columns and rows.
- `concentrations::Ref{Matrix{T}}`: Reference to the matrix holding concentration values. - `concentrations::Ref{Matrix{T}}`: Reference to the matrix holding concentration values.
- `alphaX::Ref{Matrix{T}}`: Reference to the matrix of alpha coefficients in the X direction. - `alphaX::Ref{Matrix{T}}`: Reference to the matrix of alpha coefficients in the X direction.
- `alphaY::Union{Ref{Matrix{T}},Nothing}`: Reference to the matrix of alpha coefficients in the Y direction (if applicable). - `alphaY::Union{Ref{Matrix{T}},Nothing}`: Reference to the matrix of alpha coefficients in the Y direction (if applicable).
@ -25,23 +25,31 @@ It can be either 1D or 2D and includes dimensions, domain sizes, delta values, a
# Constructors # Constructors
- `Grid(length, alphaX)` creates a 1D grid with the given length and alphaX matrix. - `Grid(length, alphaX)` creates a 1D grid with the given length and alphaX matrix.
- `Grid(rows, cols, alphaX, alphaY)` creates a 2D grid with the given rows, columns, and alphaX and alphaY matrices. - `Grid(rows, cols, alphaX, alphaY)` creates a 2D grid with the given rows, columns, and alphaX and alphaY matrices.
- `Grid(rows, cols, dim, domainCol, domainRow, deltaCol, deltaRow, concentrations, alphaX, alphaY, alphaX_t, alphaY_t)` creates a grid with the given parameters. - `Grid(rows, cols, dim, domainRow, domainCol, deltaRow, deltaCol, concentrations, alphaX, alphaY, alphaX_t, alphaY_t)` creates a grid with the given parameters.
""" """
struct Grid{T} struct Grid{T}
cols::Int
rows::Int rows::Int
cols::Int
dim::Int dim::Int
domainCol::T
domainRow::T domainRow::T
deltaCol::T domainCol::T
deltaRow::T deltaRow::T
deltaCol::T
concentrations::Matrix{T} concentrations::Matrix{T}
alphaX::Matrix{T} alphaX::Matrix{T}
alphaY::Union{Matrix{T},Nothing} alphaY::Union{Matrix{T},Nothing}
alphaX_t::Matrix{T} alphaX_t::Matrix{T}
alphaY_t::Union{Matrix{T},Nothing} alphaY_t::Union{Matrix{T},Nothing}
function Grid{T}(length::Int, alphaX::Matrix{T})::Grid{T} where {T} function Grid{T}(
length::Int,
alphaX::Matrix{T};
domainLength::T = T(-1),
)::Grid{T} where {T}
if domainLength < 0
domainLength = T(length)
end
if length <= 3 if length <= 3
throw(ArgumentError("Given grid length too small. Must be greater than 3.")) throw(ArgumentError("Given grid length too small. Must be greater than 3."))
end end
@ -56,13 +64,13 @@ struct Grid{T}
alphaX_t = alphaX' alphaX_t = alphaX'
new{T}( new{T}(
1,
length, length,
1, 1,
1,
T(length),
0, 0,
T(1), T(domainLength),
0, 0,
T(domainLength / length),
fill(T(0), 1, length), fill(T(0), 1, length),
alphaX, alphaX,
nothing, nothing,
@ -75,8 +83,17 @@ struct Grid{T}
rows::Int, rows::Int,
cols::Int, cols::Int,
alphaX::Matrix{T}, alphaX::Matrix{T},
alphaY::Matrix{T}, alphaY::Matrix{T};
domainRow::T = T(-1),
domainCol::T = T(-1),
)::Grid{T} where {T} )::Grid{T} where {T}
if domainRow < 0
domainRow = T(rows)
end
if domainCol < 0
domainCol = T(cols)
end
if rows <= 3 || cols <= 3 if rows <= 3 || cols <= 3
throw( throw(
ArgumentError( ArgumentError(
@ -96,13 +113,13 @@ struct Grid{T}
alphaY_t = alphaY' alphaY_t = alphaY'
new{T}( new{T}(
cols,
rows, rows,
cols,
2, 2,
T(cols), T(domainRow),
T(rows), T(domainCol),
T(1), T(domainRow / rows),
T(1), T(domainCol / cols),
fill(T(0), rows, cols), fill(T(0), rows, cols),
alphaX, alphaX,
alphaY, alphaY,
@ -115,10 +132,10 @@ struct Grid{T}
rows::Int, rows::Int,
cols::Int, cols::Int,
dim::Int, dim::Int,
domainCol::T,
domainRow::T, domainRow::T,
deltaCol::T, domainCol::T,
deltaRow::T, deltaRow::T,
deltaCol::T,
concentrations::Matrix{T}, concentrations::Matrix{T},
alphaX::Matrix{T}, alphaX::Matrix{T},
alphaY::Union{Matrix{T},Nothing}, alphaY::Union{Matrix{T},Nothing},
@ -126,13 +143,13 @@ struct Grid{T}
alphaY_t::Union{Matrix{T},Nothing}, alphaY_t::Union{Matrix{T},Nothing},
)::Grid{T} where {T} )::Grid{T} where {T}
new{T}( new{T}(
cols,
rows, rows,
cols,
dim, dim,
domainCol,
domainRow, domainRow,
deltaCol, domainCol,
deltaRow, deltaRow,
deltaCol,
concentrations, concentrations,
alphaX, alphaX,
alphaY, alphaY,
@ -160,10 +177,10 @@ function clone(grid::Grid{T})::Grid{T} where {T}
1, 1,
grid.cols, grid.cols,
grid.dim, grid.dim,
grid.domainCol,
grid.domainRow, grid.domainRow,
grid.deltaCol, grid.domainCol,
grid.deltaRow, grid.deltaRow,
grid.deltaCol,
copy(grid.concentrations), copy(grid.concentrations),
copy(grid.alphaX), copy(grid.alphaX),
nothing, nothing,
@ -175,10 +192,10 @@ function clone(grid::Grid{T})::Grid{T} where {T}
grid.rows, grid.rows,
grid.cols, grid.cols,
grid.dim, grid.dim,
grid.domainCol,
grid.domainRow, grid.domainRow,
grid.deltaCol, grid.domainCol,
grid.deltaRow, grid.deltaRow,
grid.deltaCol,
copy(grid.concentrations), copy(grid.concentrations),
copy(grid.alphaX), copy(grid.alphaX),
copy(grid.alphaY), copy(grid.alphaY),