Mercurial > repos > public > sbplib_julia
comparison StencilIndex.jl @ 91:c0f33eccd527 cell_based_test
Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Tue, 29 Jan 2019 14:32:28 +0100 |
parents | |
children | 93df72e2b135 |
comparison
equal
deleted
inserted
replaced
85:8d505e9bc715 | 91:c0f33eccd527 |
---|---|
1 abstract type StencilIndex end | |
2 | |
3 function Base.getindex(si::StencilIndex, i::Int) | |
4 return si.index[i] | |
5 end | |
6 | |
7 struct LowerClosureIndex <: StencilIndex | |
8 index::CartesianIndex | |
9 end | |
10 | |
11 struct UpperClosureIndex <: StencilIndex | |
12 index::CartesianIndex | |
13 end | |
14 | |
15 struct InteriorIndex <: StencilIndex | |
16 index::CartesianIndex | |
17 end | |
18 | |
19 # TODO: This should take a Stencil or DiffOp so that we can extract all the | |
20 # indices in the closures. | |
21 # TODO: Where to place this function? | |
22 function stencilindices(grid::Grid.EquidistantGrid) | |
23 lowerclosure = Vector{LowerClosureIndex}(undef, 0) | |
24 upperclosure = Vector{UpperClosureIndex}(undef, 0) | |
25 interior = Vector{InteriorIndex}(undef, 0) | |
26 # TODO: Fix such that the indices of the entire closure width is included. | |
27 islower = x -> (x == 1) | |
28 isupper = x -> (x in grid.numberOfPointsPerDim) | |
29 ci = CartesianIndices(grid.numberOfPointsPerDim) | |
30 for i ∈ ci | |
31 I = Tuple(i) | |
32 if any(islower, I) | |
33 push!(lowerclosure, LowerClosureIndex(i)) | |
34 # TODO: Corner points should be in both Lower and Upper? | |
35 # Should they have a separate type? | |
36 elseif any(isupper, I) | |
37 push!(upperclosure, UpperClosureIndex(i)) | |
38 else | |
39 push!(interior, InteriorIndex(i)) | |
40 end | |
41 end | |
42 return lowerclosure, upperclosure, interior | |
43 end |