diff src/Grids/grid.jl @ 1474:276c38a48aac feature/grids/componentview

Start implementing componentview
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 01 Dec 2023 13:34:03 +0100
parents a863aef1f799
children 76b190ca9a27
line wrap: on
line diff
--- a/src/Grids/grid.jl	Fri Dec 01 11:48:04 2023 +0100
+++ b/src/Grids/grid.jl	Fri Dec 01 13:34:03 2023 +0100
@@ -37,8 +37,17 @@
 
 The type of the components of the coordinate vector of `Grid` `g`.
 """
-component_type(::Type{<:Grid{T}}) where T = eltype(T)
+component_type(::Type{<:Grid{T}}) where T = eltype(T) #TBD: removable?
 component_type(g::Grid) = component_type(typeof(g))
+component_type(T::Type) = eltype(eltype(T))
+component_type(t) = component_type(typeof(t))
+
+function componentview(gf, component_index...)
+    A = reinterpret(reshape, component_type(gf), gf)
+
+    component_linear_index = LinearIndices(first(gf))[component_index...]
+    return @view A[component_linear_index,:,:]
+end
 
 """
     refine(g::Grid, r)