comparison sbpD2.jl @ 127:f01b70b81e95 cell_based_test

Change Type of dClosure and dClosure to stencil. Add apply_e and Apply_d
author Ylva Rydin <ylva.rydin@telia.com>
date Thu, 07 Feb 2019 16:34:55 +0100
parents 19031733bbbf
children 6b6d921e8f05
comparison
equal deleted inserted replaced
126:66c239678a21 127:f01b70b81e95
29 else 29 else
30 error("Bounds error") # TODO: Make this more standard 30 error("Bounds error") # TODO: Make this more standard
31 end 31 end
32 end 32 end
33 33
34
34 # Wrapper functions for using regular indecies without specifying regions 35 # Wrapper functions for using regular indecies without specifying regions
35 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Int) 36 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Int)
36 return apply(op, h, v, Index{Unknown}(i)) 37 return apply(op, h, v, Index{Unknown}(i))
37 end 38 end
38 39
43 44
44 struct D2{T,N,M,K} <: ConstantStencilOperator 45 struct D2{T,N,M,K} <: ConstantStencilOperator
45 quadratureClosure::NTuple{M,T} 46 quadratureClosure::NTuple{M,T}
46 innerStencil::Stencil{T,N} 47 innerStencil::Stencil{T,N}
47 closureStencils::NTuple{M,Stencil{T,K}} 48 closureStencils::NTuple{M,Stencil{T,K}}
48 eClosure::NTuple{M,T} 49 eClosure::Stencil{T,M}
49 dClosure::NTuple{M,T} 50 dClosure::Stencil{T,M}
50 parity::Parity 51 parity::Parity
51 end 52 end
52 53
53 function closureSize(D::D2)::Int 54 function closureSize(D::D2)::Int
54 return length(D.quadratureClosure) 55 return length(D.quadratureClosure)
75 r = (1-i,width-i) 76 r = (1-i,width-i)
76 closureStencils = (closureStencils..., Stencil(r, stencilWeights)) 77 closureStencils = (closureStencils..., Stencil(r, stencilWeights))
77 end 78 end
78 79
79 quadratureClosure = pad_tuple(stringToTuple(Float64, h["closure"][1]), boundarySize) 80 quadratureClosure = pad_tuple(stringToTuple(Float64, h["closure"][1]), boundarySize)
80 eClosure = pad_tuple(stringToTuple(Float64, d["e"][1]), boundarySize) 81 eClosure = Stencil((0,boundarySize-1), pad_tuple(stringToTuple(Float64, d["e"][1]), boundarySize))
81 dClosure = pad_tuple(stringToTuple(Float64, d["d1"][1]), boundarySize) 82 dClosure = Stencil((0,boundarySize-1), pad_tuple(stringToTuple(Float64, d["d1"][1]), boundarySize))
82 83
83 d2 = D2( 84 d2 = D2(
84 quadratureClosure, 85 quadratureClosure,
85 innerStencil, 86 innerStencil,
86 closureStencils, 87 closureStencils,
90 ) 91 )
91 92
92 return d2 93 return d2
93 end 94 end
94 95
96
97 function apply_e(op::D2, v::AbstractVector, ::Type{Lower})
98 apply(op.eClosure,v,1)
99 end
100
101 function apply_e(op::D2, v::AbstractVector, ::Type{Upper})
102 apply(flip(op.eClosure),v,length(v))
103 end
104
105
106 function apply_d(op::D2, h::Real, v::AbstractVector, ::Type{Lower})
107 -apply(op.dClosure,v,1)/h
108 end
109
110 function apply_d(op::D2, h::Real, v::AbstractVector, ::Type{Upper})
111 -apply(flip(op.dClosure),v,length(v))/h
112 end
95 113
96 function readSectionedFile(filename)::Dict{String, Vector{String}} 114 function readSectionedFile(filename)::Dict{String, Vector{String}}
97 f = open(filename) 115 f = open(filename)
98 sections = Dict{String, Vector{String}}() 116 sections = Dict{String, Vector{String}}()
99 currentKey = "" 117 currentKey = ""