Mercurial > repos > public > sbplib_julia
annotate src/SbpOperators/boundaryops/boundary_operator.jl @ 1657:9c84e97de895 feature/sbp_operators/laplace_curvilinear
Fix bug in normal derivative
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 27 Jun 2024 16:40:50 +0200 |
parents | 4684c7f1c4cb |
children | 3714a391545a |
rev | line source |
---|---|
610
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
1 """ |
995 | 2 BoundaryOperator{T,R,N} <: LazyTensor{T,0,1} |
610
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
3 |
995 | 4 Implements the boundary operator `op` for 1D as a `LazyTensor` |
610
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
5 |
1329
e94ddef5e72f
Clean up documentation for changed types in SbpOperatorClean up documentation for changed types in SbpOperatorss
Jonatan Werpers <jonatan@werpers.com>
parents:
1281
diff
changeset
|
6 `op` is the restriction of a grid function to the boundary using some closure |
e94ddef5e72f
Clean up documentation for changed types in SbpOperatorClean up documentation for changed types in SbpOperatorss
Jonatan Werpers <jonatan@werpers.com>
parents:
1281
diff
changeset
|
7 `Stencil{T,N}`. The boundary to restrict to is determined by `R`. `op'` is the |
e94ddef5e72f
Clean up documentation for changed types in SbpOperatorClean up documentation for changed types in SbpOperatorss
Jonatan Werpers <jonatan@werpers.com>
parents:
1281
diff
changeset
|
8 prolongation of a zero dimensional array to the whole grid using the same |
e94ddef5e72f
Clean up documentation for changed types in SbpOperatorClean up documentation for changed types in SbpOperatorss
Jonatan Werpers <jonatan@werpers.com>
parents:
1281
diff
changeset
|
9 closure stencil. |
610
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
10 """ |
995 | 11 struct BoundaryOperator{T,R<:Region,N} <: LazyTensor{T,0,1} |
610
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
12 stencil::Stencil{T,N} |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
13 size::Int |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
14 end |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
15 |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
16 """ |
1281
1cc45207817e
Fix tests for boundary operator and boundary restriction
Jonatan Werpers <jonatan@werpers.com>
parents:
1155
diff
changeset
|
17 BoundaryOperator(grid::EquidistantGrid, closure_stencil, region) |
610
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
18 |
1329
e94ddef5e72f
Clean up documentation for changed types in SbpOperatorClean up documentation for changed types in SbpOperatorss
Jonatan Werpers <jonatan@werpers.com>
parents:
1281
diff
changeset
|
19 Constructs the BoundaryOperator with stencil `closure_stencil` for a |
e94ddef5e72f
Clean up documentation for changed types in SbpOperatorClean up documentation for changed types in SbpOperatorss
Jonatan Werpers <jonatan@werpers.com>
parents:
1281
diff
changeset
|
20 `EquidistantGrid` `grid`, restricting to to the boundary specified by |
e94ddef5e72f
Clean up documentation for changed types in SbpOperatorClean up documentation for changed types in SbpOperatorss
Jonatan Werpers <jonatan@werpers.com>
parents:
1281
diff
changeset
|
21 `region`. |
610
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
22 """ |
1281
1cc45207817e
Fix tests for boundary operator and boundary restriction
Jonatan Werpers <jonatan@werpers.com>
parents:
1155
diff
changeset
|
23 function BoundaryOperator(grid::EquidistantGrid, closure_stencil::Stencil{T,N}, region::Region) where {T,N} |
610
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
24 return BoundaryOperator{T,typeof(region),N}(closure_stencil,size(grid)[1]) |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
25 end |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
26 |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
27 """ |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
28 closure_size(::BoundaryOperator) |
1155
716e721ce3eb
Fix formatting in a few docstrings
Jonatan Werpers <jonatan@werpers.com>
parents:
1154
diff
changeset
|
29 |
610
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
30 The size of the closure stencil. |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
31 """ |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
32 closure_size(::BoundaryOperator{T,R,N}) where {T,R,N} = N |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
33 |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
34 LazyTensors.range_size(op::BoundaryOperator) = () |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
35 LazyTensors.domain_size(op::BoundaryOperator) = (op.size,) |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
36 |
946
469ed954b493
Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents:
834
diff
changeset
|
37 function LazyTensors.apply(op::BoundaryOperator{<:Any,Lower}, v::AbstractVector) |
610
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
38 apply_stencil(op.stencil,v,1) |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
39 end |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
40 |
946
469ed954b493
Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents:
834
diff
changeset
|
41 function LazyTensors.apply(op::BoundaryOperator{<:Any,Upper}, v::AbstractVector) |
610
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
42 apply_stencil_backwards(op.stencil,v,op.size) |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
43 end |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
44 |
946
469ed954b493
Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents:
834
diff
changeset
|
45 function LazyTensors.apply_transpose(op::BoundaryOperator{<:Any,Lower}, v::AbstractArray{<:Any,0}, i::Index{Lower}) |
610
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
46 return op.stencil[Int(i)-1]*v[] |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
47 end |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
48 |
946
469ed954b493
Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents:
834
diff
changeset
|
49 function LazyTensors.apply_transpose(op::BoundaryOperator{<:Any,Upper}, v::AbstractArray{<:Any,0}, i::Index{Upper}) |
610
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
50 return op.stencil[op.size[1] - Int(i)]*v[] |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
51 end |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
52 |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
53 # Catch all combinations of Lower, Upper and Interior not caught by the two previous methods. |
946
469ed954b493
Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents:
834
diff
changeset
|
54 function LazyTensors.apply_transpose(op::BoundaryOperator, v::AbstractArray{<:Any,0}, i::Index) |
469ed954b493
Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents:
834
diff
changeset
|
55 return zero(eltype(v)) |
610
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
56 end |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
57 |
946
469ed954b493
Allow volume_operator, boundary_operator, and constant_interior_scaling_operator to act on arbitrary arrays
Jonatan Werpers <jonatan@werpers.com>
parents:
834
diff
changeset
|
58 function LazyTensors.apply_transpose(op::BoundaryOperator, v::AbstractArray{<:Any,0}, i) |
610
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
59 r = getregion(i, closure_size(op), op.size) |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
60 apply_transpose(op, v, Index(i,r)) |
e40e7439d1b4
Add a general boundary operator and make BoundaryRestriction a specialization of it.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
diff
changeset
|
61 end |