diff src/SbpOperators/volumeops/derivatives/second_derivative_variable.jl @ 1365:4684c7f1c4cb feature/variable_derivatives

Merge with default
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Sun, 21 May 2023 21:55:14 +0200
parents 102ebdaf7c11
children 71e89507dd9a
line wrap: on
line diff
--- a/src/SbpOperators/volumeops/derivatives/second_derivative_variable.jl	Sat May 20 14:26:36 2023 +0200
+++ b/src/SbpOperators/volumeops/derivatives/second_derivative_variable.jl	Sun May 21 21:55:14 2023 +0200
@@ -20,21 +20,21 @@
     end
 end
 
-function SecondDerivativeVariable(grid::EquidistantGrid, coeff::AbstractArray, inner_stencil, closure_stencils, dir)
-    check_coefficient(grid, coeff)
+function SecondDerivativeVariable(g::TensorGrid, coeff::AbstractArray, inner_stencil::NestedStencil, closure_stencils, dir)
+    check_coefficient(g, coeff)
 
-    Δxᵢ = spacing(grid)[dir]
+    Δxᵢ = spacing(g.grids[dir])
     scaled_inner_stencil = scale(inner_stencil, 1/Δxᵢ^2)
     scaled_closure_stencils = scale.(Tuple(closure_stencils), 1/Δxᵢ^2)
-    return SecondDerivativeVariable{dir, ndims(grid)}(scaled_inner_stencil, scaled_closure_stencils, size(grid), coeff)
+    return SecondDerivativeVariable{dir, ndims(g)}(scaled_inner_stencil, scaled_closure_stencils, size(g), coeff)
 end
 
-function SecondDerivativeVariable(grid::EquidistantGrid{1}, coeff::AbstractVector, inner_stencil::NestedStencil, closure_stencils)
-    return SecondDerivativeVariable(grid, coeff, inner_stencil, closure_stencils, 1)
+function SecondDerivativeVariable(g::EquidistantGrid, coeff::AbstractVector, inner_stencil::NestedStencil, closure_stencils)
+    return SecondDerivativeVariable(TensorGrid(g), coeff, inner_stencil, closure_stencils, 1)
 end
 
 @doc raw"""
-    SecondDerivativeVariable(grid::EquidistantGrid, coeff::AbstractArray, stencil_set, dir)
+    SecondDerivativeVariable(g::EquidistantGrid, coeff::AbstractArray, stencil_set, dir)
 
 Create a `LazyTensor` for the second derivative with a variable coefficient
 `coeff` on `grid` from the stencils in `stencil_set`. The direction is
@@ -53,20 +53,24 @@
 ```
 on ``(0,1)⨯(0,1)`` represented by `g`.
 """
-function SecondDerivativeVariable(grid::EquidistantGrid, coeff::AbstractArray, stencil_set, dir::Int)
+function SecondDerivativeVariable(g::TensorGrid, coeff::AbstractArray, stencil_set, dir::Int)
     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 SecondDerivativeVariable(grid, coeff, inner_stencil, closure_stencils, dir)
+    return SecondDerivativeVariable(g, coeff, inner_stencil, closure_stencils, dir)
+end
+
+function SecondDerivativeVariable(g::EquidistantGrid, coeff::AbstractArray, stencil_set) 
+    return SecondDerivativeVariable(TensorGrid(g), coeff, stencil_set, 1)
 end
 
-function check_coefficient(grid, coeff)
-    if ndims(grid) != ndims(coeff)
-        throw(ArgumentError("The coefficient has dimension $(ndims(coeff)) while the grid is dimension $(ndims(grid))"))
+function check_coefficient(g, coeff)
+    if ndims(g) != ndims(coeff)
+        throw(ArgumentError("The coefficient has dimension $(ndims(coeff)) while the grid is dimension $(ndims(g))"))
     end
 
-    if size(grid) != size(coeff)
-        throw(DimensionMismatch("the size $(size(coeff)) of the coefficient does not match the size $(size(grid)) of the grid"))
+    if size(g) != size(coeff)
+        throw(DimensionMismatch("the size $(size(coeff)) of the coefficient does not match the size $(size(g)) of the grid"))
     end
 end