Better engine simulation method?

Discussion in 'Ideas and Suggestions' started by TranquilTiger, Feb 13, 2021.

  1. TranquilTiger

    TranquilTiger
    Expand Collapse

    Joined:
    Oct 16, 2017
    Messages:
    6
    Now I could just be an oblivious idiot and the game already has a version of this in the damage and thermal codes but...

    Would it be possible to implement an actual ECU system that simulates the engines with individual "chance of ignition" variables for the cylenders? Speaking in terms of the diesels. The code would take Intake Air Temp and Density, Top Dead Center Cylender Temp and Density, Cylender Compression Percentage/Valve, Gasket & Piston Ring Health, Injector Effeciancy/Health and Injector Pump Health to determine the effeciancy/chance of ignition of that power stroke. This would open up the possibility of worn out and realisticly breaking engines, realistic 'used' cars that dont run right when theyre cold, cold starting engines, fighting with a diesel that only has 2 out of the 8 cylenders igniting properly. or a worn out diesel that has one injector stuck open. I know this might end up being way too many calculations especially in high RPMs so maybe as a seperate code to turn on in the settings but I thought Id offer anyways because sometimes coders can make magic happen.


    In terms of sound.
    Would it be possible to get recordings of the individual fuel injectors fireing for diesel engines as just the exaust note is only half if not a third of the full noise that diesels make. Particularaly old Mechanical Injection pumps like the D-series would have as I assume its your guys interpretation of the 6.2L and 6.5L diesels they put in the square bodies.


    If you managed to implement this right, I think Itd easily make BeamNG the most advanced vehicle simulator for a long time
     
    • Agree Agree x 1
  2. Diamondback

    Diamondback
    Expand Collapse
    Vehicle Systems Lead
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,957
    Possible? Absolutely.

    There are a few very big issues with more advanced engine simulations:
    • Performance: The model needs to be quick enough to calculate, we can't just run some super high fidelity fluid dynamics system that simulates invidual air, water, fuel molecules because that's too expensive to run for our game
    • Usability: The model also needs to be reasonably easy to use. It's not really helpful if you need to be a top notch combustion engine engineer to be able to create a working engine to your liking
    • Extendability: A new model would be of no real use if it didn't support the right engine accessories. In our case, that would at least be turbos and superchargers, which both post their own requirements to the model. Both need some sort of airflow/pressure simulation, the turbo needs some sort of exhaust simulation and the supercharger needs to be able to take off power from the crank. Then there's other potentially interesting things: NOS, alternators, water injection, timings, cams, etc
    As you are aware, not everything in this list is actually supported by the current model and that's why I have been researching new ways of doing this for years. However, we haven't been able to find the perfect mix of above requirements just yet...
     
    • Like Like x 10
    • Agree Agree x 1
  3. atv_123

    atv_123
    Expand Collapse

    Joined:
    Aug 5, 2012
    Messages:
    1,710
    This is actually something I am also working on... not for BeamNG specifically... but mostly because I really like engines and buy building a calculation full of math, it helps me understand them much better... which is really the ultimate goal.

    I currently have 2 models: A simplified model (if you only have minimal information about the engine) and then a much more complicated model which can take darn near every parameter you could want information about into account. Basically take Automations Engine builder, and then turn the simulation up to 11.

    This all being said though... I don't think that Beam's engine simulation is actually inherently "bad" or "wrong". I think stuff can be added to it to make it better, sure... but the current model is pretty darn good. The hard part is that right now, physically creating the engines is a little... odd? You essentially have a regular torque curve for the engine. No calculations involved to get that. Then a kind of torque curve (boost curve?) for the turbo/supercharger. Again, no calculations to get that. Then its all calculated and simulated after the fact to give you the final in game result. But using a naturally aspirated torque curve and then guessing the boost amount to try and simulate a real engine without the proper knowhow or tools like I made basically just comes down to a guessing game.

    I kinda feel like a meeting of the two worlds would actually be more beneficial. So in the JBeam you would define your engine parameters (basically how the engine is constructed... Bore, Stroke, Number of Cylinders, Compression Ratio, Intake Efficiency, Exhaust Efficiency, Boost Generating Device (Turbo/Supercharger), Boost... most of which can be easily looked up on darn near any engine available today. Then the game runs a calculation on these parameters and essentially "generates" a realistic torque curve to be used by the vehicle each time you load it. This would be the simple way of defining an engine, but of course, as with everything else in beam, you could define many more parameters. You could define the firing order, you could define the angle between each ignition to make really weird engine configurations, you could define the length of each intake and exhaust runner... and then using these parameters as I outlined in a post over here... https://www.beamng.com/threads/an-interesting-way-to-simulate-engine-sounds.76760/#post-1279120 ... you could actually use that configuration and information to generate a custom sound for that engine... from idle all the way up to redline.

    As you said though.... by this point what I consider to be trivial information on engines may end up being nothing more than Voodoo hocus-pocus nonsense to others. So defining these parameters in a simplistic way that can be easily interpreted and come up with by everyone can end up being a real challenge.
     
    • Like Like x 6
  4. Diamondback

    Diamondback
    Expand Collapse
    Vehicle Systems Lead
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,957
    Do you mind sharing what kind of model you are using? And where it's from? Papers, research etc.

    There's an issue with the "simplified" internals you are describing. We can't just convert whatever input parameters in some fixed torque curve.
    While that is somewhat possible for a pure NA engine (and is obviously done like that atm in the game), things change when you introduce turbos, superchargers, NOS, etc.
    These are all devices that change how the torque "curve" looks at any given moment in time based on their very own way of working. A turbo for example has lag, so with all the same inputs at one second it makes 0 boost, the next second it spooled up and makes actual boost.
    Then there's the issue with defining "boost". While we are doing this atm, it's highly unrealistic. Turbos don't produce pressure. They move air. Restriction to that airflow is what creates pressure. The tricky part now is that that "restriction", is based on other engine parameters and changes all the time.
    So when you see something stating that engine X makes Y boost, then - at best - this is referring to peak boost.
    It barely says anything on its own about how it helps the engine to produce power though.
    A re-made engine sim would also have to include a very realistic turbo sim, which is a huge challenge by itself...
     
  5. atv_123

    atv_123
    Expand Collapse

    Joined:
    Aug 5, 2012
    Messages:
    1,710
    I would actually love to share. This is something that I have actually poured my heart and soul into over the past 11 years, so any explanation of anything you want on it, just ask and I should have a good answer and explanation. Its not perfect yet, and it is getting better all the time as I find new information, new data, or find new understanding in the mathematics as I make my calculations. Here is an example of the simplified simulation.
    upload_2021-2-17_18-59-55.png upload_2021-2-17_19-1-3.png

    And then this is the new, more complicated system that I am still working on getting all set up.
    upload_2021-2-17_18-52-14.png
    upload_2021-2-17_19-2-15.png

    Now as for where I got my calculations from... a lot of it did come from here.

    http://hpwizard.com/engine-horsepower-calculator.html

    They have a lot of equations listed on their site that came in quite useful. I have college text books as well that I pulled a lot of equations from as well for the simplistic engine calculations. The more complicated system I am making now is just purely simulating the entire cycle in the engine... no faking things, no guess's as to equations that might work... basically with the more complicated system... I literally simulate EVERYTHING... as can be seen in the picture you can see above. I am still working on the finer details of this system, so right now it underperforms (the simulated engine) compared to the simplified engine setup which you can basically get darn near bang on almost every time.

    100% which is actually the part that I praise about the current engine simulation. The fact that the turbo's do react quite realistically and (even if you claim the calculations aren't 100% what they should be) it does a darn good job at making it feel like it is infact correct.

    But yes, you are correct, the "boost" aspect is basically just stating that your intake is rather inefficient... I shouldn't have thrown that in there as part of the example. Instead, as you stated, parameters for the turbo should be defined, and then just waste gate pressure (basically the max boost the engine is designed to run at) and that's it... Basically a lot like the turbo's are designated already in Beam.

    I'll admit, I haven't actually done much with my turbo/boost simulation yet. At the moment it is fairly rudimentary. I intend to do more, but I just haven't gotten there yet. I have mainly focused on getting my engine simulation working on the engine side of things. Once that is all said and done, actually adding boost is as simple as (no its not simple, but you know what I mean) changing the atmospheric pressure seen by the engine... the simulation then takes care of the rest... or at least, that's the dream right?

    Also, keep in mind, this is just something I have made in my spare time... so it is definitely not perfect.
     

    Attached Files:

    • Like Like x 14
  6. Hoodrat14x

    Hoodrat14x
    Expand Collapse

    Joined:
    Feb 18, 2021
    Messages:
    1
    That's a very impressive project, well done.

    Does it simulate an ECU fueling strategy such as Mass Airflow, Speed Density, or Alpha-N?
     
    • Like Like x 1
    • Agree Agree x 1
  7. atv_123

    atv_123
    Expand Collapse

    Joined:
    Aug 5, 2012
    Messages:
    1,710
    That's a good question.

    The first "simplistic" engine simulation doesn't really take much fueling into account... it is biased more around the intake and exhaust efficiency basically covering the good (or the bad) of a particular engine... mostly in an attempt to keep things simple. The equation it uses is:

    ((5/3)*10^-9) * Area of Piston * BMEPboosted * Total Efficiency * PSPM * Stroke - Supercharger Power Draw = kW

    The 5/3*10^-9 isn't just completely random, its mostly just unit conversion and cancelation and that just happens to be the number that's left over in the end.

    Area of Piston = pi()*( Bore /2)^2
    Bore is in mm

    BMEPboosted = IF(B6="Yes",((VE un-boosted / 100)*(((Boost Pressure / Ambient Air Pressure)+1)^(1/1.7)))* BMEP , BMEP)
    The if statement is just checking if you are running your engine with some form of boost or not, if not, then you just get your standard BMEP
    BMEP = (VE un-boosted / 100) / BMEPd
    BMEPd = a number which I pull from a table depending on the type of engine you select (values came from that website I linked before)(this is your Break Mean Effective Pressure
    VE un-boosted = a number which also comes from a table from that same sight (this is your intake/exhaust efficiency)
    Boost Pressure = The wastegate pressure in Bar
    Ambient Air Pressure = Standard Atmospheric Pressure = 1.01325 Bar

    Total Efficiency = Efficiency * Fuel Efficiency * Intake/Valves Efficiency
    Efficiency = LN(1+( RPM / Peek Torque RPM )^(1- Intake Efficiency ))^( Intake Efficiency )
    Fuel Efficiency = 1-((( RPM - Peek Torque RPM ) / Peek Torque RPM )^ Exponent )*( VE un-boosted * VE Supercharger * Intake Efficiency )
    Intake/Valves Efficiency = (1-EXP((-1*(( Max RPM (Pistons) - RPM )/ Max RPM (Pistons) )^ Intake Efficiency )-1))*(-((1-( VE Supercharger *0.75))/( Max RPM (Pistons) - Peek Torque RPM ))*( RPM - Peek Torque RPM )+1)^(IF(OR(B15="Turbo",B15="Twin Turbo"),1,0)*IF(B54<Peek Torque RPM,0,1))

    Now these are a bit harder to explain... I actually made some of these (like the Intake/Valves Efficiency) so I would assume it isn't as accurate as it could be. These stacked on top of each other are what basically "form" the torque curve.

    PSPM = Power Strokes Per Minute = RPM * Stroke Multiplication * Number of Cylinders
    RPM = How fast the engine is turning
    Stroke Multiplication = 0.5 for 4 stroke engines, 1 for two stroke engines
    Number of Cylinders = Well... Number of Cylinders

    Stroke = Stroke in mm

    Supercharger Power Draw = if(B15="Supercharged",1,0)* Ambient Air Pressure *(((0.1178889*( Boost Ratio ^0.286)* CFM )/ VE Supercharger )-((0.1178889* CFM )/ VE Supercharger ))
    This is normally 0 if no supercharger is attached, but if it is attached, it relies heavily on the CFM calculation to determine how much power it draws to make the boost you set it for at peek power.
    VE Supercharger = the efficiency of the supercharger type... again... a table look up.
    CFM = (((Displacement *0.0000610237)* Red Line RPM)/3456)*IF(B6="Yes",(VE un-boosted*(((Boost Pressure / Ambient Air Pressure)+1)^(1/1.7))),1)
    Displacement = Number of Cylinders * Disp per Cyl (this is in cubic mm... thus the odd conversion factor)
    Disp per Cyl = Area of Piston * Stroke
    Red Line RPM = (100000* Max Piston Speed )/(PI()* Stroke )
    Max Piston Speed = Again, another table lookup (m/s)

    and that's basically the whole calculation. The only other bit your gonna want is (9549.076 * Power) / RPM = Nm which converts kW into torque which can be used in Beam.

    As can be seen though, in the simplistic sim, there is no specific fueling type that it follows... it just uses generic equations to calculate power... and honestly... it gets pretty darn close 95% of the time... but of course... that wasn't good enough for me... so I created the new sim.

    What the new sim does is it measures the volume of air that is taken in on the intake stroke, it then converts that volume to grams, and then to moles of air. It then aims to hit a 14.7:1 Air to Fuel ratio and calculates the amount of fuel required (in moles). It then converts back to grams of fuel, and then from that can basically calculate the combustion energy and internal temperature off of that fuel (and the efficiency of the burn)

    So I guess most similar would be a Mass Air Flow strategy if I had to guess at which real life one compares most closely.
     
    • Like Like x 6
  8. Diamondback

    Diamondback
    Expand Collapse
    Vehicle Systems Lead
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,957
    Nice work! :) I noticed something though, you seem to be mixing units a bit here and there (SI and imperial) I'd highly suggesto avoid that, it will bring you into hell one day... (speaking from experience :) )
     
    • Like Like x 4
    • Agree Agree x 1
  9. atv_123

    atv_123
    Expand Collapse

    Joined:
    Aug 5, 2012
    Messages:
    1,710
    You are 100% correct... because of that I am actually redoing this whole thing again (to reduce equations, remove un-necessary calculations, and just improve things in general) and one of the things I am making sure I am doing in the new one is to do all the calculations in 1 set of units and then convert afterword's. I have no idea why it seemed like a good idea at the time to do ALL the math literally twice in two different sets of units rather than just having a page purely just for converting units. Back then I guess it seemed like a good idea... now I look at it and just ask myself... why would I do that :p

    But yes, I am re-doing all the math, and I will be doing the same to the newer simulation (the higher end one) and hopefully reducing calculations there as well (as well as using all metric units... because screw imperial units)

    I am actually working on turning it into an App with someone overseas at the moment. He knows how to code in Java... I do not, but I can do math with the best of em... so we are trying to combine forces and make this much better.
     
    • Like Like x 1
  10. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,060
    Metric units are the best for this kind of stuff, they make maths so much easier
     
    • Agree Agree x 5
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice