Mercurial > repos > public > sbplib_julia
comparison SbpOperators/src/d2.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 D2, closureSize, readOperator, apply_e, apply_d, apply_e_T, apply_d_T | |
2 | |
3 @enum Parity begin | |
4 odd = -1 | |
5 even = 1 | |
6 end | |
7 | |
8 struct D2{T,N,M,K} <: ConstantStencilOperator | |
9 quadratureClosure::NTuple{M,T} | |
10 innerStencil::Stencil{T,N} | |
11 closureStencils::NTuple{M,Stencil{T,K}} | |
12 eClosure::Stencil{T,M} | |
13 dClosure::Stencil{T,M} | |
14 parity::Parity | |
15 end | |
16 | |
17 function closureSize(D::D2)::Int | |
18 return length(D.quadratureClosure) | |
19 end | |
20 | |
21 function apply_e_T(op::D2, v::AbstractVector, ::Type{Lower}) | |
22 @boundscheck if length(v) < closureSize(op) | |
23 throw(BoundsError()) | |
24 end | |
25 apply(op.eClosure,v,1) | |
26 end | |
27 | |
28 function apply_e_T(op::D2, v::AbstractVector, ::Type{Upper}) | |
29 @boundscheck if length(v) < closureSize(op) | |
30 throw(BoundsError()) | |
31 end | |
32 apply(flip(op.eClosure),v,length(v)) | |
33 end | |
34 | |
35 | |
36 function apply_e(op::D2, v::Number, N::Integer, i::Integer, ::Type{Lower}) | |
37 @boundscheck if !(0<length(i) <= N) | |
38 throw(BoundsError()) | |
39 end | |
40 op.eClosure[i-1]*v | |
41 end | |
42 | |
43 function apply_e(op::D2, v::Number, N::Integer, i::Integer, ::Type{Upper}) | |
44 @boundscheck if !(0<length(i) <= N) | |
45 throw(BoundsError()) | |
46 end | |
47 op.eClosure[N-i]*v | |
48 end | |
49 | |
50 function apply_d_T(op::D2, h_inv::Real, v::AbstractVector, ::Type{Lower}) | |
51 @boundscheck if length(v) < closureSize(op) | |
52 throw(BoundsError()) | |
53 end | |
54 h_inv*apply(op.dClosure,v,1) | |
55 end | |
56 | |
57 function apply_d_T(op::D2, h_inv::Real, v::AbstractVector, ::Type{Upper}) | |
58 @boundscheck if length(v) < closureSize(op) | |
59 throw(BoundsError()) | |
60 end | |
61 -h_inv*apply(flip(op.dClosure),v,length(v)) | |
62 end | |
63 | |
64 function apply_d(op::D2, h_inv::Real, v::Number, N::Integer, i::Integer, ::Type{Lower}) | |
65 @boundscheck if !(0<length(i) <= N) | |
66 throw(BoundsError()) | |
67 end | |
68 h_inv*op.dClosure[i-1]*v | |
69 end | |
70 | |
71 function apply_d(op::D2, h_inv::Real, v::Number, N::Integer, i::Integer, ::Type{Upper}) | |
72 @boundscheck if !(0<length(i) <= N) | |
73 throw(BoundsError()) | |
74 end | |
75 -h_inv*op.dClosure[N-i]*v | |
76 end |