annotate src/SbpOperators/boundaryops/boundary_restriction.jl @ 577:cae4d5b428d6 feature/boundary_ops

Fix typo
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 01 Dec 2020 16:48:53 +0100
parents 64f1b269e9fc
children cd7d3949f692 ea4176a5dfc5
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
571
205238c342da Add methods for closure size of a boundary restriction
Jonatan Werpers <jonatan@werpers.com>
parents: 570
diff changeset
42 closuresize(::BoundaryRestriction{T,R,N}) where {T,R,N} = N
205238c342da Add methods for closure size of a boundary restriction
Jonatan Werpers <jonatan@werpers.com>
parents: 570
diff changeset
43
517
2edacece1637 Fix range_size not returning empty tuple
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 515
diff changeset
44 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
45 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
46
570
a8fe91861116 Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents: 569
diff changeset
47 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
48 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
49 end
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
50
570
a8fe91861116 Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents: 569
diff changeset
51 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
52 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
53 end
db64cfe4d9de Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff changeset
54
572
64f1b269e9fc Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents: 571
diff changeset
55 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Lower}, v::AbstractArray{T,0}, i::Index{Lower}) where T
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
56 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
57 end
513
547639572208 Get some kind of tested working implementation.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 512
diff changeset
58
572
64f1b269e9fc Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents: 571
diff changeset
59 function LazyTensors.apply_transpose(e::BoundaryRestriction{T,Upper}, v::AbstractArray{T,0}, i::Index{Upper}) where T
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
60 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
61 end
572
64f1b269e9fc Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents: 571
diff changeset
62
577
cae4d5b428d6 Fix typo
Jonatan Werpers <jonatan@werpers.com>
parents: 572
diff changeset
63 # Catch all combinations of Lower, Upper and Interior not caught by the two previous methods.
572
64f1b269e9fc Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents: 571
diff changeset
64 function LazyTensors.apply_transpose(e::BoundaryRestriction{T}, v::AbstractArray{T,0}, i::Index) where T
64f1b269e9fc Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents: 571
diff changeset
65 return zero(T)
64f1b269e9fc Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents: 571
diff changeset
66 end
64f1b269e9fc Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents: 571
diff changeset
67
64f1b269e9fc Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents: 571
diff changeset
68 function LazyTensors.apply_transpose(e::BoundaryRestriction{T}, v::AbstractArray{T,0}, i) where T
64f1b269e9fc Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents: 571
diff changeset
69 r = getregion(i, closuresize(e), e.size)
64f1b269e9fc Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents: 571
diff changeset
70 apply_transpose(e, v, Index(i,r))
64f1b269e9fc Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents: 571
diff changeset
71 end