Mercurial > repos > public > sbplib_julia
comparison sbpD2.jl @ 98:50273f745f05 cell_based_test
Add "Unknown" region and implement D2 for it
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 06 Feb 2019 08:58:32 +0100 |
parents | 8324c82c2dfb |
children | 49796ca2dfa0 |
comparison
equal
deleted
inserted
replaced
97:8324c82c2dfb | 98:50273f745f05 |
---|---|
1 abstract type ConstantStencilOperator end | 1 abstract type ConstantStencilOperator end |
2 | 2 |
3 # Apply for different regions Lower/Interior/Upper | 3 # Apply for different regions Lower/Interior/Upper or Unknown region |
4 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Lower}) | 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 | 5 return @inbounds apply(op.closureStencils[Int(i)], v, Int(i))/h^2 |
6 end | 6 end |
7 | 7 |
8 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Interior}) | 8 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Interior}) |
12 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Upper}) | 12 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Upper}) |
13 N = length(v) | 13 N = length(v) |
14 return @inbounds Int(op.parity)*apply(flip(op.closureStencils[N-Int(i)+1]), v, Int(i))/h^2 | 14 return @inbounds Int(op.parity)*apply(flip(op.closureStencils[N-Int(i)+1]), v, Int(i))/h^2 |
15 end | 15 end |
16 | 16 |
17 # Wrapper functions for using regular indecies without specifying regions | 17 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, index::Index{Unknown}) |
18 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Int) | |
19 cSize = closureSize(op) | 18 cSize = closureSize(op) |
20 N = length(v) | 19 N = length(v) |
20 | |
21 i = Int(index) | |
21 | 22 |
22 if 0 < i <= cSize | 23 if 0 < i <= cSize |
23 return apply(op, h, v, Index{Lower}(i)) | 24 return apply(op, h, v, Index{Lower}(i)) |
24 elseif cSize < i <= N-cSize | 25 elseif cSize < i <= N-cSize |
25 return apply(op, h, v, Index{Interior}(i)) | 26 return apply(op, h, v, Index{Interior}(i)) |
26 elseif N-cSize < i <= N | 27 elseif N-cSize < i <= N |
27 return apply(op, h, v, Index{Upper}(i)) | 28 return apply(op, h, v, Index{Upper}(i)) |
28 else | 29 else |
29 error("Bounds error") # TODO: Make this more standard | 30 error("Bounds error") # TODO: Make this more standard |
30 end | 31 end |
32 end | |
33 | |
34 # Wrapper functions for using regular indecies without specifying regions | |
35 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Int) | |
36 return apply(op, h, v, Index{Unknown}(i)) | |
31 end | 37 end |
32 | 38 |
33 @enum Parity begin | 39 @enum Parity begin |
34 odd = -1 | 40 odd = -1 |
35 even = 1 | 41 even = 1 |