Mercurial > repos > public > sbplib_julia
comparison SbpOperators/src/Quadrature.jl @ 301:417b767c847f
Rename DiagonalQuadrature to DiagonalNorm
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Tue, 23 Jun 2020 18:53:20 +0200 |
parents | b00eea62c78e |
children | 8c166b092b69 |
comparison
equal
deleted
inserted
replaced
300:b00eea62c78e | 301:417b767c847f |
---|---|
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 | 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 """ | 2 """ |
3 Quadrature{Dim,T<:Real,N,M,K} <: TensorMapping{T,Dim,Dim} | 3 Quadrature{Dim,T<:Real,N,M,K} <: TensorMapping{T,Dim,Dim} |
4 | 4 |
5 Implements the quadrature operator `Q` of Dim dimension as a TensorMapping | 5 Implements the quadrature operator `Q` of Dim dimension as a TensorMapping |
6 The multi-dimensional tensor operator consists of a tuple of 1D DiagonalQuadrature | 6 The multi-dimensional tensor operator consists of a tuple of 1D DiagonalNorm H |
7 tensor operators. | 7 tensor operators. |
8 """ | 8 """ |
9 struct Quadrature{Dim,T<:Real,N,M} <: TensorOperator{T,Dim} | 9 struct Quadrature{Dim,T<:Real,N,M} <: TensorOperator{T,Dim} |
10 H::NTuple{Dim,DiagonalQuadrature{T,N,M}} | 10 H::NTuple{Dim,DiagonalNorm{T,N,M}} |
11 end | 11 end |
12 export Quadrature | 12 export Quadrature |
13 | 13 |
14 LazyTensors.domain_size(Q::Quadrature{Dim}, range_size::NTuple{Dim,Integer}) where Dim = range_size | 14 LazyTensors.domain_size(Q::Quadrature{Dim}, range_size::NTuple{Dim,Integer}) where Dim = range_size |
15 | 15 |
33 @inbounds qy = apply(Q.H[2], vy, I[2]) | 33 @inbounds qy = apply(Q.H[2], vy, I[2]) |
34 return qx*qy | 34 return qx*qy |
35 end | 35 end |
36 | 36 |
37 """ | 37 """ |
38 Quadrature{Dim,T<:Real,N,M,K} <: TensorMapping{T,Dim,Dim} | 38 DiagonalNorm{Dim,T<:Real,N,M,K} <: TensorMapping{T,Dim,Dim} |
39 | 39 |
40 Implements the quadrature operator `H` of Dim dimension as a TensorMapping | 40 Implements the diagnoal norm operator `H` of Dim dimension as a TensorMapping |
41 """ | 41 """ |
42 struct DiagonalQuadrature{T<:Real,N,M} <: TensorOperator{T,1} | 42 struct DiagonalNorm{T<:Real,N,M} <: TensorOperator{T,1} |
43 h::T # The grid spacing could be included in the stencil already. Preferable? | 43 h::T # The grid spacing could be included in the stencil already. Preferable? |
44 closure::NTuple{M,T} | 44 closure::NTuple{M,T} |
45 #TODO: Write a nice constructor | 45 #TODO: Write a nice constructor |
46 end | 46 end |
47 | 47 |
48 @inline function LazyTensors.apply(H::DiagonalQuadrature{T}, v::AbstractVector{T}, I::NTuple{1,Index}) where T | 48 @inline function LazyTensors.apply(H::DiagonalNorm{T}, v::AbstractVector{T}, I::NTuple{1,Index}) where T |
49 return @inbounds apply(H, v, I[1]) | 49 return @inbounds apply(H, v, I[1]) |
50 end | 50 end |
51 | 51 |
52 LazyTensors.apply_transpose(H::Quadrature{Dim,T}, v::AbstractArray{T,2}, I::NTuple{2,Index}) where T = LazyTensors.apply(H,v,I) | 52 LazyTensors.apply_transpose(H::Quadrature{Dim,T}, v::AbstractArray{T,2}, I::NTuple{2,Index}) where T = LazyTensors.apply(H,v,I) |
53 | 53 |
54 @inline LazyTensors.apply(H::DiagonalQuadrature, v::AbstractVector{T}, i::Index{Lower}) where T | 54 @inline LazyTensors.apply(H::DiagonalNorm, v::AbstractVector{T}, i::Index{Lower}) where T |
55 return @inbounds H.h*H.closure[Int(i)]*v[Int(i)] | 55 return @inbounds H.h*H.closure[Int(i)]*v[Int(i)] |
56 end | 56 end |
57 @inline LazyTensors.apply(H::DiagonalQuadrature,v::AbstractVector{T}, i::Index{Upper}) where T | 57 @inline LazyTensors.apply(H::DiagonalNorm,v::AbstractVector{T}, i::Index{Upper}) where T |
58 N = length(v); | 58 N = length(v); |
59 return @inbounds H.h*H.closure[N-Int(i)+1]v[Int(i)] | 59 return @inbounds H.h*H.closure[N-Int(i)+1]v[Int(i)] |
60 end | 60 end |
61 | 61 |
62 @inline LazyTensors.apply(H::DiagonalQuadrature, v::AbstractVector{T}, i::Index{Interior}) where T | 62 @inline LazyTensors.apply(H::DiagonalNorm, v::AbstractVector{T}, i::Index{Interior}) where T |
63 return @inbounds H.h*v[Int(i)] | 63 return @inbounds H.h*v[Int(i)] |
64 end | 64 end |
65 | 65 |
66 function LazyTensors.apply(H::DiagonalQuadrature, v::AbstractVector{T}, index::Index{Unknown}) where T | 66 function LazyTensors.apply(H::DiagonalNorm, v::AbstractVector{T}, index::Index{Unknown}) where T |
67 N = length(v); | 67 N = length(v); |
68 r = getregion(Int(index), closuresize(H), N) | 68 r = getregion(Int(index), closuresize(H), N) |
69 i = Index(Int(index), r) | 69 i = Index(Int(index), r) |
70 return LazyTensors.apply(H, v, i) | 70 return LazyTensors.apply(H, v, i) |
71 end | 71 end |
72 export LazyTensors.apply | 72 export LazyTensors.apply |
73 | 73 |
74 function closuresize(H::DiagonalQuadrature{T<:Real,N,M}) where {T,N,M} | 74 function closuresize(H::DiagonalNorm{T<:Real,N,M}) where {T,N,M} |
75 return M | 75 return M |
76 end | 76 end |