comparison SbpOperators/src/SbpOperators.jl @ 245:d9e262cb2e8d boundary_conditions

Rename apply_e and _d to _e_T and _d_T. Implement _e _d and using them in laplace.jl
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 27 Jun 2019 12:49:58 +0200
parents 01a67d1b8b5d
children 7cb4492ccd60
comparison
equal deleted inserted replaced
244:a827568fc251 245:d9e262cb2e8d
2 2
3 using RegionIndices 3 using RegionIndices
4 4
5 include("stencil.jl") 5 include("stencil.jl")
6 6
7 export D2, closureSize, apply, readOperator, apply_e, apply_d 7 export D2, closureSize, apply, readOperator, apply_e, apply_d, apply_e_T, apply_d_T
8 8
9 abstract type ConstantStencilOperator end 9 abstract type ConstantStencilOperator end
10 10
11 # Apply for different regions Lower/Interior/Upper or Unknown region 11 # Apply for different regions Lower/Interior/Upper or Unknown region
12 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Lower}) 12 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Lower})
100 100
101 return d2 101 return d2
102 end 102 end
103 103
104 104
105 function apply_e(op::D2, v::AbstractVector, ::Type{Lower}) 105 function apply_e_T(op::D2, v::AbstractVector, ::Type{Lower})
106 @boundscheck if length(v) < closureSize(op) 106 @boundscheck if length(v) < closureSize(op)
107 throw(BoundsError()) 107 throw(BoundsError())
108 end 108 end
109 apply(op.eClosure,v,1) 109 apply(op.eClosure,v,1)
110 end 110 end
111 111
112 function apply_e(op::D2, v::AbstractVector, ::Type{Upper}) 112 function apply_e_T(op::D2, v::AbstractVector, ::Type{Upper})
113 @boundscheck if length(v) < closureSize(op) 113 @boundscheck if length(v) < closureSize(op)
114 throw(BoundsError()) 114 throw(BoundsError())
115 end 115 end
116 apply(flip(op.eClosure),v,length(v)) 116 apply(flip(op.eClosure),v,length(v))
117 end 117 end
118 118
119 119
120 function apply_d(op::D2, h_inv::Real, v::AbstractVector, ::Type{Lower}) 120 function apply_e(op::D2, v::Number, N::Integer, i::Integer, ::Type{Lower})
121 @boundscheck if !(0<length(i) <= N)
122 throw(BoundsError())
123 end
124 op.eClosure[i-1]*v
125 end
126
127 function apply_e(op::D2, v::Number, N::Integer, i::Integer, ::Type{Upper})
128 @boundscheck if !(0<length(i) <= N)
129 throw(BoundsError())
130 end
131 op.eClosure[N-i]*v
132 end
133
134 function apply_d_T(op::D2, h_inv::Real, v::AbstractVector, ::Type{Lower})
121 @boundscheck if length(v) < closureSize(op) 135 @boundscheck if length(v) < closureSize(op)
122 throw(BoundsError()) 136 throw(BoundsError())
123 end 137 end
124 h_inv*apply(op.dClosure,v,1) 138 h_inv*apply(op.dClosure,v,1)
125 end 139 end
126 140
127 function apply_d(op::D2, h_inv::Real, v::AbstractVector, ::Type{Upper}) 141 function apply_d_T(op::D2, h_inv::Real, v::AbstractVector, ::Type{Upper})
128 @boundscheck if length(v) < closureSize(op) 142 @boundscheck if length(v) < closureSize(op)
129 throw(BoundsError()) 143 throw(BoundsError())
130 end 144 end
131 -h_inv*apply(flip(op.dClosure),v,length(v)) 145 -h_inv*apply(flip(op.dClosure),v,length(v))
132 end 146 end
147
148 function apply_d(op::D2, h_inv::Real, v::Number, N::Integer, i::Integer, ::Type{Lower})
149 @boundscheck if !(0<length(i) <= N)
150 throw(BoundsError())
151 end
152 h_inv*op.dClosure[i-1]*v
153 end
154
155 function apply_d(op::D2, h_inv::Real, v::Number, N::Integer, i::Integer, ::Type{Upper})
156 @boundscheck if !(0<length(i) <= N)
157 throw(BoundsError())
158 end
159 -h_inv*op.dClosure[N-i]*v
160 end
161
133 162
134 function readSectionedFile(filename)::Dict{String, Vector{String}} 163 function readSectionedFile(filename)::Dict{String, Vector{String}}
135 f = open(filename) 164 f = open(filename)
136 sections = Dict{String, Vector{String}}() 165 sections = Dict{String, Vector{String}}()
137 currentKey = "" 166 currentKey = ""