comparison src/SbpOperators/volumeops/quadratures/inverse_diagonal_quadrature.jl @ 636:a1dfaf305f41 feature/volume_and_boundary_operators

Move SbpOpertors/quadrature to SbpOperators/volumeops/
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Fri, 01 Jan 2021 16:45:48 +0100
parents src/SbpOperators/quadrature/inverse_diagonal_quadrature.jl@04d7b4eb63ef
children
comparison
equal deleted inserted replaced
634:fb5ac62563aa 636:a1dfaf305f41
1 """
2 inverse_diagonal_quadrature(g,quadrature_closure)
3
4 Constructs the inverse `Hi` of a `DiagonalQuadrature` on a grid of `Dim` dimensions as
5 a `TensorMapping`. The one-dimensional operator is a `InverseDiagonalQuadrature`, while
6 the multi-dimensional operator is the outer-product of the one-dimensional operators
7 in each coordinate direction.
8 """
9 function inverse_diagonal_quadrature(g::EquidistantGrid{Dim}, quadrature_closure) where Dim
10 Hi = InverseDiagonalQuadrature(restrict(g,1), quadrature_closure)
11 for i ∈ 2:Dim
12 Hi = Hi⊗InverseDiagonalQuadrature(restrict(g,i), quadrature_closure)
13 end
14 return Hi
15 end
16 export inverse_diagonal_quadrature
17
18
19 """
20 InverseDiagonalQuadrature{T,M} <: TensorMapping{T,1,1}
21
22 Implements the inverse of a one-dimensional `DiagonalQuadrature` as a `TensorMapping`
23 The operator is defined by the reciprocal of the quadrature interval length `h_inv`, the
24 reciprocal of the quadrature closure weights `closure` and the number of quadrature intervals `size`. The
25 interior stencil has the weight 1.
26 """
27 struct InverseDiagonalQuadrature{T<:Real,M} <: TensorMapping{T,1,1}
28 h_inv::T
29 closure::NTuple{M,T}
30 size::Tuple{Int}
31 end
32 export InverseDiagonalQuadrature
33
34 """
35 InverseDiagonalQuadrature(g, quadrature_closure)
36
37 Constructs the `InverseDiagonalQuadrature` on the `EquidistantGrid` `g` with
38 closure given by the reciprocal of `quadrature_closure`.
39 """
40 function InverseDiagonalQuadrature(g::EquidistantGrid{1}, quadrature_closure)
41 return InverseDiagonalQuadrature(inverse_spacing(g)[1], 1 ./ quadrature_closure, size(g))
42 end
43
44 """
45 domain_size(Hi::InverseDiagonalQuadrature)
46
47 The size of an object in the range of `Hi`
48 """
49 LazyTensors.range_size(Hi::InverseDiagonalQuadrature) = Hi.size
50
51 """
52 domain_size(Hi::InverseDiagonalQuadrature)
53
54 The size of an object in the domain of `Hi`
55 """
56 LazyTensors.domain_size(Hi::InverseDiagonalQuadrature) = Hi.size
57
58 """
59 apply(Hi::InverseDiagonalQuadrature{T}, v::AbstractVector{T}, i) where T
60 Implements the application `(Hi*v)[i]` an `Index{R}` where `R` is one of the regions
61 `Lower`,`Interior`,`Upper`. If `i` is another type of index (e.g an `Int`) it will first
62 be converted to an `Index{R}`.
63 """
64 function LazyTensors.apply(Hi::InverseDiagonalQuadrature{T}, v::AbstractVector{T}, i::Index{Lower}) where T
65 return @inbounds Hi.h_inv*Hi.closure[Int(i)]*v[Int(i)]
66 end
67
68 function LazyTensors.apply(Hi::InverseDiagonalQuadrature{T}, v::AbstractVector{T}, i::Index{Upper}) where T
69 N = length(v);
70 return @inbounds Hi.h_inv*Hi.closure[N-Int(i)+1]*v[Int(i)]
71 end
72
73 function LazyTensors.apply(Hi::InverseDiagonalQuadrature{T}, v::AbstractVector{T}, i::Index{Interior}) where T
74 return @inbounds Hi.h_inv*v[Int(i)]
75 end
76
77 function LazyTensors.apply(Hi::InverseDiagonalQuadrature{T}, v::AbstractVector{T}, i) where T
78 N = length(v);
79 r = getregion(i, closure_size(Hi), N)
80 return LazyTensors.apply(Hi, v, Index(i, r))
81 end
82
83 LazyTensors.apply_transpose(Hi::InverseDiagonalQuadrature{T}, v::AbstractVector{T}, i) where T = LazyTensors.apply(Hi,v,i)
84
85 """
86 closure_size(Hi)
87 Returns the size of the closure stencil of a InverseDiagonalQuadrature `Hi`.
88 """
89 closure_size(Hi::InverseDiagonalQuadrature{T,M}) where {T,M} = M