CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   fvc::grad only gaussGrad (https://www.cfd-online.com/Forums/openfoam-programming-development/96661-fvc-grad-only-gaussgrad.html)

doubtsincfd January 28, 2012 11:58

fvc::grad only gaussGrad
 
Does fvc::grad() calculates gradients using gauss grad scheme only? Because in the file fvcGrad.C only gaussGrad is being referred.

bigphil January 29, 2012 09:39

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

idefix May 24, 2013 08:28

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

bigphil May 24, 2013 08:38

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

idefix May 25, 2013 04:14

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

bigphil May 25, 2013 07:04

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

RodriguezFatz April 16, 2014 09:57

Quote:

Originally Posted by bigphil (Post 429787)
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.

bigphil April 16, 2014 10:48

Quote:

Originally Posted by RodriguezFatz (Post 486514)
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 (Post 486514)
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

RodriguezFatz April 16, 2014 10:51

Quote:

Originally Posted by bigphil (Post 486526)
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.

bigphil April 16, 2014 11:00

Quote:

Originally Posted by RodriguezFatz (Post 486528)
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 April 16, 2014 11:02

Quote:

Originally Posted by bigphil (Post 486531)
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!

cvillescas August 24, 2015 06:09

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

bigphil August 25, 2015 04:15

Quote:

Originally Posted by cvillescas (Post 560800)
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 August 25, 2015 04:30

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

wxxq February 8, 2023 06:55

why neigbour cell igGrad[neighbour[facei]] -= Sfssf;?

bigphil February 14, 2023 05:14

Quote:

Originally Posted by wxxq (Post 844141)
why neigbour cell igGrad[neighbour[facei]] -= Sfssf;?

The Gauss gradient is calculated face-by-face, where the term at each face is equal and opposite for the two cells that share the face (called the "owner" and "neighbour" in OpenFOAM).

So, for this line, the contribution is added to the neighbour cell.


All times are GMT -4. The time now is 08:48.