Mercurial > repos > public > sbplib_julia
changeset 26:d2896e70cd4f
Merge with default
author | Ylva Rydin <ylva.rydin@telia.com> |
---|---|
date | Mon, 17 Dec 2018 16:35:08 +0100 |
parents | 1e845cd91cd3 (current diff) d1ac68092138 (diff) |
children | aff8ea85ca70 |
files | |
diffstat | 2 files changed, 63 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/diffOp.jl Mon Dec 17 16:30:39 2018 +0100 +++ b/diffOp.jl Mon Dec 17 16:35:08 2018 +0100 @@ -16,7 +16,7 @@ error("not implemented") end -function interface(Du::DiffOp, Dv::DiffOp, b::BoundaryID; type) +function interface(Du::DiffOp, Dv::DiffOp, b::grid.BoundaryId; type) error("not implemented") end @@ -29,19 +29,23 @@ end # u = L*v -function apply(L::Laplace1D, u::AbstractVector, v::AbstractVector)::AbstractVector +function apply(L::Laplace1D, u::AbstractVector, v::AbstractVector) N = closureSize(L.op) M = length(v) + h = scaling(L.grid) + for i ∈ 1:N - u[i] = apply(L.op.closureStencils[i], v, i) + u[i] = apply(L.op.closureStencils[i], v, i)/h^2 end for i ∈ N+1:M-N - u[i] = apply(L.op.innerStencil, i); + u[i] = apply(L.op.innerStencil, i)/h^2 end for i ∈ M:-1:M-N+1 - u[i] = apply(flip(L.op.closureStencils[M-i+1]), v, i) + u[i] = apply(flip(L.op.closureStencils[M-i+1]), v, i)/h^2 end + + return nothing end
--- a/grid.jl Mon Dec 17 16:30:39 2018 +0100 +++ b/grid.jl Mon Dec 17 16:35:08 2018 +0100 @@ -1,1 +1,54 @@ -abstract type BoundaryID end +module grid + +abstract type Grid end + +function numberOfDimensions(grid::Grid) + error("Not yet implemented") +end + +function numberOfPoints(grid::Grid) + error("Not yet implemented") +end + +function points(grid::Grid) + error("Not yet implemented") +end + +abstract type BoundaryId end + +# Move to seperate file. +struct EquidistantGrid <: Grid + nPointsPerDim::Vector{Int} + limits::Vector{Pair{Real, Real}} + function EquidistantGrid(nPointsPerDim, lims) + @assert length(lims) == length(nPointsPerDim) + return new(nPointsPerDim, lims) + end +end + +function numberOfDimensions(grid::EquidistantGrid) + return length(grid.nPointsPerDim) +end + +function numberOfPoints(grid::EquidistantGrid) + numberOfPoints = grid.nPointsPerDim[1]; + for i = 2:length(grid.nPointsPerDim); + numberOfPoints = numberOfPoints*grid.nPointsPerDim[i] + end + return numberOfPoints +end + +function points(grid::EquidistantGrid) + points = Vector{Real}(undef, numberOfPoints(grid)) + for i = 1:numberOfDimensions(grid) + lims = limitsForDimension(grid,i) + points = range(lims.first, stop=lims.second, length=grid.nPointsPerDim[i]) + end + return points +end + +function limitsForDimension(grid::EquidistantGrid, dim::Int) + return grid.limits[dim] +end + +end