comparison 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
comparison
equal deleted inserted replaced
1221:b3b4d29b46c3 1222:5f677cd6f0b6
1 """ 1 """
2 Grid 2 Grid{T,D,RD} <: AbstractArray{T,D}
3
4 The top level type for grids.
3 5
4 Should implement 6 Should implement
5 Base.ndims(grid::Grid) 7 # TBD:
6 points(grid::Grid) 8 """
9 #TBD: Does all the kinds of grids we want fit with this interface?
10 # Multigrid?
11 # Unstructured?
12 # Triangular structured grids?
13 # Non-simply connected?
14 #
15 # Maybe it shouldn't be an abstract array after all?
16 abstract type Grid{T,D,RD} <: AbstractArray{T,D} end
17
18
19 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)
20 nrangedims(::Grid{T,D,RD}) where {T,D,RD} = RD
21 Base.eltype(::Grid{T,D,RD}) where {T,D,RD} = T # vad ska eltype vara? Inte T väl... en vektor? SVector{T,D}?
22
23 function eval_on(::Grid) end # TODO: Should return a LazyArray and index the grid
24 function refine(::Grid) end
25 function coarsen(::Grid) end # Should this be here? What if it is not possible?
26
27 abstract type BoundaryId end
7 28
8 """ 29 """
9 abstract type Grid end 30 # TODO
10 function points end 31 """
32 function boundary_identifiers(::Grid) end
33 """
34 # TODO
35 """
36 function boundary_grid(::Grid, ::BoundaryId) end
37
38
39 # TODO: Make sure that all grids implement all of the above.
11 40
12 """ 41 """
13 dims(grid::Grid) 42 dims(grid::Grid)
14 43
15 A range containing the dimensions of `grid` 44 Enumerate the dimensions of the grid.
16 """ 45 """
17 dims(grid::Grid) = 1:ndims(grid) 46 dims(grid::Grid) = 1:ndims(grid)
18 47
48
49
50 # TBD: New file grid_functions.jl?
51
19 """ 52 """
20 evalOn(grid::Grid, f::Function) 53 getcomponent(gfun, I::Vararg{Int})
21 54
22 Evaluate function `f` on `grid` 55 Return one of the components of gfun as a grid function.
23 """ 56 """
24 function evalOn(grid::Grid, f::Function) 57 # Should it be lazy? Could it be a view?
25 F(x) = f(x...) 58 function getcomponent(gfun, I::Vararg{Int}) end
26 return F.(points(grid)) 59 # function getcomponent(gfun, s::Symbol) end ?
60
61 # TBD: New file zero_dim_grid.jl?
62 struct ZeroDimGrid{T,S,RD} <: Grid{T,0,RD}
63 p::S
64
65 function ZeroDimGrid(p)
66 T = eltype(p)
67 S = typeof(p)
68 RD = length(p)
69 return new{T,S,RD}(p)
70 end
27 end 71 end
72
73 Base.size(g::ZeroDimGrid) = ()
74 Base.getindex(g::ZeroDimGrid) = g.p
75 Base.eachindex(g::ZeroDimGrid) = CartesianIndices(())
76