comparison src/Grids/EquidistantGrid.jl @ 1093:703eaa3e50c4 feature/variable_derivatives

Merge refactor/grids
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 27 Apr 2022 10:26:11 +0200
parents c4ea28d904f5
children
comparison
equal deleted inserted replaced
1091:e3b41d48b5aa 1093:703eaa3e50c4
42 by the tuple `size`. 42 by the tuple `size`.
43 """ 43 """
44 function EquidistantGrid(size, limit_lower, limit_upper) 44 function EquidistantGrid(size, limit_lower, limit_upper)
45 return EquidistantGrid{length(size), eltype(limit_lower)}(size, limit_lower, limit_upper) 45 return EquidistantGrid{length(size), eltype(limit_lower)}(size, limit_lower, limit_upper)
46 end 46 end
47 # TBD: Should it be an AbstractArray?
47 48
48 """ 49 """
49 EquidistantGrid{T}() 50 EquidistantGrid{T}()
50 51
51 Constructs a 0-dimensional grid. 52 Constructs a 0-dimensional grid.
65 66
66 Base.eachindex(grid::EquidistantGrid) = CartesianIndices(grid.size) 67 Base.eachindex(grid::EquidistantGrid) = CartesianIndices(grid.size)
67 68
68 Base.size(g::EquidistantGrid) = g.size 69 Base.size(g::EquidistantGrid) = g.size
69 70
70 function Base.getindex(g::EquidistantGrid, I...) 71 function Base.getindex(g::EquidistantGrid, I::Vararg{Int})
71 h = spacing(g) 72 h = spacing(g)
72 return g.limit_lower .+ (I.-1).*h 73 return g.limit_lower .+ (I.-1).*h
73 end 74 end
75
76 Base.getindex(g::EquidistantGrid, I::CartesianIndex) = g[Tuple(I)...]
77 # TBD: Can this method be removed if `EquidistantGrid` is an AbstractArray?
74 78
75 """ 79 """
76 dimension(grid::EquidistantGrid) 80 dimension(grid::EquidistantGrid)
77 81
78 The dimension of the grid. 82 The dimension of the grid.