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

Implicit AD, where do I start?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 28, 2016, 13:43
Default Implicit AD, where do I start?
  #1
New Member
 
Join Date: Mar 2016
Posts: 4
Rep Power: 10
homh is on a distinguished road
Hi all,

Newbie here. I am trying to write an innocent implement of the advection diffusion in 2-d using implicit method.

I have some background on numerical methods for PDE (Leveque, Gochenback, ...) and have read some CFD (Chung, Pozrikidis). My impression is that Crank-Nicolson is the way to go.

Before I take the plunge, I would appreciate any hint, advise, experience.

Not to reinvent the wheel, I thought that I could find the relevant equations in matrix form for the C-N scheme, but fail to find these in the books that are available to me. Plenty in 1-D but not 2-D.

Many thanks in advance,
homh is offline   Reply With Quote

Old   March 28, 2016, 13:49
Default
  #2
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,768
Rep Power: 71
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Quote:
Originally Posted by homh View Post
Hi all,

Newbie here. I am trying to write an innocent implement of the advection diffusion in 2-d using implicit method.

I have some background on numerical methods for PDE (Leveque, Gochenback, ...) and have read some CFD (Chung, Pozrikidis). My impression is that Crank-Nicolson is the way to go.

Before I take the plunge, I would appreciate any hint, advise, experience.

Not to reinvent the wheel, I thought that I could find the relevant equations in matrix form for the C-N scheme, but fail to find these in the books that are available to me. Plenty in 1-D but not 2-D.

Many thanks in advance,

I suggest a prototypal of discretization useful since it is used for the momentum equation: CN for the diffusive terms and Adams-BAshforth for the convective term
FMDenaro is offline   Reply With Quote

Old   March 28, 2016, 15:34
Default
  #3
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,672
Rep Power: 65
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
It's actually not so straightforward, but I do recommend reinventing the wheel for this one (at least for a very simple case, with very innocent discretization schemes).

For diffusion problems, Crank-Nicolson becomes block tri-diagonal in 2D, requiring specialized matrix algorithms to solve (and to invert the coefficient matrix).

C-N is appropriate for diffusion problems, but not advection problems (where you need backward/upwind schemes for stability and accuracy). Even for diffusion problems, C-N isn't the end all be all scheme either. There are fractional multi-step methods and operator splitting methods that give the same order of accuracy that are much faster. One of the reasons for the slowness of C-N is the block tri-diagonal structure. Restoring the matrix structure to a purely tri/bi/diagonal system makes it much faster to solve.

Matrix equations for advection problems using an implicit scheme are more scarce because of the many many many possible ways the advective terms can be discretized.

Another problem is the setup is somewhat implementation specific.
LuckyTran is offline   Reply With Quote

Old   March 28, 2016, 16:26
Default
  #4
Senior Member
 
Michael Prinkey
Join Date: Mar 2009
Location: Pittsburgh PA
Posts: 363
Rep Power: 25
mprinkey will become famous soon enough
If you want to get up to speed quickly, I don't think you can do better than this tutorial.

http://lorenabarba.com/blog/cfd-pyth...navier-stokes/

It leverages numpy and matplotlib to get you visible results quickly. There is not a pure advection/diffusion equation example. But steps (v) and steps (vii) are 2D advection and 2D diffusion separately, and you can merge the two very easily to build explicit advection diffusion to get started. There is also a full example for Poisson and Laplace equations using the sparse linear equation solvers in numpy. You can follow those as a easy way to step forward to an explicit advection/implicit diffusion scheme. The code is very easy to understand and visualization is built in.

It may not lead you to production-level code, but it will get you up-to-speed on the algorithms faster than any other way I've seen.
mprinkey is offline   Reply With Quote

Old   March 29, 2016, 12:39
Default
  #5
New Member
 
Join Date: Mar 2016
Posts: 4
Rep Power: 10
homh is on a distinguished road
Hi Filippo,

