Solving The 1D & 2D Heat Equation Numerically in Python || FDM Simulation - Python Tutorial #4

Поделиться
HTML-код
  • Опубликовано: 1 авг 2024
  • In this video, you will learn how to solve the 1D & 2D Heat Equation with the finite difference method using Python.
    [🖥️] GitHub Link: github.com/Younes-Toumi
    [💼] LinkedIn Link: / younes-abdeldjalil-tou...
    [🐍] Check out my Python Simulation Playlist: • Simulation with Python
    Enjoy ~ 🐍
    Script found on my never used github : github.com/Younes-Toumi/Youtu...
    Outline of the video :
    0:00 - Introduction
    1:10 - Solving the 1D Heat Equation
    4:51 - Visualizing the solution
    6:29 - Solving the 2D Heat Equation
    10:27 - Surprise ?

Комментарии • 30

  • @nonato7853
    @nonato7853 7 месяцев назад +4

    Incrível, mano! Recentemente fiz um trabalho sobre a equação de calor e seu vídeo me deu uma nova perspectiva do que eu havia feito. Parabéns!

  • @v4dl45
    @v4dl45 8 месяцев назад

    Awesome tutorial! I recommend you use libraries like manim for 3d visualizations as well!

  • @charlesaugustosantosdocarm4121
    @charlesaugustosantosdocarm4121 Месяц назад

    Wonderful! Tank you!

  • @saamirjassim2108
    @saamirjassim2108 7 месяцев назад +4

    Stability of solution also accuracy comparing with another solutions .. Thanks alot .

    • @YounesLab
      @YounesLab  7 месяцев назад +1

      This might be the subject of the next video, Thank you for you suggestion!

  • @vikonja121
    @vikonja121 7 месяцев назад +12

    As straightforward as this solution is, I believe it needs to be mentioned: this approach is extremely inefficient. It has time complexity O(N^2), which renders the method practically useless when applied to models/systems with a large number of cells (which ultimately is what one will have when doing serious work). A much more efficient code can be made by adjusting to use scipy's sparse module and solvers for sparce matrices.
    A good video nonetheless, if you want to get a preview of how the finite-difference method works ;) just mentioning a relevant computational aspect

    • @jawadmansoor2456
      @jawadmansoor2456 6 месяцев назад +4

      Using a pre built library/code will render a math video useless. I, like many others, have come here to learn math not a fancy python library.
      Good work younes!

    • @vikonja121
      @vikonja121 6 месяцев назад +1

      No need for the cheeky answer, I was just trying to mention the info for people who are more interested in the performance aspect and are maybe looking for such implementations. @@jawadmansoor2456

    • @ssrini2002
      @ssrini2002 5 месяцев назад

      Could you recommend a video that uses that library please?

    • @vikonja121
      @vikonja121 3 месяца назад +1

      @@ssrini2002 I couldn't find any videos actually, there are a couple of websites with code examples, just google "python diffusion sparse matrix" and you'll find them quickly.
      Although, seeing as there's no videos about this, I might make one myself :)

    • @YounesLab
      @YounesLab  3 месяца назад +1

      Thank you for your comment @vikinja121 and for the clarification

  • @omaramdyaze
    @omaramdyaze 8 месяцев назад +1

    keep going bro , we need more solving physics problem using python , I hope if you have a vid about heat diffusion resolution for rectangular section fins and temperature profiles and thanks in advance bro

    • @YounesLab
      @YounesLab  8 месяцев назад

      I will be sure to make these in the future, thank you for your feedback!

  • @EdwardHe-jr9vg
    @EdwardHe-jr9vg Месяц назад

    Hi! It's very awesome video and very straight forward! A quick question, do you know if there's any chance to speed up the process with cuda?

    • @YounesLab
      @YounesLab  26 дней назад

      Thank you for your feedback ^^
      Personally I am not that familiar with cuda (though this surely is motivating me to make a video about it 🤔) However there are several techniques you can use drastically improuve the speed (method I discoreved after making the video)
      * writing the main calculations as a function, then using numba's jit to optimize the computation (by chacing it, ...)
      * Important note: since the result of each iteration is more or less dependent on the one before, parallezing will most likely not work, however one trick you can use is to vectorize the code by, instead of writing it in form of a loop, you replace it by some sort of linear system of equations A*T = b, which will be way faster since it uses linear algebra to find the solution (using numpy)

  • @madly1nl0v3
    @madly1nl0v3 10 месяцев назад +1

    Thank you for this tutorial. Please show me how to plot 3D graph of Riemann Zeta function where we can see the pole at s = 1 + j0, and trivial as well as nontrivial zeroes; the vertical axis shows the magnitude of the output and the color codes the phase angle. Thank you very much beforehand.

    • @YounesLab
      @YounesLab  10 месяцев назад +1

      Thank you for your Comment. Very Interesting function and Idea, I will look forward into making it.

  • @RameezRaja-qc9fi
    @RameezRaja-qc9fi 8 месяцев назад

    Please make more videos of coding on heat transfer and fluid mechanics. Thank you very much!

  • @oskarmakala
    @oskarmakala 2 месяца назад

    Could anyone explain why is it necessary to use a copy of array u in the scheme equation? I know that it gives slightly different results if we just rewrite u array in each loop, thanks

    • @YounesLab
      @YounesLab  2 месяца назад

      Hello!
      We use a separate copy of the array `u` because it represents the temperature distribution at a specific time, `t`. When we discretize our equation in time and space, we get:
      u[t+1, i] = (dt * a / dx^2) * (u[t, i-1] - 2 * u[t, i] + u[t, i+1]) + u[t, i]
      In this equation, `u[t, ...]` represents the temperature distribution at time `t`. By updating `u` using a while loop, we ensure that the computation of the distribution at all nodes is accurate for time `t`.
      If we don't use a copy of `u`, we end up computing the solution at `t+1` using a mixture of data from both `t` and `t+1`. For example, without a copy, `u` is updated dynamically, and when computing each node [i], the left node [i-1] is used from time `t+1` while the right node [i+1] is still from time `t`. This leads to:
      u[t+1, i] = (dt * a / dx^2) * (u[t+1, i-1] - 2 * u[t, i] + u[t, i+1]) + u[t, i]
      This does not conform to the established numerical scheme.
      I hope this clarifies why it's necessary to use a copy of the array `u` in the scheme equation. Let me know if you have any other questions! :)

  • @johnkevinpadro7819
    @johnkevinpadro7819 6 месяцев назад

    What software do you use @Younes

    • @YounesLab
      @YounesLab  6 месяцев назад +1

      If you mean for making the simulation i only used Visual Studio Code (for python IDLE)

  • @feweir
    @feweir 29 дней назад

    where do you take all formulas, for example that for get dd_ux and dd_uy ^

    • @YounesLab
      @YounesLab  26 дней назад

      The formulas represent an approximation of derivative via a method called "the finite difference method" often called FDM, this method represent a simple but powerfull technique for solving differential equation related problems (especially flow/heat problems)
      If you want to learn more about it I suggest you to watch another video I made (part 1) ruclips.net/video/ZuxAZxguv-0/видео.html

  • @nick45be
    @nick45be 5 месяцев назад

    in line 52 (5:49) it says "IndentationError: unexpected indent" after having copied and pasted the code from your github

    • @YounesLab
      @YounesLab  5 месяцев назад

      If you are getting an "IndentationError: unexpected indent" this means there is a problem with the indentation (tabbing) of the line, make sure to delete the tabs and manually re do it.

  • @hakankosebas2085
    @hakankosebas2085 Месяц назад

    could you do code of "Tutorial: How to simulate the wave equation" video by Nils Berglung

    • @YounesLab
      @YounesLab  26 дней назад +1

      Great suggestion thank you ^^' ! I will plan on doing this video about the wave equation it will be an interessting subject (in a couple of weeks)

    • @hakankosebas2085
      @hakankosebas2085 26 дней назад

      @@YounesLab thanks

  • @KrishnaGupta-pn8ee
    @KrishnaGupta-pn8ee 8 месяцев назад +1

    Bro kindly make more videos in hindi