Mercurial > repos > public > sbplib_julia
changeset 39:5ec57ec148ef
Merge latest changes
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 10 Jan 2019 14:57:18 +0100 |
parents | 2dce28c59429 (current diff) 5cefb9a55a50 (diff) |
children | 8b04efde1a46 3d8bfb695497 |
files | grid.jl |
diffstat | 8 files changed, 116 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2_2nd.txt Thu Jan 10 14:57:18 2019 +0100 @@ -0,0 +1,13 @@ +# D2 order 2 + +boundary_stencils +1 -2 1 + +inner_stencil +1 -2 1 + +e +1 + +d1 +-3/2 2 -1/2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2_4th.txt Thu Jan 10 14:57:18 2019 +0100 @@ -0,0 +1,16 @@ +# D2 order 4 + +boundary_stencils + 2 -5 4 -1 0 0 + 1 -2 1 0 0 0 + -4/43 59/43 -110/43 59/43 -4/43 0 + -1/49 0 59/49 -118/49 64/49 -4/49 + +inner_stencil +-1/12 4/3 -5/2 4/3 -1/12 + +e +1 + +d1 +-11/6 3 -3/2 1/3 \ No newline at end of file
--- a/diffOp.jl Thu Jan 10 14:55:57 2019 +0100 +++ b/diffOp.jl Thu Jan 10 14:57:18 2019 +0100 @@ -29,7 +29,7 @@ end # u = L*v -function apply(L::Laplace1D, u::AbstractVector, v::AbstractVector) +function apply!(L::Laplace1D, u::AbstractVector, v::AbstractVector) N = closureSize(L.op) M = length(v)
--- a/grid.jl Thu Jan 10 14:55:57 2019 +0100 +++ b/grid.jl Thu Jan 10 14:57:18 2019 +0100 @@ -133,4 +133,10 @@ end end +# Evaluate function f on the grid g +function evalOn(g::Grid, f::Function) + F(x) = f(x...) + return F.(points(g)) end + +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/h_2nd.txt Thu Jan 10 14:57:18 2019 +0100 @@ -0,0 +1,7 @@ +# H order 2 + +closure +1/2 + +inner_stencil +1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/h_4th.txt Thu Jan 10 14:57:18 2019 +0100 @@ -0,0 +1,7 @@ +# H order 4 + +closure +17/48 59/48 43/48 49/48 + +inner_stencil +1 \ No newline at end of file
--- a/sbpD2.jl Thu Jan 10 14:55:57 2019 +0100 +++ b/sbpD2.jl Thu Jan 10 14:57:18 2019 +0100 @@ -1,4 +1,3 @@ - struct D2{T} quadratureClosure::Vector{T} innerStencil::Stencil @@ -9,4 +8,66 @@ function closureSize(D::D2)::Int return length(quadratureClosure) -end \ No newline at end of file +end + +function readOperator(D2fn, Hfn) + d = readSectionedFile(D2fn) + h = readSectionedFile(Hfn) + + # Create inner stencil + innerStencilWeights = stringToVector(Float64, d["inner_stencil"][1]) + width = length(innerStencilWeights) + r = (-div(width,2), div(width,2)) + + innerStencil = Stencil(r, innerStencilWeights) + + # Create boundary stencils + boundarySize = length(d["boundary_stencils"]) + closureStencils = Vector{Stencil}() + + for i ∈ 1:boundarySize + stencilWeights = stringToVector(Float64, d["boundary_stencils"][i]) + width = length(stencilWeights) + r = (1-i,width-i) + push!(closureStencils,Stencil(r, stencilWeights)) + end + + d2 = D2( + stringToVector(Float64, h["closure"][1]), + innerStencil, + closureStencils, + stringToVector(Float64, d["e"][1]), + stringToVector(Float64, d["d1"][1]), + ) + + return d2 +end + + +function readSectionedFile(filename)::Dict{String, Vector{String}} + f = open(filename) + sections = Dict{String, Vector{String}}() + currentKey = "" + + for ln ∈ eachline(f) + if ln == "" || ln[1] == '#' # Skip comments and empty lines + continue + end + + if isletter(ln[1]) # Found start of new section + if ~haskey(sections, ln) + sections[ln] = Vector{String}() + end + currentKey = ln + continue + end + + push!(sections[currentKey], ln) + end + + return sections +end + +function stringToVector(T::DataType, s::String) + return T.(eval.(Meta.parse.(split(s)))) +end
--- a/stencil.jl Thu Jan 10 14:55:57 2019 +0100 +++ b/stencil.jl Thu Jan 10 14:57:18 2019 +0100 @@ -24,9 +24,9 @@ end end -function apply(s::Stencil, v::AbstractVector, i::Int) - w = zero(v[0]) - for j ∈ i+(s.range[1]:s.range[2]) +function apply(s::Stencil, v::AbstractVector, i::Int; stride::Int = 1) + w = zero(eltype(v)) + for j ∈ i .+ stride.*(s.range[1]:s.range[2]) w += v[j] end return w