From f9b8bef1e542dc0b2b48a1e2bb0571f3c48fee0d Mon Sep 17 00:00:00 2001 From: Sven Berger Date: Fri, 1 Dec 2023 15:54:42 +0100 Subject: [PATCH] add example plot --- examples/fluid/rectangular_tank_2d.jl | 46 +++++++++++++++++++++------ 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/examples/fluid/rectangular_tank_2d.jl b/examples/fluid/rectangular_tank_2d.jl index 417453457..2f8b8bbab 100644 --- a/examples/fluid/rectangular_tank_2d.jl +++ b/examples/fluid/rectangular_tank_2d.jl @@ -1,5 +1,6 @@ using TrixiParticles using OrdinaryDiffEq +using PyPlot # ========================================================================================== # ==== Resolution @@ -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], @@ -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()