Mercurial > repos > public > sbplib_julia
annotate 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 |
rev | line source |
---|---|
212
aa17d4d9d09e
Export some functions from AbstractGrid and move documentation to docstrings
Jonatan Werpers <jonatan@werpers.com>
parents:
211
diff
changeset
|
1 """ |
1222 | 2 Grid{T,D,RD} <: AbstractArray{T,D} |
3 | |
4 The top level type for grids. | |
212
aa17d4d9d09e
Export some functions from AbstractGrid and move documentation to docstrings
Jonatan Werpers <jonatan@werpers.com>
parents:
211
diff
changeset
|
5 |
aa17d4d9d09e
Export some functions from AbstractGrid and move documentation to docstrings
Jonatan Werpers <jonatan@werpers.com>
parents:
211
diff
changeset
|
6 Should implement |
1222 | 7 # TBD: |
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 | |
212
aa17d4d9d09e
Export some functions from AbstractGrid and move documentation to docstrings
Jonatan Werpers <jonatan@werpers.com>
parents:
211
diff
changeset
|
28 |
aa17d4d9d09e
Export some functions from AbstractGrid and move documentation to docstrings
Jonatan Werpers <jonatan@werpers.com>
parents:
211
diff
changeset
|
29 """ |
1222 | 30 # TODO |
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. | |
51
614b56a017b9
Split grid.jl into AbstractGrid.jl and EquidistantGrid.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
40 |
212
aa17d4d9d09e
Export some functions from AbstractGrid and move documentation to docstrings
Jonatan Werpers <jonatan@werpers.com>
parents:
211
diff
changeset
|
41 """ |
1117
aeeffca46b94
Minor renamings
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1116
diff
changeset
|
42 dims(grid::Grid) |
1116
c2d7e940639e
Rename AbstractGrid to Grid and clean up Grids module
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1115
diff
changeset
|
43 |
1222 | 44 Enumerate the dimensions of the grid. |
1116
c2d7e940639e
Rename AbstractGrid to Grid and clean up Grids module
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1115
diff
changeset
|
45 """ |
1128
dfbd62c7eb09
Rename dim to ndims in Grids.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1117
diff
changeset
|
46 dims(grid::Grid) = 1:ndims(grid) |
1116
c2d7e940639e
Rename AbstractGrid to Grid and clean up Grids module
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1115
diff
changeset
|
47 |
1222 | 48 |
49 | |
50 # TBD: New file grid_functions.jl? | |
51 | |
1116
c2d7e940639e
Rename AbstractGrid to Grid and clean up Grids module
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1115
diff
changeset
|
52 """ |
1222 | 53 getcomponent(gfun, I::Vararg{Int}) |
51
614b56a017b9
Split grid.jl into AbstractGrid.jl and EquidistantGrid.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
54 |
1222 | 55 Return one of the components of gfun as a grid function. |
212
aa17d4d9d09e
Export some functions from AbstractGrid and move documentation to docstrings
Jonatan Werpers <jonatan@werpers.com>
parents:
211
diff
changeset
|
56 """ |
1222 | 57 # Should it be lazy? Could it be a view? |
58 function getcomponent(gfun, I::Vararg{Int}) end | |
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 | |
1128
dfbd62c7eb09
Rename dim to ndims in Grids.jl
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1117
diff
changeset
|
71 end |
1222 | 72 |
73 Base.size(g::ZeroDimGrid) = () | |
74 Base.getindex(g::ZeroDimGrid) = g.p | |
75 Base.eachindex(g::ZeroDimGrid) = CartesianIndices(()) | |
76 |