Making My Physics Engine 10x Faster and Simulating Trusses

Поділитися
Вставка
  • Опубліковано 29 тра 2024
  • Head to squarespace.com/angethegreat to save 10% off your first purchase of a website or domain using code angethegreat
    In this video, I optimize the physics engine that powers Engine Simulator and discuss some iterative techniques for solving systems of linear equations.
    Conjugate gradient method: en.wikipedia.org/wiki/Conjuga...
    Gauss-Seidel method: en.wikipedia.org/wiki/Gauss%E...
    The paper about vectorizing the Gauss-Seidel method shown in the video: www.ncbi.nlm.nih.gov/pmc/arti...
    Support Engine Simulator 3D on Patreon!
    / atg_engine_simulator
    Download the OG Engine Simulator for free!
    github.com/Engine-Simulator/e...
    Join the Official Engine Simulator Discord Server!
    / discord
    Join my channel community Discord!
    / discord
    00:00 Master Mechanics
    00:14 Squarespace [Sponsored Segment]
    00:59 Engine Simulator Roadmap
    02:05 Physics Engine Overview
    02:55 Gauss-Seidel Method
    04:16 Optimizing the Gauss-Seidel Solver
    06:34 Conjugate Gradient Method
    07:43 Tension/Compression Demo
    10:06 Pre-emptively Addressing the Haterz
    10:34 Shout-out to Patrons and Outro
    #physics #simulation #gamedev
    FTC Disclaimer: This video was sponsored by Squarespace.
    Thanks for watching!
  • Розваги

