Skip to content

Commit ac46d1d

Browse files
chmerdonchmerdonpjaap
authored
new not_in_domain_value and check_if_not_in_domain parameters in interpolate! (#120)
Co-authored-by: chmerdon <christian.merdon@wias-berlin.de> Co-authored-by: Patrick Jaap <patrick.jaap@wias-berlin.de>
1 parent 579a277 commit ac46d1d

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
# [1.17.0] - 2026-04-15
4+
- new kwargs `not_in_domain_value = nothing` and `check_if_not_in_domain = isnothing(not_in_domain_value)` for grid interpolation.
5+
This enables the user to interpolate values between grids which do not share the same domain. The value _outside_ the target domain has to be provided by the user.
6+
37
## [1.15.0] - 2026-01-14
48
- add and export `explode` function that produces a grid with all adjacencies removed
59

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ExtendableGrids"
22
uuid = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
33
authors = ["Juergen Fuhrmann <juergen.fuhrmann@wias-berlin.de>", "Christian Merdon <christian.merdon@wias-berlin.de>", "Johannes Taraz <johannes.taraz@gmail.com>", "Patrick Jaap <patrick.jaap@wias-berlin.de>"]
4-
version = "1.16.0"
4+
version = "1.17.0"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/cellfinder.jl

Lines changed: 15 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 = nothing, check_if_not_in_domain = isnothing(not_in_domain_value), 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,14 @@ 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 && !check_if_not_in_domain
295+
u_to[inode_to] = not_in_domain_value
296+
else
297+
@assert icell_from > 0 "could not find cell for node $inode_to with coordinate $(coord[:, inode_to])"
298+
for i in 1:(dim + 1)
299+
inode_from = cn_from[i, icell_from]
300+
update!(u_to, inode_to, λ_shuffle[i], u_from, inode_from)
301+
end
293302
end
294303
icell_start = icell_from
295304
end

0 commit comments

Comments
 (0)