Mercurial > repos > public > sbplib_julia
view diffOp.jl @ 390:074862bcd626 patch_based_test
Close branch
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 01 Oct 2020 08:28:03 +0200 |
parents | 2882e1318cc3 |
children |
line wrap: on
line source
abstract type DiffOp end function apply!(D::DiffOp, u::AbstractVector, v::AbstractVector) error("not implemented") end function innerProduct(D::DiffOp, u::AbstractVector, v::AbstractVector)::Real error("not implemented") end function matrixRepresentation(D::DiffOp) error("not implemented") end function boundaryCondition(D::DiffOp,b::Grid.BoundaryId,type)::(Closure, Penalty) error("not implemented") end function interface(Du::DiffOp, Dv::DiffOp, b::Grid.BoundaryId; type) error("not implemented") end abstract type Closure end function apply(c::Closure, v::AbstractVector, i::Int) error("not implemented") end abstract type Penalty end function apply(c::Penalty, g, i::Int) error("not implemented") end # Differential operator for a*d^2/dx^2 struct Laplace{Dim,T<:Real,N,M,K} <: DiffOp grid::Grid.EquidistantGrid{Dim,T} a::T op::D2{Float64,N,M,K} end # u = L*v function apply!(L::Laplace{1}, u::AbstractVector, v::AbstractVector) h = Grid.spacings(L.grid)[1] apply!(L.op, u, v, h) u .= L.a * u return nothing end # u = L*v using UnsafeArrays @inline function apply!(L::Laplace{2}, u::AbstractVector, v::AbstractVector) fill!(u,0) h = Grid.spacings(L.grid) li = LinearIndices(L.grid.numberOfPointsPerDim) n_x, n_y = L.grid.numberOfPointsPerDim # For each x #TODO: Can remove temporary if we pass u and indices to apply! temp = zeros(eltype(u), n_y) for i ∈ 1:n_x @inbounds indices = uview(li,i,:) @inbounds apply!(L.op, temp, uview(v, indices), h[2]) for i ∈ eachindex(indices) @inbounds u[indices[i]] = temp[i] end end # For each y #TODO: Can remove temporary if we pass u and indices to apply! temp = zeros(eltype(u), n_x) for i ∈ 1:n_y @inbounds indices = uview(li,:,i) @inbounds apply!(L.op, temp, uview(v, indices), h[1]) for i ∈ eachindex(indices) @inbounds u[indices[i]] += temp[i] end end for i ∈ eachindex(u) @inbounds u[i] = L.a*u[i] end return nothing end