The simulator
The rocket simulator is composed of several tools that calculate the state of the rocket throughout the flight. This is useful to adjust rocket design (nozzle diameter, number of bottles, etc.) and launch parameters (water volume, air pressure, …).
Get started
Download the rocket simulator folder.
Open a command prompt and navigate to the folder.
Create a virtual environment and install dependencies.
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate.bat
pip install -r requirements.txt
Start Python and create a rocket object.
from waterRocketSim import WaterRocket
rocket = WaterRocket()
API reference
The documentation below is generated automatically from the docstrings in the simulator module.
Utilities for simulating a water rocket flight.
The module exposes the WaterRocket model and helper routines that
compute expulsion flow, thrust, and trajectory over time.
- class waterRocketSim.WaterRocket(s1_nozzleDiameter=0.02, s2_nozzleDiameter=0.007, s1_bottleCount=1, s2_bottleCount=2, bottleType='2L', rocket_payloadMass=0.2)[source]
Bases:
objectModel a water rocket and provide several function to simulate its flight.
- __init__(s1_nozzleDiameter=0.02, s2_nozzleDiameter=0.007, s1_bottleCount=1, s2_bottleCount=2, bottleType='2L', rocket_payloadMass=0.2)[source]
Initialize the water rocket model.
- Parameters:
s1_nozzleDiameter (float) – Nozzle diameter in meter of the lower reservoir of the rocket. The default diameter is 20mm which is the diameter of a 2L soda bottle.
s2_nozzleDiameter (float) – Nozzle diameter in meter of the upper reservoir of the rocket. The default diameter is 7mm which correspond the the internal diameter the water ejection tube use in the current rocket design.
s1_bottleCount (int) – Number of bottles in lower reservoir. Default is 1.
s2_bottleCount (int) – Number of bottles in upper reservoir. Default is 2.
bottleType (str) – Constant that identifies the bottle type. Default is 2L bootle.
rocket_payloadMass (float) – Payload mass in kilograms. Default is 0.2kg which is a raisonable payload mass for a water rocket.
- launchSimulation(simulation_step=0.01, simulation_time=5, s1_waterVolumeIni=0.001, s2_waterVolumeIni=0.0015)[source]
Simulate the launch of the water rocket using an Euler method to evaluate the evolution of the rocket state (volume, mass, pressure, altitude) based on the evolution of the expulsion flows and cinematic variables (speed, acceleration) with the help of physics laws.
- Parameters:
simulation_step (float) – Time step for the Euler simulation in seconds.
simulation_time (float) – Total time for the simulation in seconds.
s1_waterVolumeIni (float, optional) – Initial water volume in section 1 in
0.001. (cubic meters. Defaults to)
s2_waterVolumeIni (float, optional) – Initial water volume in section 2 in
0.0015. (cubic meters. Defaults to)
- Returns:
A dictionary containing the evolution of the rocket state and cinematic variables over time.
- Return type:
dict
- maxAltitude(flyVariables)[source]
Calculate the maximum altitude reached by the rocket.
- Parameters:
flyVariables (dict) – Dictionary containing the simulation results.
- Returns:
Maximum altitude reached by the rocket.
- Return type:
float
- timeToMaxAltitude(flyVariables)[source]
Calculate the time taken to reach the maximum altitude.
- Parameters:
flyVariables (dict) – Dictionary containing the simulation results.
- Returns:
Time taken to reach the maximum altitude.
- Return type:
float
- flyTime(flyVariables)[source]
Calculate the total flight time until the rocket lands.
- Parameters:
flyVariables (dict) – Dictionary containing the simulation results.
- Returns:
Total flight time until the rocket lands.
- Return type:
float
- parametersForMaxAltitude(s1_waterVolumeIni_range=numpy.arange, s2_waterVolumeIni_range=numpy.arange, simulation_step=0.01, simulation_time=20)[source]
Search for the initial water volumes that maximize altitude.
- Parameters:
s1_waterVolumeIni_range (np.ndarray) – Range of initial S1 water volumes.
s2_waterVolumeIni_range (np.ndarray) – Range of initial S2 water volumes.
simulation_step (float) – Time step for the simulation in seconds.
simulation_time (float) – Total simulation duration in seconds.
- Returns:
Best parameters for maximum altitude and the associated altitude.
- Return type:
dict
- parametersForMaxTime(payload_mass, s2_bottleCount=2, s2_nozzleDiameter_range=numpy.arange, s1_waterVolumeIni_range=numpy.arange, s2_waterVolumeIni_range=numpy.arange)[source]
Search for the parameters that maximize flight time.
- Parameters:
payload_mass (float) – Mass of the payload in kg.
s2_bottleCount (int) – Number of S2 bottles.
s2_nozzleDiameter_range (np.ndarray) – Range of S2 nozzle diameters.
s1_waterVolumeIni_range (np.ndarray) – Range of initial S1 water volumes.
s2_waterVolumeIni_range (np.ndarray) – Range of initial S2 water volumes.
- Returns:
Best parameters for maximum flight time.
- Return type:
dict
- plot_max_altitude_3d_with_s2_nozzle(s1_volume, s2_volume, s1_nozzleDiameter, s2_nozzleDiameter_range, s2_nozzleDiameter_steps, rocket_emptyMass, rocket_payloadMass, rocket_dragCoeficient, rocket_diameter, launch_Pressure)[source]
Plot maximum altitude as a 3D surface for S1/S2 water volumes and S2 nozzle diameter.
- Parameters:
s1_volume (float) – Total volume available in section 1 in cubic meters.
s2_volume (float) – Total volume available in section 2 in cubic meters.
s1_nozzleDiameter (float) – Nozzle diameter for section 1 in meters.
s2_nozzleDiameter_range (tuple) – Minimum and maximum S2 nozzle diameters.
s2_nozzleDiameter_steps (int) – Number of nozzle diameter increments to evaluate.
rocket_emptyMass (float) – Empty mass of the rocket in kilograms.
rocket_payloadMass (float) – Payload mass in kilograms.
rocket_dragCoeficient (float) – Drag coefficient of the rocket.
rocket_diameter (float) – Diameter of the rocket in meters.
launch_Pressure (float) – Launch pressure in Pascals.
- plot_flight_diagnostics(flyParameters)[source]
Plot flight diagnostics including altitude, thrust, speed, acceleration, and mass history.
- Parameters:
flyParameters (dict) – Simulation results dictionary returned by
launchSimulation().
- plot_altitudeVsTime(flyParameters)[source]
Plot the altitude of the rocket over time.
- Parameters:
flyParameters (dict) – Simulation results dictionary returned by
launchSimulation().
- animate_rocket_launch(flyParameters)[source]
Animate the rocket launch using Pygame.
- Parameters:
flyParameters (dict) – Simulation results dictionary returned by
launchSimulation().
- plot_altitude_and_thrust(flyParameters)[source]
Plot altitude and total thrust versus time on dual y-axes.
- Parameters:
flyParameters (dict) – Simulation results dictionary returned by
launchSimulation().
- class waterRocketSim.WaterRocket(s1_nozzleDiameter=0.02, s2_nozzleDiameter=0.007, s1_bottleCount=1, s2_bottleCount=2, bottleType='2L', rocket_payloadMass=0.2)[source]
Bases:
objectModel a water rocket and provide several function to simulate its flight.
- __init__(s1_nozzleDiameter=0.02, s2_nozzleDiameter=0.007, s1_bottleCount=1, s2_bottleCount=2, bottleType='2L', rocket_payloadMass=0.2)[source]
Initialize the water rocket model.
- Parameters:
s1_nozzleDiameter (float) – Nozzle diameter in meter of the lower reservoir of the rocket. The default diameter is 20mm which is the diameter of a 2L soda bottle.
s2_nozzleDiameter (float) – Nozzle diameter in meter of the upper reservoir of the rocket. The default diameter is 7mm which correspond the the internal diameter the water ejection tube use in the current rocket design.
s1_bottleCount (int) – Number of bottles in lower reservoir. Default is 1.
s2_bottleCount (int) – Number of bottles in upper reservoir. Default is 2.
bottleType (str) – Constant that identifies the bottle type. Default is 2L bootle.
rocket_payloadMass (float) – Payload mass in kilograms. Default is 0.2kg which is a raisonable payload mass for a water rocket.
- launchSimulation(simulation_step=0.01, simulation_time=5, s1_waterVolumeIni=0.001, s2_waterVolumeIni=0.0015)[source]
Simulate the launch of the water rocket using an Euler method to evaluate the evolution of the rocket state (volume, mass, pressure, altitude) based on the evolution of the expulsion flows and cinematic variables (speed, acceleration) with the help of physics laws.
- Parameters:
simulation_step (float) – Time step for the Euler simulation in seconds.
simulation_time (float) – Total time for the simulation in seconds.
s1_waterVolumeIni (float, optional) – Initial water volume in section 1 in
0.001. (cubic meters. Defaults to)
s2_waterVolumeIni (float, optional) – Initial water volume in section 2 in
0.0015. (cubic meters. Defaults to)
- Returns:
A dictionary containing the evolution of the rocket state and cinematic variables over time.
- Return type:
dict
- maxAltitude(flyVariables)[source]
Calculate the maximum altitude reached by the rocket.
- Parameters:
flyVariables (dict) – Dictionary containing the simulation results.
- Returns:
Maximum altitude reached by the rocket.
- Return type:
float
- timeToMaxAltitude(flyVariables)[source]
Calculate the time taken to reach the maximum altitude.
- Parameters:
flyVariables (dict) – Dictionary containing the simulation results.
- Returns:
Time taken to reach the maximum altitude.
- Return type:
float
- flyTime(flyVariables)[source]
Calculate the total flight time until the rocket lands.
- Parameters:
flyVariables (dict) – Dictionary containing the simulation results.
- Returns:
Total flight time until the rocket lands.
- Return type:
float
- parametersForMaxAltitude(s1_waterVolumeIni_range=numpy.arange, s2_waterVolumeIni_range=numpy.arange, simulation_step=0.01, simulation_time=20)[source]
Search for the initial water volumes that maximize altitude.
- Parameters:
s1_waterVolumeIni_range (np.ndarray) – Range of initial S1 water volumes.
s2_waterVolumeIni_range (np.ndarray) – Range of initial S2 water volumes.
simulation_step (float) – Time step for the simulation in seconds.
simulation_time (float) – Total simulation duration in seconds.
- Returns:
Best parameters for maximum altitude and the associated altitude.
- Return type:
dict
- parametersForMaxTime(payload_mass, s2_bottleCount=2, s2_nozzleDiameter_range=numpy.arange, s1_waterVolumeIni_range=numpy.arange, s2_waterVolumeIni_range=numpy.arange)[source]
Search for the parameters that maximize flight time.
- Parameters:
payload_mass (float) – Mass of the payload in kg.
s2_bottleCount (int) – Number of S2 bottles.
s2_nozzleDiameter_range (np.ndarray) – Range of S2 nozzle diameters.
s1_waterVolumeIni_range (np.ndarray) – Range of initial S1 water volumes.
s2_waterVolumeIni_range (np.ndarray) – Range of initial S2 water volumes.
- Returns:
Best parameters for maximum flight time.
- Return type:
dict
- plot_max_altitude_3d_with_s2_nozzle(s1_volume, s2_volume, s1_nozzleDiameter, s2_nozzleDiameter_range, s2_nozzleDiameter_steps, rocket_emptyMass, rocket_payloadMass, rocket_dragCoeficient, rocket_diameter, launch_Pressure)[source]
Plot maximum altitude as a 3D surface for S1/S2 water volumes and S2 nozzle diameter.
- Parameters:
s1_volume (float) – Total volume available in section 1 in cubic meters.
s2_volume (float) – Total volume available in section 2 in cubic meters.
s1_nozzleDiameter (float) – Nozzle diameter for section 1 in meters.
s2_nozzleDiameter_range (tuple) – Minimum and maximum S2 nozzle diameters.
s2_nozzleDiameter_steps (int) – Number of nozzle diameter increments to evaluate.
rocket_emptyMass (float) – Empty mass of the rocket in kilograms.
rocket_payloadMass (float) – Payload mass in kilograms.
rocket_dragCoeficient (float) – Drag coefficient of the rocket.
rocket_diameter (float) – Diameter of the rocket in meters.
launch_Pressure (float) – Launch pressure in Pascals.
- plot_flight_diagnostics(flyParameters)[source]
Plot flight diagnostics including altitude, thrust, speed, acceleration, and mass history.
- Parameters:
flyParameters (dict) – Simulation results dictionary returned by
launchSimulation().
- plot_altitudeVsTime(flyParameters)[source]
Plot the altitude of the rocket over time.
- Parameters:
flyParameters (dict) – Simulation results dictionary returned by
launchSimulation().
- animate_rocket_launch(flyParameters)[source]
Animate the rocket launch using Pygame.
- Parameters:
flyParameters (dict) – Simulation results dictionary returned by
launchSimulation().
- plot_altitude_and_thrust(flyParameters)[source]
Plot altitude and total thrust versus time on dual y-axes.
- Parameters:
flyParameters (dict) – Simulation results dictionary returned by
launchSimulation().