comparison src/Grids/grid.jl @ 1416:031514327289 feature/boundary_conditions

Merge with default
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Tue, 22 Aug 2023 22:44:42 +0200
parents 2ad518182b37
children 455e6b4c8b02
comparison
equal deleted inserted replaced
1406:b4ec84190e6b 1416:031514327289
19 """ 19 """
20 abstract type Grid{T,D} end 20 abstract type Grid{T,D} end
21 21
22 Base.ndims(::Grid{T,D}) where {T,D} = D 22 Base.ndims(::Grid{T,D}) where {T,D} = D
23 Base.eltype(::Type{<:Grid{T}}) where T = T 23 Base.eltype(::Type{<:Grid{T}}) where T = T
24
25 Base.getindex(g::Grid, I::CartesianIndex) = g[Tuple(I)...]
24 26
25 """ 27 """
26 coordinate_size(g) 28 coordinate_size(g)
27 29
28 The lenght of the coordinate vector of `Grid` `g`. 30 The lenght of the coordinate vector of `Grid` `g`.
72 # TBD: Can we implement a version here that accepts multiple ids and grouped boundaries? Maybe we need multiblock stuff? 74 # TBD: Can we implement a version here that accepts multiple ids and grouped boundaries? Maybe we need multiblock stuff?
73 75
74 """ 76 """
75 eval_on(g::Grid, f) 77 eval_on(g::Grid, f)
76 78
77 Lazy evaluation `f` on the grid. `f` can either be on the form `f(x,y,...)` 79 Lazy evaluation of `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 80 with each coordinate as an argument, or on the form `f(x̄)` taking a
79 coordinate vector. 81 coordinate vector.
80 82
81 For concrete array grid functions `map(f,g)` can be used instead. 83 For concrete array grid functions `map(f,g)` can be used instead.
82 """ 84 """
87 else 89 else
88 return LazyTensors.LazyFunctionArray((I...)->f(g[I...]...), size(g)) 90 return LazyTensors.LazyFunctionArray((I...)->f(g[I...]...), size(g))
89 end 91 end
90 end 92 end
91 93
94 """
95 eval_on(g::Grid, f::Number)
96
97 Lazy evaluation of a scalar `f` on the grid.
98 """
99 eval_on(g::Grid, f::Number) = return LazyTensors.LazyConstantArray(f, size(g))
100
92 _ncomponents(::Type{<:Number}) = 1 101 _ncomponents(::Type{<:Number}) = 1
93 _ncomponents(T::Type{<:SVector}) = length(T) 102 _ncomponents(T::Type{<:SVector}) = length(T)