changeset 1520:97af5489dcf0

Merge refactor/component_type
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 22 Mar 2024 08:48:00 +0100
parents d7bc11053951 (current diff) b48a032505f4 (diff)
children b29d2dc896a0 b2b9693aa63b
files
diffstat 2 files changed, 24 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/grid.jl	Thu Mar 21 15:36:52 2024 +0100
+++ b/src/Grids/grid.jl	Fri Mar 22 08:48:00 2024 +0100
@@ -33,12 +33,20 @@
 coordinate_size(g::Grid) = coordinate_size(typeof(g)) # TBD: Name of this function?!
 
 """
-    component_type(g)
+    component_type(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.
 
-The type of the components of the coordinate vector of `Grid` `g`.
+# Examples
+```julia-repl
+julia> component_type([[1,2], [2,3], [3,4]])
+Int64
+```
 """
-component_type(::Type{<:Grid{T}}) where T = eltype(T)
-component_type(g::Grid) = component_type(typeof(g))
+component_type(T::Type) = eltype(eltype(T))
+component_type(t) = component_type(typeof(t))
 
 """
     refine(g::Grid, r)
--- a/test/Grids/grid_test.jl	Thu Mar 21 15:36:52 2024 +0100
+++ b/test/Grids/grid_test.jl	Fri Mar 22 08:48:00 2024 +0100
@@ -15,19 +15,21 @@
     @test coordinate_size(DummyGrid{SVector{3,Float64}, 2}()) == 3
 
     @test coordinate_size(DummyGrid{SVector{3,Float64}, 2}) == 3
+end
 
-    @testset "component_type" begin
-        @test component_type(DummyGrid{Int,1}()) == Int
-        @test component_type(DummyGrid{Float64,1}()) == Float64
-        @test component_type(DummyGrid{Rational,1}()) == Rational
+@testset "component_type" begin
+    @test component_type(DummyGrid{Int,1}()) == Int
+    @test component_type(DummyGrid{Float64,1}()) == Float64
+    @test component_type(DummyGrid{Rational,1}()) == Rational
 
-        @test component_type(DummyGrid{SVector{3,Int},2}()) == Int
-        @test component_type(DummyGrid{SVector{2,Float64},3}()) == Float64
-        @test component_type(DummyGrid{SVector{4,Rational},4}()) == Rational
+    @test component_type(DummyGrid{SVector{3,Int},2}()) == Int
+    @test component_type(DummyGrid{SVector{2,Float64},3}()) == Float64
+    @test component_type(DummyGrid{SVector{4,Rational},4}()) == Rational
 
-        @test component_type(DummyGrid{Float64,1}) == Float64
-        @test component_type(DummyGrid{SVector{2,Float64},3}) == Float64
-    end
+    @test component_type(DummyGrid{Float64,1}) == Float64
+    @test component_type(DummyGrid{SVector{2,Float64},3}) == Float64
+
+    @test component_type(fill(@SVector[1,2], 4,2)) == Int
 end
 
 @testset "eval_on" begin