annotate StencilIndex.jl @ 93:93df72e2b135 stencil_index

Implement apply for 2D-Laplace which takes an StencilIndex as input
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Mon, 04 Feb 2019 09:13:48 +0100
parents c0f33eccd527
children 84b1ad5a3755
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
91
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
1 abstract type StencilIndex end
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
2
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
3 function Base.getindex(si::StencilIndex, i::Int)
93
93df72e2b135 Implement apply for 2D-Laplace which takes an StencilIndex as input
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 91
diff changeset
4 return si.gridindex[i]
91
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
5 end
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
6
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
7 struct LowerClosureIndex <: StencilIndex
93
93df72e2b135 Implement apply for 2D-Laplace which takes an StencilIndex as input
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 91
diff changeset
8 globalindex::Integer
93df72e2b135 Implement apply for 2D-Laplace which takes an StencilIndex as input
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 91
diff changeset
9 gridindex::CartesianIndex
91
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
10 end
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
11
93
93df72e2b135 Implement apply for 2D-Laplace which takes an StencilIndex as input
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 91
diff changeset
12 struct UpperClosureIndex <: StencilIndex
93df72e2b135 Implement apply for 2D-Laplace which takes an StencilIndex as input
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 91
diff changeset
13 globalindex::Integer
93df72e2b135 Implement apply for 2D-Laplace which takes an StencilIndex as input
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 91
diff changeset
14 gridindex::CartesianIndex
91
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
15 end
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
16
93
93df72e2b135 Implement apply for 2D-Laplace which takes an StencilIndex as input
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 91
diff changeset
17 struct InteriorIndex <: StencilIndex
93df72e2b135 Implement apply for 2D-Laplace which takes an StencilIndex as input
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 91
diff changeset
18 globalindex::Integer
93df72e2b135 Implement apply for 2D-Laplace which takes an StencilIndex as input
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 91
diff changeset
19 gridindex::CartesianIndex
91
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
20 end
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
21
93
93df72e2b135 Implement apply for 2D-Laplace which takes an StencilIndex as input
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 91
diff changeset
22 # TODO: The design of StencilIndex is wrong. Use Jonatans design instead.
91
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
23 # TODO: This should take a Stencil or DiffOp so that we can extract all the
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
24 # indices in the closures.
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
25 # TODO: Where to place this function?
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
26 function stencilindices(grid::Grid.EquidistantGrid)
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
27 lowerclosure = Vector{LowerClosureIndex}(undef, 0)
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
28 upperclosure = Vector{UpperClosureIndex}(undef, 0)
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
29 interior = Vector{InteriorIndex}(undef, 0)
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
30 # TODO: Fix such that the indices of the entire closure width is included.
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
31 islower = x -> (x == 1)
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
32 isupper = x -> (x in grid.numberOfPointsPerDim)
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
33 ci = CartesianIndices(grid.numberOfPointsPerDim)
93
93df72e2b135 Implement apply for 2D-Laplace which takes an StencilIndex as input
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 91
diff changeset
34 for i ∈ 1:Grid.numberOfPoints(grid)
93df72e2b135 Implement apply for 2D-Laplace which takes an StencilIndex as input
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 91
diff changeset
35 I = Tuple(ci[i])
91
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
36 if any(islower, I)
93
93df72e2b135 Implement apply for 2D-Laplace which takes an StencilIndex as input
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 91
diff changeset
37 push!(lowerclosure, LowerClosureIndex(i,ci[i]))
91
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
38 elseif any(isupper, I)
93
93df72e2b135 Implement apply for 2D-Laplace which takes an StencilIndex as input
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 91
diff changeset
39 push!(upperclosure, UpperClosureIndex(i,ci[i]))
91
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
40 else
93
93df72e2b135 Implement apply for 2D-Laplace which takes an StencilIndex as input
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 91
diff changeset
41 push!(interior, InteriorIndex(i,ci[i]))
91
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
42 end
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
43 end
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
44 return lowerclosure, upperclosure, interior
c0f33eccd527 Create types StencilIndex, LowerClosureIndex, UpperClosureIndex and InteriorIndex. First attempt at seperating out interior and closure indices from. Not fully implemented.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
45 end