Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpolate x value for plotting #64

Merged
merged 5 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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