comparison sbpD2.jl @ 104:1862e901febb cell_based_test

Merge with tip
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 07 Feb 2019 17:17:31 +0100
parents 19031733bbbf
children 6c6979ff17f4 f01b70b81e95
comparison
equal deleted inserted replaced
103:a274d6384e91 104:1862e901febb
40 odd = -1 40 odd = -1
41 even = 1 41 even = 1
42 end 42 end
43 43
44 struct D2{T,N,M,K} <: ConstantStencilOperator 44 struct D2{T,N,M,K} <: ConstantStencilOperator
45 quadratureClosure::Vector{T} 45 quadratureClosure::NTuple{M,T}
46 innerStencil::Stencil{T,N} 46 innerStencil::Stencil{T,N}
47 closureStencils::NTuple{M, Stencil{T,K}} 47 closureStencils::NTuple{M,Stencil{T,K}}
48 eClosure::Vector{T} 48 eClosure::NTuple{M,T}
49 dClosure::Vector{T} 49 dClosure::NTuple{M,T}
50 parity::Parity 50 parity::Parity
51 end 51 end
52 52
53 function closureSize(D::D2)::Int 53 function closureSize(D::D2)::Int
54 return length(D.quadratureClosure) 54 return length(D.quadratureClosure)
57 function readOperator(D2fn, Hfn) 57 function readOperator(D2fn, Hfn)
58 d = readSectionedFile(D2fn) 58 d = readSectionedFile(D2fn)
59 h = readSectionedFile(Hfn) 59 h = readSectionedFile(Hfn)
60 60
61 # Create inner stencil 61 # Create inner stencil
62 innerStencilWeights = stringToVector(Float64, d["inner_stencil"][1]) 62 innerStencilWeights = stringToTuple(Float64, d["inner_stencil"][1])
63 width = length(innerStencilWeights) 63 width = length(innerStencilWeights)
64 r = (-div(width,2), div(width,2)) 64 r = (-div(width,2), div(width,2))
65 65
66 innerStencil = Stencil(r, Tuple(innerStencilWeights)) 66 innerStencil = Stencil(r, innerStencilWeights)
67 67
68 # Create boundary stencils 68 # Create boundary stencils
69 boundarySize = length(d["boundary_stencils"]) 69 boundarySize = length(d["boundary_stencils"])
70 closureStencils = Vector{typeof(innerStencil)}() # TBD: is the the right way to get the correct type? 70 closureStencils = Vector{typeof(innerStencil)}() # TBD: is the the right way to get the correct type?
71 71
72 for i ∈ 1:boundarySize 72 for i ∈ 1:boundarySize
73 stencilWeights = stringToVector(Float64, d["boundary_stencils"][i]) 73 stencilWeights = stringToTuple(Float64, d["boundary_stencils"][i])
74 width = length(stencilWeights) 74 width = length(stencilWeights)
75 r = (1-i,width-i) 75 r = (1-i,width-i)
76 closureStencils = (closureStencils..., Stencil(r, Tuple(stencilWeights))) 76 closureStencils = (closureStencils..., Stencil(r, stencilWeights))
77 end 77 end
78 78
79 quadratureClosure = pad_tuple(stringToTuple(Float64, h["closure"][1]), boundarySize)
80 eClosure = pad_tuple(stringToTuple(Float64, d["e"][1]), boundarySize)
81 dClosure = pad_tuple(stringToTuple(Float64, d["d1"][1]), boundarySize)
82
79 d2 = D2( 83 d2 = D2(
80 stringToVector(Float64, h["closure"][1]), 84 quadratureClosure,
81 innerStencil, 85 innerStencil,
82 closureStencils, 86 closureStencils,
83 stringToVector(Float64, d["e"][1]), 87 eClosure,
84 stringToVector(Float64, d["d1"][1]), 88 dClosure,
85 even 89 even
86 ) 90 )
87 91
88 return d2 92 return d2
89 end 93 end
111 end 115 end
112 116
113 return sections 117 return sections
114 end 118 end
115 119
120 function stringToTuple(T::DataType, s::String)
121 return Tuple(stringToVector(T,s))
122 end
123
116 function stringToVector(T::DataType, s::String) 124 function stringToVector(T::DataType, s::String)
117 return T.(eval.(Meta.parse.(split(s)))) 125 return T.(eval.(Meta.parse.(split(s))))
118 end 126 end
127
128
129 function pad_tuple(t::NTuple{N, T}, n::Integer) where {N,T}
130 if N >= n
131 return t
132 else
133 return pad_tuple((t..., zero(T)), n)
134 end
135 end