Mercurial > repos > public > sbplib_julia
annotate src/SbpOperators/boundaryops/boundary_restriction.jl @ 581:ea4176a5dfc5 feature/boundary_ops
Implement boundary_restriction in a dimension independent way
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 01 Dec 2020 17:31:30 +0100 |
parents | cae4d5b428d6 |
children | aa44edea36fc |
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 |
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} |
570
a8fe91861116
Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents:
569
diff
changeset
|
35 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
|
36 end |
db64cfe4d9de
Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
37 |
571
205238c342da
Add methods for closure size of a boundary restriction
Jonatan Werpers <jonatan@werpers.com>
parents:
570
diff
changeset
|
38 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
|
39 |
517
2edacece1637
Fix range_size not returning empty tuple
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
515
diff
changeset
|
40 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
|
41 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
|
42 |
570
a8fe91861116
Change order of type parameters R and N to allow skipping N
Jonatan Werpers <jonatan@werpers.com>
parents:
569
diff
changeset
|
43 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
|
44 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
|
45 end |
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,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
|
48 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
|
49 end |
db64cfe4d9de
Start sketching on 1D boundary restriction operators.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
50 |
572
64f1b269e9fc
Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents:
571
diff
changeset
|
51 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
|
52 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
|
53 end |
513
547639572208
Get some kind of tested working implementation.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
512
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,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
|
56 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
|
57 end |
572
64f1b269e9fc
Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents:
571
diff
changeset
|
58 |
577 | 59 # 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
|
60 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
|
61 return zero(T) |
64f1b269e9fc
Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents:
571
diff
changeset
|
62 end |
64f1b269e9fc
Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents:
571
diff
changeset
|
63 |
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) where T |
64f1b269e9fc
Implement apply_transpose for different regions and remove boundschecks to simplify
Jonatan Werpers <jonatan@werpers.com>
parents:
571
diff
changeset
|
65 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
|
66 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
|
67 end |