annotate src/SbpOperators/boundaryops/boundary_restriction.jl @ 570:a8fe91861116 feature/boundary_ops

Change order of type parameters R and N to allow skipping N
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 01 Dec 2020 15:36:35 +0100
parents 2a7a258eaaa6
children 205238c342da
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 """
570
a8fe91861116 Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents: 569
diff changeset
24 BoundaryRestriction{T,R,N} <: 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
569
2a7a258eaaa6 Collect documentation for BoundaryRestriction at the type definition
Jonatan Werpers <jonatan@werpers.com>
parents: 564
diff changeset
26 Implements the boundary operator `e` for 1D as a TensorMapping
2a7a258eaaa6 Collect documentation for BoundaryRestriction at the type definition
Jonatan Werpers <jonatan@werpers.com>
parents: 564
diff changeset
27 `e` is the restriction of a grid function to the boundary using some `closureStencil`.
2a7a258eaaa6 Collect documentation for BoundaryRestriction at the type definition
Jonatan Werpers <jonatan@werpers.com>
parents: 564
diff changeset
28 The boundary to restrict to is determined by `R`.
2a7a258eaaa6 Collect documentation for BoundaryRestriction at the type definition
Jonatan Werpers <jonatan@werpers.com>
parents: 564
diff changeset
29
2a7a258eaaa6 Collect documentation for BoundaryRestriction at the type definition
Jonatan Werpers <jonatan@werpers.com>
parents: 564
diff changeset
30 `e'` is the prolongation of a zero dimensional array to the whole grid using the same `closureStencil`.
510
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
31 """
570
a8fe91861116 Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents: 569
diff changeset
32 struct BoundaryRestriction{T,R<:Region,N} <: TensorMapping{T,0,1}
564
ccb41095def6 Clean up type parameters and remove obsolete todo
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 563
diff changeset
33 stencil::Stencil{T,N}
570
a8fe91861116 Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents: 569
diff changeset
34 size::Int
510
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
35 end
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
36 export BoundaryRestriction
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
37
564
ccb41095def6 Clean up type parameters and remove obsolete todo
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 563
diff changeset
38 function BoundaryRestriction(grid::EquidistantGrid{1}, closureStencil::Stencil{T,N}, region::Region) where {T,N}
570
a8fe91861116 Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents: 569
diff changeset
39 return BoundaryRestriction{T,typeof(region),N}(closureStencil,size(grid)[1])
510
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
40 end
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
41
517
2edacece1637 Fix range_size not returning empty tuple
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 515
diff changeset
42 LazyTensors.range_size(e::BoundaryRestriction) = ()
570
a8fe91861116 Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents: 569
diff changeset
43 LazyTensors.domain_size(e::BoundaryRestriction) = (e.size,)
510
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
44
570
a8fe91861116 Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents: 569
diff changeset
45 function LazyTensors.apply(e::BoundaryRestriction{T,Lower}, v::AbstractVector{T}) where T
562
8f7919a9b398 Merge with default
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 517
diff changeset
46 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
47 end
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
48
570
a8fe91861116 Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents: 569
diff changeset
49 function LazyTensors.apply(e::BoundaryRestriction{T,Upper}, v::AbstractVector{T}) where T
a8fe91861116 Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents: 569
diff changeset
50 apply_stencil_backwards(e.stencil,v,e.size)
510
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
51 end
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
52
570
a8fe91861116 Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents: 569
diff changeset
53 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Lower}, v::AbstractArray{T,0}, i) where T
a8fe91861116 Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents: 569
diff changeset
54 @boundscheck if !(0 < Int(i) <= e.size)
510
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
570
a8fe91861116 Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents: 569
diff changeset
60 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Upper}, v::AbstractArray{T,0}, i) where T
a8fe91861116 Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents: 569
diff changeset
61 @boundscheck if !(0 < Int(i) <= e.size)
513
547639572208 Get some kind of tested working implementation.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 512
diff changeset
62 throw(BoundsError())
547639572208 Get some kind of tested working implementation.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 512
diff changeset
63 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
64 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
65 end