Mercurial > repos > public > sbplib_julia
comparison SbpOperators/src/quadrature.jl @ 326:4c8f1e9c6d73
Change name of file.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 24 Sep 2020 21:27:43 +0200 |
parents | SbpOperators/src/Quadrature.jl@777063b6f049 |
children |
comparison
equal
deleted
inserted
replaced
323:b2ddc5e4d41a | 326:4c8f1e9c6d73 |
---|---|
1 # At the moment the grid property is used all over. It could possibly be removed if we implement all the 1D operators as TensorMappings | |
2 """ | |
3 Quadrature{Dim,T<:Real,N,M,K} <: TensorMapping{T,Dim,Dim} | |
4 | |
5 Implements the quadrature operator `Q` of Dim dimension as a TensorMapping | |
6 The multi-dimensional tensor operator consists of a tuple of 1D DiagonalNorm H | |
7 tensor operators. | |
8 """ | |
9 export Quadrature | |
10 struct Quadrature{Dim,T<:Real,N,M} <: TensorOperator{T,Dim} | |
11 H::NTuple{Dim,DiagonalNorm{T,N,M}} | |
12 end | |
13 | |
14 LazyTensors.domain_size(Q::Quadrature{Dim}, range_size::NTuple{Dim,Integer}) where Dim = range_size | |
15 | |
16 function LazyTensors.apply(Q::Quadrature{Dim,T}, v::AbstractArray{T,Dim}, I::Vararg{Index,Dim}) where {T,Dim} | |
17 error("not implemented") | |
18 end | |
19 | |
20 LazyTensors.apply_transpose(Q::Quadrature{Dim,T}, v::AbstractArray{T,Dim}, I::Vararg{Index,Dim}) where {Dim,T} = LazyTensors.apply(Q,v,I) | |
21 | |
22 @inline function LazyTensors.apply(Q::Quadrature{1,T}, v::AbstractVector{T}, I::Index) where T | |
23 @inbounds q = apply(Q.H[1], v , I) | |
24 return q | |
25 end | |
26 | |
27 @inline function LazyTensors.apply(Q::Quadrature{2,T}, v::AbstractArray{T,2}, I::Index, J::Index) where T | |
28 # Quadrature in x direction | |
29 @inbounds vx = view(v, :, Int(J)) | |
30 @inbounds qx = apply(Q.H[1], vx , I) | |
31 # Quadrature in y-direction | |
32 @inbounds vy = view(v, Int(I), :) | |
33 @inbounds qy = apply(Q.H[2], vy, J) | |
34 return qx*qy | |
35 end | |
36 | |
37 """ | |
38 DiagonalNorm{Dim,T<:Real,N,M,K} <: TensorMapping{T,Dim,Dim} | |
39 | |
40 Implements the diagnoal norm operator `H` of Dim dimension as a TensorMapping | |
41 """ | |
42 export DiagonalNorm, closuresize, LazyTensors.apply | |
43 struct DiagonalNorm{T<:Real,N,M} <: TensorOperator{T,1} | |
44 h::T # The grid spacing could be included in the stencil already. Preferable? | |
45 closure::NTuple{M,T} | |
46 #TODO: Write a nice constructor | |
47 end | |
48 | |
49 @inline function LazyTensors.apply(H::DiagonalNorm{T}, v::AbstractVector{T}, I::Index) where T | |
50 return @inbounds apply(H, v, I) | |
51 end | |
52 | |
53 LazyTensors.apply_transpose(H::Quadrature{Dim,T}, v::AbstractArray{T,2}, I::Index) where T = LazyTensors.apply(H,v,I) | |
54 | |
55 @inline LazyTensors.apply(H::DiagonalNorm, v::AbstractVector{T}, I::Index{Lower}) where T | |
56 return @inbounds H.h*H.closure[Int(I)]*v[Int(I)] | |
57 end | |
58 @inline LazyTensors.apply(H::DiagonalNorm,v::AbstractVector{T}, I::Index{Upper}) where T | |
59 N = length(v); | |
60 return @inbounds H.h*H.closure[N-Int(I)+1]v[Int(I)] | |
61 end | |
62 | |
63 @inline LazyTensors.apply(H::DiagonalNorm, v::AbstractVector{T}, I::Index{Interior}) where T | |
64 return @inbounds H.h*v[Int(I)] | |
65 end | |
66 | |
67 function LazyTensors.apply(H::DiagonalNorm, v::AbstractVector{T}, index::Index{Unknown}) where T | |
68 N = length(v); | |
69 r = getregion(Int(index), closuresize(H), N) | |
70 i = Index(Int(index), r) | |
71 return LazyTensors.apply(H, v, i) | |
72 end | |
73 | |
74 function closuresize(H::DiagonalNorm{T<:Real,N,M}) where {T,N,M} | |
75 return M | |
76 end |