КОМЕНТАРІ • 440

  • @AngeTheGreat
    @AngeTheGreat  Рік тому +2094

    i don't get why this guy doesn't just use box2d and unity smh

    • @Lemmskii
      @Lemmskii Рік тому +85

      ikr smh

    • @Blitz_Protogen
      @Blitz_Protogen Рік тому +38

      Exactly bro!!!

    • @Stork2204
      @Stork2204 Рік тому +82

      Cause ange only trusts his own incredible coding brain

    • @notanengineer
      @notanengineer Рік тому +9

      Yeh fr that would solve everything

    • @melonenstrauch1306
      @melonenstrauch1306 Рік тому +42

      Also he pronounced Seidel wrong, I'm probably the only one who noticed tho

  • @oblivion_2852
    @oblivion_2852 Рік тому +766

    Bruh... not too much to show?? This is HUGE. Please don't undersell your adventures into simulation and also your educational content. Love the explanation of different types of solvers. I now know where to look if I wanna get into this.

    • @rebus_x5313
      @rebus_x5313 Рік тому +15

      He: *not too much to show*
      Me: dude i wish i could do this stuff in 5 years if i started like now

    • @whannabi
      @whannabi Рік тому +3

      ​@@rebus_x5313 I wonder what we would get if he considered something as a lot to show

    • @senboy9002
      @senboy9002 10 місяців тому

      @@whannabi Accurate simulation of the entire Earth

  • @jakobbb6405
    @jakobbb6405 Рік тому +636

    8:55 This is actually a really common thing in engineering regarding basically everything. If you have a simple axle and it is held in place with 2 bearings one of them is fixed on the axle and the "casing" whie the other needs to be a floating bearing to compensate for any sort of length changes due to for example heat. Its a huge pain if you are currently studying this lol.

    • @racercowan
      @racercowan Рік тому +64

      In relations to truss's specifically, I believe that bridges (especially longer ones) are even designed with a "floating" end that can move by a small amount.

    • @JorgetePanete
      @JorgetePanete Рік тому

      It's*

    • @jakobbb6405
      @jakobbb6405 Рік тому +32

      @@racercowan i think not even small. I ain't no bridge man but I think they can move about 10m or something. It's really interesting

    • @gabrielenitti3243
      @gabrielenitti3243 Рік тому +34

      ​@@racercowan most bridges are built in "small" pieces to allow room for expansion and contraction due to temperature. The same applies to cement pours, they have relief cuts to allow for it.

    • @dovos8572
      @dovos8572 Рік тому +25

      @@racercowan the only bridges that don't have the floating end are bridges with a bowed pavement like old river bridges out of stone. these bridges don't need the floating end becaus they expand up into the bow and not to the side.

  • @Chillin4030
    @Chillin4030 Рік тому +37

    I'm so glad the Beam devs are in on it. I cant wait to see what that entails.

  • @cpli7783
    @cpli7783 Рік тому +15

    Whilst i love reinventing the wheel, there's an old passage that one can take from all the other physics engines i.e. that: "linear algebra? that belongs on the GPU". using a compute shader to do your SIMD for you every frame could possibly allow for much more complex simulations.

    • @AngeTheGreat
      @AngeTheGreat  Рік тому +12

      I'll leave that to a future video lol but yes, offloading some of the physics to GPU would be very interesting to try

  • @actuallydaneel
    @actuallydaneel Рік тому +125

    This really does remind me of polybridge, and i'm so into it. physics visualizations are just so satisfying

  • @orthodynamicstereonails
    @orthodynamicstereonails Рік тому +74

    I love it when computer science youtubers talk about optimization! Both you and Acerola do a great job talking about it.

    • @nixel1324
      @nixel1324 Рік тому

      Have you checked out Kaze Emanuar? He's doing incredible things to optimize the Super Mario 64 source code. He's making a rom hack (which he tests on actual hardware), and the things he can get the N64 to render interactively in real time are insane.

    • @oliverer3
      @oliverer3 7 місяців тому

      I'm terrible at it and hate doing it but it's so fascinating watching other people do it and explain their motivations.

  • @felixurbanov3438
    @felixurbanov3438 Рік тому +29

    You are awesome Ange!

  • @first9279
    @first9279 Рік тому +68

    I love that you've written "Danke" at the end of the thing with "Seidel", Im a native German speaker and I dont mind it when you pronounce it wrong :)

    • @seritools
      @seritools Рік тому +1

      Since I can't comment on the wrong pronounciation anymore imma replace it with "um actually, it's '3 fewer instructions', not '3 less instructions'"

    • @kem0n0.kokomo
      @kem0n0.kokomo Рік тому +1

      @hello Skill issue

    • @dieSpinnt
      @dieSpinnt 8 місяців тому

      The correct pronunciation of "Seidel" is only important when visiting the Oktoberfest. That's what the stone beer mugs are called, hehehe.
      With Philipp Ludwig von Seidel, Ritter von Seidel it is simpler: he has been DEAD since 1896 and can no longer defend himself against the butchering of his name. But I would be careful with living people. "We're Americans(for example) and that's how we pronounce XYZ here ...", like Ange told in the video, is far from good manners or respect. Just by the way;) And yes, all of this doesn't matter here. It's a video about science and not a love letter:) Danke auch!:)

  • @jfyllipy
    @jfyllipy Рік тому +81

    Hello! I’m a structural engineer and that is exactly what we do. It’s called finite element method and we solve pretty much a very similar matrix (but the global matrix elements are in bar’s terms (based on elastic properties of material and it's geometry) and not about the nodes, although we solve it for nodes displacements). The matrix is called “stiffener matrix”. Polybridge uses this very same method (as far as I’m concerned). I even developed an web app for structure (we call it frame) solution (first and second order solver. P-Delta for the win!). I don’t know if I can post the link here but if I can please let me know. (It’s is in my mother tong (Portuguese) however. But it’s very intuitive and I’m planing to release an English version).

    • @jbritain
      @jbritain Рік тому +2

      You can absolutely put links in UA-cam comments as far as I know

    • @Inf1e
      @Inf1e Рік тому +1

      Most populat CADs (AutoCAD, SolidWorks, etc) use this very method to simulate.

    • @jfyllipy
      @jfyllipy Рік тому +2

      @@Inf1e I dont know if CAD does simulation but definitely Solidworks, ANsys, Catia, Abaqus, etc uses it. However they do it with another technic. While I (and AngeTheGreat uses a variation of) use a technic called "Displacement Method", all these simulations softwares discretize the elements even more, where a mesh can have thousands and thousands of nodes (called vertices), solving for a matrix of order 6*n (n is the number of vertices). They even compute results in between vertices solving, by many iterations, an equation that needs to converge (the convergence is a very important measurement for accuracy). This means that a normal model (2000 vertices) can have a matrix of 144 millions elements and need to be solved multiple times to converge! It requires a good computer indeed. This technic is not used only for mechanics, however. CFD, magnetism, heat transfer, soil mechanics... All of them uses this technic, changing only the way they build the global matrix.

    • @annakquinn7084
      @annakquinn7084 Рік тому +6

      This is not FEM, this is Matrix Stiffness Method. In FEA we use shape functions to approximate discrete displacements at the elements.

    • @jfyllipy
      @jfyllipy Рік тому

      @@annakquinn7084 ooooops. You are completely right

  • @MedicMainDave
    @MedicMainDave Рік тому +9

    3:04 as a german I am very happy you wrote this, not because I really mind that much about how something is pronounced, cause I'd also say it the same way when speaking english, but rather because of the "Danke" you put there lol
    Danke mein Friend :)

  • @mrkosmos9421
    @mrkosmos9421 Рік тому +31

    This man started with engines and is going with PolyBridge...
    But the progress is incredible, can't wait to see what's next
    Anyway, the licensing options are endless, from engine sound simulation for EVs to games to anything else
    And the trebuchet just takes me back to old flash games about destroying medieval castles... ah, good times
    Makes me wonder if there is the possibility of making a puzzle sandbox game about creating your own engine under a certain budget/limitation for a certain purpose, like PolyBridge, KSP or Besiege to name a few
    You know what, maybe I'll make something like that

  • @HiImKyle
    @HiImKyle Рік тому +40

    Wow BeamNG is supporting you? The official BeamNG? That's pog. Would love to see the engine sim in BeamNG.

    • @auxencefromont1989
      @auxencefromont1989 Рік тому +16

      yes that's the real one

    • @MetroidChild
      @MetroidChild Рік тому +8

      Probably partially the reason they support it, since it sounds like Ange will be going to GDC alongside BeamNG.

    • @notarobotto
      @notarobotto Рік тому +4

      they're supporting a lot of people doing this kindof stuff, i'm happy seeing that they're supporting others and not suppressing competitors

    • @elfferich1212
      @elfferich1212 Рік тому +6

      Yes. Beam team really loves what ange is doing. I could actually could see them hiring him.

  • @perplxxd
    @perplxxd Рік тому +79

    this man is singlehandedly changing the history of racing videogames
    edit: just videogames in general tbh

    • @manitoba-op4jx
      @manitoba-op4jx Рік тому +3

      the next half life is gonna use this for the engine sounds in the vehicle section

    • @ChaoticNeutralMatt
      @ChaoticNeutralMatt Рік тому

      Writing history?

    • @enorazza
      @enorazza Рік тому

      Geoff Crammond.
      Robert Scawen.
      May be it is time for a new one ;)

  • @hi_its_jerry
    @hi_its_jerry Рік тому +25

    engine sim + beamng confirmed??? im drooling at the thought

    • @YannickBo
      @YannickBo Рік тому +7

      And now we can even play Poly Bridge in Engine Sim :P

  • @dsagman
    @dsagman Рік тому +174

    have you considered simplex for solving? it can work very well on sparse matrices and there are available libraries

    • @AngeTheGreat
      @AngeTheGreat  Рік тому +163

      I've heard of it but when I looked into it in the past I couldn't wrap my head around it lol. Maybe now I could actually understand it given the knowledge I've accumulated

    • @windowsxseven
      @windowsxseven Рік тому

      @@AngeTheGreat holy fuck... you couldn't understand simplex?

    • @AngeTheGreat
      @AngeTheGreat  Рік тому +7

      @@windowsxseven Uh maybe? I never said I was smart lol

    • @windowsxseven
      @windowsxseven Рік тому +4

      @@AngeTheGreat got DAMN

    • @ffff-od3jb
      @ffff-od3jb Рік тому +1

      @@AngeTheGreat 🤓

  • @Propulus
    @Propulus Рік тому +10

    Playing BeamNG while watching the last couple of videos and seeing them support you and show interest is just insane levels of hype. It's already my driving sim of choice, but if it get's even a fraction of your engine sound simulation too, it'd probably become THE driving sim for just driving. I love the work that team does, and it keeps getting better so all of this is fantastic news.

  • @zachogdahl210
    @zachogdahl210 Рік тому +211

    The integration discussion is interesting, Having the audio simulation working natively in unreal would be incredible.
    Excellent work as always

    • @AngeTheGreat
      @AngeTheGreat  Рік тому +65

      When I get the time I'll probably look into implementing something into Unreal, or I might find someone with more Unreal skills than I have to help lol

    • @orthodynamicstereonails
      @orthodynamicstereonails Рік тому +14

      i guess you could say it would be... unreal

    • @Avetho
      @Avetho Рік тому

      @@orthodynamicstereonails Darn you beat me to it!

    • @EPICGameGuy493
      @EPICGameGuy493 Рік тому +7

      I've been working on integrating Engine Simulator inside of unreal, and I uploaded a video on my account demonstrating it. Everything works natively but the audio is unfiltered, and I'm working on getting it working with Metasounds rn

    • @MihaiZavoian
      @MihaiZavoian Рік тому

      someone also integrated it into assetto

  • @scrambledmandible
    @scrambledmandible Рік тому

    Thank you Beamng for chipping in, you're really cool for that!

  • @finneggers6612
    @finneggers6612 Рік тому +3

    I have written my own FEM simulation software for 3d problems and I figured out that iterative methods for solving sparse systems at low degrees of freedom (anything below 500k) is actually way way slower than direct methods. I recommend direct methods. Since your problem is probably symmetric positive definite, this should be simple.

    • @AngeTheGreat
      @AngeTheGreat  Рік тому +2

      Thanks for the suggestion. Do you know of any papers/sources about these methods?

    • @finneggers6612
      @finneggers6612 Рік тому +1

      @@AngeTheGreat Yes sure. I think the list of solution strategies is almost infinite here. I also thought abou tthis once more. So.
      Using direct solvers is 100% faster for your problems here. We are talking about magnitudes. For 1000 DOF the direct methods are magnitudes faster (maybe a factor 100-1000).
      Now when using iterative methods like CG, you never ever want to use plain CG. CG converges faster the better the condition number of your problem is. The condition number is basically a scalar describing how difficult it is to numerically solve your problem. for linear symmetric positive definite systems it is k = max(lambda) / min(lambda) (IIRC). Multiple things. The higher k, the longer CG will take to converge. I am 90% sure your k value is absurdly high. One method if you want to stick with indirect methods is using preconditioning. Sadly preconditioning is hard to implement yourself. (technically preconditioning is a direct solver which you just stop in the middle). A common preconditioner here is the incomplete cholesky (again, hard to implement yourself).
      When using direct methods for these type of problems, the probably best way is doing a simple LDL* decomposition. Understanding the decomposition is easy. Implementing it is stupidly hard. I have tried some of these and it gets incredibly complex for sparse matrices.
      There are a few things to consider here:
      A) what sparse matrix format you use, CSR may not be the best
      B) For C/C++ there are free libraries. At some point I was so annoying by implementing this myself, that I went with Eigen.
      I can give you a link where I used Eigen for:
      LDLT: github.com/Luecx/FFES/blob/main/src/solver/LDLT.cpp
      PCG: github.com/Luecx/FFES/blob/main/src/solver/CG.cpp
      Eigen: eigen.tuxfamily.org/index.php?title=Main_Page
      If you really want to write this yourself:
      condition number: en.wikipedia.org/wiki/Condition_number
      pcg: en.wikipedia.org/wiki/Conjugate_gradient_method (scroll down to pcg)
      positive definite: en.wikipedia.org/wiki/Definite_matrix
      I can give you more resources. Its easier to read on this on wikipedia initially.

  • @saar5947
    @saar5947 Рік тому +8

    You should do a collab with Sebastian Lague

  • @CharlesVanNoland
    @CharlesVanNoland Рік тому +4

    I've never been able to employ SIMD intrinsics in my code that performs better than what the compiler optimizations can do, especially when link-time optimizations and 'expensive optimizations' are enabled. GCC's auto-vectorization is legit, as long as pointer indirection and whatnot don't throw it off, which just means conforming code to the optimization 'templates' (that's how I think of them as) that it employs to determine when/where the vectorization should happen.

    • @AngeTheGreat
      @AngeTheGreat  Рік тому +6

      I can relate. I actually had a few hours of recordings showing how I did the SIMD optimization but I thought it would be too boring to watch for most people. After first adding SIMD, the code was actually 2x SLOWER. But by looking at the disassembly I was able to find the places where MSVC was not producing optimal SIMD code and guide the compiler by massaging the C++ code. Maybe GCC is better but I haven't really used it's auto-vectorization features much.

    • @empireempire3545
      @empireempire3545 Рік тому +1

      I also work with GCC. I had a case at work, my colleague has rewritten one piece using intrinsics and got something like 2-3 times improvement. The thing about intrinsics is, they will only help you if you optimized memory access in the first place - most of the people don't know what that means, much less do that. And memory access is much more potent optimization anyway.
      Whether the compiler will or will not employ intrinsics is very, very hard to predict.

  • @BI4ck_J
    @BI4ck_J Рік тому +5

    this is getting more and more exciting as time pass by!

  • @hcmcnae
    @hcmcnae Рік тому

    this is so sick. Found you today and I'm looking forward to seeing your progression!

  • @danielpalecek4090
    @danielpalecek4090 Рік тому +1

    shaking explosions or "kraken attack" are in every physics game on every physics setting, you won't avoid it

  • @erikziak1249
    @erikziak1249 Рік тому +2

    Thank you for this video and all your work.

  • @emirozturk3462
    @emirozturk3462 Рік тому +1

    Good job! As a side note, you might consider Newton-Raphson or Fast Decoupled methods to solve non-linear equations. For Newton-raphson, computation time won’t be increasing as much as Gauss-Seidel as the size of the matrix increases and it is very robust. However, Fast decoupled will be the fastest but It won’t be as robust. These options might help you.
    As an electrical engineer, we are using these methods to solve power flow equations on large systems.

  • @DrNabeel20
    @DrNabeel20 Рік тому

    This actually amazing! great video

  • @DasParedes
    @DasParedes Рік тому

    maaan, this is incredible, Thank you for showing us that!

  • @KanzakiZD
    @KanzakiZD Рік тому +41

    if your works will be included in beamng, that'll be extremely amazing 😳

  • @fazbeark1ng
    @fazbeark1ng Рік тому

    im really excited for the engine sim to be complete! it already awesome

  • @Gimble_Gamble
    @Gimble_Gamble Рік тому

    Your content is so cool! I am really inspired by you, keep up the good work!

  • @gedaliakoehler6992
    @gedaliakoehler6992 Рік тому +1

    Great video again! Fun stuff. One idea (could be interesting) is to save off some of your large sparse matrices and try different already implemented solvers on them in (with numpy or package you like) to play around with different techniques and their performance. Then once you know a technique is better for performance you can implement it.

  • @ZeldaACFan17
    @ZeldaACFan17 Рік тому +6

    For the damage thing, maybe have it as an option that can be enabled or disabled 🙂 Some people might not want the damage simulation, like someone who is just starting with Engine Sim, or a returning user who's been away for a while and wants to gradually come back in, so they can refresh their memory on how Engine Sim works 😉

    • @AngeTheGreat
      @AngeTheGreat  Рік тому +12

      Good idea! I imagined having something like "unbreakable mode" in PolyBridge.

    • @ZeldaACFan17
      @ZeldaACFan17 Рік тому +5

      @@AngeTheGreat Thanks 😉 But I've noticed something about BeamNG too... The way I like to play it is like a standard driving or racing sim, not like the crash simulator type videos that I see a lot of... I think BeamNG should have a reduced damage mode or something like a damage sensitivity slider, so for racing scenarios like I like to do, the damage would be less sensitive globally, or even turned off entirely if I just want to drive for fun (I mostly play Beam for the driving physics portion, trying *not* to crash 😂)

    • @ZeldaACFan17
      @ZeldaACFan17 Рік тому +5

      Now don't get me wrong, I do like how realistic the crashes look in Beam. It's just that I don't only play it for the crashing itself. I play Beam for the driving aspect, and creating my own custom car configs to drive on my favorite maps, which are racing maps. Drag strips, offroad, or standard circuit style 🙂🏁🏎️

  • @slightlyinsaneraf
    @slightlyinsaneraf Рік тому +4

    So enjoyable to watch these videos

  • @Swaggie255
    @Swaggie255 Рік тому +5

    I love watching this series!

  • @Velkanis
    @Velkanis Рік тому +4

    with the readmap out im never leaving this dev log train again, something tells me this will be real fun! also grats on getting dragged along beamNG to gdc! do have yourself a great load of fun there fam!

  • @GuildOfCalamity
    @GuildOfCalamity Рік тому

    Awesome video and very educational!

  • @luukvanoijen7082
    @luukvanoijen7082 Рік тому +6

    Holy shit I cannot tell you how excited I am that BeamNG is supporting you. I really hope something incredible will come out of this partnership :D

  • @felipeferreira00
    @felipeferreira00 7 місяців тому +1

    @RealCivilEngineerGaming
    This, this is the future, and i love it.

  • @Radi0he4d1
    @Radi0he4d1 Рік тому

    Looking forward to the gdc talk!

  • @redship7532
    @redship7532 Рік тому

    this is crazy, very good job!

  • @amirsayfiddinov
    @amirsayfiddinov Рік тому +1

    Love the ending. "Watch me reinvent the wheal" 😂

  • @joancasals4365
    @joancasals4365 Рік тому

    Very interesting video, keep going!

  • @logtrimmer
    @logtrimmer Рік тому

    Your explanations go way over my head since I am not that familiar with coding, but I can understand the optimization thanks to the time it takes per iteration.

  • @heisenburgeronthetoilet
    @heisenburgeronthetoilet Рік тому +5

    this is really awesome that a big game developing team knows that you have a really good idea. I hope that the steam realese is not far away. Excellent work!!

  • @WoolieOG
    @WoolieOG Рік тому

    fascinating video, loved dive into algorithm and their flaws

  •  Рік тому +1

    As a mechanical engineer it's a joy to watch this video.
    I work with fluid simulations, where approximation methods are a must. The stability is an issue as well, but depending on what program you use for the simulations it might be handled with an ever increasing relaxation factor. XD
    Keep up the awesome work!

  • @jakubpollak2067
    @jakubpollak2067 Рік тому +6

    I hope you will make next gen Algodoo simulator with sounds
    I'll would definitely pay for that!
    Seeing these truss constructions reminds me of university :D

  • @user-ep4dr2tu2w
    @user-ep4dr2tu2w Рік тому +1

    impressive stuff. I should look into reinventing the wheel myself

  • @sjeses
    @sjeses 11 місяців тому

    Please keep reinventing the wheel, and take as much time as the process needs. It's fascinating!

  • @shahars3134
    @shahars3134 Рік тому +1

    Amazing video as always! Seriously engine simulator updates are one of my favorite things on the internet right now.
    I'm wondering about the implementation of the CG method. How much can it be optimized?

  • @charliemw333
    @charliemw333 Рік тому +1

    I'm sure you already know about this, but you may want to look into the numerical methods that are used for computer fluid dynamics simulations or finite element method simulations. Sparse matrices pop up all the time, and you may be able to use some of the info you find in ur game.

  • @hfitfxhfhfufgugugu6589
    @hfitfxhfhfufgugugu6589 Рік тому +1

    In Seidel (and many other german words like Sohn=son Sonne=sun Seide=silk Sieben=seven so=so Säge=saw Seife=soap.....) jus pronounce the s like a bee Zzzz (like in desining=deZzzzining, not like in signing) , we call it ein weiches s=a soft s. Ein Scharfes s=a sharp s would often, if not always be in st like in Stiefel=boot (the big shoe, not booting up your computer, that would be hochfahren as a verb). There is ß for a scharfes s as well. It is used to make sure it should be scharf eventhough, there is a vowel after it. In Was=What it is scharf btw. I think that is because it is at the end.
    PS: Sch=sh

  • @stinkytoby
    @stinkytoby Рік тому +2

    Hah
    When you mentioned the tension/compression right after stability, I immediately remembered how PolyBridge 2 had much more deterministic physics than its prequel

  • @_XoR_
    @_XoR_ Рік тому +6

    Have you considered using graph neural networks (GNNs) for solving the systems, there are many already proven SOTAs used for industrial grade FEMs. I myself might be interested in the topic.

    • @JustSayin24
      @JustSayin24 Рік тому

      Real-time video game and FEM solver are wildly different constraints

    • @_XoR_
      @_XoR_ Рік тому

      Yes and no, I don't see why you can't make the models inference time realtime in tandem with the scene updates

    • @JustSayin24
      @JustSayin24 Рік тому

      @@_XoR_ Admittedly I have never used GNNs before, but the engineering challenge of getting inference latency of a NN down to real-time seems significant. I suppose DLSS exists, so there's that. Do you have any interesting resources you could share on the topic?

    • @_XoR_
      @_XoR_ Рік тому

      UA-cam won't let me post links but look up Graph Network-based Simulators, PyG, DeepXDE (for non GNN PDE/ODE deeplearning approaches), unfortunately idk many C++ libs in this regard at least for GNNs. The challenge indeed will be the lower level aspect of gpu scheduling in cuda, not sure if triton could be used for a higher level solution.

  • @fasogoss
    @fasogoss Рік тому

    I get performance aware programming vibes here, Great work man!

  • @sebleaf8433
    @sebleaf8433 Рік тому

    Really cool. You could also experiment using gauss seidel as a preconditioner for your conjugate solver

  • @fiery_transition
    @fiery_transition Рік тому +7

    Honest question, would you normally use a math library (NOT game libraries/engines) which does the numerical and linear solving? EVEN when you are implementing things like this from scratch? It's more a question of, is it necessary to have complete control of the simulation, all the way to the numerical methods, or could a fast math library be used at the cost of it being blackboxed, and would that create issues further down wrt. mismatches in how the numerical methods behave?

    • @AngeTheGreat
      @AngeTheGreat  Рік тому +9

      As I said in this video, this is 100% about gaining knowledge and not necessarily about having complete control. I would barely even understand what a linear equation solver even is if I hadn't implemented one myself and having this knowledge would allow someone to use third party libraries more effectively since you'd actually understand it. Would I consider using one? If it was really a slam dunk performance-wise and I was under time pressure, possibly. But at the end of the day both of those things are not really true, I'd like to create entertaining and engaging content for people to watch and I personally enjoy the process of writing things from scratch and that's ultimately the most important thing to me

    • @fiery_transition
      @fiery_transition Рік тому +2

      @@AngeTheGreat I totally can get behind just doing it for learning, one of my great memories of learning was implementing numerical solving methods for integral equations. Sometimes the different numerical methods converge differently or lose precision at an earlier or later stage in the iteration count. I thought it might be hard to debug making your own physics engine, while at the same time, using a blackbox math library which might have all sorts of behavior which one does not know about, due to not having implemented it yourself, and then having problems when the solvers converge and behave differently, in the same program. So I was wondering if it even was realistic using another library, since it could create all sorts of weird issues, since the solver math might be different? But I totally get the educational/learning perspective, and do really enjoy your videoes!

  • @g.paudra8942
    @g.paudra8942 Рік тому +2

    You may get more real-time performance and lower computation cost using CUDA (GPU), there's a CUDA version of Gauss-Seidel method btw.

    • @AngeTheGreat
      @AngeTheGreat  Рік тому +3

      "Possibly" but there are costs to this as well and for smaller matrices the performance advantages may not be that significant. In any case, I'd need to test this to confirm whether there are any real benefits to using the GPU.

    • @empireempire3545
      @empireempire3545 Рік тому

      @@AngeTheGreat Be careful with the test. One of the biggest bottlenecks for GPU is transfer of data between RAM and VRAM. So, for small systems, CPU implementation may be better simply because of the latency of just shuttling the data to/from the GPU memory. But for bigger systems the raw computational power of the GPU may take over.

  • @tensevo
    @tensevo Рік тому

    Great, i cant fully appreciate what is going on but will look forward to seeing the final product and maybe integrating in other sims.

  • @iancunnyngham7120
    @iancunnyngham7120 Рік тому +1

    You know you want to just go ahead and build a complete racing simulator :D Get all the important physics extremely accurate, make it super mod-able, don't worry about it being pretty. Bonus for me and my few dozen closest friends: make it able to run just the physics as fast as possible headless so we can trail reinforcement learning drivers!!

  • @ulyssesmoura4890
    @ulyssesmoura4890 Рік тому

    My final course work in civil engineer i did a python program for construct a matrix like this one using cholesky decomposition to solve the equations. It's so cool watch this and remember my college years. Hello from Brazil

  • @bbqgiraffe3766
    @bbqgiraffe3766 Рік тому +3

    As a reinvent the wheel guy myself I totally understand, although my physics engines are usually way more janky

  • @danielmachado4389
    @danielmachado4389 Рік тому

    Not sure if could be of help, but for that stiffness of the transmission you could use the value of a beam like element in tortion:
    k=G*pi(R^4-r^4)/2/L where G id the shear modulus of the material (steel or whatever), R is the outer radius of the shaft, r is the inner radius of a hollowed shaft (typically r=0) and L is the shaft length

  • @houseisforthesoul
    @houseisforthesoul Рік тому

    oh my lord - this is a fantastic project

  • @davidvargas7651
    @davidvargas7651 Рік тому

    You should check out algebraic multigrid (AMG) for solving the linear system. I think it could work well for your systems, and it is super fast. You can also use AMG as a precondioner for CG and it can greatly reduce the number of iterations required.

  • @codesymphony
    @codesymphony Рік тому

    nice. keep me updated

  • @vuvu7005
    @vuvu7005 Рік тому

    insanly cool video !

  • @ardaokay6862
    @ardaokay6862 Рік тому

    At least you said Danke at the end... I'll allow it 👍🏻
    You are great

  • @raztaz826
    @raztaz826 Рік тому +4

    You could also try the XPBD method which is on the 10 Minute Physics channel

    • @MetroidChild
      @MetroidChild Рік тому +1

      It's actually fairly similar, both uses conjugate gradients (edit: you don't need to, but most implementations do). The main difference is that XPBD can produce a vastly more stable result for low iteration counts and stiffness coefficients (but costs the same as increasing iterations).
      For problems which can be simplified to pure rigid bodies such as simulating the engine itself it doesn't make that much of a difference, except perhaps valve springs if they are not programed as their own special entities.

  • @aSpyIntheHaus
    @aSpyIntheHaus Місяць тому

    Oh i love this idea!

  • @amukh1_dev274
    @amukh1_dev274 Рік тому

    I used to watch your videos in the past, and I never really understood the physics or math, but today I clicked on this video and was met with a pleasant surprise.

  • @Teflora
    @Teflora Рік тому +1

    idk how reasonable it is, but having a VST of this in the future would be awesome! Good work!

  • @louispender9347
    @louispender9347 Рік тому

    The method I cover in my degree is to remove parts of the structure (constraints or beams) until the structure can solved trivially. Then finding the orthogonal states of self stress representing unit forces in the locations where beams/constraints were removed. Virtual work is used to impose geometric constraints and solve for the self stress coefficients. This method, as far as I know, only works for static structures but may be worth looking at.

  • @microcolonel
    @microcolonel Рік тому

    It's kinda fun that popular games and toys are now based on nonlinear finite element analysis.

  • @nikbivation
    @nikbivation Рік тому

    golden content!!

  • @MikeM8891
    @MikeM8891 Рік тому +2

    Did you consider Jacobi method for solving the matrix. It is not as computational efficient as Guass-Seidel but is very parallel and could be implemented on the GPU. A bespoke spare matrix data structure might help skip the massive amount of zero entries.

    • @AngeTheGreat
      @AngeTheGreat  Рік тому +7

      I tried it and found that it was pretty unstable and definitely wouldn't be able to compete with the conjugate gradient method anyway. It's unfortunate though because if it wasn't for its poor convergence/stability properties, it would have been much easier to parallelize than the Gauss-Seidel method.

  • @PBOZAI
    @PBOZAI Рік тому

    For linkages that are supposed to be perfectly rigid, you could use maximum cliques to group “trussed”/“triangluated” sturctures and treat them as a single object within the simulation.

  • @rwilson4073
    @rwilson4073 Рік тому +1

    Babe wake up, new engine sim vid just dropped

  • @CubeAtlantic
    @CubeAtlantic Рік тому

    This looks kind of detailed but it's still alive & with optimized physics/engineering i like this honestly.

  • @pavelperina7629
    @pavelperina7629 Рік тому

    Quite interesting. I would likely use Eigen library for this, but it's always good to know there are other methods and when they are more useful than first one that comes into mind (despite both are in Eigen).
    Sometimes experimenting and deeply understanding the problem is better than using any library. Sometimes it's arguable, cause spending extra four months on problem that's already solved costs a lot - more than double of your income.

  • @sterlingmakara
    @sterlingmakara Рік тому

    I just had an idea while in the bathroom. A slider that can change the spark timing. You can slide it to the left to delay the timing a bit and slide it right to advance the timing. This will especially play a big role in how a diesel engine sounds when you get around to that. Would be neat to see.

  • @shanegonzales
    @shanegonzales Рік тому

    this reminds me of that bridge builder cellphone game. so much fun.

  • @sebastianojeda5283
    @sebastianojeda5283 Рік тому

    bro this is the best channel ever, love this, keep the good work, somehow you are doing God's job

  • @Alexander_Sannikov
    @Alexander_Sannikov Рік тому +2

    in my experience the converge that you gain from conjugated gradients applied to linearized system of your constraints should be less than convergence (and stability) of nonlinear gauss seidel.
    in your examples nonlinear gauss seidel with a simple verlet integrator should be unconditionally stable and should converge in microseconds, not milliseconds.
    i suggest trying nonlinear gauss seidel, that amounts to simply solving each individual distance constraint multiple times: there's no matrix to be stored, no fancy maths involved, it's so simple that getting anything to converge better is extremely hard.

    • @AngeTheGreat
      @AngeTheGreat  Рік тому +1

      Do you know any good papers/sources about this? I find that getting decent information on this is the most challenging part for me

    • @Alexander_Sannikov
      @Alexander_Sannikov Рік тому +2

      @@AngeTheGreat in literature this approach is simply callex position-based dynamics. you literally just satisfy constraints in random order independently from each other. just push particles of each constraint to their resting position closest to the current configuration. it's the dumbest thing you can do and it works annoyingly well when coupled with verlet integrator. unconditionally stable for rigid link constraints.
      the reason why it works is because it's a projection-based relaxation scheme. the reason why it works better than anything linear is because each constraint keeps its nonlinearity during the entire solving process: contrast this to conjugated gradients where you have to linearize constraints in the beginning of a time step and then crucially assume that constraints don't rotate during the entire time step.
      the test case where everything linearized will fail (including analytical solution) is just a rigid rope with a 100 links sustaining a heavy weight: it will develop zigzag-shaped instabilities regardless of your solver, as long as you linearize your system.

    • @AngeTheGreat
      @AngeTheGreat  Рік тому +1

      @@Alexander_Sannikov hmm I've implemented a system like that in the past and I didn't find that it worked very well for precise machines, maybe I missed something

    • @Alexander_Sannikov
      @Alexander_Sannikov Рік тому +1

      @@AngeTheGreat systems like in this video should be trivial for it, however, there can be some dampening. i'm not sure how important energy conservation in your case is, but often in game physics some amount of dampening is desirable.

    • @AngeTheGreat
      @AngeTheGreat  Рік тому +1

      @@Alexander_Sannikov For my use-case, dampening and energy-loss in general is extremely undesirable. I might play around with position-based dynamics again but based on experiments I've done in the past, I don't think it would be the best option when simulating engines since I need very precise object positions and velocities even at high engine speeds

  • @Doct
    @Doct Рік тому

    4 days after this video released I started a Numerical Analysis class here at uni. I (thought) I had no idea what it was but then they mentioned the Gauss-Seidel method, and I was like oooooooooooooooh so that's what this is about lol

  • @t4g2s
    @t4g2s Рік тому

    I would love to hear about how do you construct given matrix that we are solving!

  • @flankana
    @flankana Рік тому

    1:42 seeing this in Richard burns rally would be interesting

  • @user-fm7uq4fb3f
    @user-fm7uq4fb3f Рік тому

    Lol the matrix at 5:50 looks like a huge game of life board

  • @raptorjeezus2607
    @raptorjeezus2607 Рік тому +1

    man its like you read my comment on compute intensity for a beamng implementation. Great work!

  • @Eidachsans
    @Eidachsans Рік тому

    If you are interested in improving efficiency you may want to look into recursive methods for evaluating the equations of motion. These algorithms create a graph based on the structure of the joints and bodies and evaluate all relevant terms in a very efficient manner recursively. This scales as O(n) instead of O(n^3) where n is the number of motion bodies. You may look into the code from the library simbody. There also have a great theory manual describing all the relevant math. Be warned, the recursive approach is quite a bit more involved.
    Also consider using a different time stepping algorithm. An explicit method like the RK4 typically requires very small timesteps to achieve good stability. Implicit methods or even mutltistep methods like BDF or some PECE methods are more common in the field.
    Are you using contraint stabilization technique like Baumgarte or projection methods? Since you only satisfy the contraints on a acceleration level there will be some drift for velocities and positions which can accumulate if the simulation runs longer.
    Otherwise I am very impressed with your project, keep up the good work!

  • @chrismofer
    @chrismofer Рік тому

    there may be plenty of times in simulating the physics of an engine where a simple look up table or curve fitting function is as good as a more complex calculation but saves runtime

  • @MrHaggyy
    @MrHaggyy Рік тому +1

    CPU's are cool but if you want really fast calculations with matricies you want to use the GPU for calculation as well. Also you can (LU or QR) factor your matrix into two smaller once. Helps with the O(n^3) as well as storing and moving the matrix around in memory.

  • @kshysztof9649
    @kshysztof9649 Рік тому +3

    If you are going to realease an actual game, in 3D, with car models and stuff, will you still make like a "base" program, that looks like the prototype ? I honestly like it a lot, and many people propably do as well

    • @AngeTheGreat
      @AngeTheGreat  Рік тому +5

      Haha that IS what I'm working on. The car game I showed in my last video was just for fun, the final game might include a mini-game like that just to try out engines

  • @somelaser5906
    @somelaser5906 Рік тому

    Ange, I love your videos... but, I'll be damned if I understood anything in this video besides Poly Bridge hahahaha. For real though I really enjoy a lot of in depth commentary videos regarding physics and coding so this hits the spot real good. Keep it up 👍

  • @sxkwa
    @sxkwa Рік тому

    wow, very impressive!

  • @johannesssssssss
    @johannesssssssss Рік тому

    First time seeing a dev optimizing before release 😳

  • @appalling22
    @appalling22 Рік тому

    Awesome video! Have you looked into Verlet (really 'Velocity Verlet') integration? It's not always going to be applicable as it gradually loses energy, but it's brain-dead simple to implement and extremely fast.

  • @Larslegos
    @Larslegos Рік тому

    I'm loving what I see