Skip to content

Commit 36af216

Browse files
vincmarksandrewwinters5000JoshuaLampert
authored
Add Lavery splines (#23) (#83)
* add lavery splines * improve performance of 1D Lavery spline. Some restructuring. * first prototype of 2D implementation * add contributers * rename new 1d test file * simplify the evaluation of the 2D Lavery spline * small adjusts to 1D files * apply Horner rule to 2D Lavery spline evaluation * prototype of the 2D Lavery spline * adjust new 2D Lavery example * add 2D test for Lavery spline * fix formatting of new data file * add extra test points to exercise all pieces of Lavery evaluation routine * fix docs refs * fix broken links in docstrings * new implementation of the 2D Lavery splines that is much faster * fix formatting in the new examples * fix formatting in 1D files * fix formatting in 2D files * merge constraints to remove some allocations * move new Lavery implementation into a package extension * add NEWS entry with new functionality * added to docstring for the 1D spline * Apply suggestions from code review Co-authored-by: Joshua Lampert <51029046+JoshuaLampert@users.noreply.github.com> * adjust names and constructors * update README * fix formatting * try to fix broken docs build * another attempt to fix docs build * reorganize and docs now build * works on generic real type * adjust reference.md for docs build * run formatter * remove old comment * Apply suggestions from code review Co-authored-by: Joshua Lampert <51029046+JoshuaLampert@users.noreply.github.com> * use lambda and same default everywhere --------- Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se> Co-authored-by: Joshua Lampert <51029046+JoshuaLampert@users.noreply.github.com>
1 parent 65550b1 commit 36af216

18 files changed

Lines changed: 777 additions & 6 deletions

AUTHORS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ The following people contributed major additions or modifications to TrixiBottom
1818
are listed in alphabetical order:
1919

2020
* Maximilian D. Bertrand
21+
* Logan Eriksson
22+
* Oscar Jemsson
2123
* Joshua Lampert
24+
* Vincent Marks
2225
* Hendrik Ranocha
2326
* Michael Schlottke-Lakemper
2427
* Andrew Winters

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ for human readability.
99

1010
#### Added
1111

12+
- Added shape preserving splines and interpolation using [JuMP.jl](https://github.com/jump-dev/JuMP.jl) and [HiGHS.jl](https://github.com/jump-dev/HiGHS.jl) [#83]
1213
- Added scattered radial basis function interpolation using [KernelInterpolation.jl](https://github.com/JoshuaLampert/KernelInterpolation.jl) [#73]
1314
- Implementation of visualization routines `plot_topography` and `plot_topography_with_interpolation_knots`
1415

Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1010
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1111

1212
[weakdeps]
13+
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
14+
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
1315
KernelInterpolation = "95686e15-3c94-4443-8f08-76d06d509f7b"
1416
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
1517

1618
[extensions]
19+
JuMPHiGHSExt = ["JuMP", "HiGHS"]
1720
KernelInterpolationExt = "KernelInterpolation"
1821
MakieExt = "Makie"
1922

2023
[compat]
2124
Downloads = "1.6"
25+
HiGHS = "1.0"
26+
JuMP = "1.0"
2227
KernelInterpolation = "0.3.5"
2328
LinearAlgebra = "1"
2429
Makie = "0.21, 0.22, 0.24"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ This package contains the following main functionalities:
3838
- Setting up a B-spline interpolation structure in one and two dimensions which contains all the relevant information to define a B-spline interpolation function with additional specifications
3939
- Using the B-spline structure to set up a B-spline interpolation function
4040
- Setting up a radial basis function interpolation based on scattered data leveraging [KernelInterpolation.jl](https://github.com/JoshuaLampert/KernelInterpolation.jl)
41+
- Setting up a shape preserving cubic spline structure (Lavery spline) for interpolation that avoids generating new extrema.
4142

4243
A detailed description of the functionalities can be found in the [documentation](https://trixi-framework.github.io/TrixiBottomTopography.jl/stable/) to this package.
4344

docs/Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
33
Changelog = "5217a498-cd5d-4ec6-b8c2-9b85a09b6e3e"
44
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
5+
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
6+
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
57
KernelInterpolation = "95686e15-3c94-4443-8f08-76d06d509f7b"
68
OrdinaryDiffEqLowStorageRK = "b0944070-b475-4768-8dec-fb6eb410534d"
79
Trixi = "a7f1ee26-1774-49b1-8366-f1abc58fbfcb"
@@ -15,6 +17,8 @@ path = ".."
1517
CairoMakie = "0.13, 0.15"
1618
Changelog = "1.1"
1719
Documenter = "1.3"
20+
HiGHS = "1.0"
21+
JuMP = "1.0"
1822
KernelInterpolation = "0.3.5"
1923
OrdinaryDiffEqLowStorageRK = "1.3"
2024
Trixi = "0.12, 0.13, 0.14"

docs/make.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ using Changelog: Changelog
55
# To load the extensions
66
import CairoMakie
77
import KernelInterpolation
8+
import JuMP
9+
import HiGHS
810

911
# Copy list of authors to not need to synchronize it manually.
1012
# Since the authors header exists twice we create a unique identifier for the docs section.
@@ -94,7 +96,8 @@ rm(joinpath(@__DIR__, "src", "changelog_tmp.md"))
9496
makedocs(;
9597
modules = [TrixiBottomTopography,
9698
Base.get_extension(TrixiBottomTopography, :MakieExt),
97-
Base.get_extension(TrixiBottomTopography, :KernelInterpolationExt)],
99+
Base.get_extension(TrixiBottomTopography, :KernelInterpolationExt),
100+
Base.get_extension(TrixiBottomTopography, :JuMPHiGHSExt)],
98101
authors = "Andrew R. Winters <andrew.ross.winters@liu.se>, Michael Schlottke-Lakemper <michael@sloede.com>",
99102
sitename = "TrixiBottomTopography.jl",
100103
format = Documenter.HTML(;

docs/src/reference.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@ TrixiBottomTopography.RBFInterpolation
2323
TrixiBottomTopography.RBFInterpolation1D
2424
TrixiBottomTopography.RBFInterpolation2D
2525
```
26+
27+
## JuMPHiGHS.jl extension
28+
```@docs
29+
TrixiBottomTopography.LaverySpline1D(::Vector{T}, ::Vector{T}) where {T<:Real}
30+
TrixiBottomTopography.LaverySpline1D(::String)
31+
TrixiBottomTopography.LaverySpline2D(::Vector{T}, ::Vector{T}, ::Matrix{T}) where {T<:Real}
32+
TrixiBottomTopography.LaverySpline2D(::String)
33+
TrixiBottomTopography.spline_interpolation(::LaverySpline1D, ::Number)
34+
TrixiBottomTopography.spline_interpolation(::LaverySpline2D, ::Number, ::Number)
35+
```

examples/lavery_spline_1d.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
##############################################################################
2+
# Script which uses the functionalities implemented in TrixiBottomTopography #
3+
# to plot a one dimensional Lavery spline of data with sharp transitions. #
4+
##############################################################################
5+
6+
# Include packages
7+
using TrixiBottomTopography
8+
using JuMP
9+
using HiGHS
10+
11+
# Load in data from one of the examples from Eriksson and Jemsson thesis
12+
# https://liu.diva-portal.org/smash/get/diva2:1918338/FULLTEXT01.pdf
13+
xData = Vector(0.0:29.0)
14+
yData = [0.0, 0.0, 0.0, 0.0, 0.0, 4.0, 2.0, 4.0, 3.0, 2.0,
15+
1.0, 0.0, 9.0, 9.0, 9.0, 0.0, 0.0, 0.0, 6.0, 7.0,
16+
5.0, 6.0, 7.0, 8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
17+
18+
# Lavery spline that does not generate new extrema
19+
spline_struct = LaverySpline1D(xData, yData)
20+
# Define Lavery spline interpolation function
21+
spline_func(x) = spline_interpolation(spline_struct, x)
22+
23+
# Evaluate the cubic Lavery spline on a new set of nodes and plot
24+
if isdefined(Main, :Makie)
25+
# Define interpolation points
26+
n = 500
27+
x_int_pts = Vector(LinRange(spline_struct.x[1], spline_struct.x[end], n))
28+
29+
# Get interpolated values
30+
y_int_pts = spline_func.(x_int_pts)
31+
32+
# Get the original interpolation knots
33+
x_knots = spline_struct.x
34+
y_knots = spline_func.(x_knots)
35+
36+
plot_topography_with_interpolation_knots(x_int_pts, y_int_pts, x_knots, y_knots;
37+
xlabel = "x",
38+
ylabel = "y",
39+
legend_position = :lt)
40+
end

examples/lavery_spline_2d.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
##############################################################################
2+
# Script which uses the functionalities implemented in TrixiBottomTopography #
3+
# to plot a two dimensional Lavery spline of data with sharp transitions. #
4+
##############################################################################
5+
6+
# Include packages
7+
using TrixiBottomTopography
8+
using JuMP
9+
using HiGHS
10+
11+
# Load in data from one of the examples from Eriksson and Jemsson thesis
12+
# https://liu.diva-portal.org/smash/get/diva2:1918338/FULLTEXT01.pdf
13+
x_knots = Vector(0.0:9.0)
14+
y_knots = Vector(0.0:9.0)
15+
z_knots = [1.0 1.0 1.0 0.0 0.0 4.0 4.0 4.0 4.0 1.0;
16+
1.0 1.0 1.0 0.0 0.0 1.0 1.0 1.0 1.0 1.0;
17+
1.0 1.0 1.0 3.0 3.0 3.0 3.0 3.0 3.0 3.0;
18+
2.0 2.0 2.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0;
19+
3.0 3.0 3.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0;
20+
4.0 4.0 4.0 1.0 0.0 0.0 2.0 2.0 0.0 0.0;
21+
1.0 0.0 3.0 1.0 0.0 0.0 2.0 2.0 0.0 0.0;
22+
1.0 0.0 3.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0;
23+
1.0 0.0 3.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0;
24+
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0]
25+
26+
# Lavery spline that does not generate new extrema
27+
spline_struct = LaverySpline2D(x_knots, y_knots, z_knots)
28+
# Define Lavery spline interpolation function
29+
spline_func(x, y) = spline_interpolation(spline_struct, x, y)
30+
31+
# Evaluate the bicubic Lavery spline on a new set of nodes and plot
32+
if isdefined(Main, :Makie)
33+
# Define interpolation points
34+
n = 150
35+
x_int_pts = Vector(LinRange(spline_struct.x[1], spline_struct.x[end], n))
36+
y_int_pts = Vector(LinRange(spline_struct.y[1], spline_struct.y[end], n))
37+
38+
# Get interpolated matrix
39+
z_int_pts = evaluate_two_dimensional_interpolant(spline_func, x_int_pts, y_int_pts)
40+
41+
plot_topography_with_interpolation_knots(x_int_pts, y_int_pts, z_int_pts,
42+
x_knots, y_knots, z_knots;
43+
xlabel = "x",
44+
ylabel = "y",
45+
zlabel = "z")
46+
end

0 commit comments

Comments
 (0)