CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

fvc::grad only gaussGrad

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree6Likes
  • 1 Post By bigphil
  • 2 Post By bigphil
  • 1 Post By bigphil
  • 1 Post By bigphil
  • 1 Post By bigphil

Reply
 
LinkBack Thread Tools Display Modes
Old   January 28, 2012, 12:58
Default fvc::grad only gaussGrad
  #1
Senior Member
 
Join Date: Nov 2009
Location: Michigan
Posts: 135
Rep Power: 7
doubtsincfd is on a distinguished road
Does fvc::grad() calculates gradients using gauss grad scheme only? Because in the file fvcGrad.C only gaussGrad is being referred.
doubtsincfd is offline   Reply With Quote

Old   January 29, 2012, 10:39
Default
  #2
Senior Member
 
bigphil's Avatar
 
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 570
Rep Power: 19
bigphil will become famous soon enoughbigphil will become famous soon enough
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
Tushar@cfd likes this.
bigphil is offline   Reply With Quote

Old   May 24, 2013, 08:28
Default
  #3
Member
 
Join Date: Aug 2011
Posts: 81
Rep Power: 6
idefix is on a distinguished road
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
idefix is offline   Reply With Quote

Old   May 24, 2013, 08:38
Default
  #4
Senior Member
 
bigphil's Avatar
 
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 570
Rep Power: 19
bigphil will become famous soon enoughbigphil will become famous soon enough
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
kosan and HuZexi like this.
bigphil is offline   Reply With Quote

Old   May 25, 2013, 04:14
Default
  #5
Member
 
Join Date: Aug 2011
Posts: 81
Rep Power: 6
idefix is on a distinguished road
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
idefix is offline   Reply With Quote

Old   May 25, 2013, 07:04
Default
  #6
Senior Member
 
bigphil's Avatar
 
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 570
Rep Power: 19
bigphil will become famous soon enoughbigphil will become famous soon enough
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 }
specifically line 00133:
Code:
gradf(tinterpScheme_().interpolate(vsf), name)
This looks up the specified interpolation scheme (linear in your case).

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     }
and division by the volume:
Code:
00105     igGrad /= mesh.V();
I recommend brushing up on C++ and following the function calls.

Hope it helps,
Philip
cvillescas likes this.
bigphil is offline   Reply With Quote

Old   April 16, 2014, 09:57
Default
  #7
Senior Member
 
RodriguezFatz's Avatar
 
Philipp
Join Date: Jun 2011
Location: Germany
Posts: 1,099
Rep Power: 16
RodriguezFatz will become famous soon enough
Quote:
Originally Posted by bigphil View Post
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.
bigphil, thank you for the explanations.
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.
RodriguezFatz is offline   Reply With Quote

Old   April 16, 2014, 10:48
Default
  #8
Senior Member
 
bigphil's Avatar
 
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 570
Rep Power: 19
bigphil will become famous soon enoughbigphil will become famous soon enough
Quote:
Originally Posted by RodriguezFatz View Post
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)?
Using "grad(p) Gauss linear" calculates the cell gradient using the Gauss theorem,
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:
Originally Posted by RodriguezFatz View Post
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.
OpenFOAM is written in a general fashion such that you could choose any gradient calculation method for grad(p) even if 'Gauss' is mostly selected by the user.

Best regards,
Philip
bigphil is offline   Reply With Quote

Old   April 16, 2014, 10:51
Default
  #9
Senior Member
 
RodriguezFatz's Avatar
 
Philipp
Join Date: Jun 2011
Location: Germany
Posts: 1,099
Rep Power: 16
RodriguezFatz will become famous soon enough
Quote:
Originally Posted by bigphil View Post
Using "grad(p) Gauss linear" calculates the cell gradient using the Gauss theorem,
whereas "grad(p) leastSquares" calculates the cell gradient by fitting a 'least squares' plane, no need to calculate any volume integrals.
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.
RodriguezFatz is offline   Reply With Quote

Old   April 16, 2014, 11:00
Default
  #10
Senior Member
 
bigphil's Avatar
 
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 570
Rep Power: 19
bigphil will become famous soon enoughbigphil will become famous soon enough
Quote:
Originally Posted by RodriguezFatz View Post
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 volume integral is not considered when the gradient is calculated, as you may want a gradient for some other reason;

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 }
Philip
RodriguezFatz likes this.
bigphil is offline   Reply With Quote

Old   April 16, 2014, 11:02
Default
  #11
Senior Member
 
RodriguezFatz's Avatar
 
Philipp
Join Date: Jun 2011
Location: Germany
Posts: 1,099
Rep Power: 16
RodriguezFatz will become famous soon enough
Quote:
Originally Posted by bigphil View Post
The volume integral is not considered when the gradient is calculated, as you may want a gradient for some other reason;
Great, that was exactly what I wasn't keeping in mind. Thanks!
__________________
The skeleton ran out of shampoo in the shower.
RodriguezFatz is offline   Reply With Quote

Old   August 24, 2015, 06:09
Default
  #12
New Member
 
Carla
Join Date: Jun 2015
Posts: 5
Rep Power: 2
cvillescas is on a distinguished road
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
cvillescas is offline   Reply With Quote

Old   August 25, 2015, 04:15
Default
  #13
Senior Member
 
bigphil's Avatar
 
Philip Cardiff
Join Date: Mar 2009
Location: Dublin,Ireland
Posts: 570
Rep Power: 19
bigphil will become famous soon enoughbigphil will become famous soon enough
Quote:
Originally Posted by cvillescas View Post
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
Hi Carla,

The definition of the gradient in OpenFOAM is given in Equation 2.3 (Page 25) of the Programmer's Guide.

Best,
Philip
cvillescas likes this.
bigphil is offline   Reply With Quote

Old   August 25, 2015, 04:30
Default
  #14
New Member
 
Carla
Join Date: Jun 2015
Posts: 5
Rep Power: 2
cvillescas is on a distinguished road
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
cvillescas is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 09:19.