Mercurial > repos > public > sbplib_julia
comparison src/Grids/equidistant_grid.jl @ 1282:11b08b242e48 refactor/grids
Make equdistant_grid return an EquidistantGrid for the 1d Case
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Mon, 27 Feb 2023 15:39:13 +0100 |
| parents | 17d435c08773 |
| children | ed3ea0630825 |
comparison
equal
deleted
inserted
replaced
| 1281:1cc45207817e | 1282:11b08b242e48 |
|---|---|
| 94 completely integer grid, `equidistant_grid` will still return a floating point | 94 completely integer grid, `equidistant_grid` will still return a floating point |
| 95 grid. This simlifies the implementation and avoids certain surprise | 95 grid. This simlifies the implementation and avoids certain surprise |
| 96 behaviours. | 96 behaviours. |
| 97 """ | 97 """ |
| 98 function equidistant_grid(size::Dims, limit_lower, limit_upper) | 98 function equidistant_grid(size::Dims, limit_lower, limit_upper) |
| 99 if any(size .<= 0) | 99 gs = map(equidistant_grid, size, limit_lower, limit_upper) |
| 100 throw(DomainError("all components of size must be postive")) | |
| 101 end | |
| 102 | |
| 103 if any(limit_upper.-limit_lower .<= 0) | |
| 104 throw(DomainError("all side lengths must be postive")) | |
| 105 end | |
| 106 | |
| 107 gs = map(size, limit_lower, limit_upper) do s,l,u | |
| 108 EquidistantGrid(range(l, u, length=s)) # TBD: Should it use LinRange instead? | |
| 109 end | |
| 110 | |
| 111 return TensorGrid(gs...) | 100 return TensorGrid(gs...) |
| 112 end | 101 end |
| 113 | |
| 114 | 102 |
| 115 """ | 103 """ |
| 116 equidistant_grid(size::Int, limit_lower::T, limit_upper::T) | 104 equidistant_grid(size::Int, limit_lower::T, limit_upper::T) |
| 117 | 105 |
| 118 Constructs a 1D equidistant grid. | 106 Constructs a 1D equidistant grid. |
| 119 """ | 107 """ |
| 120 function equidistant_grid(size::Int, limit_lower::T, limit_upper::T) where T | 108 function equidistant_grid(size::Int, limit_lower::T, limit_upper::T) where T |
| 121 # TBD: Should this really return a TensorGrid? | 109 if any(size .<= 0) |
| 122 return equidistant_grid((size,),(limit_lower,),(limit_upper,)) | 110 throw(DomainError("size must be postive")) |
| 111 end | |
| 112 | |
| 113 if any(limit_upper.-limit_lower .<= 0) | |
| 114 throw(DomainError("side length must be postive")) | |
| 115 end | |
| 116 return EquidistantGrid(range(limit_lower, limit_upper, length=size)) # TBD: Should it use LinRange instead? | |
| 123 end | 117 end |
| 124 | 118 |
| 125 CartesianBoundary{D,BID} = TensorGridBoundary{D,BID} # TBD: What should we do about the naming of this boundary? | 119 CartesianBoundary{D,BID} = TensorGridBoundary{D,BID} # TBD: What should we do about the naming of this boundary? |
| 126 | 120 |
| 127 | 121 |
