annotate src/SbpOperators/volumeops/laplace/laplace.jl @ 1106:b4ee47f2aafb feature/boundary_conditions

Start implementing functions for boundary conditions associated with Laplace
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Mon, 13 Jun 2022 13:46:24 +0200
parents 7fc8df5157a7
children 302d36b5ba8e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
624
a85db383484f Update documentation and remove some out-commented lines
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 618
diff changeset
1 """
995
1ba8a398af9c Rename types
Jonatan Werpers <jonatan@werpers.com>
parents: 962
diff changeset
2 Laplace{T, Dim, TM} <: LazyTensor{T, Dim, Dim}
667
f3a0d1f7d842 Make Laplace a type storing relevant operators used when writing a scheme, e.g. quadratures, normal derivatives etc.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 648
diff changeset
3
f3a0d1f7d842 Make Laplace a type storing relevant operators used when writing a scheme, e.g. quadratures, normal derivatives etc.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 648
diff changeset
4 Implements the Laplace operator, approximating ∑d²/xᵢ² , i = 1,...,`Dim` as a
1040
7fc8df5157a7 Merge default
Jonatan Werpers <jonatan@werpers.com>
parents: 995 1036
diff changeset
5 `LazyTensor`. Additionally `Laplace` stores the `StencilSet`
7fc8df5157a7 Merge default
Jonatan Werpers <jonatan@werpers.com>
parents: 995 1036
diff changeset
6 used to construct the `LazyTensor `.
667
f3a0d1f7d842 Make Laplace a type storing relevant operators used when writing a scheme, e.g. quadratures, normal derivatives etc.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 648
diff changeset
7 """
995
1ba8a398af9c Rename types
Jonatan Werpers <jonatan@werpers.com>
parents: 962
diff changeset
8 struct Laplace{T, Dim, TM<:LazyTensor{T, Dim, Dim}} <: LazyTensor{T, Dim, Dim}
951
66e8faf4bb4b Reviwe: Some more comments
Jonatan Werpers <jonatan@werpers.com>
parents: 948
diff changeset
9 D::TM # Difference operator
989
7bf3121c6864 Add type StencilSet
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 962
diff changeset
10 stencil_set::StencilSet # Stencil set of the operator
667
f3a0d1f7d842 Make Laplace a type storing relevant operators used when writing a scheme, e.g. quadratures, normal derivatives etc.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 648
diff changeset
11 end
f3a0d1f7d842 Make Laplace a type storing relevant operators used when writing a scheme, e.g. quadratures, normal derivatives etc.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 648
diff changeset
12
924
12e8e431b43c Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 922
diff changeset
13 """
936
22c80fb36400 Fix docs and add some references
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 926
diff changeset
14 Laplace(grid::Equidistant, stencil_set)
667
f3a0d1f7d842 Make Laplace a type storing relevant operators used when writing a scheme, e.g. quadratures, normal derivatives etc.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 648
diff changeset
15
989
7bf3121c6864 Add type StencilSet
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 962
diff changeset
16 Creates the `Laplace` operator `Δ` on `grid` given a `stencil_set`.
7bf3121c6864 Add type StencilSet
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 962
diff changeset
17
7bf3121c6864 Add type StencilSet
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 962
diff changeset
18 See also [`laplace`](@ref).
924
12e8e431b43c Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 922
diff changeset
19 """
1036
99d1f5651d0b Remove todo, add ::StencilSet to some methods, and update docs
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 989
diff changeset
20 function Laplace(grid::EquidistantGrid, stencil_set::StencilSet)
924
12e8e431b43c Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 922
diff changeset
21 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
12e8e431b43c Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 922
diff changeset
22 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
12e8e431b43c Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 922
diff changeset
23 Δ = laplace(grid, inner_stencil,closure_stencils)
12e8e431b43c Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 922
diff changeset
24 return Laplace(Δ,stencil_set)
667
f3a0d1f7d842 Make Laplace a type storing relevant operators used when writing a scheme, e.g. quadratures, normal derivatives etc.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 648
diff changeset
25 end
f3a0d1f7d842 Make Laplace a type storing relevant operators used when writing a scheme, e.g. quadratures, normal derivatives etc.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 648
diff changeset
26
f3a0d1f7d842 Make Laplace a type storing relevant operators used when writing a scheme, e.g. quadratures, normal derivatives etc.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 648
diff changeset
27 LazyTensors.range_size(L::Laplace) = LazyTensors.range_size(L.D)
f3a0d1f7d842 Make Laplace a type storing relevant operators used when writing a scheme, e.g. quadratures, normal derivatives etc.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 648
diff changeset
28 LazyTensors.domain_size(L::Laplace) = LazyTensors.domain_size(L.D)
f3a0d1f7d842 Make Laplace a type storing relevant operators used when writing a scheme, e.g. quadratures, normal derivatives etc.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 648
diff changeset
29 LazyTensors.apply(L::Laplace, v::AbstractArray, I...) = LazyTensors.apply(L.D,v,I...)
f3a0d1f7d842 Make Laplace a type storing relevant operators used when writing a scheme, e.g. quadratures, normal derivatives etc.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 648
diff changeset
30
995
1ba8a398af9c Rename types
Jonatan Werpers <jonatan@werpers.com>
parents: 962
diff changeset
31 # TODO: Implement pretty printing of Laplace once pretty printing of LazyTensors is implemented.
924
12e8e431b43c Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 922
diff changeset
32 # Base.show(io::IO, L::Laplace) = ...
755
36adc15d3935 Reduce the number of type perameters used by Laplace.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 754
diff changeset
33
36adc15d3935 Reduce the number of type perameters used by Laplace.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 754
diff changeset
34 """
924
12e8e431b43c Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 922
diff changeset
35 laplace(grid::EquidistantGrid, inner_stencil, closure_stencils)
624
a85db383484f Update documentation and remove some out-commented lines
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 618
diff changeset
36
995
1ba8a398af9c Rename types
Jonatan Werpers <jonatan@werpers.com>
parents: 962
diff changeset
37 Creates the Laplace operator operator `Δ` as a `LazyTensor`
624
a85db383484f Update documentation and remove some out-commented lines
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 618
diff changeset
38
a85db383484f Update documentation and remove some out-commented lines
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 618
diff changeset
39 `Δ` approximates the Laplace operator ∑d²/xᵢ² , i = 1,...,`Dim` on `grid`, using
a85db383484f Update documentation and remove some out-commented lines
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 618
diff changeset
40 the stencil `inner_stencil` in the interior and a set of stencils `closure_stencils`
a85db383484f Update documentation and remove some out-commented lines
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 618
diff changeset
41 for the points in the closure regions.
a85db383484f Update documentation and remove some out-commented lines
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 618
diff changeset
42
690
1accc3e051d0 Start changing the name of functions creating operators that are not types to lower case. E.g SecondDerivative->second_derivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 648
diff changeset
43 On a one-dimensional `grid`, `Δ` is equivalent to `second_derivative`. On a
1accc3e051d0 Start changing the name of functions creating operators that are not types to lower case. E.g SecondDerivative->second_derivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 648
diff changeset
44 multi-dimensional `grid`, `Δ` is the sum of multi-dimensional `second_derivative`s
947
38d1752a9aff Reformat "See also:"
Jonatan Werpers <jonatan@werpers.com>
parents: 936
diff changeset
45 where the sum is carried out lazily.
38d1752a9aff Reformat "See also:"
Jonatan Werpers <jonatan@werpers.com>
parents: 936
diff changeset
46
38d1752a9aff Reformat "See also:"
Jonatan Werpers <jonatan@werpers.com>
parents: 936
diff changeset
47 See also: [`second_derivative`](@ref).
624
a85db383484f Update documentation and remove some out-commented lines
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 618
diff changeset
48 """
926
47425442bbc5 Fix tests after refactoring
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 924
diff changeset
49 function laplace(grid::EquidistantGrid, inner_stencil, closure_stencils)
47425442bbc5 Fix tests after refactoring
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 924
diff changeset
50 Δ = second_derivative(grid, inner_stencil, closure_stencils, 1)
820
b4acd25943f4 Remove some more types and type parameters
Jonatan Werpers <jonatan@werpers.com>
parents: 690
diff changeset
51 for d = 2:dimension(grid)
690
1accc3e051d0 Start changing the name of functions creating operators that are not types to lower case. E.g SecondDerivative->second_derivative
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 648
diff changeset
52 Δ += second_derivative(grid, inner_stencil, closure_stencils, d)
356
0844069ab5ff Reinclude SbpOperators and fix most of the code and tests there.
Jonatan Werpers <jonatan@werpers.com>
parents: 333
diff changeset
53 end
611
e71f2f81b5f8 NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 542
diff changeset
54 return Δ
947
38d1752a9aff Reformat "See also:"
Jonatan Werpers <jonatan@werpers.com>
parents: 936
diff changeset
55 end
1106
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
56
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
57 sat(Δ::Laplace, g::EquidistantGrid, bc::BoundaryCondition{Neumann}) = neumann_sat(Δ, g, bc.id)
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
58
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
59 function neumann_sat(Δ::Laplace, g::EquidistantGrid{1}, id::BoundaryIdentifier)
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
60 set = Δ.stencil_set
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
61 H⁻¹ = inverse_inner_product(g,set)
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
62 e = boundary_restriction(g, set, id)
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
63 d = normal_derivative(g, set, id)
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
64 return f(u,data) = H⁻¹∘e'∘(d*u .- data)
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
65 #closure = H⁻¹∘e'∘d
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
66 #penalty = -H⁻¹∘e'
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
67 #return closure, penalty
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
68 end
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
69
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
70
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
71
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
72 function neumann_sat(Δ::Laplace, g::EquidistantGrid, id::BoundaryIdentifier)
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
73 set = Δ.stencil_set
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
74 H⁻¹ = inverse_inner_product(g, set)
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
75 orth_dims = Tuple(filter(i -> i != dimension(g), 1:dimension(g)))
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
76 Hᵧ = inner_product(restrict(g, orth_dims...), set)
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
77 e = boundary_restriction(g, set, id)
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
78 d = normal_derivative(g, set, id)
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
79 return f(u,data) = H⁻¹∘e'∘Hᵧ∘(d*u .- data)
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
80 #closure = H⁻¹∘e'∘Hᵧ∘d
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
81 #penalty = -H⁻¹∘e'∘Hᵧ
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
82 #return closure, penalty
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
83 end