comparison src/SbpOperators/volumeops/volume_operator.jl @ 1761:0656b46a1a74 feature/jet_aqua

Simplify size type in VolumeOperator
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 13 Sep 2024 14:47:23 +0200
parents aba2ce166546
children
comparison
equal deleted inserted replaced
1760:aba2ce166546 1761:0656b46a1a74
4 A one-dimensional constant coefficients stencil operator. 4 A one-dimensional constant coefficients stencil operator.
5 """ 5 """
6 struct VolumeOperator{T,N,M,K} <: LazyTensor{T,1,1} 6 struct VolumeOperator{T,N,M,K} <: LazyTensor{T,1,1}
7 inner_stencil::Stencil{T,N} 7 inner_stencil::Stencil{T,N}
8 closure_stencils::NTuple{M,Stencil{T,K}} 8 closure_stencils::NTuple{M,Stencil{T,K}}
9 size::NTuple{1,Int} 9 size::Int
10 parity::Parity 10 parity::Parity
11 11
12 function VolumeOperator(inner_stencil::Stencil{T,N}, closure_stencils::Tuple{Stencil{T,K}, Vararg{Stencil{T,K}}}, size::NTuple{1,Int}, parity::Parity) where {T,N,K} 12 function VolumeOperator(inner_stencil::Stencil{T,N}, closure_stencils::Tuple{Stencil{T,K}, Vararg{Stencil{T,K}}}, size::Int, parity::Parity) where {T,N,K}
13 M = length(closure_stencils) 13 M = length(closure_stencils)
14 return new{T,N,M,K}(inner_stencil, closure_stencils, size, parity) 14 return new{T,N,M,K}(inner_stencil, closure_stencils, size, parity)
15 end 15 end
16 end 16 end
17 17
18 function VolumeOperator(grid::EquidistantGrid, inner_stencil, closure_stencils, parity) 18 function VolumeOperator(grid::EquidistantGrid, inner_stencil, closure_stencils, parity)
19 return VolumeOperator(inner_stencil, Tuple(closure_stencils), size(grid), parity) 19 return VolumeOperator(inner_stencil, Tuple(closure_stencils), size(grid,1), parity)
20 end # TBD: Remove this function? 20 end # TBD: Remove this function?
21 21
22 closure_size(::VolumeOperator{T,N,M}) where {T,N,M} = M 22 closure_size(::VolumeOperator{T,N,M}) where {T,N,M} = M
23 23
24 LazyTensors.range_size(op::VolumeOperator) = op.size 24 LazyTensors.range_size(op::VolumeOperator) = (op.size,)
25 LazyTensors.domain_size(op::VolumeOperator) = op.size 25 LazyTensors.domain_size(op::VolumeOperator) = (op.size,)
26 26
27 function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i::Index{Lower}) 27 function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i::Index{Lower})
28 return @inbounds apply_stencil(op.closure_stencils[Int(i)], v, Int(i)) 28 return @inbounds apply_stencil(op.closure_stencils[Int(i)], v, Int(i))
29 end 29 end
30 30
31 function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i::Index{Interior}) 31 function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i::Index{Interior})
32 return apply_stencil(op.inner_stencil, v, Int(i)) 32 return apply_stencil(op.inner_stencil, v, Int(i))
33 end 33 end
34 34
35 function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i::Index{Upper}) 35 function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i::Index{Upper})
36 return @inbounds Int(op.parity)*apply_stencil_backwards(op.closure_stencils[op.size[1]-Int(i)+1], v, Int(i)) 36 return @inbounds Int(op.parity)*apply_stencil_backwards(op.closure_stencils[op.size-Int(i)+1], v, Int(i))
37 end 37 end
38 38
39 function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i) 39 function LazyTensors.apply(op::VolumeOperator, v::AbstractVector, i)
40 r = getregion(i, closure_size(op), op.size[1]) 40 r = getregion(i, closure_size(op), op.size)
41 return LazyTensors.apply(op, v, Index(i, r)) 41 return LazyTensors.apply(op, v, Index(i, r))
42 end 42 end
43 # TODO: Move this to LazyTensors when we have the region communication down. 43 # TODO: Move this to LazyTensors when we have the region communication down.