comparison SbpOperators/src/constantstenciloperator.jl @ 249:7cb4492ccd60 boundary_conditions

Refactor package SbpOperators
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 27 Jun 2019 14:18:48 +0200
parents
children 396eadb652bd
comparison
equal deleted inserted replaced
248:05e7bbe0af97 249:7cb4492ccd60
1 export apply
2
3 abstract type ConstantStencilOperator end
4
5 # Apply for different regions Lower/Interior/Upper or Unknown region
6 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Lower})
7 return @inbounds h*h*apply(op.closureStencils[Int(i)], v, Int(i))
8 end
9
10 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Interior})
11 return @inbounds h*h*apply(op.innerStencil, v, Int(i))
12 end
13
14 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Upper})
15 N = length(v)
16 return @inbounds h*h*Int(op.parity)*apply_backwards(op.closureStencils[N-Int(i)+1], v, Int(i))
17 end
18
19 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, index::Index{Unknown})
20 cSize = closureSize(op)
21 N = length(v)
22
23 i = Int(index)
24
25 if 0 < i <= cSize
26 return apply(op, h, v, Index{Lower}(i))
27 elseif cSize < i <= N-cSize
28 return apply(op, h, v, Index{Interior}(i))
29 elseif N-cSize < i <= N
30 return apply(op, h, v, Index{Upper}(i))
31 else
32 error("Bounds error") # TODO: Make this more standard
33 end
34 end
35
36 # Wrapper functions for using regular indecies without specifying regions
37 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Int)
38 return apply(op, h, v, Index{Unknown}(i))
39 end