Skip to content

Commit

Permalink
add example plot
Browse files Browse the repository at this point in the history
  • Loading branch information
svchb committed Dec 1, 2023
1 parent c83061e commit f9b8bef
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions examples/fluid/rectangular_tank_2d.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using TrixiParticles
using OrdinaryDiffEq
using PyPlot

# ==========================================================================================
# ==== Resolution
Expand Down Expand Up @@ -84,18 +85,23 @@ sol = solve(ode, RDPK3SpFSAL49(),
dtmax=1e-2, # Limit stepsize to prevent crashing
save_everystep=false, callback=callbacks);

# Example for using interpolation
#######################################################################################

# interpolate_point can be used to interpolate the properties of the 'fluid_system' with the original kernel and smoothing_length
println(interpolate_point([1.0, 0.01], semi, fluid_system, sol))
# or with an increased smoothing_length smoothing the result
println(interpolate_point([1.0, 0.01], semi, fluid_system, sol,
smoothing_length=2.0 * smoothing_length))
println(interpolate_point([1.0, 0.1], semi, fluid_system, sol))
println(interpolate_point([1.0, 0.1], semi, fluid_system, sol,
smoothing_length=2.0 * smoothing_length))


# a point outside of the domain will result in properties with value 0
# on the boundary a result can still be obtained
println(interpolate_point([1.0, 0.0], semi, fluid_system, sol))
println(interpolate_point([1.0, 0.0], semi, fluid_system, sol,
smoothing_length=2.0 * smoothing_length))
# slightly befind the result is 0
println(interpolate_point([1.0, -0.01], semi, fluid_system, sol))
println(interpolate_point([1.0, -0.05], semi, fluid_system, sol))

# multiple points can be interpolated by providing an array
println(interpolate_point([
[1.0, 0.01],
[1.0, 0.1],
Expand All @@ -104,7 +110,27 @@ println(interpolate_point([
[1.0, -0.05],
], semi, fluid_system, sol))

println(interpolate_line([1.0, -0.05], [1.0, 1.0], 5, semi, fluid_system,
sol))
println(interpolate_line([1.0, -0.05], [1.0, 1.0], 5, semi, fluid_system,
sol, endpoint=false))
# it is also possible to interpolate along a line
result = interpolate_line([1.0, -0.05], [1.0, 1.0], 10, semi, fluid_system, sol)
result_endpoint = interpolate_line([1.0, -0.05], [1.0, 1.0], 10, semi, fluid_system, sol,
endpoint=false)
# Extract densities and coordinates for plotting
densities = [r.density for r in result]
coords = [r.coord[2] for r in result] # Assuming you want to plot against the y-coordinate

densities_endpoint = [r.density for r in result_endpoint]
coords_endpoint = [r.coord[2] for r in result_endpoint]

# Create the plot
figure()
plot(coords, densities, marker="o", linestyle="-", label="With Endpoint")
plot(coords_endpoint, densities_endpoint, marker="x", linestyle="--", label="Without Endpoint")

# Add labels and legend
xlabel("Y-Coordinate")
ylabel("Density")
title("Density Interpolation Along a Line")
legend()

# Display the plot
show()

0 comments on commit f9b8bef

Please sign in to comment.