Mercurial > repos > public > sbplib_julia
view src/Grids/grid.jl @ 1288:7de1df0aad6a refactor/grids
Add component_type function to Grid
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 03 Mar 2023 15:42:05 +0100 |
parents | 1157f889bf50 |
children | 3b7ebd135918 |
line wrap: on
line source
""" Grid{T,D} The top level type for grids. TODO: Should implement * interfaces for iteration and indexing """ abstract type Grid{T,D} end Base.ndims(::Grid{T,D}) where {T,D} = D Base.eltype(::Type{<:Grid{T}}) where T = T target_manifold_dim(::Grid{T}) where T = _ncomponents(T) # TBD: Name of this function?! component_type(::Grid{T}) where T = eltype(T) """ # TODO """ function refine end """ # TODO """ function coarsen end """ # TODO """ function boundary_identifiers end """ # TODO """ function boundary_grid end # TBD Can we implement a version here that accepts multiple ids and grouped boundaries? Maybe we need multiblock stuff? # TODO: Make sure that all grids implement all of the above. """ dims(grid::Grid) Enumerate the dimensions of the grid. """ dims(grid::Grid) = 1:ndims(grid) # TBD: Is this function needed? Where is it used """ TODO: * Mention map(f,g) if you want a concrete array """ eval_on(g::Grid, f) = eval_on(g, f, Base.IteratorSize(g)) # TBD: Borde f vara först som i alla map, sum, och dylikt function eval_on(g::Grid, f, ::Base.HasShape) if hasmethod(f, (Any,)) return LazyTensors.LazyFunctionArray((I...)->f(g[I...]), size(g)) else return LazyTensors.LazyFunctionArray((I...)->f(g[I...]...), size(g)) end end # TODO: Explain how and where these are intended to be used _ncomponents(::Type{<:Number}) = 1 _ncomponents(T::Type{<:SVector}) = length(T) _component_type(T::Type{<:Number}) = T _component_type(T::Type{<:SVector}) = eltype(T)