Mercurial > repos > public > sbplib_julia
diff src/Grids/grid.jl @ 1526:4df668d00d03 feature/grids/curvilinear
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 09 Apr 2024 07:58:27 +0200 |
parents | 553111a15506 2fa325f08b66 |
children | 9113f437431d |
line wrap: on
line diff
--- a/src/Grids/grid.jl Fri Feb 16 15:28:19 2024 +0100 +++ b/src/Grids/grid.jl Tue Apr 09 07:58:27 2024 +0200 @@ -27,7 +27,7 @@ """ coordinate_size(g) -The lenght of the coordinate vector of `Grid` `g`. +The length of the coordinate vector of `Grid` `g`. """ coordinate_size(::Type{<:Grid{T}}) where T = _ncomponents(T) coordinate_size(g::Grid) = coordinate_size(typeof(g)) # TBD: Name of this function?! @@ -35,11 +35,33 @@ """ component_type(gf) -The type of the components of `gf`. +The type of the components of the elements of `gf`. I.e if `gf` is a vector +valued grid function, `component_view(gf)` is the element type of the vectors +at each grid point. + +# Examples +```julia-repl +julia> component_type([[1,2], [2,3], [3,4]]) +Int64 +``` """ component_type(T::Type) = eltype(eltype(T)) component_type(t) = component_type(typeof(t)) +""" + componentview(gf, component_index...) + +A view of `gf` with only the components specified by `component_index...`. + +# Examples +```julia-repl +julia> componentview([[1,2], [2,3], [3,4]],2) +3-element ArrayComponentView{Int64, Vector{Int64}, 1, Vector{Vector{Int64}}, Tuple{Int64}}: + 2 + 3 + 4 +``` +""" componentview(gf, component_index...) = ArrayComponentView(gf, component_index) struct ArrayComponentView{CT,T,D,AT <: AbstractArray{T,D}, IT} <: AbstractArray{CT,D} @@ -57,20 +79,7 @@ Base.getindex(cv::ArrayComponentView, I::Vararg{Int}) = cv.v[I...][cv.component_index...] IndexStyle(::Type{<:ArrayComponentView{<:Any,<:Any,AT}}) where AT = IndexStyle(AT) -# TODO: Implement the remaining optional methods from the array interface -# setindex!(A, v, i::Int) -# setindex!(A, v, I::Vararg{Int, N}) -# iterate -# length(A) -# similar(A) -# similar(A, ::Type{S}) -# similar(A, dims::Dims) -# similar(A, ::Type{S}, dims::Dims) -# # Non-traditional indices -# axes(A) -# similar(A, ::Type{S}, inds) -# similar(T::Union{Type,Function}, inds) - +# TODO: Implement `setindex!`? # TODO: Implement a more general ComponentView that can handle non-AbstractArrays. """