Skip to content

Commit 2695093

Browse files
chmerdonpjaap
authored andcommitted
allow a not_in_domain_value in interpolate!
1 parent 579a277 commit 2695093

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/cellfinder.jl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Upon return, xref contains the barycentric coordinates of the point in the seque
9595
!!! warning
9696
Currently implemented for simplex grids only.
9797
"""
98-
function gFindLocal!(xref, CF::CellFinder{Tv, Ti}, x; icellstart = 1, trybrute = true, eps = 1.0e-14) where {Tv, Ti}
98+
function gFindLocal!(xref, CF::CellFinder{Tv, Ti}, x; icellstart = 1, stay_in_cell = false, trybrute = true, eps = 1.0e-14) where {Tv, Ti}
9999
# works for convex domains and simplices only !
100100
xCellFaces::Adjacency{Ti} = CF.xCellFaces
101101
xFaceCells::Adjacency{Ti} = CF.xFaceCells
@@ -131,6 +131,11 @@ function gFindLocal!(xref, CF::CellFinder{Tv, Ti}, x; icellstart = 1, trybrute =
131131
cx[j] = x[j] - L2Gb[j]
132132
end
133133
mapderiv!(invA, L2G, xref)
134+
135+
if stay_in_cell
136+
return icell
137+
end
138+
134139
fill!(xreftest, 0)
135140
for j in 1:length(cx), k in 1:length(cx)
136141
xreftest[k] += invA[j, k] * cx[j]
@@ -258,7 +263,7 @@ end
258263
259264
Mutating form of [`interpolate`](@ref)
260265
"""
261-
function interpolate!(u_to::AbstractArray, grid_to, u_from::AbstractArray, grid_from; eps = 1.0e-14, trybrute = true)
266+
function interpolate!(u_to::AbstractArray, grid_to, u_from::AbstractArray, grid_from; eps = 1.0e-14, not_in_domain_value = NaN, trybrute = true)
262267
shuffle = [[2, 1], [3, 1, 2], [4, 1, 2, 3]]
263268

264269
update!(u_to::AbstractVector, inode_to, λ, u_from::AbstractVector, inode_from) = u_to[inode_to] += λ * u_from[inode_from]
@@ -286,10 +291,13 @@ function interpolate!(u_to::AbstractArray, grid_to, u_from::AbstractArray, grid_
286291
icellstart = 1
287292
for inode_to in 1:nnodes_to
288293
@views icell_from = gFindLocal!(λ, cf, coord[:, inode_to]; icellstart, eps, trybrute)
289-
@assert icell_from > 0
290-
for i in 1:(dim + 1)
291-
inode_from = cn_from[i, icell_from]
292-
update!(u_to, inode_to, λ_shuffle[i], u_from, inode_from)
294+
if icell_from <= 0
295+
u_to[inode_to] = not_in_domain_value
296+
else
297+
for i in 1:(dim + 1)
298+
inode_from = cn_from[i, icell_from]
299+
update!(u_to, inode_to, λ_shuffle[i], u_from, inode_from)
300+
end
293301
end
294302
icell_start = icell_from
295303
end

0 commit comments

Comments
 (0)