Mercurial > repos > public > sbplib_julia
comparison sbpD2.jl @ 97:8324c82c2dfb cell_based_test
Make D2 support sbp.Index and specification of region
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 05 Feb 2019 22:30:46 +0100 |
parents | 8d505e9bc715 |
children | 50273f745f05 |
comparison
equal
deleted
inserted
replaced
96:0743e1247384 | 97:8324c82c2dfb |
---|---|
1 abstract type ConstantStencilOperator end | 1 abstract type ConstantStencilOperator end |
2 | 2 |
3 # Apply for different regions Lower/Interior/Upper | |
4 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Lower}) | |
5 return @inbounds apply(op.closureStencils[Int(i)], v, Int(i))/h^2 | |
6 end | |
7 | |
8 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Interior}) | |
9 return @inbounds apply(op.innerStencil, v, Int(i))/h^2 | |
10 end | |
11 | |
12 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Upper}) | |
13 N = length(v) | |
14 return @inbounds Int(op.parity)*apply(flip(op.closureStencils[N-Int(i)+1]), v, Int(i))/h^2 | |
15 end | |
16 | |
17 # Wrapper functions for using regular indecies without specifying regions | |
3 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Int) | 18 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Int) |
4 cSize = closureSize(op) | 19 cSize = closureSize(op) |
5 N = length(v) | 20 N = length(v) |
6 | 21 |
7 if i ∈ range(1; length=cSize) | 22 if 0 < i <= cSize |
8 @inbounds uᵢ = apply(op.closureStencils[i], v, i)/h^2 | 23 return apply(op, h, v, Index{Lower}(i)) |
9 elseif i ∈ range(N - cSize+1, length=cSize) | 24 elseif cSize < i <= N-cSize |
10 @inbounds uᵢ = Int(op.parity)*apply(flip(op.closureStencils[N-i+1]), v, i)/h^2 | 25 return apply(op, h, v, Index{Interior}(i)) |
26 elseif N-cSize < i <= N | |
27 return apply(op, h, v, Index{Upper}(i)) | |
11 else | 28 else |
12 @inbounds uᵢ = apply(op.innerStencil, v, i)/h^2 | 29 error("Bounds error") # TODO: Make this more standard |
13 end | 30 end |
14 | |
15 return uᵢ | |
16 end | 31 end |
17 | 32 |
18 @enum Parity begin | 33 @enum Parity begin |
19 odd = -1 | 34 odd = -1 |
20 even = 1 | 35 even = 1 |