Mercurial > repos > public > sbplib_julia
comparison src/Grids/grid.jl @ 1360:f59228534d3a tooling/benchmarks
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 20 May 2023 15:15:22 +0200 |
parents | 08f06bfacd5c |
children | 4d628c83987e 86026367a9ff |
comparison
equal
deleted
inserted
replaced
1321:42738616422e | 1360:f59228534d3a |
---|---|
1 """ | 1 """ |
2 Grid | 2 Grid{T,D} |
3 | 3 |
4 Should implement | 4 A grid with coordinates of type `T`, e.g. `SVector{3,Float64}`, and dimension |
5 Base.ndims(grid::Grid) | 5 `D`. The grid can be embedded in a higher dimension in which case the number |
6 points(grid::Grid) | 6 of indices and the number of components of the coordinate vectors will be |
7 different. | |
8 | |
9 All grids are expected to behave as a grid function for the coordinates. | |
10 | |
11 `Grids` is top level abstract type for grids. A grid should implement Julia's interfaces for | |
12 indexing and iteration. | |
13 | |
14 ## Note | |
15 | |
16 Importantly a grid does not have to be an `AbstractArray`. The reason is to | |
17 allow flexible handling of special types of grids like multi-block grids, or | |
18 grids with special indexing. | |
19 """ | |
20 abstract type Grid{T,D} end | |
21 | |
22 Base.ndims(::Grid{T,D}) where {T,D} = D | |
23 Base.eltype(::Type{<:Grid{T}}) where T = T | |
7 | 24 |
8 """ | 25 """ |
9 abstract type Grid end | 26 coordinate_size(g) |
10 function points end | 27 |
28 The lenght of the coordinate vector of `Grid` `g`. | |
29 """ | |
30 coordinate_size(::Type{<:Grid{T}}) where T = _ncomponents(T) | |
31 coordinate_size(g::Grid) = coordinate_size(typeof(g)) # TBD: Name of this function?! | |
11 | 32 |
12 """ | 33 """ |
13 dims(grid::Grid) | 34 component_type(g) |
14 | 35 |
15 A range containing the dimensions of `grid` | 36 The type of the components of the coordinate vector of `Grid` `g`. |
16 """ | 37 """ |
17 dims(grid::Grid) = 1:ndims(grid) | 38 component_type(::Type{<:Grid{T}}) where T = eltype(T) |
39 component_type(g::Grid) = component_type(typeof(g)) | |
18 | 40 |
19 """ | 41 """ |
20 evalOn(grid::Grid, f::Function) | 42 refine(g::Grid, r) |
21 | 43 |
22 Evaluate function `f` on `grid` | 44 The grid where `g` is refined by the factor `r`. |
45 | |
46 See also: [`coarsen`](@ref). | |
23 """ | 47 """ |
24 function evalOn(grid::Grid, f::Function) | 48 function refine end |
25 F(x) = f(x...) | 49 |
26 return F.(points(grid)) | 50 """ |
51 coarsen(g::Grid, r) | |
52 | |
53 The grid where `g` is coarsened by the factor `r`. | |
54 | |
55 See also: [`refine`](@ref). | |
56 """ | |
57 function coarsen end | |
58 | |
59 """ | |
60 boundary_identifiers(g::Grid) | |
61 | |
62 Identifiers for all the boundaries of `g`. | |
63 """ | |
64 function boundary_identifiers end | |
65 | |
66 """ | |
67 boundary_grid(g::Grid, id::BoundaryIdentifier) | |
68 | |
69 The grid for the boundary specified by `id`. | |
70 """ | |
71 function boundary_grid end | |
72 # TBD: Can we implement a version here that accepts multiple ids and grouped boundaries? Maybe we need multiblock stuff? | |
73 | |
74 """ | |
75 eval_on(g::Grid, f) | |
76 | |
77 Lazy evaluation `f` on the grid. `f` can either be on the form `f(x,y,...)` | |
78 with each coordinate as an argument, or on the form `f(x̄)` taking a | |
79 coordinate vector. | |
80 | |
81 For concrete array grid functions `map(f,g)` can be used instead. | |
82 """ | |
83 eval_on(g::Grid, f) = eval_on(g, f, Base.IteratorSize(g)) | |
84 function eval_on(g::Grid, f, ::Base.HasShape) | |
85 if hasmethod(f, (Any,)) | |
86 return LazyTensors.LazyFunctionArray((I...)->f(g[I...]), size(g)) | |
87 else | |
88 return LazyTensors.LazyFunctionArray((I...)->f(g[I...]...), size(g)) | |
89 end | |
27 end | 90 end |
91 | |
92 _ncomponents(::Type{<:Number}) = 1 | |
93 _ncomponents(T::Type{<:SVector}) = length(T) |