annotate src/SbpOperators/volumeops/derivatives/first_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
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
1 """
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
2 first_derivative(g, ..., [direction])
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
3
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
4 The first derivative operator `D1` as a `LazyTensor` on the given grid.
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
5
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 `D1` approximates the first-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
7 dimension specified by `direction`.
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 """
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
9 function first_derivative end
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
10
972
803f60f461c1 Start adding the first derivative
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
11 """
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
12 first_derivative(g::TensorGrid, stencil_set, direction)
972
803f60f461c1 Start adding the first derivative
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
13
1104
c0ab81e4c39c Update docs
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1100
diff changeset
14 See also: [`VolumeOperator`](@ref), [`LazyTensors.inflate`](@ref).
972
803f60f461c1 Start adding the first derivative
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
15 """
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
16 function first_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
17 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
18 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
19 end
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
20 D₁ = first_derivative(g.grids[direction], stencil_set)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
21 return LazyTensors.inflate(D₁, size(g), direction)
972
803f60f461c1 Start adding the first derivative
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
22 end
974
ba023fc09961 Add stencil_set method and accuracy tests
Jonatan Werpers <jonatan@werpers.com>
parents: 972
diff changeset
23
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
24 function first_derivative(g::EquidistantGrid, 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
25 return first_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
26 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
27
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
28 """
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
29 first_derivative(g::EquidistantGrid, stencil_set::StencilSet)
972
803f60f461c1 Start adding the first derivative
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
30
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
31 The first derivative operator on an `EquidistantGrid`.
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
32 Uses the `D1` stencil in `stencil_set`.
974
ba023fc09961 Add stencil_set method and accuracy tests
Jonatan Werpers <jonatan@werpers.com>
parents: 972
diff changeset
33 """
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
34 function first_derivative(g::EquidistantGrid, stencil_set::StencilSet)
974
ba023fc09961 Add stencil_set method and accuracy tests
Jonatan Werpers <jonatan@werpers.com>
parents: 972
diff changeset
35 inner_stencil = parse_stencil(stencil_set["D1"]["inner_stencil"])
ba023fc09961 Add stencil_set method and accuracy tests
Jonatan Werpers <jonatan@werpers.com>
parents: 972
diff changeset
36 closure_stencils = parse_stencil.(stencil_set["D1"]["closure_stencils"])
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
37 return first_derivative(g, inner_stencil, closure_stencils);
974
ba023fc09961 Add stencil_set method and accuracy tests
Jonatan Werpers <jonatan@werpers.com>
parents: 972
diff changeset
38 end
989
7bf3121c6864 Add type StencilSet
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 974
diff changeset
39
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 first_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
42
1347
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
43 The first derivative operator on an `EquidistantGrid` given an
08f06bfacd5c Fix typos and formatting of documentation
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents: 1329
diff changeset
44 `inner_stencil` and `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
45 """
1291
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
46 function first_derivative(g::EquidistantGrid, inner_stencil::Stencil, closure_stencils)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
47 h⁻¹ = inverse_spacing(g)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
48 return VolumeOperator(g, scale(inner_stencil,h⁻¹), scale.(closure_stencils,h⁻¹), odd)
356ec6a72974 Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents: 1104
diff changeset
49 end