Mercurial > repos > public > sbplib_julia
annotate sbpD2.jl @ 4:ef878a3df87d
Use stencils in D2
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 17 Dec 2018 13:05:16 +0100 |
parents | 19492ab142c3 |
children | 2737156fb884 |
rev | line source |
---|---|
0
b714e341a0ba
Starting julia project
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
1 |
1 | 2 struct D2{T} |
3 quadratureClosure::Vector{T} | |
4 | 4 innerStencil::Stencil |
5 closureStencils::Vector{Stencil} # TBD: Should this be a tuple? | |
1 | 6 eClosure::Vector{T} |
7 dClosure::Vector{T} | |
8 end | |
2
43be32298ae2
Add function to get closure size
Jonatan Werpers <jonatan@werpers.com>
parents:
1
diff
changeset
|
9 |
43be32298ae2
Add function to get closure size
Jonatan Werpers <jonatan@werpers.com>
parents:
1
diff
changeset
|
10 function closureSize(D::D2)::Int |
43be32298ae2
Add function to get closure size
Jonatan Werpers <jonatan@werpers.com>
parents:
1
diff
changeset
|
11 return length(quadratureClosure) |
43be32298ae2
Add function to get closure size
Jonatan Werpers <jonatan@werpers.com>
parents:
1
diff
changeset
|
12 end |
3 | 13 |
4 | 14 struct Stencil{T} |
3 | 15 range::NTuple{2,Int} |
4 | 16 weights::Vector{T} # TBD: Should this be a tuple? |
3 | 17 function Stencil(range, weights) |
18 width = range[2]-range[1]+1 | |
19 if width != length(weights) | |
20 error("The width and the number of weights must be the same") | |
21 end | |
22 new(range, weights) | |
23 end | |
24 end | |
25 | |
26 # Provides index into the Stencil based on offset for the root element | |
27 function Base.getindex(s::Stencil, i::Int) | |
28 if s.range[1] <= i <= s.range[2] | |
29 return s.weights[1 + i - s.range[1]] | |
30 else | |
31 return 0 | |
32 end | |
33 end | |
34 | |
35 function apply(s::Stencil, v::AbstractVector, i::Int) | |
36 w = zero(v[0]) | |
37 for j ∈ i+(s.range[1]:s.range[2]) | |
38 w += v[j] | |
39 end | |
40 return w | |
41 end |