comparison diffOp.jl @ 171:d407611ed71a boundary_conditions

Add BondaryValue operator
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 21 May 2019 16:11:16 +0200
parents 24ee4def7ffb
children a8bc71608588
comparison
equal deleted inserted replaced
170:6ba2238a9687 171:d407611ed71a
104 bId::CartesianBoundary 104 bId::CartesianBoundary
105 end 105 end
106 106
107 function apply_transpose(d::NormalDerivative, v::AbstractArray, I::Integer) 107 function apply_transpose(d::NormalDerivative, v::AbstractArray, I::Integer)
108 u = selectdim(v,dim(d.bId),I) 108 u = selectdim(v,dim(d.bId),I)
109 return apply_d(d.op, h, u, region(d.bId)) 109 return apply_d(d.op, d.grid.inverse_spacing[dim(d.bId)], u, region(d.bId))
110 end 110 end
111 111
112 # Not correct abstraction level 112 # Not correct abstraction level
113 # TODO: Not type stable D:< 113 # TODO: Not type stable D:<
114 function apply(d::NormalDerivative, v::AbstractArray, I::Tuple{Integer,Integer}) 114 function apply(d::NormalDerivative, v::AbstractArray, I::Tuple{Integer,Integer})
122 return 0 122 return 0
123 end 123 end
124 124
125 if r == Lower 125 if r == Lower
126 # Note, closures are indexed by offset. Fix this D:< 126 # Note, closures are indexed by offset. Fix this D:<
127 return d.op.dClosure[i-1]*v[j] 127 return d.grid.inverse_spacing[dim(d.bId)]*d.op.dClosure[i-1]*v[j]
128 elseif r == Upper 128 elseif r == Upper
129 return d.op.dClosure[N_i-j]*v[j] 129 return d.grid.inverse_spacing[dim(d.bId)]*d.op.dClosure[N_i-j]*v[j]
130 end 130 end
131 end 131 end
132 132
133 struct Laplace{Dim,T<:Real,N,M,K} <: DiffOpCartesian{Dim} 133 struct Laplace{Dim,T<:Real,N,M,K} <: DiffOpCartesian{Dim}
134 grid::EquidistantGrid{Dim,T} 134 grid::EquidistantGrid{Dim,T}
168 168
169 end 169 end
170 170
171 struct BoundaryValue{N,M,K} 171 struct BoundaryValue{N,M,K}
172 op::D2{Float64,N,M,K} 172 op::D2{Float64,N,M,K}
173 end 173 grid::EquidistantGrid
174 174 bId::CartesianBoundary
175 function apply(e::BoundaryValue) 175 end
176 176
177 end 177 function apply(e::BoundaryValue, v::AbstractArray, I::Tuple{Integer,Integer})
178 178 i = I[dim(e.bId)]
179 function apply_adjoint(e::BoundaryValue) 179 j = I[3-dim(e.bId)]
180 180 N_i = e.grid.size[dim(e.bId)]
181
182 r = getregion(i, closureSize(e.op), N_i)
183
184 if r != region(e.bId)
185 return 0
186 end
187
188 if r == Lower
189 # Note, closures are indexed by offset. Fix this D:<
190 return e.op.eClosure[i-1]*v[j]
191 elseif r == Upper
192 return e.op.eClosure[N_i-j]*v[j]
193 end
194 end
195
196 function apply_transpose(e::BoundaryValue, v::AbstractArray, I::Integer)
197 u = selectdim(v,dim(e.bId),I)
198 return apply_e(e.op, u, region(e.bId))
181 end 199 end
182 200
183 201
184 """ 202 """
185 A BoundaryCondition should implement the method 203 A BoundaryCondition should implement the method