Mercurial > repos > public > sbplib_julia
annotate src/SbpOperators/boundaryops/boundary_restriction.jl @ 582:aa44edea36fc feature/boundary_ops
Merge
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 01 Dec 2020 19:41:16 +0100 |
parents | ea4176a5dfc5 0779713f95a2 |
children | 6db96ef13a29 |
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 """ |
581
ea4176a5dfc5
Implement boundary_restriction in a dimension independent way
Jonatan Werpers <jonatan@werpers.com>
parents:
577
diff
changeset
|
6 function boundary_restriction(grid::EquidistantGrid{D,T}, closureStencil::Stencil{T,M}, boundary::CartesianBoundary) where {D,T,M} |
ea4176a5dfc5
Implement boundary_restriction in a dimension independent way
Jonatan Werpers <jonatan@werpers.com>
parents:
577
diff
changeset
|
7 r = region(boundary) |
ea4176a5dfc5
Implement boundary_restriction in a dimension independent way
Jonatan Werpers <jonatan@werpers.com>
parents:
577
diff
changeset
|
8 d = dim(boundary) |
ea4176a5dfc5
Implement boundary_restriction in a dimension independent way
Jonatan Werpers <jonatan@werpers.com>
parents:
577
diff
changeset
|
9 e = BoundaryRestriction(restrict(grid, d), closureStencil, r) |
ea4176a5dfc5
Implement boundary_restriction in a dimension independent way
Jonatan Werpers <jonatan@werpers.com>
parents:
577
diff
changeset
|
10 |
ea4176a5dfc5
Implement boundary_restriction in a dimension independent way
Jonatan Werpers <jonatan@werpers.com>
parents:
577
diff
changeset
|
11 one_d_grids = restrict.(Ref(grid), tuple(1:D)) |
ea4176a5dfc5
Implement boundary_restriction in a dimension independent way
Jonatan Werpers <jonatan@werpers.com>
parents:
577
diff
changeset
|
12 Is = IdentityMapping{T}.(size.(one_d_grids)) |
ea4176a5dfc5
Implement boundary_restriction in a dimension independent way
Jonatan Werpers <jonatan@werpers.com>
parents:
577
diff
changeset
|
13 parts = Base.setindex(Is, e, d) |
ea4176a5dfc5
Implement boundary_restriction in a dimension independent way
Jonatan Werpers <jonatan@werpers.com>
parents:
577
diff
changeset
|
14 return foldl(⊗, parts) |
514
14e722e8607d
Clean up constructors
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
513
diff
changeset
|
15 end |
14e722e8607d
Clean up constructors
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
513
diff
changeset
|
16 |
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
|
17 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
|
18 |
510
db64cfe4d9de
Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
19 """ |
570
a8fe91861116
Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents:
569
diff
changeset
|
20 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
|
21 |
569
2a7a258eaaa6
Collect documentation for BoundaryRestriction at the type definition
Jonatan Werpers <jonatan@werpers.com>
parents:
564
diff
changeset
|
22 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
|
23 `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
|
24 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
|
25 |
2a7a258eaaa6
Collect documentation for BoundaryRestriction at the type definition
Jonatan Werpers <jonatan@werpers.com>
parents:
564
diff
changeset
|
26 `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
|
27 """ |
570
a8fe91861116
Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents:
569
diff
changeset
|
28 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
|
29 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
|
30 size::Int |
510
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 |
580
0779713f95a2
Add constructor that infers T and N
Jonatan Werpers <jonatan@werpers.com>
parents:
579
diff
changeset
|
34 BoundaryRestriction{R}(stencil::Stencil{T,N}, size::Int) where {T,R,N} = BoundaryRestriction{T,R,N}(stencil, size) |
0779713f95a2
Add constructor that infers T and N
Jonatan Werpers <jonatan@werpers.com>
parents:
579
diff
changeset
|
35 |
564
ccb41095def6
Clean up type parameters and remove obsolete todo
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
563
diff
changeset
|
36 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
|
37 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
|
38 end |
db64cfe4d9de
Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
39 |
579
cd7d3949f692
Change name from closuresize() to closure_size()
Jonatan Werpers <jonatan@werpers.com>
parents:
577
diff
changeset
|
40 closure_size(::BoundaryRestriction{T,R,N}) where {T,R,N} = N |
571
205238c342da
Add methods for closure size of a boundary restriction
Jonatan Werpers <jonatan@werpers.com>
parents:
570
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 |
572
64f1b269e9fc
Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents:
571
diff
changeset
|
53 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
|
54 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
|
55 end |
513
547639572208
Get some kind of tested working implementation.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
512
diff
changeset
|
56 |
572
64f1b269e9fc
Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents:
571
diff
changeset
|
57 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
|
58 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
|
59 end |
572
64f1b269e9fc
Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents:
571
diff
changeset
|
60 |
577 | 61 # 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
|
62 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
|
63 return zero(T) |
64f1b269e9fc
Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents:
571
diff
changeset
|
64 end |
64f1b269e9fc
Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents:
571
diff
changeset
|
65 |
64f1b269e9fc
Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents:
571
diff
changeset
|
66 function LazyTensors.apply_transpose(e::BoundaryRestriction{T}, v::AbstractArray{T,0}, i) where T |
579
cd7d3949f692
Change name from closuresize() to closure_size()
Jonatan Werpers <jonatan@werpers.com>
parents:
577
diff
changeset
|
67 r = getregion(i, closure_size(e), e.size) |
572
64f1b269e9fc
Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents:
571
diff
changeset
|
68 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
|
69 end |