comparison src/Grids/equidistant_grid.jl @ 1829:871f3f1decea refactor/grids/iterable_boundary_indices

Merge default
author Jonatan Werpers <jonatan@werpers.com>
date Sun, 20 Oct 2024 21:38:09 +0200
parents b0c019acb50b 863385aae454
children 805b9b7fcc39
comparison
equal deleted inserted replaced
1828:8adecef380b4 1829:871f3f1decea
45 45
46 The reciprocal of the spacing between grid points. 46 The reciprocal of the spacing between grid points.
47 """ 47 """
48 inverse_spacing(g::EquidistantGrid) = 1/step(g.points) 48 inverse_spacing(g::EquidistantGrid) = 1/step(g.points)
49 49
50 min_spacing(g::EquidistantGrid) = spacing(g)
50 51
51 boundary_identifiers(::EquidistantGrid) = (Lower(), Upper()) 52 """
52 boundary_grid(g::EquidistantGrid, id::Lower) = ZeroDimGrid(g[begin]) 53 LowerBoundary <: BoundaryIdentifier
53 boundary_grid(g::EquidistantGrid, id::Upper) = ZeroDimGrid(g[end]) 54
54 boundary_indices(g::EquidistantGrid, id::Lower) = 1 55 Boundary identifier for the the lower (left) boundary of a one-dimensional grid.
55 boundary_indices(g::EquidistantGrid, id::Upper) = length(g) 56
57 See also: [`BoundaryIdentifier`](@ref)
58 """
59 struct LowerBoundary <: BoundaryIdentifier end
60
61 """
62 UpperBoundary <: BoundaryIdentifier
63
64 Boundary identifier for the the upper (right) boundary of a one-dimensional grid.
65
66 See also: [`BoundaryIdentifier`](@ref)
67 """
68 struct UpperBoundary <: BoundaryIdentifier end
69
70
71 boundary_identifiers(::EquidistantGrid) = (LowerBoundary(), UpperBoundary())
72 boundary_grid(g::EquidistantGrid, id::LowerBoundary) = ZeroDimGrid(g[begin])
73 boundary_grid(g::EquidistantGrid, id::UpperBoundary) = ZeroDimGrid(g[end])
74 boundary_indices(g::EquidistantGrid, id::LowerBoundary) = (firstindex(g),)
75 boundary_indices(g::EquidistantGrid, id::UpperBoundary) = (lastindex(g),)
56 76
57 """ 77 """
58 refine(g::EquidistantGrid, r::Int) 78 refine(g::EquidistantGrid, r::Int)
59 79
60 The grid where `g` is refined by the factor `r`. The factor is applied to the number of 80 The grid where `g` is refined by the factor `r`. The factor is applied to the number of
117 """ 137 """
118 equidistant_grid(limit_lower::T, limit_upper::T, size::Int) 138 equidistant_grid(limit_lower::T, limit_upper::T, size::Int)
119 139
120 Constructs a 1D equidistant grid. 140 Constructs a 1D equidistant grid.
121 """ 141 """
122 function equidistant_grid(limit_lower::T, limit_upper::T, size::Int) where T 142 function equidistant_grid(limit_lower::Number, limit_upper::Number, size::Int)
123 if any(size .<= 0) 143 if any(size .<= 0)
124 throw(DomainError("size must be postive")) 144 throw(DomainError("size must be postive"))
125 end 145 end
126 146
127 if any(limit_upper.-limit_lower .<= 0) 147 if any(limit_upper.-limit_lower .<= 0)