Does anyone know how the Flight Club website is able to provide falcon 9 launch simulations? Given the estimated weight, fuel mass, thrust, ect, how are they able to provide a graph of how it could play out?
Flight Club creator here. Thanks for the ping @uhoh ;)
@RussellBorogove got the implementation of the code spot on and it's actually almost exactly what I do. The only points that I feel are worth mentioning are that I use a leapfrog integrator instead of RK4, because it conserves energy over time and is reversible. This means that the 100th orbit will look identical to the 1st (assuming gravity is the only external force). Also I can implement coast periods between stage separations and ignitions.
The only thing that could do with some more fleshing out, I feel, is talking about the guidance algorithms. In Flight Club's case, 'algorithm' is an extremely generous word, as the guidance profile is completely user-defined. The user defines the elevation, azimuth, and throttle profile of every stage with time. These can be validated by comparing the resulting trajectory with webcast data, and also with some domain knowledge of orbital launches which I've just garnered through experience - for example a SpaceX GTO launch will have a parking orbit of about 170x450km, give or take, and the upper stage usually loses a small bit of altitude towards the end of it's first burn.
I'm working on automating the guidance profile definitions in the background to make my life easier in the future (currently I am manually creating flight profiles for every launch that my Patrons will be photographing - usually I can reuse an old flight profile, but it's trickier when I'm modelling a vehicle for the first time, like D4H for Parker Solar Probe, or Delta II's last flight).
At this time, the only thing that is automated is the landing burn throttle profile, but it's a very simple recalculation of the throttle profile during descent to ensure zero velocity at zero altitude. There is nothing ensuring that the touchdown coordinates are correct - this also needs to be validated and tweaked by the user after the simulation has completed.
All of these manual tasks are semi-easily automated, but most of my development work at the moment is going into developing more of the front-end and migrating the backend to more scalable technologies. When I'm happy with those things, I can get back into improving the GNC stuff
I don't know exactly how Flight Club does it, but I've created a simulation modeled on Joan Creus-Costa's launchsim and I believe it's probably not too dissimilar from what Flight Club does. I also got a lot of insight from Braeunig's Saturn V simulation page.
The basic approach is discrete time simulation: start with known initial conditions and simulate the passage of time in short chunks, updating the state of the simulation according to physical law at each step. I use a time step of 1/100 second; even at that rate, my laptop is fast enough to simulate a launch at about 50 times faster than real time (i.e. ascent to Earth orbit for most launchers in around 12 seconds).
Given the known mass of the rocket (recalculated on each time step as fuel is consumed) and the thrust of the currently active stage's engines, acceleration from thrust is applied, along with acceleration from gravity, and retarding force from drag. I do use RK4 when applying the physics, but with a small enough time step it doesn't matter much.
I simulate varying air density with altitude according to a fixed model based on this NASA page. I don't do anything for weather, crosswind, etc. Nothing in my sim presently is randomized.
Given sea level and vacuum specific impulse figures for an engine, I linearly interpolate the specific impulse as air pressure goes from 1 to 0 atmospheres. This is a very good match to the actual performance of the Saturn V's F-1 engines; I haven't found Isp-versus-pressure curves for other engines, but the F-1s are so linear that I suspect there's a fundamental physical law controlling it.
A guidance system is simulated to determine what direction to apply thrust in -- I don't simulate the actual gimbal angle and control authority, I just assume the desired thrust angle is achievable. I've got a variety of guidance algorithms that I'm not yet happy with.
When the fuel runs out on a stage I just disconnect the mass and engines associated with the stage and activate the next instantly; it would be more realistic to add some interstage delay time.
Launchers are defined as a list of stages. Stages have dry mass, fuel mass, cross sectional area, and a list of engines. Engines have fuel flow rate, specific-impulse-by-altitude function, min and max throttle settings, etc. In my launcher definition code, I can add scheduled events, like throttle-down or jettisoning LES systems (and thus reducing mass of the remaining rocket) at a given point in the flight. I'm not yet modeling Isp falloff with throttle-down. In principle, you can define any rocket you like, real or fictional; you just need the stage masses and engine specs.
The Earth (or whatever body being launched from) is modeled as a uniformly rotating sphere; my coordinate system supports launch site latitude, but always rotates the world so that the launch site is at the coordinate system's zero X coordinate. Initial velocity from planetary rotation is included. Gravitational falloff with altitude is modeled.
Here's a screenshot of my embarrassingly bad UI:
This is modeling the ascent of an Apollo LM from the moon (in the service of answering an earlier question on the site). Graph 1 on the left is altitude versus time; graph 2 is acceleration versus time. We're paused at 25 simulated seconds after insertion into a 18 km x 87 km orbit.
Flight Club does things like tracking the detached first stage separately; my sim only works with one vehicle at a time, but it wouldn't be too difficult to change that.