comparison diffOp.jl @ 169:24ee4def7ffb boundary_conditions

Move NormalDerivative methods to type definition
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 21 May 2019 14:24:28 +0200
parents 45840a8127d6
children d407611ed71a
comparison
equal deleted inserted replaced
168:45840a8127d6 169:24ee4def7ffb
102 op::D2{Float64,N,M,K} 102 op::D2{Float64,N,M,K}
103 grid::EquidistantGrid 103 grid::EquidistantGrid
104 bId::CartesianBoundary 104 bId::CartesianBoundary
105 end 105 end
106 106
107 function apply_transpose(d::NormalDerivative, v::AbstractArray, I::Integer)
108 u = selectdim(v,dim(d.bId),I)
109 return apply_d(d.op, h, u, region(d.bId))
110 end
111
112 # Not correct abstraction level
113 # TODO: Not type stable D:<
114 function apply(d::NormalDerivative, v::AbstractArray, I::Tuple{Integer,Integer})
115 i = I[dim(d.bId)]
116 j = I[3-dim(d.bId)]
117 N_i = d.grid.size[dim(d.bId)]
118
119 r = getregion(i, closureSize(d.op), N_i)
120
121 if r != region(d.bId)
122 return 0
123 end
124
125 if r == Lower
126 # Note, closures are indexed by offset. Fix this D:<
127 return d.op.dClosure[i-1]*v[j]
128 elseif r == Upper
129 return d.op.dClosure[N_i-j]*v[j]
130 end
131 end
132
107 struct Laplace{Dim,T<:Real,N,M,K} <: DiffOpCartesian{Dim} 133 struct Laplace{Dim,T<:Real,N,M,K} <: DiffOpCartesian{Dim}
108 grid::EquidistantGrid{Dim,T} 134 grid::EquidistantGrid{Dim,T}
109 a::T 135 a::T
110 op::D2{Float64,N,M,K} 136 op::D2{Float64,N,M,K}
111 # e::BoundaryValue 137 # e::BoundaryValue
153 function apply_adjoint(e::BoundaryValue) 179 function apply_adjoint(e::BoundaryValue)
154 180
155 end 181 end
156 182
157 183
158
159 function apply_transpose(d::NormalDerivative, v::AbstractArray, I::Integer)
160 u = selectdim(v,dim(d.bId),I)
161 return apply_d(d.op, h, u, region(d.bId))
162 end
163
164 # Not correct abstraction level
165 # TODO: Not type stable D:<
166 function apply(d::NormalDerivative, v::AbstractArray, I::Tuple{Integer,Integer})
167 i = I[dim(d.bId)]
168 j = I[3-dim(d.bId)]
169 N_i = d.grid.size[dim(d.bId)]
170
171 r = getregion(i, closureSize(d.op), N_i)
172
173 if r != region(d.bId)
174 return 0
175 end
176
177 if r == Lower
178 # Note, closures are indexed by offset. Fix this D:<
179 return d.op.dClosure[i-1]*v[j]
180 elseif r == Upper
181 return d.op.dClosure[N_i-j]*v[j]
182 end
183 end
184
185 """ 184 """
186 A BoundaryCondition should implement the method 185 A BoundaryCondition should implement the method
187 sat(::DiffOp, v::AbstractArray, data::AbstractArray, ...) 186 sat(::DiffOp, v::AbstractArray, data::AbstractArray, ...)
188 """ 187 """
189 abstract type BoundaryCondition end 188 abstract type BoundaryCondition end