Lap Time Simulation with Fuel Mass Dynamics and XFOIL Integration
Inspiration
We have always been fascinated by the real-world physics of motorsport, especially how aerodynamics, vehicle dynamics, and fuel mass combine to influence lap times.
Simulating a race car's lap — accounting for drag, lift, fuel burn, tire friction, and changing vehicle mass — felt like the perfect way to bring engineering theory into a real-world style project.
We wanted to create something deeper than a simple kinematic simulation — a model that would respond to real aerodynamic coefficients at different speeds and fuel loads, making it behave like an actual race car on track.
How We Built It
- Physics Model: We used classical dynamics (F=ma) for straights, and frictional cornering limits (lateral force balance) for turns.
- Fuel Mass Tracking: The car's total mass decreases over time by consuming fuel, which affects acceleration, deceleration, and cornering speeds.
- XFOIL Integration: We called XFOIL to calculate the lift and drag coefficients (
ClandCd) based on the Reynolds number at each velocity. - Caching System: To avoid slowing down with repeated XFOIL calls, we added a caching layer that reuses aerodynamic results when possible.
- Fuel Burn Model: Instead of simply subtracting fuel based on distance traveled, we updated the fuel at every small timestep, making the fuel usage dynamic and local to that section of track.
- Crash Handling: We added defaults for low-speed cases where XFOIL might crash, making the simulation stable across all scenarios.
What We Learned
- How aerodynamic forces like drag and lift affect both straight-line speed and cornering behavior.
- How critical it is to model changing mass when simulating anything involving fuel usage — it heavily impacts acceleration, braking, and max cornering speeds.
- How to automate external tools like XFOIL inside Python, including managing errors when they fail.
- How to optimize simulations by caching repeated computations and approximating intelligently when needed.
- How small modeling choices — like fuel consumption rate or friction coefficient — can dramatically alter the final lap time.
Challenges We Faced
- XFOIL Instability: At low Reynolds numbers, XFOIL would crash because aerodynamic data becomes unreliable. We had to catch these errors and provide reasonable fallback values.
- Mass Coupling: Because the car’s mass decreases with fuel burn, and that mass directly affects cornering and acceleration, everything becomes interconnected — solving this carefully took a lot of trial and error.
- Fuel Usage Granularity: Initially, we calculated fuel usage based on total distance traveled, but realized it needed to update each time step for better accuracy.
- Performance Bottlenecks: Calling XFOIL repeatedly for every small change in velocity was too slow — caching results solved this.
- Balancing Realism and Speed: We had to find the right balance between high-fidelity physics and a simulation that runs fast enough to be usable.
Final Thoughts
This project was a deep dive into blending aerodynamics, vehicle physics, and software simulation — just like what engineers might do in real-world motorsports or aerospace applications.
It showed us how small physical assumptions can scale into big performance outcomes, and how important it is to design simulations that are both stable and accurate.
We are super excited to keep building on this — maybe adding tire modeling, track layouts, or full race simulations next!
Built With
- calculus
- derivatives
- f1
- integration
- numerical
- python
- simulation
- xfoil
Log in or sign up for Devpost to join the conversation.