annotate src/SbpOperators/volumeops/laplace/laplace.jl @ 1751:f3d7e2d7a43f feature/sbp_operators/laplace_curvilinear

Merge feature/grids/manifolds
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 11 Sep 2024 16:26:19 +0200
parents 29b96fc75bee b5690ab5f0b8
children 1f42944d4a72
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
1329
e94ddef5e72f Clean up documentation for changed types in SbpOperatorClean up documentation for changed types in SbpOperatorss
Jonatan Werpers <jonatan@werpers.com>
parents: 1291
diff changeset
4 The Laplace operator, approximating ∑d²/xᵢ² , i = 1,...,`Dim` as a
e94ddef5e72f Clean up documentation for changed types in SbpOperatorClean up documentation for changed types in SbpOperatorss
Jonatan Werpers <jonatan@werpers.com>
parents: 1291
diff changeset
5 `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
6 """
995
1ba8a398af9c Rename types
Jonatan Werpers <jonatan@werpers.com>
parents: 962
diff changeset
7 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
8 D::TM # Difference operator
989
7bf3121c6864 Add type StencilSet
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 962
diff changeset
9 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
10 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
11
924
12e8e431b43c Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 922
diff changeset
12 """
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
13 Laplace(g::Grid, stencil_set::StencilSet)
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
14
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
15 Creates the `Laplace` operator `Δ` on `g` given `stencil_set`.
989
7bf3121c6864 Add type StencilSet
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 962
diff changeset
16
7bf3121c6864 Add type StencilSet
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 962
diff changeset
17 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
18 """
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
19 function Laplace(g::Grid, stencil_set::StencilSet)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
20 Δ = laplace(g, stencil_set)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
21 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
22 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
23
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
24 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
25 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
26 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
27
995
1ba8a398af9c Rename types
Jonatan Werpers <jonatan@werpers.com>
parents: 962
diff changeset
28 # 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
29 # 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
30
36adc15d3935 Reduce the number of type perameters used by Laplace.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 754
diff changeset
31 """
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
32 laplace(g::Grid, stencil_set)
624
a85db383484f Update documentation and remove some out-commented lines
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 618
diff changeset
33
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
34 Creates the Laplace operator operator `Δ` as a `LazyTensor` on `g`.
624
a85db383484f Update documentation and remove some out-commented lines
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 618
diff changeset
35
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
36 `Δ` approximates the Laplace operator ∑d²/xᵢ² , i = 1,...,`Dim` on `g`. The
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
37 approximation depends on the type of grid and the stencil set.
947
38d1752a9aff Reformat "See also:"
Jonatan Werpers <jonatan@werpers.com>
parents: 936
diff changeset
38
38d1752a9aff Reformat "See also:"
Jonatan Werpers <jonatan@werpers.com>
parents: 936
diff changeset
39 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
40 """
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
41 function laplace end
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
42 function laplace(g::TensorGrid, stencil_set)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
43 # return mapreduce(+, enumerate(g.grids)) do (i, gᵢ)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
44 # Δᵢ = laplace(gᵢ, stencil_set)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
45 # LazyTensors.inflate(Δᵢ, size(g), i)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
46 # end
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
47
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
48 Δ = LazyTensors.inflate(laplace(g.grids[1], stencil_set), size(g), 1)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
49 for d = 2:ndims(g)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
50 Δ += LazyTensors.inflate(laplace(g.grids[d], stencil_set), size(g), d)
356
0844069ab5ff Reinclude SbpOperators and fix most of the code and tests there.
Jonatan Werpers <jonatan@werpers.com>
parents: 333
diff changeset
51 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
52 return Δ
947
38d1752a9aff Reformat "See also:"
Jonatan Werpers <jonatan@werpers.com>
parents: 936
diff changeset
53 end
1651
707fc9761c2b Merge feature/grids/manifolds
Jonatan Werpers <jonatan@werpers.com>
parents: 1592 1619
diff changeset
54
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1128
diff changeset
55 laplace(g::EquidistantGrid, stencil_set) = second_derivative(g, stencil_set)
1395
bdcdbd4ea9cd Merge with default. Comment out broken tests for boundary_conditions at sat
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1136 1347
diff changeset
56
1585
d359d0d7fb12 Fix some typos and rename g to grid
Jonatan Werpers <jonatan@werpers.com>
parents: 1562
diff changeset
57 function laplace(grid::MappedGrid, stencil_set)
d359d0d7fb12 Fix some typos and rename g to grid
Jonatan Werpers <jonatan@werpers.com>
parents: 1562
diff changeset
58 J = jacobian_determinant(grid)
d359d0d7fb12 Fix some typos and rename g to grid
Jonatan Werpers <jonatan@werpers.com>
parents: 1562
diff changeset
59 J⁻¹ = DiagonalTensor(map(inv, J))
1562
efa994405c38 Add attempt at laplace for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents: 1347
diff changeset
60
1696
29b96fc75bee Merge feature/grids/manifolds
Jonatan Werpers <jonatan@werpers.com>
parents: 1651
diff changeset
61 Jg = map(*, J, metric_tensor_inverse(grid))
1585
d359d0d7fb12 Fix some typos and rename g to grid
Jonatan Werpers <jonatan@werpers.com>
parents: 1562
diff changeset
62 lg = logicalgrid(grid)
1562
efa994405c38 Add attempt at laplace for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents: 1347
diff changeset
63
1585
d359d0d7fb12 Fix some typos and rename g to grid
Jonatan Werpers <jonatan@werpers.com>
parents: 1562
diff changeset
64 return mapreduce(+, CartesianIndices(first(Jg))) do I
1592
4f6f5e5daa35 very minor edit
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1589
diff changeset
65 i, j = I[1], I[2]
4f6f5e5daa35 very minor edit
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1589
diff changeset
66 Jgⁱʲ = componentview(Jg, i, j)
1562
efa994405c38 Add attempt at laplace for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents: 1347
diff changeset
67
efa994405c38 Add attempt at laplace for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents: 1347
diff changeset
68 if i == j
efa994405c38 Add attempt at laplace for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents: 1347
diff changeset
69 J⁻¹∘second_derivative_variable(lg, Jgⁱʲ, stencil_set, i)
efa994405c38 Add attempt at laplace for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents: 1347
diff changeset
70 else
efa994405c38 Add attempt at laplace for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents: 1347
diff changeset
71 Dᵢ = first_derivative(lg, stencil_set, i)
efa994405c38 Add attempt at laplace for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents: 1347
diff changeset
72 Dⱼ = first_derivative(lg, stencil_set, j)
efa994405c38 Add attempt at laplace for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents: 1347
diff changeset
73 J⁻¹∘Dᵢ∘DiagonalTensor(Jgⁱʲ)∘Dⱼ
efa994405c38 Add attempt at laplace for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents: 1347
diff changeset
74 end
efa994405c38 Add attempt at laplace for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents: 1347
diff changeset
75 end
efa994405c38 Add attempt at laplace for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents: 1347
diff changeset
76 end
1651
707fc9761c2b Merge feature/grids/manifolds
Jonatan Werpers <jonatan@werpers.com>
parents: 1592 1619
diff changeset
77
707fc9761c2b Merge feature/grids/manifolds
Jonatan Werpers <jonatan@werpers.com>
parents: 1592 1619
diff changeset
78
1598
19cdec9c21cb Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1484
diff changeset
79 """
1616
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1608
diff changeset
80 sat_tensors(Δ::Laplace, g::Grid, bc::DirichletCondition; H_tuning, R_tuning)
1598
19cdec9c21cb Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1484
diff changeset
81
1619
1937be9502a7 REVIEW: Minor fixes to doc strings in laplace.jl
Jonatan Werpers <jonatan@werpers.com>
parents: 1616
diff changeset
82 The operators required to construct the SAT for imposing a Dirichlet
1937be9502a7 REVIEW: Minor fixes to doc strings in laplace.jl
Jonatan Werpers <jonatan@werpers.com>
parents: 1616
diff changeset
83 condition. `H_tuning` and `R_tuning` are used to specify the strength of the
1937be9502a7 REVIEW: Minor fixes to doc strings in laplace.jl
Jonatan Werpers <jonatan@werpers.com>
parents: 1616
diff changeset
84 penalty.
1598
19cdec9c21cb Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1484
diff changeset
85
1711
84aed3abab94 Minor documentation fixed to laplace.jl
Jonatan Werpers <jonatan@werpers.com>
parents: 1619
diff changeset
86 See also: [`sat`](@ref), [`DirichletCondition`](@ref), [`positivity_decomposition`](@ref).
1598
19cdec9c21cb Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1484
diff changeset
87 """
1606
93b86625fcfd REVIEW: Suggest split of tuning tuple. Please help with names!
Jonatan Werpers <jonatan@werpers.com>
parents: 1603
diff changeset
88 function sat_tensors(Δ::Laplace, g::Grid, bc::DirichletCondition; H_tuning = 1., R_tuning = 1.)
1602
3e7438e2a033 Address review comments (1 left to be discussed)
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1600
diff changeset
89 id = boundary(bc)
1598
19cdec9c21cb Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1484
diff changeset
90 set = Δ.stencil_set
19cdec9c21cb Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1484
diff changeset
91 H⁻¹ = inverse_inner_product(g,set)
19cdec9c21cb Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1484
diff changeset
92 Hᵧ = inner_product(boundary_grid(g, id), set)
19cdec9c21cb Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1484
diff changeset
93 e = boundary_restriction(g, set, id)
19cdec9c21cb Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1484
diff changeset
94 d = normal_derivative(g, set, id)
1673
f28c92ec843c Address TODO in laplace.jl + minor fixes
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1619
diff changeset
95 B = positivity_decomposition(Δ, g, boundary(bc); H_tuning, R_tuning)
1602
3e7438e2a033 Address review comments (1 left to be discussed)
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1600
diff changeset
96 penalty_tensor = H⁻¹∘(d' - B*e')∘Hᵧ
3e7438e2a033 Address review comments (1 left to be discussed)
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1600
diff changeset
97 return penalty_tensor, e
1598
19cdec9c21cb Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1484
diff changeset
98 end
1106
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
99
1136
470a70a6c1e6 Reformulate boundary routines (sat tensors) for Laplace and fix export
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1133
diff changeset
100 """
1616
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1608
diff changeset
101 sat_tensors(Δ::Laplace, g::Grid, bc::NeumannCondition)
1106
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
102
1619
1937be9502a7 REVIEW: Minor fixes to doc strings in laplace.jl
Jonatan Werpers <jonatan@werpers.com>
parents: 1616
diff changeset
103 The operators required to construct the SAT for imposing a Neumann condition.
1484
8d60d045c2a2 Add todo and minor edits to variable naming and docstring
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1396
diff changeset
104
1619
1937be9502a7 REVIEW: Minor fixes to doc strings in laplace.jl
Jonatan Werpers <jonatan@werpers.com>
parents: 1616
diff changeset
105 See also: [`sat`](@ref), [`NeumannCondition`](@ref).
1136
470a70a6c1e6 Reformulate boundary routines (sat tensors) for Laplace and fix export
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1133
diff changeset
106 """
1603
fca4a01d60c9 Remove module BoundaryConditions, moving its content to SbpOperators
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1602
diff changeset
107 function sat_tensors(Δ::Laplace, g::Grid, bc::NeumannCondition)
1602
3e7438e2a033 Address review comments (1 left to be discussed)
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1600
diff changeset
108 id = boundary(bc)
1106
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
109 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
110 H⁻¹ = inverse_inner_product(g,set)
1136
470a70a6c1e6 Reformulate boundary routines (sat tensors) for Laplace and fix export
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1133
diff changeset
111 Hᵧ = inner_product(boundary_grid(g, id), set)
1106
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
112 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
113 d = normal_derivative(g, set, id)
1395
bdcdbd4ea9cd Merge with default. Comment out broken tests for boundary_conditions at sat
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1136 1347
diff changeset
114
1602
3e7438e2a033 Address review comments (1 left to be discussed)
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1600
diff changeset
115 penalty_tensor = -H⁻¹∘e'∘Hᵧ
3e7438e2a033 Address review comments (1 left to be discussed)
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1600
diff changeset
116 return penalty_tensor, d
1106
b4ee47f2aafb Start implementing functions for boundary conditions associated with Laplace
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1040
diff changeset
117 end
1598
19cdec9c21cb Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1484
diff changeset
118
1616
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1608
diff changeset
119 """
1673
f28c92ec843c Address TODO in laplace.jl + minor fixes
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1619
diff changeset
120 positivity_decomposition(Δ::Laplace, g::Grid, b::BoundaryIdentifier; H_tuning, R_tuning)
1607
7216448d0c5a REVIEW: Suggest deduplication of positivity decompostion code
Jonatan Werpers <jonatan@werpers.com>
parents: 1606
diff changeset
121
1619
1937be9502a7 REVIEW: Minor fixes to doc strings in laplace.jl
Jonatan Werpers <jonatan@werpers.com>
parents: 1616
diff changeset
122 Constructs the scalar `B` such that `d' - 1/2*B*e'` is symmetric positive
1937be9502a7 REVIEW: Minor fixes to doc strings in laplace.jl
Jonatan Werpers <jonatan@werpers.com>
parents: 1616
diff changeset
123 definite with respect to the boundary quadrature. Here `d` is the normal
1937be9502a7 REVIEW: Minor fixes to doc strings in laplace.jl
Jonatan Werpers <jonatan@werpers.com>
parents: 1616
diff changeset
124 derivative and `e` is the boundary restriction operator. `B` can then be used
1937be9502a7 REVIEW: Minor fixes to doc strings in laplace.jl
Jonatan Werpers <jonatan@werpers.com>
parents: 1616
diff changeset
125 to form a symmetric and energy stable penalty for a Dirichlet condition. The
1937be9502a7 REVIEW: Minor fixes to doc strings in laplace.jl
Jonatan Werpers <jonatan@werpers.com>
parents: 1616
diff changeset
126 parameters `H_tuning` and `R_tuning` are used to specify the strength of the
1937be9502a7 REVIEW: Minor fixes to doc strings in laplace.jl
Jonatan Werpers <jonatan@werpers.com>
parents: 1616
diff changeset
127 penalty and must be greater than 1. For details we refer to
1711
84aed3abab94 Minor documentation fixed to laplace.jl
Jonatan Werpers <jonatan@werpers.com>
parents: 1619
diff changeset
128 <https://doi.org/10.1016/j.jcp.2020.109294>
1616
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1608
diff changeset
129 """
1673
f28c92ec843c Address TODO in laplace.jl + minor fixes
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1619
diff changeset
130 function positivity_decomposition(Δ::Laplace, g::Grid, b::BoundaryIdentifier; H_tuning, R_tuning)
1616
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1608
diff changeset
131 @assert(H_tuning ≥ 1.)
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1608
diff changeset
132 @assert(R_tuning ≥ 1.)
1673
f28c92ec843c Address TODO in laplace.jl + minor fixes
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1619
diff changeset
133 Nτ_H, τ_R = positivity_limits(Δ,g,b)
1607
7216448d0c5a REVIEW: Suggest deduplication of positivity decompostion code
Jonatan Werpers <jonatan@werpers.com>
parents: 1606
diff changeset
134 return H_tuning*Nτ_H + R_tuning*τ_R
7216448d0c5a REVIEW: Suggest deduplication of positivity decompostion code
Jonatan Werpers <jonatan@werpers.com>
parents: 1606
diff changeset
135 end
7216448d0c5a REVIEW: Suggest deduplication of positivity decompostion code
Jonatan Werpers <jonatan@werpers.com>
parents: 1606
diff changeset
136
1673
f28c92ec843c Address TODO in laplace.jl + minor fixes
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1619
diff changeset
137 function positivity_limits(Δ::Laplace, g::EquidistantGrid, b::BoundaryIdentifier)
1602
3e7438e2a033 Address review comments (1 left to be discussed)
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1600
diff changeset
138 h = spacing(g)
1608
8315c456e3b4 Simplify parsing of constants from stencil set
Jonatan Werpers <jonatan@werpers.com>
parents: 1607
diff changeset
139 θ_H = parse_scalar(Δ.stencil_set["H"]["closure"][1])
8315c456e3b4 Simplify parsing of constants from stencil set
Jonatan Werpers <jonatan@werpers.com>
parents: 1607
diff changeset
140 θ_R = parse_scalar(Δ.stencil_set["D2"]["positivity"]["theta_R"])
8315c456e3b4 Simplify parsing of constants from stencil set
Jonatan Werpers <jonatan@werpers.com>
parents: 1607
diff changeset
141
1712
b42a38900c9d Improve type handling in positivity_limits()
Jonatan Werpers <jonatan@werpers.com>
parents: 1711
diff changeset
142 τ_H = one(eltype(Δ))/(h*θ_H)
b42a38900c9d Improve type handling in positivity_limits()
Jonatan Werpers <jonatan@werpers.com>
parents: 1711
diff changeset
143 τ_R = one(eltype(Δ))/(h*θ_R)
1607
7216448d0c5a REVIEW: Suggest deduplication of positivity decompostion code
Jonatan Werpers <jonatan@werpers.com>
parents: 1606
diff changeset
144 return τ_H, τ_R
1598
19cdec9c21cb Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1484
diff changeset
145 end
19cdec9c21cb Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1484
diff changeset
146
1673
f28c92ec843c Address TODO in laplace.jl + minor fixes
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1619
diff changeset
147 function positivity_limits(Δ::Laplace, g::TensorGrid, b::BoundaryIdentifier)
f28c92ec843c Address TODO in laplace.jl + minor fixes
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1619
diff changeset
148 τ_H, τ_R = positivity_limits(Δ, g.grids[grid_id(b)], b)
1607
7216448d0c5a REVIEW: Suggest deduplication of positivity decompostion code
Jonatan Werpers <jonatan@werpers.com>
parents: 1606
diff changeset
149 return τ_H*ndims(g), τ_R
1602
3e7438e2a033 Address review comments (1 left to be discussed)
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1600
diff changeset
150 end