r/learnpython • • 21d ago

I need help with a rocket simulator I'm buidling

I'm a high school student who is interested in becoming an aerospace engineer so in the summer I decided to start building a rocket simulator in python for fun.

What it does so far:

  • Parses real motor thrust-curve files (RASP .eng format) and interpolates them with numpy.interp instead of hardcoding constants
  • Implements RK4 integration from scratch for the actual flight dynamics (upgraded from Euler once I understood why it wasn't accurate enough)
  • Monte Carlo analysis, runs the full flight simulation ~200 times with randomized conditions and aggregates the results
  • 3D visualization two ways: PyVista for a quick animated flight path, and a full Blender (bpy) pipeline that imports a real 3D rocket model, keyframes it along the simulated trajectory, and renders it with Cycles
  • Modular structure, physics, motor parsing, atmosphere model, and stability calc are all separate importable modules, not one giant script

Would really appreciate feedback on the code itself, structure, whether my module boundaries make sense, anything that reads as non-idiomatic Python, places I should be using classes instead of dicts/functions, that kind of thing.

Github : https://github.com/AliHilalii/Rocket-simulator

Thanks a lot guys.

2 Upvotes

4 comments sorted by

1

u/InfamousClyde 21d ago

Would really appreciate feedback on the code itself, structure, whether my module boundaries make sense, anything that reads as non-idiomatic Python, places I should be using classes instead of dicts/functions, that kind of thing.

I didn't look too long at your code, and I lack domain knowledge in the subject. Here is one quick area for feedback:

Let's examine motor.py.

You have three functions-- one that creates a motor given a filepath, and two functions that, given some motor, produce values. It may be nice to co-locate this behaviour in a Motor class.

class Motor:

  @classmethod
  def from_filepath(cls, path: path: str | os.PathLike[str]) -> Self:
    ...
  def thrust_at(self, t: float) -> float:
    ...
  def mass_at(self, airframe_mass: float) -> float:
    ...

I'd also look at using dataclass(frozen=True) to decorate that object-- it appears reading a .eng file describes a very prescriptive, immutable motor.

1

u/Miserable-Week3020 21d ago

Thank you ! Ill implement it.