Mercurial > repos > public > sbplib_julia
comparison 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 |
comparison
equal
deleted
inserted
replaced
1358:e7861cfb6ede | 1365:4684c7f1c4cb |
---|---|
18 TArray = typeof(coefficient) | 18 TArray = typeof(coefficient) |
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(g::TensorGrid, coeff::AbstractArray, inner_stencil::NestedStencil, closure_stencils, dir) |
24 check_coefficient(grid, coeff) | 24 check_coefficient(g, coeff) |
25 | 25 |
26 Δxᵢ = spacing(grid)[dir] | 26 Δxᵢ = spacing(g.grids[dir]) |
27 scaled_inner_stencil = scale(inner_stencil, 1/Δxᵢ^2) | 27 scaled_inner_stencil = scale(inner_stencil, 1/Δxᵢ^2) |
28 scaled_closure_stencils = scale.(Tuple(closure_stencils), 1/Δxᵢ^2) | 28 scaled_closure_stencils = scale.(Tuple(closure_stencils), 1/Δxᵢ^2) |
29 return SecondDerivativeVariable{dir, ndims(grid)}(scaled_inner_stencil, scaled_closure_stencils, size(grid), coeff) | 29 return SecondDerivativeVariable{dir, ndims(g)}(scaled_inner_stencil, scaled_closure_stencils, size(g), coeff) |
30 end | 30 end |
31 | 31 |
32 function SecondDerivativeVariable(grid::EquidistantGrid{1}, coeff::AbstractVector, inner_stencil::NestedStencil, closure_stencils) | 32 function SecondDerivativeVariable(g::EquidistantGrid, coeff::AbstractVector, inner_stencil::NestedStencil, closure_stencils) |
33 return SecondDerivativeVariable(grid, coeff, inner_stencil, closure_stencils, 1) | 33 return SecondDerivativeVariable(TensorGrid(g), coeff, inner_stencil, closure_stencils, 1) |
34 end | 34 end |
35 | 35 |
36 @doc raw""" | 36 @doc raw""" |
37 SecondDerivativeVariable(grid::EquidistantGrid, coeff::AbstractArray, stencil_set, dir) | 37 SecondDerivativeVariable(g::EquidistantGrid, coeff::AbstractArray, stencil_set, dir) |
38 | 38 |
39 Create a `LazyTensor` for the second derivative with a variable coefficient | 39 Create a `LazyTensor` for the second derivative with a variable coefficient |
40 `coeff` on `grid` from the stencils in `stencil_set`. The direction is | 40 `coeff` on `grid` from the stencils in `stencil_set`. The direction is |
41 determined by `dir`. | 41 determined by `dir`. |
42 | 42 |
51 ```math | 51 ```math |
52 \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}, |
53 ``` | 53 ``` |
54 on ``(0,1)⨯(0,1)`` represented by `g`. | 54 on ``(0,1)⨯(0,1)`` represented by `g`. |
55 """ | 55 """ |
56 function SecondDerivativeVariable(grid::EquidistantGrid, coeff::AbstractArray, stencil_set, dir::Int) | 56 function SecondDerivativeVariable(g::TensorGrid, coeff::AbstractArray, stencil_set, dir::Int) |
57 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"]) |
58 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"]) |
59 | 59 |
60 return SecondDerivativeVariable(grid, coeff, inner_stencil, closure_stencils, dir) | 60 return SecondDerivativeVariable(g, coeff, inner_stencil, closure_stencils, dir) |
61 end | 61 end |
62 | 62 |
63 function check_coefficient(grid, coeff) | 63 function SecondDerivativeVariable(g::EquidistantGrid, coeff::AbstractArray, stencil_set) |
64 if ndims(grid) != ndims(coeff) | 64 return SecondDerivativeVariable(TensorGrid(g), coeff, stencil_set, 1) |
65 throw(ArgumentError("The coefficient has dimension $(ndims(coeff)) while the grid is dimension $(ndims(grid))")) | 65 end |
66 | |
67 function check_coefficient(g, coeff) | |
68 if ndims(g) != ndims(coeff) | |
69 throw(ArgumentError("The coefficient has dimension $(ndims(coeff)) while the grid is dimension $(ndims(g))")) | |
66 end | 70 end |
67 | 71 |
68 if size(grid) != size(coeff) | 72 if size(g) != size(coeff) |
69 throw(DimensionMismatch("the size $(size(coeff)) of the coefficient does not match the size $(size(grid)) of the grid")) | 73 throw(DimensionMismatch("the size $(size(coeff)) of the coefficient does not match the size $(size(g)) of the grid")) |
70 end | 74 end |
71 end | 75 end |
72 | 76 |
73 derivative_direction(::SecondDerivativeVariable{Dir}) where {Dir} = Dir | 77 derivative_direction(::SecondDerivativeVariable{Dir}) where {Dir} = Dir |
74 | 78 |