Solving 2D Diffusion Equation using MATLAB | Lecture 7 | ICFDM

Поділитися
Вставка
  • Опубліковано 18 вер 2024
  • Now, we are writing a 2D code using MATLAB to solve the diffusion equation. Please write in the comments if you have any question.
    #CFD #MATLAB #FluidDynamics #FluidMechanics #MechanicalEngineering #CFDusingMATLAB #NavierStokes #Finitedifferencemethod #Finitevolumemethod
    Suggested readings:
    1) Numerical Heat Transfer and Fluid Flow: Excellent book to get a hang of CFD/HT through finite volume methodology.
    amzn.to/3mEYuSz
    PS: The author invented SIMPLE method :)
    2) An Introduction to Computational Fluid Dynamics: The Finite Volume Method: My goto book for advanced understanding of CFD concept and their applications.
    amzn.to/3ehkQH4
    PS: Excellent discussion on turbulence!
    3) Computational Fluid Dynamics: An Introduction: Nail the finite differences with this book; my first-ever CFD book and that's what I recommend to anyone else as their first CFD read!
    amzn.to/37ZHD9e
    4) Fluid Mechanics: Revise your fundamentals through this excellently written book by Prof. White.
    amzn.to/320BuFT
    PS: It's not so fundamental, you'll also gain advanced understanding.
    5) MATLAB: An Introduction with Applications: Handy guide to learn MATLAB effortlessly, can't recommend it enough:
    amzn.to/3oGIrFM
    The script is as follows:
    _________________________________________________________________________________________
    clear all
    close all
    clc
    %% Defining the mesh
    n_points = 51;
    dom_size = 1;
    h = dom_size/(n_points - 1);
    %% Initialising the problem
    y(n_points, n_points) = 0;
    y(1,:) = 1;
    y_new(n_points, n_points) = 0;
    y_new(1,:) = 1;
    error_mag = 1;
    error_req = 1e-6;
    iterations = 0;
    %% Calculations
    while error_mag (USE THE LARGER THAN SIGN HERE) error_req
    for i = 2:(n_points-1)
    for j = 2:(n_points-1)
    y_new(i,j) = 0.25.*(y_new(i-1,j) + y(i+1,j) + y_new(i,j-1) + y(i,j+1));
    iterations = iterations + 1;
    end
    end
    % Calculation of error magnitude
    error_mag = 0;
    for i = 2:(n_points-1)
    for j = 2:(n_points-1)
    error_mag = error_mag + abs(y(i,j) - y_new(i,j));
    end
    end
    % Assigning new to be old
    y = y_new;
    end
    %% Plotting
    x_dom = ((1:n_points)-1).*h;
    y_dom = 1-((1:n_points)-1).*h;
    [X,Y] = meshgrid(x_dom,y_dom);
    contourf(X,Y,y, 12)
    colorbar