Could you suggest some literature about the in/stability of the C-N/Adams-Bashforth methods for the convection equation. I seem to get the impression that C-N is inconditionally stable.

Thanks,

homh

Last edited by homh; March 29, 2016 at 12:40. Reason: Wrong attribution
homh is offline   Reply With Quote

Old   March 29, 2016, 12:44
Default
  #6
New Member
 
Join Date: Mar 2016
Posts: 4
Rep Power: 10
homh is on a distinguished road
Quote:
Originally Posted by mprinkey View Post
If you want to get up to speed quickly, I don't think you can do better than this tutorial.

http://lorenabarba.com/blog/cfd-pyth...navier-stokes/

It leverages numpy and matplotlib to get you visible results quickly. There is not a pure advection/diffusion equation example. But steps (v) and steps (vii) are 2D advection and 2D diffusion separately, and you can merge the two very easily to build explicit advection diffusion to get started. There is also a full example for Poisson and Laplace equations using the sparse linear equation solvers in numpy. You can follow those as a easy way to step forward to an explicit advection/implicit diffusion scheme. The code is very easy to understand and visualization is built in.

It may not lead you to production-level code, but it will get you up-to-speed on the algorithms faster than any other way I've seen.
Hi Micheal,

Thanks for the link. I did come across this site and did some coding based on the examples. It turned out well except for the instability of the explicit scheme.

Cheers,

homh
homh is offline   Reply With Quote

Old   March 29, 2016, 12:56
Default
  #7
Senior Member
 
Michael Prinkey
Join Date: Mar 2009
Location: Pittsburgh PA
Posts: 363
Rep Power: 25
mprinkey will become famous soon enough
Quote:
Originally Posted by homh View Post
Hi Micheal,

Thanks for the link. I did come across this site and did some coding based on the examples. It turned out well except for the instability of the explicit scheme.

Cheers,

homh
Explicit diffusion is generally a bad idea. The maximum timestep allowed scales as dx^2, which makes it get very small as you increase grid resolution. Crank Nicholson is well-documented in any Numerical PDE book or just wikipedia:

https://en.wikipedia.org/wiki/Crank%...icolson_method

You should be able to modify the python code from the Poisson example based on the discrete formula in the above link.

It will involve evaluating the diffusion operator "implicitly" by filling a sparse matrix in exactly the same way the Laplacian and Poisson examples do and then solving that linear system of equations for the new timestep solution. CN actually averages the diffusion operator applied to the old-time solution with the diffusion operator applied to the new-time solution and in doing so, makes linear diffusion 2nd-order accurate in time and unconditionally stable.

Just to give you an overview. The new-time laplacian operator is loaded into the sparse linear matrix (and in the Poisson case), the old-time laplacian operator and the old-time advection operator are evaluated with data already on hand and are inserted into the right-hand-side of the linear system (like the source terms in the Poisson example). Then solving the linear system gives you the new time solution.
mprinkey is offline   Reply With Quote

Old   March 29, 2016, 12:59
Default
  #8
New Member
 
Join Date: Mar 2016
Posts: 4
Rep Power: 10
homh is on a distinguished road
Quote:
Originally Posted by LuckyTran View Post
It's actually not so straightforward, but I do recommend reinventing the wheel for this one (at least for a very simple case, with very innocent discretization schemes).

For diffusion problems, Crank-Nicolson becomes block tri-diagonal in 2D, requiring specialized matrix algorithms to solve (and to invert the coefficient matrix).

C-N is appropriate for diffusion problems, but not advection problems (where you need backward/upwind schemes for stability and accuracy). Even for diffusion problems, C-N isn't the end all be all scheme either. There are fractional multi-step methods and operator splitting methods that give the same order of accuracy that are much faster. One of the reasons for the slowness of C-N is the block tri-diagonal structure. Restoring the matrix structure to a purely tri/bi/diagonal system makes it much faster to solve.

