annotate src/SbpOperators/boundaryops/boundary_restriction.jl @ 568:34d9e10f0001 feature/boundary_ops

Make grid larger in test to make sure there all kinds of regions are represented
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 01 Dec 2020 15:15:06 +0100
parents ccb41095def6
children 2a7a258eaaa6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
515
d55008f5e2f3 Fix the range of the BoundaryRestriction tensor mapping (the range is zero for the 1D operator). Add some documentation and todos.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 514
diff changeset
1 """
d55008f5e2f3 Fix the range of the BoundaryRestriction tensor mapping (the range is zero for the 1D operator). Add some documentation and todos.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 514
diff changeset
2 boundary_restriction(grid,closureStencil,boundary)
d55008f5e2f3 Fix the range of the BoundaryRestriction tensor mapping (the range is zero for the 1D operator). Add some documentation and todos.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 514
diff changeset
3
d55008f5e2f3 Fix the range of the BoundaryRestriction tensor mapping (the range is zero for the 1D operator). Add some documentation and todos.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 514
diff changeset
4 Creates a BoundaryRestriction operator for the specified boundary
d55008f5e2f3 Fix the range of the BoundaryRestriction tensor mapping (the range is zero for the 1D operator). Add some documentation and todos.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 514
diff changeset
5 """
564
ccb41095def6 Clean up type parameters and remove obsolete todo
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 563
diff changeset
6 function boundary_restriction(grid::EquidistantGrid{1}, closureStencil::Stencil, boundary::CartesianBoundary{1})
563
212e266043dd Fix region(CartesianBoundary) not returning an instance.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 562
diff changeset
7 return e = BoundaryRestriction(grid, closureStencil, region(boundary))
514
14e722e8607d Clean up constructors
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 513
diff changeset
8 end
14e722e8607d Clean up constructors
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 513
diff changeset
9
564
ccb41095def6 Clean up type parameters and remove obsolete todo
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 563
diff changeset
10 function boundary_restriction(grid::EquidistantGrid{2,T}, closureStencil::Stencil{T}, boundary::CartesianBoundary{1}) where T
563
212e266043dd Fix region(CartesianBoundary) not returning an instance.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 562
diff changeset
11 e = BoundaryRestriction(restrict(grid, 1), closureStencil, region(boundary))
514
14e722e8607d Clean up constructors
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 513
diff changeset
12 I = IdentityMapping{T}(size(restrict(grid,2)))
14e722e8607d Clean up constructors
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 513
diff changeset
13 return e⊗I
512
5a8cfcc0765d Sketch on boundary_restriction function in 2D, returning an inflated BoundaryRestriction
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 511
diff changeset
14 end
514
14e722e8607d Clean up constructors
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 513
diff changeset
15
564
ccb41095def6 Clean up type parameters and remove obsolete todo
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 563
diff changeset
16 function boundary_restriction(grid::EquidistantGrid{2,T}, closureStencil::Stencil{T}, boundary::CartesianBoundary{2}) where T
563
212e266043dd Fix region(CartesianBoundary) not returning an instance.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 562
diff changeset
17 e = BoundaryRestriction(restrict(grid, 2), closureStencil, region(boundary))
514
14e722e8607d Clean up constructors
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 513
diff changeset
18 I = IdentityMapping{T}(size(restrict(grid,1)))
14e722e8607d Clean up constructors
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 513
diff changeset
19 return I⊗e
14e722e8607d Clean up constructors
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 513
diff changeset
20 end
512
5a8cfcc0765d Sketch on boundary_restriction function in 2D, returning an inflated BoundaryRestriction
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 511
diff changeset
21 export boundary_restriction
5a8cfcc0765d Sketch on boundary_restriction function in 2D, returning an inflated BoundaryRestriction
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 511
diff changeset
22
510
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
23 """
515
d55008f5e2f3 Fix the range of the BoundaryRestriction tensor mapping (the range is zero for the 1D operator). Add some documentation and todos.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 514
diff changeset
24 BoundaryRestriction{T,N,R} <: TensorMapping{T,0,1}
510
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
25
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
26 Implements the boundary operator `e` as a TensorMapping
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
27 """
564
ccb41095def6 Clean up type parameters and remove obsolete todo
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 563
diff changeset
28 struct BoundaryRestriction{T,N,R<:Region} <: TensorMapping{T,0,1}
ccb41095def6 Clean up type parameters and remove obsolete todo
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 563
diff changeset
29 stencil::Stencil{T,N}
510
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
30 size::NTuple{1,Int}
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
31 end
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
32 export BoundaryRestriction
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
33
564
ccb41095def6 Clean up type parameters and remove obsolete todo
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 563
diff changeset
34 function BoundaryRestriction(grid::EquidistantGrid{1}, closureStencil::Stencil{T,N}, region::Region) where {T,N}
ccb41095def6 Clean up type parameters and remove obsolete todo
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 563
diff changeset
35 return BoundaryRestriction{T,N,typeof(region)}(closureStencil,size(grid))
510
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
36 end
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
37
517
2edacece1637 Fix range_size not returning empty tuple
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 515
diff changeset
38 LazyTensors.range_size(e::BoundaryRestriction) = ()
510
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
39 LazyTensors.domain_size(e::BoundaryRestriction) = e.size
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
40
511
f5f3b832f9c4 Fix boundschecking for BoundaryRestriction
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 510
diff changeset
41 " Restricts a grid function v on a grid of size m to the scalar element v[1]"
564
ccb41095def6 Clean up type parameters and remove obsolete todo
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 563
diff changeset
42 function LazyTensors.apply(e::BoundaryRestriction{T,N,Lower}, v::AbstractVector{T}) where {T,N}
562
8f7919a9b398 Merge with default
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 517
diff changeset
43 apply_stencil(e.stencil,v,1)
510
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
44 end
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
45
511
f5f3b832f9c4 Fix boundschecking for BoundaryRestriction
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 510
diff changeset
46 " Restricts a grid function v on a grid of size m to the scalar element v[m]"
564
ccb41095def6 Clean up type parameters and remove obsolete todo
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 563
diff changeset
47 function LazyTensors.apply(e::BoundaryRestriction{T,N,Upper}, v::AbstractVector{T}) where {T,N}
562
8f7919a9b398 Merge with default
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 517
diff changeset
48 apply_stencil_backwards(e.stencil,v,e.size[1])
510
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
49 end
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
50
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
51 " Transpose of a restriction is an inflation or prolongation.
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
52 Inflates the scalar (1-element) vector to a vector of size of the grid"
564
ccb41095def6 Clean up type parameters and remove obsolete todo
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 563
diff changeset
53 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,N,Lower}, v::AbstractArray{T,0}, i) where {T,N}
510
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
54 @boundscheck if !(0 < Int(i) <= e.size[1])
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
55 throw(BoundsError())
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
56 end
515
d55008f5e2f3 Fix the range of the BoundaryRestriction tensor mapping (the range is zero for the 1D operator). Add some documentation and todos.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 514
diff changeset
57 return e.stencil[Int(i)-1]*v[]
510
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
58 end
513
547639572208 Get some kind of tested working implementation.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 512
diff changeset
59
547639572208 Get some kind of tested working implementation.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 512
diff changeset
60 " Transpose of a restriction is an inflation or prolongation.
547639572208 Get some kind of tested working implementation.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 512
diff changeset
61 Inflates the scalar (1-element) vector to a vector of size of the grid"
564
ccb41095def6 Clean up type parameters and remove obsolete todo
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 563
diff changeset
62 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,N,Upper}, v::AbstractArray{T,0}, i) where {T,N}
513
547639572208 Get some kind of tested working implementation.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 512
diff changeset
63 @boundscheck if !(0 < Int(i) <= e.size[1])
547639572208 Get some kind of tested working implementation.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 512
diff changeset
64 throw(BoundsError())
547639572208 Get some kind of tested working implementation.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 512
diff changeset
65 end
515
d55008f5e2f3 Fix the range of the BoundaryRestriction tensor mapping (the range is zero for the 1D operator). Add some documentation and todos.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 514
diff changeset
66 return e.stencil[e.size[1] - Int(i)]*v[]
513
547639572208 Get some kind of tested working implementation.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 512
diff changeset
67 end