КОМЕНТАРІ • 79

  • @sumeyyetezcan9459
    @sumeyyetezcan9459 4 місяці тому

    Hi Tanmay, thank you for providing beginner friendly tutorials. It’s much understandable by this way. I can’t thank you enough. I’m grateful to find your channel!

  • @FabricioRWitt
    @FabricioRWitt 3 роки тому +1

    Very good video Mr. Agrawal, example of Bharat teacher being exceptionally excellent as always! Namaskar from southern Brazil!
    #FreeTNTemples

  • @ichigoduzumaki3150
    @ichigoduzumaki3150 4 роки тому +1

    Great vedio really helpful to understand the practical application of all these equation as I am currently studying CFD in my engineering

  • @traavel_bug
    @traavel_bug 3 роки тому

    beautifully explained the application for 2d diffusion.

  • @sathishahm6880
    @sathishahm6880 3 роки тому +2

    Hi Tanmay I learning many concepts related to CFD from your video... In this you did not explain the Boundary conditions ... Can you please explain this problem with Boundary conditions..

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

    Thanks for uploading FDM , please do some lectures related to LBM using MATLAB.

  • @frankunderdown9677
    @frankunderdown9677 4 роки тому

    Hi Tanmay:
    Thank you for the video.
    My comment is a request: I have taken several CFD courses in the past. The problem domains were very small (5 points in a line or a 2D grid of 25 points, etc.). This was good to teach the basic concepts of CFD coding. However, I would like you to include in your course some videos on how to code a real problem, where the grid could have a couple of million cells. Obviously, we are not going to write in a couple of million boundary conditions my hand.
    To work on a industrial size problem, our options are: 1) Buy a commercial software package (expensive) or 2) code in OpenFoam, which is not user friendly.
    Note: Currently, I am learning how to use open foam. But, I would would like a 3rd option, writing my own codes in Matlab (Octave/Scilab). So my requests are:
    1) Please include a discussion on using meshing software (i.e. Gmesh, etc.) and how to deal with boundary conditions of a car, a plane, fan, etc. Some recommendations on meshing software would be helpful.
    2) Also, if we model a fan, pump or turbine, (anything with rotational velocity) then we have to deal with rotating boundary conditions. So, I would like you to include a discussion on how to approach these problems.
    In the end, because of time, I might have to buy or use a commercial CFD package. Or painstakingly learn how to run OpenFoam. However, I would like the 3rd option of writing my own codes.
    Note: When I was a grad, student I took a year of computational physics and I wrote my own codes in Matlab or other languages. But the problem domains were small. Now, I need to learn how to deal with large problem domains, complex geometries and difficult/many boundary conditions, etc.
    Thank you in advance for your help with my request.
    Cheers!
    Frank

    • @TanmayAgrawal7
      @TanmayAgrawal7  4 роки тому

      Hi Frank,
      Thanks for this detailed feedback. The kind of problems you mentioned are indeed quite challenging (and are considered "complex" problems from a CFD perspective). Although not in this series, but in my parallel work on Fluent, I'll try to address some aspects of it.
      Since this course is an introductory part to both CFD and MATLAB, the rotational aspects are going to be hard to tackle.
      ANSYS Fluent offers a student version for free that you can use for upto half a million elements (if I can remember correctly). OpenFOAM has a good community though on the other hand. Personally, I haven't used it much.

    • @frankunderdown9677
      @frankunderdown9677 4 роки тому

      @@TanmayAgrawal7
      Thank you for your reply.
      I guess I only have two choices:
      1) I will continue learning OpenFoam but
      2) I have already started investigating commercial solvers.
      Cheers!
      Frank

  • @eslamahmed7022
    @eslamahmed7022 3 роки тому +1

    Great videos
    Great great greaaaaaaaaaaat effort
    I've learnt alot from you
    and I hope that one day I could make a video using matlab solving 2-D wave equation and I would dedicate it to you of course
    No words can describe my gratitude ♥

    • @TanmayAgrawal7
      @TanmayAgrawal7  2 роки тому

      I can see that it's not very far when you'll create that. Let me know if you need any help :)

  • @KundanKumar-tf6lu
    @KundanKumar-tf6lu 4 роки тому

    sir, I found this series much helpful for me. I will wait for your next lecture

    • @jesusmonteiro5394
      @jesusmonteiro5394 3 роки тому

      Hi Tanmay. I’ m solving a 1D transient diffusion convection problem with implicit Scheme. I’m having a problem to find the result as it is on the book. I’m using Gaussian elemination. I solved the same problem with explicit scheme and the result is ok. But I have problem with the implicit scheme. Help me please.

  • @ruchitapatel8369
    @ruchitapatel8369 3 роки тому

    Tanmay, thank you so much for making such nice videos explaining various concepts. I am sure your videos will be very useful for beginners to advance level. Please make some videos describing the Multigrid method as well.

    • @TanmayAgrawal7
      @TanmayAgrawal7  3 роки тому +1

      That's in the plan, but not sure when they would be recorded. If you need help, you can drop me an email.

    • @ruchitapatel8369
      @ruchitapatel8369 3 роки тому

      ​@@TanmayAgrawal7 thanks for the response. Will contact you soon.

  • @nawesqamar1574
    @nawesqamar1574 3 роки тому +1

    thanks a lot brother for such interesting videos. Can you suggest from where I can practice more coding problems related to cfd?

  • @pfernandezsan
    @pfernandezsan 3 роки тому

    Hi Tanmay,
    Many thanks for the videos, they are really helpful.
    The plot figure I get is inverted in the y-direction. I have inverted it with the auxiliary y_dom1, but I don't know if it is possible to create it directly in the right way.
    x_dom=((1:n_points)-1)*h;
    y_dom=((1:n_points)-1)*h;
    y_dom1=dom_size-y_dom;
    [X,Y]=meshgrid(x_dom,y_dom);
    [X_1,Y_1]=meshgrid(x_dom,y_dom1);
    f1=figure;
    contourf(X,Y,y,12);
    colorbar;
    f2=figure;
    contourf(X_1,Y_1,y,12);
    colorbar;
    I am using the online version, I don't know if the syntax is different.

    • @TanmayAgrawal7
      @TanmayAgrawal7  3 роки тому

      It might be different, I'm not sure. I haven't used the online version so far. Your code looks alright. See if you can get the offline version perhaps?

  • @abhigyanmajumdar9552
    @abhigyanmajumdar9552 3 роки тому +1

    Firstly, thank you so much for such great videos! I had one doubt in the plotting section. While defining the "y_dom", we subtract the elements from 1. Is this done because matrices in matlab are indexed from top-left, while we want the origin to be at bottom-left?

    • @TanmayAgrawal7
      @TanmayAgrawal7  3 роки тому +1

      Yes. If you don't subtract, you'll sort of see things upside down as compared to what you visualize in head. Silly MATLAB indexing!

  • @vijayalakshmit9987
    @vijayalakshmit9987 2 роки тому

    Thank you so much for this video.Can you explain how the same equation can be solved by Alternating direction implicit method in matlab?

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

    Hello, thank you so much for your helpful videos. It was a great explaining. I find them very useful ...
    I 'm just wondering if you have any lectures or videos that explain the 2D advection diffusion using finite difference. I will be very thankful if my comment has found any reply

    • @TanmayAgrawal7
      @TanmayAgrawal7  8 місяців тому +1

      I am not sure if that’s there on the channel yet. But I’ll upload later on in future. Thanks for watching my content.

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

      @TanmayAgrawal7 I'm very interested in your content. I wonder if i can i find anything for transient flow for Confined and unconfined aquifer and relation with solute transport???

  • @johnbohn3626
    @johnbohn3626 2 роки тому

    Sir can you please make video on total concentration method in cfd

  • @hardworkalwayspay178
    @hardworkalwayspay178 2 роки тому

    sir after putting the same code i am not getting the countours please help me to solve the issue ..error is showing i n xdomain

  • @RAJEEVRANJAN-cx4xv
    @RAJEEVRANJAN-cx4xv Рік тому

    why did you take err_mag =1 initially and then 0

  • @kailashchandrakar4958
    @kailashchandrakar4958 3 роки тому

    very interesting sir.

    • @TanmayAgrawal7
      @TanmayAgrawal7  3 роки тому

      Feel free to ask questions if you have in later videos.

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

    hello there, I ran the code, but the y-coordinate is appearing as 0,-0.2,....,-1 in the downward direction in the plot..???

  • @sourabhdas5062
    @sourabhdas5062 2 роки тому

    Under what conditions, the solution starts to resemble a 1D behavior?

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

    Boundary condition kya hai ?

  • @Rio-mark
    @Rio-mark 2 роки тому

    Hello, first of all, thank you so much for explaining everything in such a detailed and easy way..Actually, I am trying to solve 2D problem in polar coordinates for the evolution of concentration through a cylindrical tube..I used the finite vol method and arrived at set of ODE but I am struggling to write the code for it.. Is there any way I can contact you to get help?

  • @amianifineug1353
    @amianifineug1353 3 роки тому

    please I want to solve fick's equation to study dialyse phenomena ? could you help me
    thank you

  • @yinjun5937
    @yinjun5937 3 роки тому

    Hello, Tanmay . May I ask another question? you changed the y(i-1,j) and y(i,j-1) to y_new(i-1,j) and y_new(i,j-1). what is the numerical method you call?

    • @TanmayAgrawal7
      @TanmayAgrawal7  3 роки тому +2

      This is called Gauss Seidal method where we use the new values of y. If they were all old values, then we call it a Jacobi method.

    • @yinjun5937
      @yinjun5937 3 роки тому

      @@TanmayAgrawal7 thank you very much

  • @ankitadawar5970
    @ankitadawar5970 3 роки тому

    hi sir thnq so much your video are so helpful, can you please tell me how to do iteration on excel for same problem of cfd

  • @rahalabdelhak5370
    @rahalabdelhak5370 2 роки тому

    I didn't understand why you were talking about the time step although we are in steady case. As I know we talk about it only in unsteady case..

  • @azzagamal9243
    @azzagamal9243 2 роки тому

    can you make captions available please sir ?

  • @championsuccess1303
    @championsuccess1303 3 роки тому

    Thanks this is beautifully explained. Please I have solved a 2d unsteady cylindrical diffusion equation, can I ask for your kind assistance on using matlab to run the code. Am not getting the desired solutions. Thanks

    • @TanmayAgrawal7
      @TanmayAgrawal7  3 роки тому +1

      Please try to debug. Cylindrical systems are a little more painful

  • @SHUBHAM-xn5cx
    @SHUBHAM-xn5cx 4 роки тому

    Today I tried 1-d transient conduction and was not able to code it....I request you to take this example in next lecture 😄

    • @TanmayAgrawal7
      @TanmayAgrawal7  4 роки тому +1

      Indeed. The 2D transient problem is going to be covered in next lecture.

  • @hulk8889
    @hulk8889 2 роки тому

    Sir how I contact with you. Thank you very much

  • @yinjun5937
    @yinjun5937 3 роки тому

    hello, thanks for your help with this useful video, I have one qeustion, why you y_dom=1-((1:n_points)-1).*h; ? I mean why y should be be 1- ?

    • @TanmayAgrawal7
      @TanmayAgrawal7  3 роки тому

      Because in MATLAB, 0 is towards the top otherwise. If you don't do "1 - ..." Then you'll have 0 at the top and one at the bottom (which would be a little counter intuitive for Cartesian system)

  • @huihuichee4945
    @huihuichee4945 3 роки тому

    Hi Tanmay,
    thank you for the helpful videos
    may i know how can i code for amplification factor for 1D explicit and forward scheme?
    Would be great if you'd help.
    Thanks

    • @TanmayAgrawal7
      @TanmayAgrawal7  3 роки тому

      What do you mean by amplification factor? Do you mean over-relaxation?

    • @huihuichee4945
      @huihuichee4945 3 роки тому

      @@TanmayAgrawal7 hi Tanmay, thanks for your reply, the amplification factor is for Von Neumann stability to check bounds for stability, do you happen to have worked on it before?

  • @sathishahm6880
    @sathishahm6880 3 роки тому

    Hi Tanmay... in your code you had given boundary condition for the first row, you have not defined all the boundary conditions (Left wall, Right wall, Top wall). Please check and verify

    • @TanmayAgrawal7
      @TanmayAgrawal7  3 роки тому

      Hi! Since they remain the same as their initial values, therefore it is not needed to re-code their values. Also for the same reason, in the FOR loop, we do not change the corresponding rows and columns.

  • @bhawnasingh6353
    @bhawnasingh6353 3 роки тому

    Sir how to control the number of iterations to be performed?

  • @VARUNPANDEYBEM
    @VARUNPANDEYBEM 4 роки тому

    why are we making the top row as 1 only and other as zero?

    • @TanmayAgrawal7
      @TanmayAgrawal7  4 роки тому

      Boundary conditions. Top row is 1 and everything else is 0.

    • @VARUNPANDEYBEM
      @VARUNPANDEYBEM 4 роки тому

      @@TanmayAgrawal7 ok thanks a lot?

  • @kandarpshah8951
    @kandarpshah8951 4 роки тому

    how do we plot at different time step

  • @LuisMartins-fb2jg
    @LuisMartins-fb2jg 3 роки тому

    Joinha

  • @jesusmonteiro5394
    @jesusmonteiro5394 3 роки тому

    Hi Tanmay. I’ m solving a 1D transient diffusion convection problem with implicit Scheme. I’m having a problem to find the result as it is on the book. I’m using Gaussian elemination. I solved the same problem with explicit scheme and the result is ok. But I have problem with the implicit scheme. Help me please.
    Could send me your e-mail or something like that so I share with you my matlab script.

  • @idreeskhan1629
    @idreeskhan1629 3 роки тому

    sir i send you the 2D heat equation code please,

  • @SHUBHAM-xn5cx
    @SHUBHAM-xn5cx 4 роки тому

    Bhaiya plz provide the script file in description

    • @TanmayAgrawal7
      @TanmayAgrawal7  4 роки тому +1

      I've added it there. Replace (USE THE LARGER THAN SIGN HERE) with > and you're good to go.

    • @SHUBHAM-xn5cx
      @SHUBHAM-xn5cx 4 роки тому

      Thanks a lot !!!

  • @ALOKSRK1
    @ALOKSRK1 4 роки тому

    New look, it's like CFD problem is converging 😂😂😂😂😂 kidding..

    • @TanmayAgrawal7
      @TanmayAgrawal7  4 роки тому +1

      It's a converging diverging problem in that aspect 😀

  • @b.mallick5905
    @b.mallick5905 4 роки тому

    H A P P Y T E A C H E R S' DAY S I R