comparison src/SbpOperators/stencil.jl @ 1053:cb0a5f41be02 feature/nested_stencils

Add some tests and fix some bugs (grafted from e37ee63bf9ace6cfb3bdd1c24c3e4a99e6650652)
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 20 Jan 2022 10:23:15 +0100
parents ca718fd4e816
children 011d3ff65e9f
comparison
equal deleted inserted replaced
1052:ca718fd4e816 1053:cb0a5f41be02
86 end 86 end
87 87
88 NestedStencil(s::Vararg{Stencil}; center) = NestedStencil(Stencil(s... ; center)) 88 NestedStencil(s::Vararg{Stencil}; center) = NestedStencil(Stencil(s... ; center))
89 89
90 function NestedStencil(weights::Vararg{Tuple}; center) 90 function NestedStencil(weights::Vararg{Tuple}; center)
91 inner_stencils = map((w,c) -> Stencil(w...,center=c), weights, 1:length(weights)) 91 inner_stencils = map(w -> Stencil(w...; center), weights)
92 return NestedStencil(Stencil(inner_stencils... ; center)) 92 return NestedStencil(Stencil(inner_stencils... ; center))
93 end 93 end
94 94
95 CenteredNestedStencil(s...) = NestedStencil(CenteredStencil(s...)) 95 CenteredNestedStencil(s...) = NestedStencil(CenteredStencil(s...))
96 96
102 end 102 end
103 103
104 Base.getindex(ns::NestedStencil, i::Int) = ns.s[i] 104 Base.getindex(ns::NestedStencil, i::Int) = ns.s[i]
105 105
106 "Apply inner stencils to `c` and get a concrete stencil" 106 "Apply inner stencils to `c` and get a concrete stencil"
107 Base.@propagate_inbounds function apply_stencil(ns::NestedStencil, c::AbstractVector, i::Int) 107 Base.@propagate_inbounds function apply_inner_stencils(ns::NestedStencil, c::AbstractVector, i::Int)
108 weights = apply_stencil.(ns.s.weights, Ref(c), i) 108 weights = apply_stencil.(ns.s.weights, Ref(c), i)
109 return Stencil(ns.s.range, weights) 109 return Stencil(ns.s.range, weights)
110 end 110 end
111 111
112 "Apply the whole nested stencil" 112 "Apply the whole nested stencil"
113 Base.@propagate_inbounds function apply_stencil(ns::NestedStencil, c::AbstractVector, v::AbstractVector, i::Int) 113 Base.@propagate_inbounds function apply_stencil(ns::NestedStencil, c::AbstractVector, v::AbstractVector, i::Int)
114 s = apply_stencil(ns,c,i) 114 s = apply_inner_stencils(ns,c,i)
115 return apply_stencil(s, v, i) 115 return apply_stencil(s, v, i)
116 end 116 end
117 117
118 "Apply inner stencils backwards to `c` and get a concrete stencil" 118 "Apply inner stencils backwards to `c` and get a concrete stencil"
119 Base.@propagate_inbounds @inline function apply_stencil_backwards(ns::NestedStencil, c::AbstractVector, v::AbstractVector, i::Int) 119 Base.@propagate_inbounds @inline function apply_inner_stencils_backwards(ns::NestedStencil, c::AbstractVector, i::Int)
120 weights = apply_stencil_backwards.(ns.s.weights, Ref(c), i) 120 weights = apply_stencil_backwards.(ns.s.weights, Ref(c), i)
121 return Stencil(ns.s.range, weights) 121 return Stencil(ns.s.range, weights)
122 end 122 end
123 123
124 "Apply the whole nested stencil backwards" 124 "Apply the whole nested stencil backwards"
125 Base.@propagate_inbounds @inline function apply_stencil_backwards(ns::NestedStencil, c::AbstractVector, v::AbstractVector, i::Int) 125 Base.@propagate_inbounds @inline function apply_stencil_backwards(ns::NestedStencil, c::AbstractVector, v::AbstractVector, i::Int)
126 s = apply_stencil_backwards(ns,c,i) 126 s = apply_inner_stencils_backwards(ns,c,i)
127 return apply_stencil_backwards(s, v, i) 127 return apply_stencil_backwards(s, v, i)
128 end 128 end