comparison src/SbpOperators/laplace/laplace.jl @ 611:e71f2f81b5f8 feature/volume_and_boundary_operators

NOT WORKING: Draft implementation of VolumeOperator and make SecondDerivative specialize it. Reformulate Laplace for the new SecondDerivative.
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Sat, 05 Dec 2020 19:14:39 +0100
parents 011ca1639153
children d9324671b412
comparison
equal deleted inserted replaced
610:e40e7439d1b4 611:e71f2f81b5f8
1 # """
2 # Laplace{Dim,T<:Real,N,M,K} <: TensorMapping{T,Dim,Dim}
3 #
4 # Implements the Laplace operator `L` in Dim dimensions as a tensor operator
5 # The multi-dimensional tensor operator consists of a tuple of 1D SecondDerivative
6 # tensor operators.
7 # """
8 function Laplace(grid::EquidistantGrid{Dim}, innerStencil, closureStencils) where Dim
9 Δ = SecondDerivative(grid, innerStencil, closureStencils, 1)
10 for d = 2:Dim
11 Δ += SecondDerivative(grid, innerStencil, closureStencils, d)
12 end
13 return Δ
14 end
1 export Laplace 15 export Laplace
2 """
3 Laplace{Dim,T<:Real,N,M,K} <: TensorMapping{T,Dim,Dim}
4
5 Implements the Laplace operator `L` in Dim dimensions as a tensor operator
6 The multi-dimensional tensor operator consists of a tuple of 1D SecondDerivative
7 tensor operators.
8 """
9 #export quadrature, inverse_quadrature, boundary_quadrature, boundary_value, normal_derivative
10 struct Laplace{Dim,T,N,M,K} <: TensorMapping{T,Dim,Dim}
11 D2::NTuple{Dim,SecondDerivative{T,N,M,K}}
12 end
13
14 function Laplace(g::EquidistantGrid{Dim}, innerStencil, closureStencils) where Dim
15 D2 = ()
16 for i ∈ 1:Dim
17 D2 = (D2..., SecondDerivative(restrict(g,i), innerStencil, closureStencils))
18 end
19
20 return Laplace(D2)
21 end
22
23 LazyTensors.range_size(L::Laplace) = getindex.(range_size.(L.D2),1)
24 LazyTensors.domain_size(L::Laplace) = getindex.(domain_size.(L.D2),1)
25
26 function LazyTensors.apply(L::Laplace{Dim,T}, v::AbstractArray{T,Dim}, I::Vararg{Any,Dim}) where {T,Dim}
27 error("not implemented")
28 end
29
30 # u = L*v
31 function LazyTensors.apply(L::Laplace{1,T}, v::AbstractVector{T}, i) where T
32 @inbounds u = LazyTensors.apply(L.D2[1],v,i)
33 return u
34 end
35
36 function LazyTensors.apply(L::Laplace{2,T}, v::AbstractArray{T,2}, i, j) where T
37 # 2nd x-derivative
38 @inbounds vx = view(v, :, Int(j))
39 @inbounds uᵢ = LazyTensors.apply(L.D2[1], vx , i)
40
41 # 2nd y-derivative
42 @inbounds vy = view(v, Int(i), :)
43 @inbounds uᵢ += LazyTensors.apply(L.D2[2], vy , j)
44
45 return uᵢ
46 end
47 16
48 # quadrature(L::Laplace) = Quadrature(L.op, L.grid) 17 # quadrature(L::Laplace) = Quadrature(L.op, L.grid)
49 # inverse_quadrature(L::Laplace) = InverseQuadrature(L.op, L.grid) 18 # inverse_quadrature(L::Laplace) = InverseQuadrature(L.op, L.grid)
50 # boundary_value(L::Laplace, bId::CartesianBoundary) = BoundaryValue(L.op, L.grid, bId) 19 # boundary_value(L::Laplace, bId::CartesianBoundary) = BoundaryValue(L.op, L.grid, bId)
51 # normal_derivative(L::Laplace, bId::CartesianBoundary) = NormalDerivative(L.op, L.grid, bId) 20 # normal_derivative(L::Laplace, bId::CartesianBoundary) = NormalDerivative(L.op, L.grid, bId)