Matrix equations for advection problems using an implicit scheme are more scarce because of the many many many possible ways the advective terms can be discretized.

Another problem is the setup is somewhat implementation specific.
Hi Lucky,

Thanks for the tips. I did use Thomas tridiagonal algorithm for the C-N convection in 1-D. Do you have any reading suggestion for the operator splitting method? I found this (also semi Lagrangian) out in Spiegelman's "Myths and Methods in Modeling" but not as much detail as I wish.

Cheers,

homh
homh is offline   Reply With Quote

Old   March 29, 2016, 13:09
Default
  #9
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,768
Rep Power: 71
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Quote:
Originally Posted by homh View Post
Hi Filippo,

Could you suggest some literature about the in/stability of the C-N/Adams-Bashforth methods for the convection equation. I seem to get the impression that C-N is inconditionally stable.

Thanks,

homh

hello,
the structure of the CN scheme for the diffusion and AB for the convection is the basis of many codes for incompressible flows since 30-year ago (see http://www.ann.jussieu.fr/frey/paper...0equations.pdf).

Tha stability analysis for a 2D discretization can be done by means of the Von Neumann analysis, as in the doc attached.
Attached Files
File Type: doc abcn_stability.doc (88.0 KB, 2 views)
FMDenaro is offline   Reply With Quote

Old   March 29, 2016, 13:14
Default
  #10
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,768
Rep Power: 71
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Quote:
Originally Posted by homh View Post
Hi Lucky,

Thanks for the tips. I did use Thomas tridiagonal algorithm for the C-N convection in 1-D. Do you have any reading suggestion for the operator splitting method? I found this (also semi Lagrangian) out in Spiegelman's "Myths and Methods in Modeling" but not as much detail as I wish.

Cheers,

homh

using the second order discretization for diffusion, you get a five-entry diagonal matrix and a block Thomas-based algorithm can be used. However, since the matrix is well conditioned a simple iterative solver will rapidly converge. I suggest using the SOR since it has few sum/multiplication operations and it is very fast with thge correct forcing parameter.
FMDenaro is offline   Reply With Quote

Old   March 29, 2016, 15:03
Default
  #11
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,672
Rep Power: 65
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
Quote:
Originally Posted by homh View Post
Hi Lucky,

Thanks for the tips. I did use Thomas tridiagonal algorithm for the C-N convection in 1-D. Do you have any reading suggestion for the operator splitting method? I found this (also semi Lagrangian) out in Spiegelman's "Myths and Methods in Modeling" but not as much detail as I wish.

Cheers,

homh
The alternating direction implicit method is one such method that is a good example. Keep in mind though, that ADIM, still uses central differencing and is not good for advection dominated problems. But it is a good example, the intermediate steps in the ADIM can be solved with tridiagonal algorithm. Like C-N, it is unconditionally stable (for diffusion problems) and second order accurate.

https://en.wikipedia.org/wiki/Altern...mplicit_method

Operator splitting method is a very broad field and very vague, so I don't mean to generalize it. For example, discretizing your diffusion terms using central differencing and advection terms using upwind differencing is technically also an operator splitting technique. the ADIM method is an operator splitting technique that splits the same spatial discretization for the diffusion term separately in x and y directions which is very different than splitting different phenomena separately.
LuckyTran 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
TimeVaryingMappedFixedValue irishdave OpenFOAM Running, Solving & CFD 32 June 16, 2021 06:55
using chemkin JMDag2004 OpenFOAM Pre-Processing 2 March 8, 2016 22:38
Can anybody give a introduction of the term "point implicit" and 'line implicit' ? Tommy Chen Main CFD Forum 2 August 3, 2015 03:30
Sample not working correctly sihaqqi OpenFOAM Running, Solving & CFD 1 July 12, 2014 01:36
Lets start the public domain CFD-Project! Heinz Wilkening Main CFD Forum 3 March 11, 1999 22:55


All times are GMT -4. The time now is 20:56.