How to compute gradient for nonorthogonal grids?
HI,
I am reading the CFD book written by Peric (2nd edition). I am confused about calculating gradient of a scalar function when dealing with bodyfitted, nonorthogonal grid. Especially, when reading the code that he placed on the internet. This is the piece of code that calculates gradient, it will be highly appreciate if anyone can descibe in "plain english" how the gradient is calculated. Paul PS: Peric has this code available for download on the internet. I hope that it is OK to put this small piece of code here.  FI: scalar function DFX: gradient, Xcomponent DFY: gradient, Ycomponent FAC: ratio: (cell center to cell face)/(cell center at P to cell center to it's neighbor E)  Pe/PE IJP: node P IJN: neighbor node E (east side) IJ1: node P IJ2: neight node S (south side) C################################################# ############## SUBROUTINE GRADCO(FI,DFX,DFY,FAC,IJP,IJN,IJ1,IJ2) C################################################# ############## C This routine calculates contribution to the gradient C vector of a scalar FI at the CV center, arising from C an inner cell face (cellface value of FI times the C corresponding component of the surface vector). C================================================= ==============C C.....COORDINATES OF POINT ON THE LINE CONNECTING CENTER AND NEIGHBOR, C OLD GRADIENT VECTOR COMPONENTS INTERPOLATED FOR THIS LOCATION C FACP=1.FAC XI=XC(IJN)*FAC+XC(IJP)*FACP YI=YC(IJN)*FAC+YC(IJP)*FACP DFXI=DFXO(IJN)*FAC+DFXO(IJP)*FACP DFYI=DFYO(IJN)*FAC+DFYO(IJP)*FACP C C.....COORDINATES OF THE CELLFACE CENTER, VARIABLE VALUE THERE C XF=0.5*(X(IJ1)+X(IJ2)) YF=0.5*(Y(IJ1)+Y(IJ2)) FIE=FI(IJN)*FAC+FI(IJP)*FACP+DFXI*(XFXI)+DFYI*(YFYI) C C.....SURFACE VECTOR COMPONENTS, GRADIENT CONTRIBUTION FROM CELL FACE C RE=(R(IJ1)+R(IJ2))*0.5 SX=(Y(IJ1)Y(IJ2))*RE SY=(X(IJ2)X(IJ1))*RE DFXE=FIE*SX DFYE=FIE*SY C C.....ACCUMULATE CONTRIBUTION AT CELL CENTER AND NEIGHBOR C DFX(IJP)=DFX(IJP)+DFXE DFY(IJP)=DFY(IJP)+DFYE DFX(IJN)=DFX(IJN)DFXE DFY(IJN)=DFY(IJN)DFYE C RETURN END C 
Re: How to compute gradient for nonorthogonal gri
The gradient of a function F at cell center is calculated by Gauss Theorem. \int_Vol{ gadient F dV} == \int_S { F * n_j * dS_j}.

Re: How to compute gradient for nonorthogonal gri
Hi,
Thanks for the reply. Yes, but, what confuses me is the "correction" due to nonorthogonality. In Peric's book, it mentioned using gradient at previous step when calculating the correction. But, in his code, it looks like it only used gradient at previous step when calculating Fi (function in interests) at e (not E). Paul 
Re: How to compute gradient for nonorthogonal gri
When dealing with the diffusion term you need the gradient of a property dotted with the face area vector (the dot product between the gradient and the face area vector). Thus "in English", you need the gradient of the property in the direction of the face area vector. On an orthogonal mesh the face area vector points in the direction of the line connection the centres of the two cells bracketing a face. The gradient of your property is simply the difference of the two centre values divided by the distance between the two cell centres.
In the case of the nonorthogonal meshes the face area vector (say A) is decomposed into two vectors, one parallel to the line connection the two cell centres (say D), and the other (say k) such that A=D+k. The gradient of your property is now multiplied to D + k instead. The portion in the direction of the neighbouring cell centre is similar to the orthogonal mesh case. The nonorthogonal contribution (gradient of the property times k) is treated somewhat differently. This is your question. Versi mentioned the formula for calculating the gradient of your property at a cell centre. Use the formulation for the two cell centres bracketing the face and interpolate this value to the face centre and get the dot product with your vector k. You do this with old iteration level values (as mentioned in your follow up question). Thus the contribution of nonorthogonality is treated "explicitly" and slightly lagged in "time". By the time you have convergence, the values does not change and it does not matter whether you used old or new values. However, the process to convergence might be a tedious one with more underrelaxation. This is the price you pay for grid nonorthogonality. 
All times are GMT 4. The time now is 23:51. 