|
[Sponsors] |
How do CFD softwares calculate derivatives in unstructured grids? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
August 4, 2019, 06:25 |
How do CFD softwares calculate derivatives in unstructured grids?
|
#1 |
Senior Member
Join Date: Jan 2018
Posts: 121
Rep Power: 8 |
Suppose that we have the following unstructured grid:
I want to know that how do CFD softwares like ANSYS Fluent calculate the derivatives in this grid? Is this possible to write a universal code for it to calculate the values in any unstructured grid? |
|
August 4, 2019, 06:34 |
|
#2 |
Senior Member
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,291
Rep Power: 35 |
it is done in two passes:
First pass is to calculate the gradients by green gauss or least square method. In green guass here the face values are some sort of averages from cell center values (can be volume weighted or distance weighted, example in Wildkatze i use distance weighted). Then you limit these gradients and call them reconstruction gradients. Using these reconstruction gradients and using green gauss calculate the final gradients using second order interpolation to face centers. Thats all. |
|
August 4, 2019, 10:23 |
|
#3 |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,897
Rep Power: 73 |
There are many ways to do that, you cannot think that all codes use a unique technique.
For example, in a Finite Element way you can express analytically the derivatives everywhere by means of the shape functions of different degree. |
|
August 4, 2019, 17:36 |
|
#4 |
Senior Member
|
Yes, it is possible. To give you some perspective, I would say there are three general methods for cell centered, unstructured finite volumes:
1) Methods based on some form of Green-Gauss theorem. Fluent uses the simpler of these, but a lot of variants and possibilities exists. Still, it is actually inconsistent if used naively, without proper corrections, and woukd only work on uniform structured grids. 2) Methods based on writing down the Taylor series for the cell center and evaluating it in the neighbor cells. The resulting overdetermined system is solved in a least squares sense, giving the name to this class of methods. 3) Methods based on finding a certain interpolant for the solution in the neighborhood of a given cell center and then taking the analytical derivative of the interpolant. The shape functions mentioned by Filippo is one possible approach. But, say, one could use radial basis functions or any suitable interpolant. For Fluent specifically, you can look at its manual and the mentioned references. It basically does what Arjun suggested. |
|
August 4, 2019, 18:28 |
|
#5 | |
Senior Member
Join Date: Jan 2018
Posts: 121
Rep Power: 8 |
Quote:
Thank You! In the 2nd method, suppose that we want to calculate central 1st derivative at point (b,b'). The red dots are cell centers. How can we use Taylor series at three red points (cell centers) to calculate the derivative? How to decide to choose which neighbor cells for better accuracy? |
||
August 4, 2019, 18:40 |
|
#6 |
Senior Member
|
In the standard approach under the class of methods I numbered as 2, you would actually use also the cell on the bottom, for a total of three equations for the 2D gradient. That is, a full stencil of neighbors is used, and there is no direct link with the structured stencils. Still, in the standard approach the selected stencil seems naturally centered.
However, I am aware of some non mainstream approaches that use partial stencils. Some of these have as main target the selection of a stencil that resembles the structured central one. But I can't recall the references now. The general idea, however, is that, once you have a stencil, whose center is cell 0, you write for each cell i in the stencil (2D): f_i = f_0 + df/dx_0 * (x_i-x_0) + df/dy_0 * (y_i-y_0) which has the gradient components in cell 0 as unknowns. |
|
August 4, 2019, 19:37 |
|
#7 | |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,897
Rep Power: 73 |
Quote:
As Paolo wrote, you have to consider all the connecting nodes for the Taylor expansion method. Actually, from the figure you posted I would use the very simple linear shape functions built on the triangle having nodes a',c' and the lower node you did not considered in the figure. Then, f(x,y) = Ni*fi+Nj*fj+Nk*fk allow you to compute the derivatives. Note that this corresponds to a linear polynomial f(x,y) = a+b*x+c*y -> df/dx=b; df/dy=c. If you need higher accuracy, the polynomial requires at least six nodes. Other classical methods that are used on unstructured grid starts from the polynomial reconstruction of Barth: https://www.researchgate.net/publica...reconstruction and check this application https://www.google.com/url?sa=t&rct=...RrYTrKcZZjIPch |
||
August 4, 2019, 20:49 |
|
#8 |
Senior Member
Svetlana Tkachenko
Join Date: Oct 2013
Location: Australia, Sydney
Posts: 416
Rep Power: 15 |
I am just wondering why do you ask? Are you writing your own CFD code?
|
|
August 5, 2019, 06:18 |
|
#9 | |
Senior Member
Join Date: Jan 2018
Posts: 121
Rep Power: 8 |
Quote:
1- I'm using a Navier-Stokes solver without postprocessing features ,so in some cases I may need to calculate derivatives on these grids as in a special case, I had to calculate them in a non-uniform grid. 2- I don't like to use CFD softwares like Photoshop and etc. and don't know what is happening behind there. Last edited by Moreza7; August 6, 2019 at 16:35. |
||
August 5, 2019, 21:51 |
|
#10 | |
Member
Join Date: Apr 2012
Posts: 71
Rep Power: 14 |
Quote:
Any references on the third method ? It seems very interesting. Oh, I cannot resist to reference the work of Hiroaki Nishikawa. He has a very organized website and, from what I've been reading, computing derivatives on unstructured grids is one of his strongest research branches. |
||
August 6, 2019, 04:06 |
|
#11 |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,897
Rep Power: 73 |
The use of the shape functions can be found in any textbook about Finite Element Method
|
|
August 6, 2019, 06:50 |
|
#12 |
Senior Member
|
For what concerns the shape functions approach, as mentioned by Filippo, it is standard Finite Element Theory. Whenever the solution method implies basis functions it kind of is standard to obtain derivatives in this way.
For cell centered finite volumes on general unstructured grids, which have general polygons/polyhedra as possible cell shapes, it is not possible anymore to resort to the classical shape functions used in the Finite Element field. Radial Basis Functions (RBF) are the only, sufficiently accurate, scattered data interpolation method I am aware of that can handle such general case. RBF literature is abundant, especially in the last two decades, and there are a lot of applications of the method for partial differential equations. Yet, most of these concern finite differences, finite-element-like approaches or meshless-like ones. Thus, the concept of taking the derivative of a shape function, and a RBF one in particular, is kind of regular stuff. However, the very first traditional Finite Volume like use of RBF, to the best of my knowledge, is in this work: https://lra.le.ac.uk/handle/2381/4138 where the RBF is used as a base for the WENO reconstruction. I approached RBF for fun around 2010, because I saw some potential in using the Gaussian RBF as a basis for explicit filtering in LES on unstructured grids. Eventually, I couldn't develop the topic anymore because of a lack of time, but I was left with part of the job done, which included up to the 6th analytical derivative of some RBFs and verification tests on their accuracy, which showed good performances for gradient reconstruction (compared to other traditional approaches). Only recently (2018-2019), as part of an actual CFD job requiring accurate gradient reconstruction on severely distorted grids, I also implemented it in my actual code. Yet, I couldn't reproduce the same performances. Today I use Weighted Least Squares followed by a single iteration of a specific Green-Gauss method using face normal derivatives (computed according to Muppidi and Mahesh, JFM 2008) instead of face values, an idea based on the work of Perot on staggered grids and recently revamped in a JCP paper in 2018 (can't remember the specific reference). The problem with RBF was not as much in the accuracy (which however lacked with respect to the best in class methods at fixed, small, stencil size) as in the computational cost. Solving a RBF problem, in the end, requires solving a SVD problem. This cost was unacceptably large even for a one-shot pre-processing task. So I abandoned it definitely. In conclusion, the idea was clearly there, but taking the analytical derivative of a RBF to specifically use it for gradient reconstruction in a cell-centered FV unstructured framework was kind of novel... yet, I don't suggest it Nonetheless, I still use RBF and their derivative for other stuff. |
|
March 28, 2022, 20:32 |
|
#13 | |
Senior Member
Sayan Bhattacharjee
Join Date: Mar 2020
Posts: 495
Rep Power: 8 |
Quote:
I was looking to find out how to calculate a derivative using 2 layers of ghost cells in an unstructured grid. In structured grid it's easy since we can just look at the 2 neighbor cells in left,right,top,bottom direction. The stencil is simple because it's structured and we can form the derivatives based on either x and y direction... How would the stencil look for an unstructured grid ? ... for simplicity let's consider that only triangle cells are present. I don't understand how to do d/dx (property), d/dy (property), d2/dx2 (property) and d2/dy2 (property) for the unstructured grids. Do you have any reference paper or the book chapter where I can find this? EDIT : I see that arjun and you have already shared a lot of reference resource for this. I will study them. However I would appreciate if you have something that's very easy to understand, or at least explains the topic without using too much advanced maths. Thanks |
||
March 29, 2022, 02:22 |
|
#14 | |
Senior Member
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,291
Rep Power: 35 |
Creating the extended stencil is main challenge here specially in parallel. Second challenge is when you have polyhedral meshes then you are looking at like 300 to 400 neighbours and if you were to use all of them your solver will be very very slow.
The strategey in wildkatze is to limit maximum neighbours in such stencil to 30 or so in 3D and around 20 in 2D. (this means one CAN NOT get parallel consistent behaviour from solver in case of polyhedrals, but it little effect on overall accuracy). Once this stencil is there for third order we solve 9x9 matrix system. Some people just calculate the inverse and store it , in wildkatze i do not do it because 81 arrays is too much memory. I use LU factoriation with some trick to have storage upto around 9 arrays. In second order gradients one can just solve 3x3 matrix system and have first gradients. These gradients are not much affected by skew (since lot more neighbours are involved). Quote:
|
||
March 29, 2022, 07:07 |
|
#15 | |
Senior Member
|
Quote:
1) Green-Gauss based methods: they don't really have a stencil, but when you put them down you will notice that they are somehow implicit. To compute the gradient in a cell, you need the gradient to properly interpolate on the faces. So, what happens here is that you start with no gradient and make multiple iterations. Each of these iterations only explicitly involves the first layer of neighbor cells, but in practice each iterations calls in a new layer of cells. Note, however, that this method has been shown to still lack formal consistency for non orthogonal grids, I just mention it here for completeness. 2) All the other methods: I explicitly store a list of cell ids and the corresponding weight, the gradient of each variable being just the weighted sum of the variable over those cells with those weights. The stencil here only appears in the construction of the cell list. My routine to build it is just as simple as an iterative loop over a dynamic list initialized with the current cell. At each iteration I add to the list the neighbors of the cells added at the previous iteration and that were not already in the list. So every iteration is a new layer. The book of blazek has most of the relevant content on unstructured grids: https://www.elsevier.com/books/compu...-0-08-099995-1 and it has example codes as well: https://booksite.elsevier.com/978008...amplecodes.php especially the least squares method and related aspects. Note that the LSQ gradient problem can be solved in two similar ways, Normal Equations or QR factorization. Blazek presents the latter. There are also a number of papers from Prof. Wang on the former. Unfortunately, I remember a lot of references having little errors here and there, so the full exact solution is something you have to figure out by yourself or comparing multiple sources (even from the same author). EDIT: of course, the base stencil selection can be improved in a number of way, say https://www.researchgate.net/publica...istorted_Grids, but it still remains an ids list in the end. |
||
March 29, 2022, 07:18 |
|
#16 | |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,897
Rep Power: 73 |
Quote:
I can say what I did on my old 2D unstructured code. Ghost triangles were built by mirroring the two internal layers. Then, second degree lagrangian interpolation (6-nodes) allowed me to compute all I needed. |
||
March 29, 2022, 09:18 |
|
#17 |
Senior Member
Sayan Bhattacharjee
Join Date: Mar 2020
Posts: 495
Rep Power: 8 |
Thank you all for your help.
|
|
March 29, 2022, 13:42 |
|
#18 |
Senior Member
|
For what concerns the ghost cell part, I don't understand if you refer to the parallel implementation or the boundary conditions.
For the parallel case, of course, in order for this to work, you need multiple layers of halo/ghost cells. At least one for each layer/iteration in the gradient. But, unless you want a very complicated code, you won't probably implement boundary conditions for your halo cells. So what happens in parallel with more than 1 layer is that you might have slight inconsistencies in the gradients computed with different numbers of processors. Typically it's not such a big deal, but in high Re cases the differences might be larger. For the boundary conditions, at least for FV, I dn't use the ghost cell approach and just rely on fluxes on boundary faces. In this case you simply have gradients or values available on the boundary face, and you just need to properly insert them into the procedure so that they are correctly taken into account. In my case this is very simple as I can convert all the bcs in face values, so that everything is basically the same as for interiors. Otherwise, your gradient routine might become slightly bc dependent (which, in the end, is still not as horrible as it sounds) |
|
March 29, 2022, 14:53 |
|
#19 | |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,897
Rep Power: 73 |
Quote:
Paolo, for higher order reconstruction (at least third order), the diffusive flux (both momentum and energy) on the boundary requires to integrate the normal derivative along the face. Thus, I used to define more conditions in order to mantain the second degree interpolation. How do you manage that without reducing the accuracy at the boundary? |
||
March 29, 2022, 17:11 |
|
#20 | |
Senior Member
|
Quote:
Actually, my method, which relies on one-sided differences at the boundary with just one interior cell, is (or should be) formally just first order accurate. But in practice you never see that (also because I have to switch to wall functions whenever the underlying functions is presumably not linear anymore). This, of course, is for a second order code. I see the need for higher order discretizations. What I don't like about the ghost cell approach for bcs is that it generates almost arbitrary states in ghost cells and then we pretend that our equations can be continued in this way across the domain boundary (so that we can apply the scheme on it). |
||
Tags |
derivatives, unstructured grid |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
export multi-blocks structured grids to unstructured CGNS format | cfdbooks | Pointwise & Gridgen | 4 | September 21, 2017 21:02 |
collect User Experience about CFD softwares | dxw_CFD | Main CFD Forum | 12 | October 24, 2011 23:08 |
References for the finite volume method on unstructured grids | old newbie | Main CFD Forum | 1 | April 26, 2011 00:53 |
'Best' algorithm for CFD on unstructured 2d grids? | andy2o | Main CFD Forum | 6 | August 19, 2008 13:50 |
combining structured and unstructured grids | Shane | FLUENT | 2 | January 23, 2007 21:57 |