comparison src/SbpOperators/volumeops/derivatives/second_derivative_variable.jl @ 2089:1bc63fa55145 refactor/sbp_operators/direction_check

Change variable name from `direction` to `dim`
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 02 Mar 2026 14:11:32 +0100
parents 438dc7664c1f
children 67d8fbbb9e58
comparison
equal deleted inserted replaced
2088:438dc7664c1f 2089:1bc63fa55145
1 """ 1 """
2 second_derivative_variable(g, coeff ..., [direction]) 2 second_derivative_variable(g, coeff ..., [dim])
3 3
4 The variable second derivative operator as a `LazyTensor` on the given grid. 4 The variable second derivative operator as a `LazyTensor` on the given grid.
5 `coeff` is a grid function of the variable coefficient. 5 `coeff` is a grid function of the variable coefficient.
6 6
7 Approximates the d/dξ c d/dξ on `g` along the coordinate dimension specified 7 Approximates the d/dξ c d/dξ on `g` along the coordinate dimension specified
8 by `direction`. 8 by `dim`.
9 """ 9 """
10 function second_derivative_variable end 10 function second_derivative_variable end
11 11
12 function second_derivative_variable(g::TensorGrid, coeff, stencil_set, direction::Int) 12 function second_derivative_variable(g::TensorGrid, coeff, stencil_set, dim::Int)
13 if direction ∉ 1:ndims(g) 13 if dim ∉ 1:ndims(g)
14 throw(DomainError(direction, "Direction must be inside [0, $(ndims(g))].")) 14 throw(DomainError(dim, "Direction must be inside [0, $(ndims(g))]."))
15 end 15 end
16 inner_stencil = parse_nested_stencil(eltype(coeff), stencil_set["D2variable"]["inner_stencil"]) 16 inner_stencil = parse_nested_stencil(eltype(coeff), stencil_set["D2variable"]["inner_stencil"])
17 closure_stencils = parse_nested_stencil.(eltype(coeff), stencil_set["D2variable"]["closure_stencils"]) 17 closure_stencils = parse_nested_stencil.(eltype(coeff), stencil_set["D2variable"]["closure_stencils"])
18 18
19 return second_derivative_variable(g, coeff, inner_stencil, closure_stencils, direction) 19 return second_derivative_variable(g, coeff, inner_stencil, closure_stencils, dim)
20 end 20 end
21 21
22 function second_derivative_variable(g::EquidistantGrid, coeff, stencil_set, direction) 22 function second_derivative_variable(g::EquidistantGrid, coeff, stencil_set, dim)
23 return second_derivative_variable(TensorGrid(g), coeff, stencil_set, direction) 23 return second_derivative_variable(TensorGrid(g), coeff, stencil_set, dim)
24 end 24 end
25 25
26 function second_derivative_variable(g::EquidistantGrid, coeff, stencil_set) 26 function second_derivative_variable(g::EquidistantGrid, coeff, stencil_set)
27 return second_derivative_variable(g::EquidistantGrid, coeff, stencil_set, 1) 27 return second_derivative_variable(g::EquidistantGrid, coeff, stencil_set, 1)
28 end 28 end
29 29
30 function second_derivative_variable(g::TensorGrid, coeff, inner_stencil::NestedStencil, closure_stencils, direction) 30 function second_derivative_variable(g::TensorGrid, coeff, inner_stencil::NestedStencil, closure_stencils, dim)
31 check_coefficient(g, coeff) 31 check_coefficient(g, coeff)
32 32
33 Δxᵢ = spacing(g.grids[direction]) 33 Δxᵢ = spacing(g.grids[dim])
34 scaled_inner_stencil = scale(inner_stencil, 1/Δxᵢ^2) 34 scaled_inner_stencil = scale(inner_stencil, 1/Δxᵢ^2)
35 scaled_closure_stencils = scale.(Tuple(closure_stencils), 1/Δxᵢ^2) 35 scaled_closure_stencils = scale.(Tuple(closure_stencils), 1/Δxᵢ^2)
36 return SecondDerivativeVariable(coeff, scaled_inner_stencil, scaled_closure_stencils, direction) 36 return SecondDerivativeVariable(coeff, scaled_inner_stencil, scaled_closure_stencils, dim)
37 end 37 end
38 38
39 function check_coefficient(g, coeff) 39 function check_coefficient(g, coeff)
40 if ndims(g) != ndims(coeff) 40 if ndims(g) != ndims(coeff)
41 throw(ArgumentError("The coefficient has dimension $(ndims(coeff)) while the grid is dimension $(ndims(g))")) 41 throw(ArgumentError("The coefficient has dimension $(ndims(coeff)) while the grid is dimension $(ndims(g))"))