Mercurial > repos > public > sbplib_julia
comparison src/SbpOperators/volumeops/derivatives/second_derivative_variable.jl @ 940:b15f39ae1643 feature/variable_derivatives
Add size checking for the coefficient
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 10 Mar 2022 08:18:29 +0100 |
parents | 025a506ca2fa |
children | 3bb94ce74697 |
comparison
equal
deleted
inserted
replaced
939:d8da3a1060b7 | 940:b15f39ae1643 |
---|---|
19 return new{Dir,T,D,M,IStencil,CStencil,TArray}(inner_stencil,closure_stencils,size, coefficient) | 19 return new{Dir,T,D,M,IStencil,CStencil,TArray}(inner_stencil,closure_stencils,size, coefficient) |
20 end | 20 end |
21 end | 21 end |
22 | 22 |
23 function SecondDerivativeVariable(grid::EquidistantGrid, coeff::AbstractArray, inner_stencil, closure_stencils, dir) | 23 function SecondDerivativeVariable(grid::EquidistantGrid, coeff::AbstractArray, inner_stencil, closure_stencils, dir) |
24 check_coefficient(grid, coeff) | |
25 | |
24 Δxᵢ = spacing(grid)[dir] | 26 Δxᵢ = spacing(grid)[dir] |
25 scaled_inner_stencil = scale(inner_stencil, 1/Δxᵢ^2) | 27 scaled_inner_stencil = scale(inner_stencil, 1/Δxᵢ^2) |
26 scaled_closure_stencils = scale.(Tuple(closure_stencils), 1/Δxᵢ^2) | 28 scaled_closure_stencils = scale.(Tuple(closure_stencils), 1/Δxᵢ^2) |
27 return SecondDerivativeVariable{dir, dimension(grid)}(scaled_inner_stencil, scaled_closure_stencils, size(grid), coeff) | 29 return SecondDerivativeVariable{dir, dimension(grid)}(scaled_inner_stencil, scaled_closure_stencils, size(grid), coeff) |
28 end | 30 end |
49 ```math | 51 ```math |
50 \frac{\partial}{\partial y} c(x,y) \frac{\partial u}{\partial y}, | 52 \frac{\partial}{\partial y} c(x,y) \frac{\partial u}{\partial y}, |
51 ``` | 53 ``` |
52 on ``(0,1)⨯(0,1)`` represented by `g`. | 54 on ``(0,1)⨯(0,1)`` represented by `g`. |
53 """ | 55 """ |
54 function SecondDerivativeVariable(grid::EquidistantGrid, coeff::AbstractArray, stencil_set, dir) | 56 function SecondDerivativeVariable(grid::EquidistantGrid, coeff::AbstractArray, stencil_set, dir::Int) |
55 inner_stencil = parse_nested_stencil(eltype(coeff), stencil_set["D2variable"]["inner_stencil"]) | 57 inner_stencil = parse_nested_stencil(eltype(coeff), stencil_set["D2variable"]["inner_stencil"]) |
56 closure_stencils = parse_nested_stencil.(eltype(coeff), stencil_set["D2variable"]["closure_stencils"]) | 58 closure_stencils = parse_nested_stencil.(eltype(coeff), stencil_set["D2variable"]["closure_stencils"]) |
57 | 59 |
58 return SecondDerivativeVariable(grid, coeff, inner_stencil, closure_stencils, dir) | 60 return SecondDerivativeVariable(grid, coeff, inner_stencil, closure_stencils, dir) |
61 end | |
62 | |
63 function check_coefficient(grid, coeff) | |
64 if dimension(grid) != ndims(coeff) | |
65 throw(ArgumentError("The coefficient has dimension $(ndims(coeff)) while the grid is dimension $(dimension(grid))")) | |
66 end | |
67 | |
68 if size(grid) != size(coeff) | |
69 throw(DimensionMismatch("the size $(size(coeff)) of the coefficient does not match the size $(size(grid)) of the grid")) | |
70 end | |
59 end | 71 end |
60 | 72 |
61 derivative_direction(::SecondDerivativeVariable{Dir}) where {Dir} = Dir | 73 derivative_direction(::SecondDerivativeVariable{Dir}) where {Dir} = Dir |
62 | 74 |
63 closure_size(op::SecondDerivativeVariable) = length(op.closure_stencils) | 75 closure_size(op::SecondDerivativeVariable) = length(op.closure_stencils) |