comparison SbpOperators/src/quadrature/inversequadrature.jl @ 329:408c37b295c2

Refactor 1D tensor mapping in inverse quadrature to separate file, InverseDiagonalNorm. Add tests
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Fri, 25 Sep 2020 09:34:37 +0200
parents SbpOperators/src/InverseQuadrature.jl@9cc5d1498b2d
children
comparison
equal deleted inserted replaced
328:9cc5d1498b2d 329:408c37b295c2
1 export InverseQuadrature
2 """
3 InverseQuadrature{Dim,T<:Real,M,K} <: TensorMapping{T,Dim,Dim}
4
5 Implements the inverse quadrature operator `Qi` of Dim dimension as a TensorOperator
6 The multi-dimensional tensor operator consists of a tuple of 1D InverseDiagonalInnerProduct
7 tensor operators.
8 """
9 struct InverseQuadrature{Dim,T<:Real,M} <: TensorOperator{T,Dim}
10 Hi::NTuple{Dim,InverseDiagonalInnerProduct{T,M}}
11 end
12
13 LazyTensors.domain_size(Qi::InverseQuadrature{Dim}, range_size::NTuple{Dim,Integer}) where Dim = range_size
14
15 function LazyTensors.apply(Qi::InverseQuadrature{Dim,T}, v::AbstractArray{T,Dim}, I::Vararg{Index,Dim}) where {T,Dim}
16 error("not implemented")
17 end
18
19 @inline function LazyTensors.apply(Qi::InverseQuadrature{1,T}, v::AbstractVector{T}, I::Index) where T
20 @inbounds q = apply(Qi.Hi[1], v , I)
21 return q
22 end
23
24 @inline function LazyTensors.apply(Qi::InverseQuadrature{2,T}, v::AbstractArray{T,2}, I::Index, J::Index) where T
25 # InverseQuadrature in x direction
26 @inbounds vx = view(v, :, Int(J))
27 @inbounds qx_inv = apply(Qi.Hi[1], vx , I)
28 # InverseQuadrature in y-direction
29 @inbounds vy = view(v, Int(I), :)
30 @inbounds qy_inv = apply(Qi.Hi[2], vy, J)
31 return qx_inv*qy_inv
32 end
33
34 LazyTensors.apply_transpose(Qi::InverseQuadrature{Dim,T}, v::AbstractArray{T,Dim}, I::Vararg{Index,Dim}) where {Dim,T} = LazyTensors.apply(Qi,v,I...)