annotate src/SbpOperators/volumeops/derivatives/second_derivative.jl @ 2080:0f949681d3d3 refactor/sbp_operators/direction_check tip

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.
author Vidar Stiernström <vidar.stiernstrom@gmail.com>
date Fri, 20 Feb 2026 12:01:05 +0100
parents 08f06bfacd5c
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 """
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
2 second_derivative(g::TensorGrid, stencil_set, direction)
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
3 second_derivative(g::EquidistantGrid, stencil_set, direction)
623
914428a1fc61 Add documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 619
diff changeset
4
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
5 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
6
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
7 `D2` approximates the second-derivative d²/dξ² on `g` along the coordinate
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
8 dimension specified by `direction`.
623
914428a1fc61 Add documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 619
diff changeset
9
1104
c0ab81e4c39c Update docs
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1100
diff changeset
10 See also: [`VolumeOperator`](@ref), [`LazyTensors.inflate`](@ref).
623
914428a1fc61 Add documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 619
diff changeset
11 """
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
12 function second_derivative(g::TensorGrid, stencil_set, direction)
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
13 if direction ∉ Interval(0, ndims(g))
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 throw(DomainError(direction, "Direction must be inside [0, $(ndims(g))]."))
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
15 end
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
16 D₂ = second_derivative(g.grids[direction], stencil_set)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
17 return LazyTensors.inflate(D₂, size(g), direction)
356
0844069ab5ff Reinclude SbpOperators and fix most of the code and tests there.
Jonatan Werpers <jonatan@werpers.com>
parents: 348
diff changeset
18 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
19
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
20 function second_derivative(g::EquidistantGrid, stencil_set::StencilSet, direction)
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
21 return second_derivative(TensorGrid(g), stencil_set, direction)
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
22 end
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
23
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 """
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
25 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
26
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
27 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
28 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
29 """
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
30 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
31 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
32 closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
33 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
34 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
35
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
36 """
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
37 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
38
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
39 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
40 `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
41 """
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
42 function second_derivative(g::EquidistantGrid, inner_stencil::Stencil, closure_stencils)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
43 h⁻¹ = inverse_spacing(g)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
44 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
45 end