CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Calculating gradient only at patchInternalField (https://www.cfd-online.com/Forums/openfoam-solving/59845-calculating-gradient-only-patchinternalfield.html)

7islands January 30, 2007 19:19

Hi all, I'd like to know how
 
Hi all,
I'd like to know how to calculate gradient (not surface-normal gradient) at patchInternalField within a boundary condition code in a computationally efficient way. Doing it simple programming-wise I could write

#include "fvcGrad.H"
const volScalarField& phi = db().lookupObject<volscalarfield>("phi");
const Field<vector> gPhip
= patchInternalField(Field<vector>(fvc::grad(phi)));

but obviously this is computationally too inefficient (calculating gradient of the entire field just for patchInternalField).

I appreciate any suggestions.

Thanks,
Takuya

akidess February 2, 2011 04:17

Takuya, did you ever find a more efficient way to do this?

7islands February 2, 2011 19:36

I'm afraid not. :(

T

eugene March 17, 2011 08:51

I just had a look at the grad calculation code and what you suggest should be relatively easy to implement (for an explicit gauss gradient at least, I didn't check the requirements for least squares and other gradient calculation methods).

The gradient is calculated from: grad(phi)_cell = sum_cellfaces(Sf*phi_f) / cellVolume;

Simple as that. So all you would need for the gradient at the patchInternalField is to loop through the cells, calculate the interpolated face value on each face in the set and compute the simple sum. There is no parallel complexity or anything required that I can see. You will just have to find an efficient way to limit the number of face interpolations so there is no duplicate calculation.

ata March 20, 2011 08:43

What is db?
 
Hi
I have a question. May be it is not related. What is db() in db().lookupObject?
Thanks a lot

deepsterblue March 20, 2011 18:59

I actually think this is straightforward. Create a cellSet and use that to make an fvMeshSubset. This should also carry all necessary information to estimate the cell-centered gradient that you're asking for.

7islands March 20, 2011 21:06

Hi all, thanks for the input.

@Eugene: Yes you are right, that was exactly what came up to my mind, but I was so lazy that I thought there would have been a simpler (or more OpenFOAM-ish) way.

@ata: db() returns a reference to the object registry.

@Sandeep: That sounds like what I was looking for at that time if the subsetMesh and the field do not have to be constructed each time step. In fact I no longer have to do this, but shall try your proposal if I have to do this next time :)

Takuya


All times are GMT -4. The time now is 04:06.