Mercurial > repos > public > sbplib_julia
comparison SbpOperators/src/Quadrature.jl @ 304:5645021683d3
Merge
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 09 Sep 2020 20:41:31 +0200 |
parents | 417b767c847f |
children | 8c166b092b69 |
comparison
equal
deleted
inserted
replaced
303:d5475ad78b28 | 304:5645021683d3 |
---|---|
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 struct Quadrature{Dim,T<:Real,N,M} <: TensorOperator{T,Dim} | |
10 H::NTuple{Dim,DiagonalNorm{T,N,M}} | |
11 end | |
12 export Quadrature | |
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::NTuple{Dim,Index}) where {T,Dim} | |
17 error("not implemented") | |
18 end | |
19 | |
20 LazyTensors.apply_transpose(Q::Quadrature{Dim,T}, v::AbstractArray{T,2}, I::NTuple{2,Index}) where {Dim,T} = LazyTensors.apply(Q,v,I) | |
21 | |
22 @inline function LazyTensors.apply(Q::Quadrature{1,T}, v::AbstractVector{T}, I::NTuple{1,Index}) where T | |
23 @inbounds q = apply(Q.H[1], v , I[1]) | |
24 return q | |
25 end | |
26 | |
27 @inline function LazyTensors.apply(Q::Quadrature{2,T}, v::AbstractArray{T,2}, I::NTuple{2,Index}) where T | |
28 # Quadrature in x direction | |
29 @inbounds vx = view(v, :, Int(I[2])) | |
30 @inbounds qx = apply(Q.H[1], vx , I[1]) | |
31 # Quadrature in y-direction | |
32 @inbounds vy = view(v, Int(I[1]), :) | |
33 @inbounds qy = apply(Q.H[2], vy, I[2]) | |
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 struct DiagonalNorm{T<:Real,N,M} <: TensorOperator{T,1} | |
43 h::T # The grid spacing could be included in the stencil already. Preferable? | |
44 closure::NTuple{M,T} | |
45 #TODO: Write a nice constructor | |
46 end | |
47 | |
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]) | |
50 end | |
51 | |
52 LazyTensors.apply_transpose(H::Quadrature{Dim,T}, v::AbstractArray{T,2}, I::NTuple{2,Index}) where T = LazyTensors.apply(H,v,I) | |
53 | |
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)] | |
56 end | |
57 @inline LazyTensors.apply(H::DiagonalNorm,v::AbstractVector{T}, i::Index{Upper}) where T | |
58 N = length(v); | |
59 return @inbounds H.h*H.closure[N-Int(i)+1]v[Int(i)] | |
60 end | |
61 | |
62 @inline LazyTensors.apply(H::DiagonalNorm, v::AbstractVector{T}, i::Index{Interior}) where T | |
63 return @inbounds H.h*v[Int(i)] | |
64 end | |
65 | |
66 function LazyTensors.apply(H::DiagonalNorm, v::AbstractVector{T}, index::Index{Unknown}) where T | |
67 N = length(v); | |
68 r = getregion(Int(index), closuresize(H), N) | |
69 i = Index(Int(index), r) | |
70 return LazyTensors.apply(H, v, i) | |
71 end | |
72 export LazyTensors.apply | |
73 | |
74 function closuresize(H::DiagonalNorm{T<:Real,N,M}) where {T,N,M} | |
75 return M | |
76 end |