CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

How does numerical diffusion happen?

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 1 Post By FMDenaro
  • 1 Post By FMDenaro
  • 2 Post By sbaffini
  • 1 Post By arjun

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 25, 2022, 12:21
Default How does numerical diffusion happen?
  #1
Senior Member
 
Sayan Bhattacharjee
Join Date: Mar 2020
Posts: 495
Rep Power: 8
aerosayan is on a distinguished road
I was testing with calculating local dt to satisfy CFL condition for a 1d non-linear convection solver.



I used the formula dt = cfl*dx/un[i]

When CFL was 1.0, the wave didn't have have any numerical diffusion, but for CFL 0.9 the numerical diffusion started to occur.

Why? For CFL 0.9, the code should be more stable, right?


I still don't 100% understand: How does numerical diffusion happen?


Julia code:
Code:
using Plots;

n      = 1000; # no. of nodes in the domain
c      = +1.0; # linear velocity of the wave

xstart = +0.0;   # start of domain
xend   = +100.0; # end of domain

dt     = +99999999;             # timestep (*needs* to be computed later to satisfy cfl condition)
dx     = (xend-xstart)/(n-1.0); # spacestep
cfl    = 1.0;                   # courant-freidrichs-lewy condition

icstart = 25;  # initial condition start index
icend   = 100; # initial condition end index

x = collect(LinRange(xstart,xend,n)); # domain or mesh of n nodes
u = collect(LinRange(1.0,1.0,n));     # solution of the linear wave equation
u[icstart:icend] .= 2.0;              # set initial condition, a hat function
u0 = copy(u);                         # initial solution

for t in 1:2^8; # timestep iterations
    un = copy(u);
    for i in 2:n
        dt   = cfl*dx/un[i];
        u[i] = un[i] - un[i]*dt/dx*(un[i]-un[i-1]);
    end
end

display(plot(x,[u0,u]));
Attached Images
File Type: png clf-1.0.png (13.6 KB, 11 views)
File Type: png cfl-0.9.png (16.0 KB, 12 views)
aerosayan is offline   Reply With Quote

Old   August 25, 2022, 12:48
Default
  #2
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,855
Rep Power: 73
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Sorry but what about your background in CFD?

This is one of the fundamental topics in any CFD course! Just start considering the analysis in the physical space by adopting the modified differential equation technique. Have a look to the evaluated expression that multiplies the second derivative in space.
Then you can also see the same issu in the wavenumber space.


That has no need of any code to be seen. In your code I see that you compute a different dt value for different location i and that is wrong!
I also suggest to use the conservative form, not the quasi-linear form of the Burgers equation.
aerosayan likes this.
FMDenaro is offline   Reply With Quote

Old   August 25, 2022, 13:34
Default
  #3
Senior Member
 
Sayan Bhattacharjee
Join Date: Mar 2020
Posts: 495
Rep Power: 8
aerosayan is on a distinguished road
Thanks for your help! I'm self-taught, with some gaps in knowledge.
aerosayan is offline   Reply With Quote

Old   August 25, 2022, 13:41
Default
  #4
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,855
Rep Power: 73
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Quote:
Originally Posted by aerosayan View Post
Thanks for your help! I'm self-taught, with some gaps in knowledge.



Be careful, you need to learn carefully the basics...

Your code has the first order upwind with backward formula but you have to consider that the Burgers equation can have initial negative data and your code will not work.


PS: I strongly suggest to check what happen using a Heaviside initial condition. Compare the velocity of your shock wave with the theoretical value.
aerosayan likes this.
FMDenaro is offline   Reply With Quote

Old   August 25, 2022, 15:07
Default
  #5
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 2,191
Blog Entries: 29
Rep Power: 39
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
For the linear, pure convection case in 1D with uniform grid, first order upwind and first order explicit Euler (I don't know for other cases) it can be shown analytically that CFL = 1 leads to exactly 0 numerical error (diffusion included) because ALL the spurious terms in the MDE become 0.

Of course, if you think about it, it is as much obvious as useless in real cases. Yet, it tells you something important about numerical convection that lagrangian schemes explicitly try to leverage.
haydena and aerosayan like this.
sbaffini is offline   Reply With Quote

Old   August 25, 2022, 16:03
Default
  #6
Senior Member
 
Sayan Bhattacharjee
Join Date: Mar 2020
Posts: 495
Rep Power: 8
aerosayan is on a distinguished road
Quote:
Originally Posted by sbaffini View Post
For the linear, pure convection case in 1D with uniform grid, first order upwind and first order explicit Euler (I don't know for other cases) it can be shown analytically that CFL = 1 leads to exactly 0 numerical error (diffusion included) because ALL the spurious terms in the MDE become 0.

Didn't know that. Thanks!
aerosayan is offline   Reply With Quote

Old   August 25, 2022, 16:54
Default
  #7
Senior Member
 
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,285
Rep Power: 34
arjun will become famous soon enougharjun will become famous soon enough
if you can find this book

https://link.springer.com/book/10.10...-94-007-4038-9


There is a detailed discussion about what you have asked. What you asked is not a simple question.


A very very short and crude answer to your question is that at cfl of 0.9 the wave moves somewhere in between the cells and now the face values are not well constructed (for any reason, mostly it is limiting that would do this). Thus you end up with all sorts of issues, this diffusion is one of them.
aerosayan likes this.
arjun is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[ANSYS Meshing] MultiZone/multiblock near-wall numerical diffusion mlazim14 ANSYS Meshing & Geometry 0 April 19, 2020 07:48
Numerical error at false diffusion case jpeter3 OpenFOAM Running, Solving & CFD 0 January 28, 2015 07:18
Reducing numerical diffusion in compressibleInterFoam kd55 OpenFOAM Verification & Validation 0 September 12, 2013 20:34
numerical diffusion & patch operation ronen FLUENT 4 April 10, 2011 18:44
How to estimate numerical diffusion ? Mukhopadhyay Main CFD Forum 3 June 19, 2001 10:35


All times are GMT -4. The time now is 10:11.