comparison 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
comparison
equal deleted inserted replaced
1506:535f32316637 1526:4df668d00d03
25 Base.getindex(g::Grid, I::CartesianIndex) = g[Tuple(I)...] 25 Base.getindex(g::Grid, I::CartesianIndex) = g[Tuple(I)...]
26 26
27 """ 27 """
28 coordinate_size(g) 28 coordinate_size(g)
29 29
30 The lenght of the coordinate vector of `Grid` `g`. 30 The length of the coordinate vector of `Grid` `g`.
31 """ 31 """
32 coordinate_size(::Type{<:Grid{T}}) where T = _ncomponents(T) 32 coordinate_size(::Type{<:Grid{T}}) where T = _ncomponents(T)
33 coordinate_size(g::Grid) = coordinate_size(typeof(g)) # TBD: Name of this function?! 33 coordinate_size(g::Grid) = coordinate_size(typeof(g)) # TBD: Name of this function?!
34 34
35 """ 35 """
36 component_type(gf) 36 component_type(gf)
37 37
38 The type of the components of `gf`. 38 The type of the components of the elements of `gf`. I.e if `gf` is a vector
39 valued grid function, `component_view(gf)` is the element type of the vectors
40 at each grid point.
41
42 # Examples
43 ```julia-repl
44 julia> component_type([[1,2], [2,3], [3,4]])
45 Int64
46 ```
39 """ 47 """
40 component_type(T::Type) = eltype(eltype(T)) 48 component_type(T::Type) = eltype(eltype(T))
41 component_type(t) = component_type(typeof(t)) 49 component_type(t) = component_type(typeof(t))
42 50
51 """
52 componentview(gf, component_index...)
53
54 A view of `gf` with only the components specified by `component_index...`.
55
56 # Examples
57 ```julia-repl
58 julia> componentview([[1,2], [2,3], [3,4]],2)
59 3-element ArrayComponentView{Int64, Vector{Int64}, 1, Vector{Vector{Int64}}, Tuple{Int64}}:
60 2
61 3
62 4
63 ```
64 """
43 componentview(gf, component_index...) = ArrayComponentView(gf, component_index) 65 componentview(gf, component_index...) = ArrayComponentView(gf, component_index)
44 66
45 struct ArrayComponentView{CT,T,D,AT <: AbstractArray{T,D}, IT} <: AbstractArray{CT,D} 67 struct ArrayComponentView{CT,T,D,AT <: AbstractArray{T,D}, IT} <: AbstractArray{CT,D}
46 v::AT 68 v::AT
47 component_index::IT 69 component_index::IT
55 Base.size(cv) = size(cv.v) 77 Base.size(cv) = size(cv.v)
56 Base.getindex(cv::ArrayComponentView, i::Int) = cv.v[i][cv.component_index...] 78 Base.getindex(cv::ArrayComponentView, i::Int) = cv.v[i][cv.component_index...]
57 Base.getindex(cv::ArrayComponentView, I::Vararg{Int}) = cv.v[I...][cv.component_index...] 79 Base.getindex(cv::ArrayComponentView, I::Vararg{Int}) = cv.v[I...][cv.component_index...]
58 IndexStyle(::Type{<:ArrayComponentView{<:Any,<:Any,AT}}) where AT = IndexStyle(AT) 80 IndexStyle(::Type{<:ArrayComponentView{<:Any,<:Any,AT}}) where AT = IndexStyle(AT)
59 81
60 # TODO: Implement the remaining optional methods from the array interface 82 # TODO: Implement `setindex!`?
61 # setindex!(A, v, i::Int)
62 # setindex!(A, v, I::Vararg{Int, N})
63 # iterate
64 # length(A)
65 # similar(A)
66 # similar(A, ::Type{S})
67 # similar(A, dims::Dims)
68 # similar(A, ::Type{S}, dims::Dims)
69 # # Non-traditional indices
70 # axes(A)
71 # similar(A, ::Type{S}, inds)
72 # similar(T::Union{Type,Function}, inds)
73
74 # TODO: Implement a more general ComponentView that can handle non-AbstractArrays. 83 # TODO: Implement a more general ComponentView that can handle non-AbstractArrays.
75 84
76 """ 85 """
77 refine(g::Grid, r) 86 refine(g::Grid, r)
78 87