Intro
In [1]:
Copied!
"""
with this package you can create a water rocket simulation.
there are following modules:
- core: contains the main simulation logic
- rocket: defines the rocket structure and components
- analysis: provides tools for analyzing simulation results
- utils: utility functions and classes for saving/loading data
- visualization: tools for visualizing simulation data
- optimization: tools for optimizing rocket parameters
"""
"""
with this package you can create a water rocket simulation.
there are following modules:
- core: contains the main simulation logic
- rocket: defines the rocket structure and components
- analysis: provides tools for analyzing simulation results
- utils: utility functions and classes for saving/loading data
- visualization: tools for visualizing simulation data
- optimization: tools for optimizing rocket parameters
"""
Out[1]:
'\nwith this package you can create a water rocket simulation.\nthere are following modules:\n- core: contains the main simulation logic\n- rocket: defines the rocket structure and components\n- analysis: provides tools for analyzing simulation results\n- utils: utility functions and classes for saving/loading data\n- visualization: tools for visualizing simulation data\n- optimization: tools for optimizing rocket parameters\n'
In [2]:
Copied!
"""Creating a Water Rocket"""
from waterrocketpy.rocket.builder import create_standard_rocket
rocket = create_standard_rocket()
print(f" Rocket created: {rocket.name}")
print(f" Total mass: {rocket.total_mass:.3f} kg")
"""Creating a Water Rocket"""
from waterrocketpy.rocket.builder import create_standard_rocket
rocket = create_standard_rocket()
print(f" Rocket created: {rocket.name}")
print(f" Total mass: {rocket.total_mass:.3f} kg")
Rocket created: Standard 2L Rocket Total mass: 0.910 kg
In [3]:
Copied!
from waterrocketpy.core.simulation import WaterRocketSimulator
from waterrocketpy.rocket.builder import RocketBuilder
"""Running a Water Rocket Simulation"""
# Convert to simulation parameters
print("\n2. Converting to simulation parameters...")
sim_params = rocket.to_simulation_params()
print(f" Parameters ready: {len(sim_params)} parameters")
# Run simulation
print("\n3. Running simulation...")
simulator = WaterRocketSimulator()
# Short simulation for testing
sim_settings = {"max_time": 100.0, "time_step": 0.01, "solver": "RK45"}
flight_data = simulator.simulate(sim_params, sim_settings)
from waterrocketpy.core.simulation import WaterRocketSimulator
from waterrocketpy.rocket.builder import RocketBuilder
"""Running a Water Rocket Simulation"""
# Convert to simulation parameters
print("\n2. Converting to simulation parameters...")
sim_params = rocket.to_simulation_params()
print(f" Parameters ready: {len(sim_params)} parameters")
# Run simulation
print("\n3. Running simulation...")
simulator = WaterRocketSimulator()
# Short simulation for testing
sim_settings = {"max_time": 100.0, "time_step": 0.01, "solver": "RK45"}
flight_data = simulator.simulate(sim_params, sim_settings)
2. Converting to simulation parameters... Parameters ready: 9 parameters 3. Running simulation... Starting water expulsion phase... Water depleted at t=0.123s, starting air expulsion phase... Air depleted at t=0.199s, starting coasting phase...
In [4]:
Copied!
"""
How the Rocket builder Works: Step by step:
1. Manual approach
"""
from waterrocketpy.core.simulation import WaterRocketSimulator
from waterrocketpy.rocket.builder import RocketBuilder,create_standard_rocket
from waterrocketpy.core.constants import ATMOSPHERIC_PRESSURE
#create a Rocket Builder
custom_rocket_Builder = (
RocketBuilder()
.set_bottle(volume=0.002, diameter=0.1) # 2L bottle
.set_nozzle(diameter=0.015)
.set_mass(empty_mass=0.25, water_fraction=0.33)
.set_initial_conditions(pressure=8 * ATMOSPHERIC_PRESSURE)
.set_metadata("Standard 2L Rocket", "Standard configuration for 2L bottle")
)
#let the Rocket Builder create a rocket:
custom_rocket = custom_rocket_Builder.build()
sim_params = custom_rocket_Builder.to_simulation_params()
simulator = WaterRocketSimulator()
flight_data = simulator.simulate(sim_params)
print(f"Maximum altitude: {flight_data.max_altitude:.2f} m")
"""
How the Rocket builder Works: Step by step:
1. Manual approach
"""
from waterrocketpy.core.simulation import WaterRocketSimulator
from waterrocketpy.rocket.builder import RocketBuilder,create_standard_rocket
from waterrocketpy.core.constants import ATMOSPHERIC_PRESSURE
#create a Rocket Builder
custom_rocket_Builder = (
RocketBuilder()
.set_bottle(volume=0.002, diameter=0.1) # 2L bottle
.set_nozzle(diameter=0.015)
.set_mass(empty_mass=0.25, water_fraction=0.33)
.set_initial_conditions(pressure=8 * ATMOSPHERIC_PRESSURE)
.set_metadata("Standard 2L Rocket", "Standard configuration for 2L bottle")
)
#let the Rocket Builder create a rocket:
custom_rocket = custom_rocket_Builder.build()
sim_params = custom_rocket_Builder.to_simulation_params()
simulator = WaterRocketSimulator()
flight_data = simulator.simulate(sim_params)
print(f"Maximum altitude: {flight_data.max_altitude:.2f} m")
Starting water expulsion phase... Water depleted at t=0.123s, starting air expulsion phase... Air depleted at t=0.199s, starting coasting phase... Maximum altitude: 61.45 m
In [5]:
Copied!
#2. automatic approach
from waterrocketpy.rocket.builder import RocketBuilder
from waterrocketpy.core.constants import ATMOSPHERIC_PRESSURE
from waterrocketpy.core.simulation import WaterRocketSimulator
# Smart approach - specify dimensions, let the function calculate everything!
smart_builder = RocketBuilder()
smart_config = (smart_builder
.build_from_dimensions(
L_body=0.25, # 25 cm body length
L_cone=0.08, # 8 cm nose cone length
d_body=0.088, # 88 mm diameter (standard 2L bottle)
p_max=8 * ATMOSPHERIC_PRESSURE, # 8 bar maximum pressure
nozzle_diameter=0.01, # 10 mm nozzle diameter
material_name="PET", # PET plastic material
water_fraction=0.3, # 30% water fill
safety_factor=2.0 # 2x safety factor
)
.set_metadata("Smart Rocket", "Built using build_from_dimensions")
.build()
)
print("Smart Rocket Configuration:")
print(f" Volume: {smart_config.bottle_volume:.6f} m³")
print(f" Empty Mass: {smart_config.empty_mass:.3f} kg")
print(f" Drag Coefficient: {smart_config.drag_coefficient:.3f}")
print(f" Description: {smart_config.description}")
#simulate
simulator = WaterRocketSimulator()
flight_data = simulator.simulate(smart_config.to_simulation_params())
print(f"Maximum altitude: {flight_data.max_altitude:.2f} m")
#2. automatic approach
from waterrocketpy.rocket.builder import RocketBuilder
from waterrocketpy.core.constants import ATMOSPHERIC_PRESSURE
from waterrocketpy.core.simulation import WaterRocketSimulator
# Smart approach - specify dimensions, let the function calculate everything!
smart_builder = RocketBuilder()
smart_config = (smart_builder
.build_from_dimensions(
L_body=0.25, # 25 cm body length
L_cone=0.08, # 8 cm nose cone length
d_body=0.088, # 88 mm diameter (standard 2L bottle)
p_max=8 * ATMOSPHERIC_PRESSURE, # 8 bar maximum pressure
nozzle_diameter=0.01, # 10 mm nozzle diameter
material_name="PET", # PET plastic material
water_fraction=0.3, # 30% water fill
safety_factor=2.0 # 2x safety factor
)
.set_metadata("Smart Rocket", "Built using build_from_dimensions")
.build()
)
print("Smart Rocket Configuration:")
print(f" Volume: {smart_config.bottle_volume:.6f} m³")
print(f" Empty Mass: {smart_config.empty_mass:.3f} kg")
print(f" Drag Coefficient: {smart_config.drag_coefficient:.3f}")
print(f" Description: {smart_config.description}")
#simulate
simulator = WaterRocketSimulator()
flight_data = simulator.simulate(smart_config.to_simulation_params())
print(f"Maximum altitude: {flight_data.max_altitude:.2f} m")
Smart Rocket Configuration: Volume: 0.001521 m³ Empty Mass: 0.175 kg Drag Coefficient: 0.239 Description: Built using build_from_dimensions Starting water expulsion phase... Water depleted at t=0.186s, starting air expulsion phase... Air depleted at t=0.321s, starting coasting phase...
Maximum altitude: 81.59 m
In [ ]:
Copied!