annotate src/SbpOperators/volumeops/derivatives/second_derivative.jl @ 2096:5af7534e5b3c feature/sbp_operators/laplace_curvilinear tip

Merge default
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 02 Mar 2026 15:58:27 +0100
parents e21c295fb2da
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
623
914428a1fc61 Add documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 619
diff changeset
1 """
2091
e21c295fb2da Restructure methods for equidistant grids with a dim argument
Jonatan Werpers <jonatan@werpers.com>
parents: 2090
diff changeset
2 second_derivative(g::TensorGrid, stencil_set, dim)
623
914428a1fc61 Add documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 619
diff changeset
3
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
4 Creates the second derivative operator `D2` as a `LazyTensor`
623
914428a1fc61 Add documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 619
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: 1291
diff changeset
6 `D2` approximates the second-derivative d²/dξ² on `g` along the coordinate
2089
1bc63fa55145 Change variable name from `direction` to `dim`
Jonatan Werpers <jonatan@werpers.com>
parents: 2088
diff changeset
7 dimension specified by `dim`.
623
914428a1fc61 Add documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 619
diff changeset
8
1104
c0ab81e4c39c Update docs
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1100
diff changeset
9 See also: [`VolumeOperator`](@ref), [`LazyTensors.inflate`](@ref).
623
914428a1fc61 Add documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 619
diff changeset
10 """
2089
1bc63fa55145 Change variable name from `direction` to `dim`
Jonatan Werpers <jonatan@werpers.com>
parents: 2088
diff changeset
11 function second_derivative(g::TensorGrid, stencil_set, dim)
1bc63fa55145 Change variable name from `direction` to `dim`
Jonatan Werpers <jonatan@werpers.com>
parents: 2088
diff changeset
12 if dim ∉ 1:ndims(g)
2090
67d8fbbb9e58 Update error messages
Jonatan Werpers <jonatan@werpers.com>
parents: 2089
diff changeset
13 throw(DomainError(dim, "Derivative direction must be in 1:$(ndims(g))."))
2080
0f949681d3d3 Check that direction of first/second derivative operators is within the dimension of the grid. Add 1D functions for first/second derivative operators that take a direction.
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents: 1347
diff changeset
14 end
2089
1bc63fa55145 Change variable name from `direction` to `dim`
Jonatan Werpers <jonatan@werpers.com>
parents: 2088
diff changeset
15 D₂ = second_derivative(g.grids[dim], stencil_set)
1bc63fa55145 Change variable name from `direction` to `dim`
Jonatan Werpers <jonatan@werpers.com>
parents: 2088
diff changeset
16 return LazyTensors.inflate(D₂, size(g), dim)
356
0844069ab5ff Reinclude SbpOperators and fix most of the code and tests there.
Jonatan Werpers <jonatan@werpers.com>
parents: 348
diff changeset
17 end
990
b6238afd3bb0 Add methods for creating derivative operators in 1D from stencil sets without providing directions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 989
diff changeset
18
964
2ae62dbaf839 Add method for creating second derivative from a stencil set.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 952
diff changeset
19 """
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
20 second_derivative(g::EquidistantGrid, stencil_set::::StencilSet)
952
6a8d7fbf55fc Review: Stencil set method for second_derivative?
Jonatan Werpers <jonatan@werpers.com>
parents: 947
diff changeset
21
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
22 The second derivative operator on an `EquidistantGrid`.
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
23 Uses the `D2` stencil in `stencil_set`.
964
2ae62dbaf839 Add method for creating second derivative from a stencil set.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 952
diff changeset
24 """
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
25 function second_derivative(g::EquidistantGrid, stencil_set::StencilSet)
964
2ae62dbaf839 Add method for creating second derivative from a stencil set.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 952
diff changeset
26 inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
2ae62dbaf839 Add method for creating second derivative from a stencil set.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 952
diff changeset
27 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
28 return second_derivative(g, inner_stencil, closure_stencils)
990
b6238afd3bb0 Add methods for creating derivative operators in 1D from stencil sets without providing directions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 989
diff changeset
29 end
b6238afd3bb0 Add methods for creating derivative operators in 1D from stencil sets without providing directions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 989
diff changeset
30
2091
e21c295fb2da Restructure methods for equidistant grids with a dim argument
Jonatan Werpers <jonatan@werpers.com>
parents: 2090
diff changeset
31 function second_derivative(g::EquidistantGrid, stencil_set::StencilSet, dim)
e21c295fb2da Restructure methods for equidistant grids with a dim argument
Jonatan Werpers <jonatan@werpers.com>
parents: 2090
diff changeset
32 if dim != 1
e21c295fb2da Restructure methods for equidistant grids with a dim argument
Jonatan Werpers <jonatan@werpers.com>
parents: 2090
diff changeset
33 throw(DomainError(dim, "Derivative direction must be 1."))
e21c295fb2da Restructure methods for equidistant grids with a dim argument
Jonatan Werpers <jonatan@werpers.com>
parents: 2090
diff changeset
34 end
e21c295fb2da Restructure methods for equidistant grids with a dim argument
Jonatan Werpers <jonatan@werpers.com>
parents: 2090
diff changeset
35 return second_derivative(g, stencil_set)
e21c295fb2da Restructure methods for equidistant grids with a dim argument
Jonatan Werpers <jonatan@werpers.com>
parents: 2090
diff changeset
36 end
e21c295fb2da Restructure methods for equidistant grids with a dim argument
Jonatan Werpers <jonatan@werpers.com>
parents: 2090
diff changeset
37
990
b6238afd3bb0 Add methods for creating derivative operators in 1D from stencil sets without providing directions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 989
diff changeset
38 """
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
39 second_derivative(g::EquidistantGrid, inner_stencil::Stencil, closure_stencils)
990
b6238afd3bb0 Add methods for creating derivative operators in 1D from stencil sets without providing directions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 989
diff changeset
40
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
41 The second derivative operator on an `EquidistantGrid`, given `inner_stencil` and
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
42 `closure_stencils`.
990
b6238afd3bb0 Add methods for creating derivative operators in 1D from stencil sets without providing directions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 989
diff changeset
43 """
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
44 function second_derivative(g::EquidistantGrid, inner_stencil::Stencil, closure_stencils)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
45 h⁻¹ = inverse_spacing(g)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
46 return VolumeOperator(g, scale(inner_stencil,h⁻¹^2), scale.(closure_stencils,h⁻¹^2), even)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
47 end