From 3b5b30d578f9c9dec053d30fa0cd64059643ce55 Mon Sep 17 00:00:00 2001 From: Augusto Finger Pacheco <44980634+fingeraugusto@users.noreply.github.com> Date: Thu, 23 May 2024 17:36:33 -0300 Subject: [PATCH] Added use of GridFunctions to an example (#59) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- CONTRIBUTORS.md | 1 + .../particle_wall_interaction_with_motion.py | 30 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 52bdcc1d..79477aa2 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -7,6 +7,7 @@ ## Individual Contributors * [Alejandro Fernández Luces](https://github.com/AlejandroFernandezLuces) +* [Augusto Finger Pacheco](https://github.com/fingeraugusto) * [Gustavo Corrêa Martins](https://github.com/gcmartins) * [Jorge Martínez Garrido](https://github.com/jorgepiloto) * [Roberto Pastor Muela](https://github.com/RobPasMue) diff --git a/examples/basic_examples/particle_wall_interaction_with_motion.py b/examples/basic_examples/particle_wall_interaction_with_motion.py index 76f51213..dc8a18ff 100644 --- a/examples/basic_examples/particle_wall_interaction_with_motion.py +++ b/examples/basic_examples/particle_wall_interaction_with_motion.py @@ -114,6 +114,18 @@ times, mass_flow_in = particles.GetNumpyCurve("Particles Mass Flow In", unit="t/h") times, mass_flow_out = particles.GetNumpyCurve("Particles Mass Flow Out", unit="t/h") +# Obtain the maximum and minimum velocities of the particles at each time step. +import numpy as np + +simulation_times = study.GetTimeSet() +velocity_gf = particles.GetGridFunction("Velocity : Translational : Absolute") +velocity_max = np.array( + [velocity_gf.GetMax(unit="m/s", time_step=i) for i in range(len(simulation_times))] +) +velocity_min = np.array( + [velocity_gf.GetMin(unit="m/s", time_step=i) for i in range(len(simulation_times))] +) + ################################################################################# # Plot curves @@ -121,13 +133,19 @@ import matplotlib.pyplot as plt -fig, ax = plt.subplots(1) +fig, (ax1, ax2) = plt.subplots(2, 1) + +ax1.plot(times, mass_flow_in, "b", label="Mass Flow In") +ax1.plot(times, mass_flow_out, "r", label="Mass Flow Out") +ax1.set_xlabel("Time [s]") +ax1.set_ylabel("Mass Flow [t/h]") +ax1.legend(loc="upper left") -ax.plot(times, mass_flow_in, "b", label="Mass Flow In") -ax.plot(times, mass_flow_out, "r", label="Mass Flow Out") -ax.set_xlabel("Time [s]") -ax.set_ylabel("Mass Flow [t/h]") -ax.legend(loc="upper left") +ax2.plot(simulation_times, velocity_max, "b", label="Max Velocity") +ax2.plot(simulation_times, velocity_min, "r", label="Min Velocity") +ax2.set_xlabel("Time [s]") +ax2.set_ylabel("Velocity [m/s]") +ax2.legend(loc="upper left") plt.draw()