Mercurial > repos > public > sbplib_julia
comparison sbpD2.jl @ 39:5ec57ec148ef
Merge latest changes
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 10 Jan 2019 14:57:18 +0100 |
parents | 91e662512e9a |
children | 8b04efde1a46 |
comparison
equal
deleted
inserted
replaced
38:2dce28c59429 | 39:5ec57ec148ef |
---|---|
1 | |
2 struct D2{T} | 1 struct D2{T} |
3 quadratureClosure::Vector{T} | 2 quadratureClosure::Vector{T} |
4 innerStencil::Stencil | 3 innerStencil::Stencil |
5 closureStencils::Vector{Stencil} # TBD: Should this be a tuple? | 4 closureStencils::Vector{Stencil} # TBD: Should this be a tuple? |
6 eClosure::Vector{T} | 5 eClosure::Vector{T} |
8 end | 7 end |
9 | 8 |
10 function closureSize(D::D2)::Int | 9 function closureSize(D::D2)::Int |
11 return length(quadratureClosure) | 10 return length(quadratureClosure) |
12 end | 11 end |
12 | |
13 function readOperator(D2fn, Hfn) | |
14 d = readSectionedFile(D2fn) | |
15 h = readSectionedFile(Hfn) | |
16 | |
17 # Create inner stencil | |
18 innerStencilWeights = stringToVector(Float64, d["inner_stencil"][1]) | |
19 width = length(innerStencilWeights) | |
20 r = (-div(width,2), div(width,2)) | |
21 | |
22 innerStencil = Stencil(r, innerStencilWeights) | |
23 | |
24 # Create boundary stencils | |
25 boundarySize = length(d["boundary_stencils"]) | |
26 closureStencils = Vector{Stencil}() | |
27 | |
28 for i ∈ 1:boundarySize | |
29 stencilWeights = stringToVector(Float64, d["boundary_stencils"][i]) | |
30 width = length(stencilWeights) | |
31 r = (1-i,width-i) | |
32 push!(closureStencils,Stencil(r, stencilWeights)) | |
33 end | |
34 | |
35 d2 = D2( | |
36 stringToVector(Float64, h["closure"][1]), | |
37 innerStencil, | |
38 closureStencils, | |
39 stringToVector(Float64, d["e"][1]), | |
40 stringToVector(Float64, d["d1"][1]), | |
41 ) | |
42 | |
43 return d2 | |
44 end | |
45 | |
46 | |
47 function readSectionedFile(filename)::Dict{String, Vector{String}} | |
48 f = open(filename) | |
49 sections = Dict{String, Vector{String}}() | |
50 currentKey = "" | |
51 | |
52 for ln ∈ eachline(f) | |
53 if ln == "" || ln[1] == '#' # Skip comments and empty lines | |
54 continue | |
55 end | |
56 | |
57 if isletter(ln[1]) # Found start of new section | |
58 if ~haskey(sections, ln) | |
59 sections[ln] = Vector{String}() | |
60 end | |
61 currentKey = ln | |
62 continue | |
63 end | |
64 | |
65 push!(sections[currentKey], ln) | |
66 end | |
67 | |
68 return sections | |
69 end | |
70 | |
71 function stringToVector(T::DataType, s::String) | |
72 return T.(eval.(Meta.parse.(split(s)))) | |
73 end |