diff src/SbpOperators/volumeops/derivatives/second_derivative_variable.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 e9dfc1998d31
children
line wrap: on
line diff
--- a/src/SbpOperators/volumeops/derivatives/second_derivative_variable.jl	Wed Feb 18 21:33:00 2026 +0100
+++ b/src/SbpOperators/volumeops/derivatives/second_derivative_variable.jl	Fri Feb 20 12:01:05 2026 +0100
@@ -9,24 +9,31 @@
 """
 function second_derivative_variable end
 
-function second_derivative_variable(g::TensorGrid, coeff, stencil_set, dir::Int)
+function second_derivative_variable(g::TensorGrid, coeff, stencil_set, direction::Int)
+    if direction ∉ Interval(0, ndims(g))
+        throw(DomainError(direction, "Direction must be inside [0, $(ndims(g))]."))
+    end
     inner_stencil    = parse_nested_stencil(eltype(coeff), stencil_set["D2variable"]["inner_stencil"])
     closure_stencils = parse_nested_stencil.(eltype(coeff), stencil_set["D2variable"]["closure_stencils"])
 
-    return second_derivative_variable(g, coeff, inner_stencil, closure_stencils, dir)
+    return second_derivative_variable(g, coeff, inner_stencil, closure_stencils, direction)
+end
+
+function second_derivative_variable(g::EquidistantGrid, coeff, stencil_set, direction)
+    return second_derivative_variable(TensorGrid(g), coeff, stencil_set, direction)
 end
 
 function second_derivative_variable(g::EquidistantGrid, coeff, stencil_set)
-    return second_derivative_variable(TensorGrid(g), coeff, stencil_set, 1)
+    return second_derivative_variable(g::EquidistantGrid, coeff, stencil_set, 1)
 end
 
-function second_derivative_variable(g::TensorGrid, coeff, inner_stencil::NestedStencil, closure_stencils, dir)
+function second_derivative_variable(g::TensorGrid, coeff, inner_stencil::NestedStencil, closure_stencils, direction)
     check_coefficient(g, coeff)
 
-    Δxᵢ = spacing(g.grids[dir])
+    Δxᵢ = spacing(g.grids[direction])
     scaled_inner_stencil = scale(inner_stencil, 1/Δxᵢ^2)
     scaled_closure_stencils = scale.(Tuple(closure_stencils), 1/Δxᵢ^2)
-    return SecondDerivativeVariable(coeff, scaled_inner_stencil, scaled_closure_stencils, dir)
+    return SecondDerivativeVariable(coeff, scaled_inner_stencil, scaled_closure_stencils, direction)
 end
 
 function check_coefficient(g, coeff)