CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   How to calculate the gradient in the boundary cells (http://www.cfd-online.com/Forums/openfoam/91568-how-calculate-gradient-boundary-cells.html)

 ywang August 15, 2011 18:04

How to calculate the gradient in the boundary cells

Hi, everyone.

I want to calculate the gradients of a volScalarField parameter F in the boundary cells. Now, I am using fvc::grad(F,gradF) to calculate the gradients in all cells, and then look up the values in the boundary cells.

Is there any other more efficient method? I just want to reduce the time used for calculating.

Thanks.

Yong

 stevenvanharen August 18, 2011 15:56

Maybe take a look at the wallGradU utility?

 ywang August 18, 2011 17:50

Quote:
 Originally Posted by stevenvanharen (Post 320673) Maybe take a look at the wallGradU utility? Is that helpful for you?

Thanks.

Based on the Programmers Guide, snGrad still calculate all cells in the computational region. Right?

 stevenvanharen August 19, 2011 02:55

because u use:

U.boundaryField()[patchi]

only the faces on this patch are calculated

 eugene August 19, 2011 05:27

snGrad in this context only calculates the wall normal gradient. It does so in a completely local and efficient way though. If you want to calculate the cell centred gradient for a subset of cells, I suggest you look at the code in finiteVolume/lnInclude/gaussGrad.C. This will show you the steps to calculate a gradient on a cell-by-cell basis.

 stevenvanharen August 19, 2011 05:56

Quote:
 Originally Posted by eugene (Post 320739) snGrad in this context only calculates the wall normal gradient. It does so in a completely local and efficient way though. If you want to calculate the cell centred gradient for a subset of cells, I suggest you look at the code in finiteVolume/lnInclude/gaussGrad.C. This will show you the steps to calculate a gradient on a cell-by-cell basis.
Ah ok, I missed the fact that cell-center gradients were required.

 ywang August 19, 2011 15:27

Quote:
 Originally Posted by eugene (Post 320739) snGrad in this context only calculates the wall normal gradient. It does so in a completely local and efficient way though. If you want to calculate the cell centred gradient for a subset of cells, I suggest you look at the code in finiteVolume/lnInclude/gaussGrad.C. This will show you the steps to calculate a gradient on a cell-by-cell basis.
Yes, I have read the code of gaussGrad and found there was the very thing I wanted. Thanks.

 ywang August 19, 2011 15:30

Quote:
 Originally Posted by stevenvanharen (Post 320741) Ah ok, I missed the fact that cell-center gradients were required.
It's ok. I noticed it. Thanks very much :) .

 ywang August 30, 2011 04:39

Hi, everyone. As I want to calculate the gradient at the cells close to the boundaries. I checked the code in the gaussGrad.C:

PHP Code:

```     const unallocLabelList& owner = mesh.owner();     const unallocLabelList& neighbour = mesh.neighbour();     const vectorField& Sf = mesh.Sf();     Field<GradType>& igGrad = gGrad;     const Field<Type>& issf = ssf;         forAll(owner, facei)     {         GradType Sfssf = Sf[facei]*issf[facei];         igGrad[owner[facei]] += Sfssf;         igGrad[neighbour[facei]] -= Sfssf;     }          forAll(mesh.boundary(), patchi)     {         const unallocLabelList& pFaceCells = mesh.boundary()[patchi].faceCells();         const vectorField& pSf = mesh.Sf().boundaryField()[patchi];         const fvsPatchField<Type>& pssf = ssf.boundaryField()[patchi];         forAll(mesh.boundary()[patchi], facei)         {                  igGrad[pFaceCells[facei]] += pSf[facei]*pssf[facei];               }           }  ```

However, in the first loop, all internal faces are calculated. So, I changed the code as:

PHP Code:

```     const unallocLabelList& owner = mesh.owner();     const unallocLabelList& neighbour = mesh.neighbour();     const vectorField& Sf = mesh.Sf();     Field<GradType>& igGrad = gGrad;     const Field<Type>& issf = ssf;     forAll(mesh.boundary(), patchi)     {         const unallocLabelList& pFaceCells = mesh.boundary()[patchi].faceCells();         const vectorField& pSf = mesh.Sf().boundaryField()[patchi];         const fvsPatchField<Type>& pssf = ssf.boundaryField()[patchi];         forAll(pFaceCells, facei)         {             if(!mesh.isInternalFace(facei))             {                    igGrad[pFaceCells[facei]] += pSf[facei]*pssf[facei];                   }             else             {                 GradType Sfssf = Sf[facei]*issf[facei];                 igGrad[owner[facei]] += Sfssf;                 igGrad[neighbour[facei]] -= Sfssf;                  }         }           }  ```
There is no error when I compile it. But the solver will lead to unphysical results. I know there must be something wrong with pFaceCells, but have no idea to revise it. Any message from you are welcome.