Over the past week, and with encouragement and help from Max98, i've been writing some advanced thermodynamics code to simulate a basic 'turbojet' engine. In the future it could easily be expanded to handle any configuration of gas turbine engine, such as turbofans, afterburning engines with variable geometry nozzles & intakes, even turbo-shafts for use in wheeled vehicles. How it works: You can feed in some basic parameters for the engine, usually all taken from the 'design point', which is usually maximum thrust designThrust designRPM idleRPM designCompressorPressureRatio designTurbineInletTemperature Inertia Friction CalorificFuel --calorific value of the fuel used (kerosene) 46000kJ/kg It will run once at the design point, and is able to work out the other things about the engine that are unknown and impossible to find unless you have the design data such as turbine temperature ratio, max mass and fuel flow rates. It is based on a 1D thermodynamic cycle analysis, https://www.grc.nasa.gov/www/k-12/airplane/shortp.html but has some extra parts things to handle transient simulation, such as excess power leading to RPM acceleration, the inertia of the compressor/turbine and changing mass flow rate etc.. If you have any suggestions or questions then fire away
Update. Simulation is now in-game and working with the a turbojet simulation. I am using Dummiesmans Gloster Meteor Mk. III as a testbed, and simulating the Rolls Royce Welland engine used on the early meteors: Max98 has also helped by adding some thermal code that monitors engine & oil temperatures, as well as a debug app, which is great. We also added emergency power, the ability to go above 100% throttle, as well as calculating the fuel flow rate into the engine. Currently I am looking at the exhaust/nozzle process to correctly simulate things like mass flow choking, 'off design' conditions like partial throttle, over/under expansion and the contribution to thrust from pressure. Future Steps; I will keep working on the turbojet simulation and finish it before adding additional functionality. Once the basic 'core' of the engine is done, it is possible to write small updates to consider things like afterburners, variable geometry nozzles, and supersonic intakes. Bypass ratio (turbofans) will probably require a bit more work, as the fan basically requires a kind of propeller model.
Another update: The base code is working really well now and will cover a large range of RPM unlike before. I found some mistakes in my derivations and implementation of the thermodynamics that lead to the RPM always being high and not dropping even on 0% throttle. This was caused by a incorrect pressure ratio curve having its minimum at 0 instead of 1, meaning below a certain RPM the compressor would actually generate power, and because the compressor and turbine works are balanced when the engine is steady, the RPM would never drop very low. Now the engine will die below a certain RPM, as the turbine is unable to provide enough power to drive the compressor and frictions in the engine. I also added a calibration/matching functionality to determine multiple unknown properties of the engine though iteration. This finds unknown properties like the matched turbine temperature ratio, mass flow rate, and max fuel flow required which are used later in the 'transient' section of the simulation. The simulation is very accurate provided the input values are good. To give you and idea, If i put the properties of the Rolls Royce R.B.44 Tay, I get a almost identical mass flow value to the real engine. The Whittle Turbojet/Welland is also within 10%. There is a full todo/feature list in the gasTurbine.lua code. I will probably only add the bits that are required for whatever vehicle i'm working on, or if they are needed for anybodies mod. Attached is the simple test vehicle/prop jbeam I have been using, as well as the debug/display app. It is fixed to the ground, but that can be changed in the jbeam. It also provides an example of how to make the lua code work with thrusters using electrics. Keys for throttle are 'Y' and 'H'. The App will give some errors in the console, I'm not sure what causes them but it still works. I want to re-write the app so it will show graphs of RPM and thrust like the braking force app, which would be cool. I'm aware this code is 100% overkill, and for most applications a slider from 0-100% throttle would be fine, but it is pretty funny that BeamNG now has the basis of a more realistic engine simulation than most flight simulators.
Tested and its didn't works for me... don't know why and the debug app not show nothing, only NaN for all thing, but i like the idea and all the way! Looks forward for this and other new things. Good to know at have a lua genius here
Thanks for trying it out If you post the screen of the console log, the default button is '~', I can help you. It is most likely that the code is running in the background, just the debug app is broken. Remove the Code: {"fixed":true}, from the jbeam file, and if it flies away when you throttle up that will be the case.
the debug run too fast to make a screenshoot the test bad didnt do nothing, cant accelerate and so on.... {"fixed":true} whan i set to false the bed hit the ground but not working.
I forgot to initialise some variables that are shared between functions. I must have removed their initialisation from the start of the .lua and because I had already loaded the script It ran fine on my end. Thanks for the bug report. It is fixed now, both the app and jbeam should be working as this was a problem with the lua. Updated Lua file is attached, just overwrite the old one.
hmmm i dont know why but it is the same on my side! tried some other capture program and the game say something wrong in the line 59...
I'm not sure what is causing it then. I moved my version out of the mods folder, cleared the cache and then downloaded and installed the version I have uploaded in this thread and it runs perfectly. Do still get the same errors in the console? If yes then try clearing your cache and re-downloading the .zip
Nice to see you in the development! Now i understand why the turbine not worked for me with the version 0.6 which relesed 22 July 2016, because after the game updated to version 0.6.1 on 29 July 2016, everything worked for me without problem!
Ah yes, there was a switch from using onInit() (will now give a depreciated error) to onExtensionLoaded() for custom lua extensions. The latest release at that time was using the old way and wouldn't have known about it, so good catch As for where I am with the code. I have now gotten a lot of supersonic stuff done, normal shock (F-16 style) intakes can be simulated, as well as afterburners and corresponding variable geometry nozzles. I have it working on a Rolls Royce Avon found in BAC/E.E. Lightning aircraft, with its intake, afterburner and convergent-divergent nozzle. I'll try and get some performance graphs of this soon, but since It has been running in BeamNG, the original code has not been updated (and is in a slightly different language). And for some personal fun I also made a very nice mesh, as need something to test multiple engines, as well as all the speed and altitude ranges I can dream off. Lightning fits this perfectly, and who doesn't love something from the 50's that has similar performance to a modern jet.