
[Sponsors] 
January 28, 2012, 12:58 
fvc::grad only gaussGrad

#1 
Senior Member
Join Date: Nov 2009
Location: Michigan
Posts: 135
Rep Power: 9 
Does fvc::grad() calculates gradients using gauss grad scheme only? Because in the file fvcGrad.C only gaussGrad is being referred.


January 29, 2012, 10:39 

#2 
Senior Member
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 636
Rep Power: 23 
Hi,
As far as I can see (in fvcGrad.C), fvcGrad of a volumeField checks what gradScheme is specified (i.e. Gauss, leastSquares, etc.) and then uses that to calculate the grad. Philip 

May 24, 2013, 08:28 

#3 
Member
Join Date: Aug 2011
Posts: 83
Rep Power: 7 
Hello
I just wanted to know what OpenFOAM is calculating when I write: gradScheme default Gauss linear how is for example grad(p) calculated? Are the values on the faces used for this? I also looked at fvcGrad.C but I donīt understand the code and how I can get the answer to my question from code. Can anybody help me? Thanks a lot Idefix 

May 24, 2013, 08:38 

#4 
Senior Member
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 636
Rep Power: 23 
Hi,
Gauss linear means that the gradient is calculated using the Gauss method (i.e. volume integrals are converted to surface integrals) and linear means that cell centre values are interpolated linearly to the face centres. This presentation by Hrv gives a bit more info: http://powerlab.fsb.hr/ped/kturbo/Op...niteVolume.pdf By Gauss' law, the volume integral of the gradient can be written as a surface integral: volume_integral gradp dV == surface_integral dS p In discrete form, this means: gradp = (1/V) surface_sum Sf pf where V is the cell volume, Sf is a face area vector and pf is the value of p at that face. The surface_sum is performed over all the faces of the cell. You can find the relevant code in the $FOAM_SRC/finiteVolume/finiteVolume/gradSchemes/gaussGrad/GaussGrad.C file. Hope it helps, Philip 

May 25, 2013, 04:14 

#5 
Member
Join Date: Aug 2011
Posts: 83
Rep Power: 7 
Hey Philip,
thanks for your useful explanation. Now I understand the theory but I still donīt understand the code. Am I right that in GaussGrad.C only the sum (surface_sum Sf pf) is calculated? If itīs the case: where can I find the linear interpolation from the cell centre to the cell faces? Thanks a lot Idefix 

May 25, 2013, 07:04 

#6 
Senior Member
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 636
Rep Power: 23 
Idefix,
If you follow the trail of code from fvc::grad(volField) you can find where everything is calculated. In short, fvc::grad(volField) > fvc::grad(volField, word) > gradScheme.grad(volField, word) > GaussGrad.calcGrad(volField, word) > GaussGrad.gradf(surfaceField, name). The interpolation of the volField (cell centres) to surfaceField (face centres) occurs in GaussGrad.calcGrad(volField, word): Code:
00113 template<class Type> 00114 Foam::tmp 00115 < 00116 Foam::GeometricField 00117 < 00118 typename Foam::outerProduct<Foam::vector, Type>::type, 00119 Foam::fvPatchField, 00120 Foam::volMesh 00121 > 00122 > 00123 Foam::fv::gaussGrad<Type>::calcGrad 00124 ( 00125 const GeometricField<Type, fvPatchField, volMesh>& vsf, 00126 const word& name 00127 ) const 00128 { 00129 typedef typename outerProduct<vector, Type>::type GradType; 00130 00131 tmp<GeometricField<GradType, fvPatchField, volMesh> > tgGrad 00132 ( 00133 gradf(tinterpScheme_().interpolate(vsf), name) 00134 ); 00135 GeometricField<GradType, fvPatchField, volMesh>& gGrad = tgGrad(); 00136 00137 correctBoundaryConditions(vsf, gGrad); 00138 00139 return tgGrad; 00140 } Code:
gradf(tinterpScheme_().interpolate(vsf), name) The surface sum happens in the GaussGrad.gradf(surfaceField, name) function: Code:
00082 forAll(owner, facei) 00083 { 00084 GradType Sfssf = Sf[facei]*issf[facei]; 00085 00086 igGrad[owner[facei]] += Sfssf; 00087 igGrad[neighbour[facei]] = Sfssf; 00088 } Code:
00105 igGrad /= mesh.V(); Hope it helps, Philip 

