Skip to content

Commit 26185cd

Browse files
do -not- use Interpolations.jl
1 parent cffa3b1 commit 26185cd

4 files changed

Lines changed: 22 additions & 8 deletions

File tree

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ version = "1.1.0"
55
[deps]
66
EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
77
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
8-
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
98
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
109
NearestNeighbors = "b8a86587-4115-5ab1-83bc-aa920d37bbce"
1110
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
@@ -31,7 +30,6 @@ BlockArrays = "0.16, 1"
3130
EnumX = "1"
3231
ForwardDiff = "0.10, 1"
3332
HCubature = "1.7.0"
34-
Interpolations = "0.16.1"
3533
Metis = "1.3"
3634
NearestNeighbors = "0.4"
3735
OrderedCollections = "1"

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ using OrderedCollections
1212
using WriteVTK
1313
import Metis
1414
using HCubature: hcubature, hquadrature
15-
using Interpolations
1615

1716
include("test_utils.jl")
1817

test/test_l2_projection.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ function test_projection(order, elementtype)
5353
elseif dim == 3
5454
f_res = [f((x_1, x_2, x_3)) for x_1 in qp_1D_coord, x_2 in qp_1D_coord, x_3 in qp_1D_coord]
5555
end
56-
interp_linear = linear_interpolation(ntuple(_ -> qp_1D_coord, dim), f_res; extrapolation_bc = Interpolations.Line())
57-
ae = [interp_linear(coords...) for coords in cellcoords]
56+
ae = [interp_linear(qp_1D_coord, f_res, coords...) for coords in cellcoords]
5857
elseif order == 2
5958
# For a quadratic approximation the analytical solution is recovered
6059
ae = zeros(length(point_vars))
@@ -67,7 +66,7 @@ function test_projection(order, elementtype)
6766
qp_values = analytical(f_vector)
6867
point_vars = project(proj, qp_values, qr)
6968
if order == 1
70-
ae = [Vec{1, Float64}((interp_linear(coords...),)) for coords in cellcoords]
69+
ae = [Vec{1, Float64}((interp_linear(qp_1D_coord, f_res, coords...),)) for coords in cellcoords]
7170
elseif order == 2
7271
ae = zeros(length(point_vars))
7372
apply_analytical!(ae, proj.dh, :_, x -> f_vector(x)[1])
@@ -82,7 +81,7 @@ function test_projection(order, elementtype)
8281
point_vars = project(proj, qp_values, qr)
8382
point_vars_2 = project(proj, qp_values_matrix, qr)
8483
if order == 1
85-
ae = [Tensor{2, 2, Float64}((interp_linear(coords...), 2 * interp_linear(coords...), 3 * interp_linear(coords...), 4 * interp_linear(coords...))) for coords in cellcoords]
84+
ae = [Tensor{2, 2, Float64}((interp_linear(qp_1D_coord, f_res, coords...), 2 * interp_linear(qp_1D_coord, f_res, coords...), 3 * interp_linear(qp_1D_coord, f_res, coords...), 4 * interp_linear(qp_1D_coord, f_res, coords...))) for coords in cellcoords]
8685
elseif order == 2
8786
ae = zeros(4, length(point_vars))
8887
for i in 1:4
@@ -99,7 +98,7 @@ function test_projection(order, elementtype)
9998
point_vars = project(proj, qp_values, qr)
10099
point_vars_2 = project(proj, qp_values_matrix, qr)
101100
if order == 1
102-
ae = [SymmetricTensor{2, 2, Float64}((interp_linear(coords...), 2 * interp_linear(coords...), 3 * interp_linear(coords...))) for coords in cellcoords]
101+
ae = [SymmetricTensor{2, 2, Float64}((interp_linear(qp_1D_coord, f_res, coords...), 2 * interp_linear(qp_1D_coord, f_res, coords...), 3 * interp_linear(qp_1D_coord, f_res, coords...))) for coords in cellcoords]
103102
elseif order == 2
104103
ae = zeros(3, length(point_vars))
105104
for i in 1:3

test/test_utils.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,21 @@ function single_element_grid(::Type{CellType}) where {RefShape, CellType <: Ferr
383383
cells = [CellType(ntuple(i -> i, length(nodes)))]
384384
return Grid(cells, nodes)
385385
end
386+
387+
interpolate_linear(t₁, t₂, y₁, y₂, t) = t₂>t₁ ? y₁*(t₂-t)/(t₂-t₁) .+ y₂*(t-t₁)/(t₂-t₁) : y₁
388+
# generic tensor-product interpolator using corner weights; handles any dim
389+
interp_linear = function (xs, ys, coords...)
390+
# locate interval and compute weight for each dimension
391+
is = map(c -> clamp(searchsortedlast(xs, c), 1, length(xs)-1), coords)
392+
ws = [(coords[k] - xs[i])/(xs[i+1] - xs[i]) for (k,i) in enumerate(is)]
393+
val = zero(eltype(ys))
394+
for corner in Iterators.product((0:1 for _ in coords)...) # iterate over 2^dim corners
395+
weight = one(val)
396+
idxs = ntuple(k -> is[k] + corner[k], length(coords))
397+
for k in 1:length(coords)
398+
weight *= corner[k] == 0 ? 1 - ws[k] : ws[k]
399+
end
400+
val += weight * getindex(ys, idxs...)
401+
end
402+
return val
403+
end

0 commit comments

Comments
 (0)