Mercurial > repos > public > sbplib_julia
diff src/Grids/grid.jl @ 1222:5f677cd6f0b6 refactor/grids
Start refactoring
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 18 Feb 2023 11:37:35 +0100 |
parents | dfbd62c7eb09 |
children | 3924c1f6ec6d |
line wrap: on
line diff
--- a/src/Grids/grid.jl Fri Feb 10 08:36:56 2023 +0100 +++ b/src/Grids/grid.jl Sat Feb 18 11:37:35 2023 +0100 @@ -1,27 +1,76 @@ """ - Grid + Grid{T,D,RD} <: AbstractArray{T,D} + +The top level type for grids. Should implement - Base.ndims(grid::Grid) - points(grid::Grid) +# TBD: +""" +#TBD: Does all the kinds of grids we want fit with this interface? +# Multigrid? +# Unstructured? +# Triangular structured grids? +# Non-simply connected? +# +# Maybe it shouldn't be an abstract array after all? +abstract type Grid{T,D,RD} <: AbstractArray{T,D} end + + +Base.ndims(::Grid{T,D,RD}) where {T,D,RD} = D # nidms borde nog vara antalet index som används för att indexera nätet. Snarare än vilken dimension nätet har (tänk ostrukturerat) +nrangedims(::Grid{T,D,RD}) where {T,D,RD} = RD +Base.eltype(::Grid{T,D,RD}) where {T,D,RD} = T # vad ska eltype vara? Inte T väl... en vektor? SVector{T,D}? + +function eval_on(::Grid) end # TODO: Should return a LazyArray and index the grid +function refine(::Grid) end +function coarsen(::Grid) end # Should this be here? What if it is not possible? + +abstract type BoundaryId end """ -abstract type Grid end -function points end +# TODO +""" +function boundary_identifiers(::Grid) end +""" +# TODO +""" +function boundary_grid(::Grid, ::BoundaryId) end + + +# TODO: Make sure that all grids implement all of the above. """ dims(grid::Grid) -A range containing the dimensions of `grid` +Enumerate the dimensions of the grid. """ dims(grid::Grid) = 1:ndims(grid) + + +# TBD: New file grid_functions.jl? + """ - evalOn(grid::Grid, f::Function) + getcomponent(gfun, I::Vararg{Int}) -Evaluate function `f` on `grid` +Return one of the components of gfun as a grid function. """ -function evalOn(grid::Grid, f::Function) - F(x) = f(x...) - return F.(points(grid)) +# Should it be lazy? Could it be a view? +function getcomponent(gfun, I::Vararg{Int}) end +# function getcomponent(gfun, s::Symbol) end ? + +# TBD: New file zero_dim_grid.jl? +struct ZeroDimGrid{T,S,RD} <: Grid{T,0,RD} + p::S + + function ZeroDimGrid(p) + T = eltype(p) + S = typeof(p) + RD = length(p) + return new{T,S,RD}(p) + end end + +Base.size(g::ZeroDimGrid) = () +Base.getindex(g::ZeroDimGrid) = g.p +Base.eachindex(g::ZeroDimGrid) = CartesianIndices(()) +