April 16, 2014, 09:57 

#7  
Senior Member
Philipp
Join Date: Jun 2011
Location: Germany
Posts: 1,297
Rep Power: 19 
Quote:
1) Does that additionally mean, that using "grad(p) Gaus ..." always calulates the volume integral over "grad p" as a sum of surface integrals (thus the using gauss theorem), whereas using "grad(p) leastSquares" actually calculates the gradient at the cell center and then calculates the volume integral (gradp * V)? 2) If the latter is true, can anyone confirm, that this is not available in Fluent? As far as I understand the Fluent help, pressure gradient integral is allways solved using Gauss theorem. Just the way of face interpolation can be choosen.
__________________
The skeleton ran out of shampoo in the shower. 

April 16, 2014, 10:48 

#8  
Senior Member
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 636
Rep Power: 23 
Quote:
whereas "grad(p) leastSquares" calculates the cell gradient by fitting a 'least squares' plane, no need to calculate any volume integrals. See Hrv presentation here for some more info on gradient calculation: http://powerlab.fsb.hr/ped/kturbo/Op...niteVolume.pdf Quote:
Best regards, Philip 

April 16, 2014, 10:51 

#9 
Senior Member
Philipp
Join Date: Jun 2011
Location: Germany
Posts: 1,297
Rep Power: 19 
Yes, but momentum equation is solved in conservative form, i.e. all parts of the differential equation are integrated over space. Also the "grad p" term, thus the reason why "grad p" needs to be known is because You actually want to solve "Integral( grad p) dV)". That's why I was talking about volume integrals.
__________________
The skeleton ran out of shampoo in the shower. 

April 16, 2014, 11:00 

#10  
Senior Member
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 636
Rep Power: 23 
Quote:
the volume integral is performed when you add grad(p) to the momentum equation: The momentum equation in the solver is an object of type fvVectorMatrix and then grad(p) which is a scalar field is added to it; grad(p) times the volume is then added to the source of the fvVectorMatrix. You can see this in the fvMatrix.C file: Code:
01064 template<class Type> 01065 void Foam::fvMatrix<Type>::operator+= 01066 ( 01067 const DimensionedField<Type, volMesh>& su 01068 ) 01069 { 01070 checkMethod(*this, su, "+="); 01071 source() = su.mesh().V()*su.field(); 01072 } 

April 16, 2014, 11:02 

#11 
Senior Member
Philipp
Join Date: Jun 2011
Location: Germany
Posts: 1,297
Rep Power: 19 
Great, that was exactly what I wasn't keeping in mind. Thanks!
__________________
The skeleton ran out of shampoo in the shower. 

August 24, 2015, 06:09 

#12 
New Member
Carla
Join Date: Jun 2015
Posts: 16
Rep Power: 4 
Hi to everyone,
I have a question also related to the gradient. I suspect that in OpenFOAM the velocity gradient tensor is assigned as the transpose of the "standard". What I understand by "standard" is that the term du/dx would be in the first row&second column, and I suspect OpenFOAM places it in the second row&first column. However, I struggle to read the code. Can anyone confirm this or at least tell me the .C file where tensor components are assigned? Thanks in advance. Carla 

August 25, 2015, 04:15 

#13  
Senior Member
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 636
Rep Power: 23 
Quote:
The definition of the gradient in OpenFOAM is given in Equation 2.3 (Page 25) of the Programmer's Guide. Best, Philip 

August 25, 2015, 04:30 

#14 
New Member
Carla
Join Date: Jun 2015
Posts: 16
Rep Power: 4 
Hi Philip,
Thank you for your answer. It hadn't even thougth about the programmers guide! But that is exactly what I was looking for. Thanks again. By the way, I've just noticed that in my previous post I was mentioning du/dx when I meant du/dy. Bests, Carla 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
gaussGrad  pino@JAEA  OpenFOAM  1  August 24, 2011 23:02 
Eigenvector for the largest positive eigenvalue of the symm( fvc::grad ( U ) )  jaswi  OpenFOAM Running, Solving & CFD  1  September 13, 2010 08:43 
How to control the fvcgrad scheme  ivan_cozza  OpenFOAM Running, Solving & CFD  2  October 14, 2008 10:30 