Mercurial > repos > public > sbplib_julia
annotate src/SbpOperators/quadrature/inverse_diagonal_quadrature.jl @ 559:08e27dee76c3 feature/quadrature_as_outer_product
Restructure and extend tests for InverseDiagonalQuadrature. Also minor cleanup in tests for DiagonalQuadrature.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Sun, 29 Nov 2020 22:42:23 +0100 |
parents | 9b5710ae6587 |
children | 04d7b4eb63ef |
rev | line source |
---|---|
504
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
1 """ |
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
2 inverse_diagonal_quadrature(g,quadrature_closure) |
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
3 |
558
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
4 Constructs the inverse `Hi` of a `DiagonalQuadrature` on a grid of `Dim` dimensions as |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
5 a `TensorMapping`. The one-dimensional operator is a `InverseDiagonalQuadrature`, while |
504
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
6 the multi-dimensional operator is the outer-product of the one-dimensional operators |
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
7 in each coordinate direction. |
342
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
8 """ |
504
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
9 function inverse_diagonal_quadrature(g::EquidistantGrid{Dim}, quadrature_closure) where Dim |
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
10 Hi = InverseDiagonalQuadrature(restrict(g,1), quadrature_closure) |
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
11 for i ∈ 2:Dim |
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
12 Hi = Hi⊗InverseDiagonalQuadrature(restrict(g,i), quadrature_closure) |
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
13 end |
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
14 return Hi |
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
15 end |
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
16 export inverse_diagonal_quadrature |
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
17 |
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
18 |
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
19 """ |
506 | 20 InverseDiagonalQuadrature{T,M} <: TensorMapping{T,1,1} |
342
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
21 |
558
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
22 Implements the inverse of a one-dimensional `DiagonalQuadrature` as a `TensorMapping` |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
23 The operator is defined by the reciprocal of the quadrature interval length `h_inv`, the |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
24 reciprocal of the quadrature closure weights `closure` and the number of quadrature intervals `size`. The |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
25 interior stencil has the weight 1. |
342
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
26 """ |
504
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
27 struct InverseDiagonalQuadrature{T<:Real,M} <: TensorMapping{T,1,1} |
356
0844069ab5ff
Reinclude SbpOperators and fix most of the code and tests there.
Jonatan Werpers <jonatan@werpers.com>
parents:
344
diff
changeset
|
28 h_inv::T |
504
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
29 closure::NTuple{M,T} |
356
0844069ab5ff
Reinclude SbpOperators and fix most of the code and tests there.
Jonatan Werpers <jonatan@werpers.com>
parents:
344
diff
changeset
|
30 size::Tuple{Int} |
342
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
31 end |
504
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
32 export InverseDiagonalQuadrature |
342
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
33 |
558
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
34 """ |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
35 InverseDiagonalQuadrature(g, quadrature_closure) |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
36 |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
37 Constructs the `InverseDiagonalQuadrature` on the `EquidistantGrid` `g` with |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
38 closure given by the reciprocal of `quadrature_closure`. |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
39 """ |
504
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
40 function InverseDiagonalQuadrature(g::EquidistantGrid{1}, quadrature_closure) |
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
41 return InverseDiagonalQuadrature(inverse_spacing(g)[1], 1 ./ quadrature_closure, size(g)) |
356
0844069ab5ff
Reinclude SbpOperators and fix most of the code and tests there.
Jonatan Werpers <jonatan@werpers.com>
parents:
344
diff
changeset
|
42 end |
0844069ab5ff
Reinclude SbpOperators and fix most of the code and tests there.
Jonatan Werpers <jonatan@werpers.com>
parents:
344
diff
changeset
|
43 |
558
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
44 """ |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
45 domain_size(Hi::InverseDiagonalQuadrature) |
504
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
46 |
558
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
47 The size of an object in the range of `Hi` |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
48 """ |
504
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
49 LazyTensors.range_size(Hi::InverseDiagonalQuadrature) = Hi.size |
558
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
50 |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
51 """ |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
52 domain_size(Hi::InverseDiagonalQuadrature) |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
53 |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
54 The size of an object in the domain of `Hi` |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
55 """ |
504
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
56 LazyTensors.domain_size(Hi::InverseDiagonalQuadrature) = Hi.size |
356
0844069ab5ff
Reinclude SbpOperators and fix most of the code and tests there.
Jonatan Werpers <jonatan@werpers.com>
parents:
344
diff
changeset
|
57 |
558
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
58 """ |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
59 apply(Hi::InverseDiagonalQuadrature{T}, v::AbstractVector{T}, i) where T |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
60 Implements the application `(Hi*v)[i]` an `Index{R}` where `R` is one of the regions |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
61 `Lower`,`Interior`,`Upper`. If `i` is another type of index (e.g an `Int`) it will first |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
62 be converted to an `Index{R}`. |
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
63 """ |
504
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
64 function LazyTensors.apply(Hi::InverseDiagonalQuadrature{T}, v::AbstractVector{T}, I::Index{Lower}) where T |
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
65 return @inbounds Hi.h_inv*Hi.closure[Int(I)]*v[Int(I)] |
342
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
66 end |
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
67 |
504
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
68 function LazyTensors.apply(Hi::InverseDiagonalQuadrature{T}, v::AbstractVector{T}, I::Index{Upper}) where T |
342
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
69 N = length(v); |
504
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
70 return @inbounds Hi.h_inv*Hi.closure[N-Int(I)+1]*v[Int(I)] |
342
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
71 end |
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
72 |
504
21fba50cb5b0
Use LazyOuterProduct to construct multi-dimensional quadratures. This change allwed to:
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
362
diff
changeset
|
73 function LazyTensors.apply(Hi::InverseDiagonalQuadrature{T}, v::AbstractVector{T}, I::Index{Interior}) where T |
342
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
74 return @inbounds Hi.h_inv*v[Int(I)] |
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
75 end |
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
76 |
557 | 77 function LazyTensors.apply(Hi::InverseDiagonalQuadrature{T}, v::AbstractVector{T}, i) where T |
342
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
78 N = length(v); |
557 | 79 r = getregion(i, closure_size(Hi), N) |
80 return LazyTensors.apply(Hi, v, Index(i, r)) | |
342
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
81 end |
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
82 |
557 | 83 LazyTensors.apply_transpose(Hi::InverseDiagonalQuadrature{T}, v::AbstractVector{T}, i) where T = LazyTensors.apply(Hi,v,i) |
342
3c2238c681b5
Add missing file.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
84 |
506 | 85 """ |
558
9b5710ae6587
Update documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
557
diff
changeset
|
86 closure_size(Hi) |
506 | 87 Returns the size of the closure stencil of a InverseDiagonalQuadrature `Hi`. |
88 """ | |
507
576c6d1acc28
Make function naming more consistent.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
506
diff
changeset
|
89 closure_size(Hi::InverseDiagonalQuadrature{T,M}) where {T,M} = M |