Skip to content

Commit

Permalink
Interpolate x value for plotting (#64)
Browse files Browse the repository at this point in the history
* interpolate x value for plotting

* format

* add compat for Interpolations
  • Loading branch information
JoshuaLampert authored Nov 20, 2023
1 parent fa16ae3 commit 0182e0a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.1.2-pre"

[deps]
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PolynomialBases = "c74db56a-226d-5e98-8bb0-a6049094aeea"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Expand All @@ -19,6 +20,7 @@ SummationByPartsOperators = "9f78cca6-572e-554e-b819-917d2f1cf240"

[compat]
DiffEqBase = "6.121"
Interpolations = "0.14"
LinearAlgebra = "1"
PolynomialBases = "0.4.15"
Printf = "1"
Expand Down
1 change: 1 addition & 0 deletions src/DispersiveShallowWater.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module DispersiveShallowWater

using DiffEqBase
using Interpolations
using LinearAlgebra: mul!, ldiv!, factorize, I, Diagonal
using PolynomialBases
using Printf: @printf, @sprintf
Expand Down
8 changes: 5 additions & 3 deletions src/visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ end
nsubplots -= 1
end

index = argmin(abs.(grid(semi) .- x))
solution = zeros(nvariables(semi), length(sol.t))
data = zeros(nvars, length(sol.t))
for i in 1:nvariables(semi)
for k in 1:length(sol.t)
solution[i, k] = wrap_array(sol.u[k], semi)[i, index]
# Allow that the spatial value `x` is not on the grid. Thus, interpolate the given values to the provided `x`
# with a linear spline.
solution[i, k] = linear_interpolation(grid(semi),
view(wrap_array(sol.u[k], semi), i, :))(x)
end
end

Expand All @@ -120,7 +122,7 @@ end

names = varnames(conversion, equations)
plot_title -->
"$(get_name(semi.equations)) at x = $(round(grid(semi)[index], digits=5))"
"$(get_name(semi.equations)) at x = $(round(x, digits=5))"
layout --> nsubplots

for i in 1:nsubplots
Expand Down

0 comments on commit 0182e0a

Please sign in to comment.