CFD Online Discussion Forums

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 17: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 14:56

Maybe take a look at the wallGradU utility?

Is that helpful for you?

ywang August 18, 2011 16:50

Quote:

Originally Posted by stevenvanharen (Post 320673)
Maybe take a look at the wallGradU utility?

Is that helpful for you?


Thanks.

wallGradU is using
wallGradU.boundaryField()[patchi] =-U.boundaryField()[patchi].snGrad();.

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

I am also reading the code about grad and check if it's helpful.

stevenvanharen August 19, 2011 01:55

because u use:

U.boundaryField()[patchi]

only the faces on this patch are calculated

eugene August 19, 2011 04: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 04: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 14: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 14: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 03: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 unallocLabelListowner mesh.owner();
    const 
unallocLabelListneighbour mesh.neighbour();
    const 
vectorFieldSf mesh.Sf();

    
Field<GradType>& igGrad gGrad;
    const 
Field<Type>& issf ssf;

   
    
forAll(ownerfacei)
    {
        
GradType Sfssf Sf[facei]*issf[facei];

        
igGrad[owner[facei]] += Sfssf;
        
igGrad[neighbour[facei]] -= Sfssf;
    }
    
    
forAll(mesh.boundary(), patchi)
    {
        const 
unallocLabelListpFaceCells mesh.boundary()[patchi].faceCells();
        const 
vectorFieldpSf 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 unallocLabelListowner mesh.owner();
    const 
unallocLabelListneighbour mesh.neighbour();
    const 
vectorFieldSf mesh.Sf();

    
Field<GradType>& igGrad gGrad;
    const 
Field<Type>& issf ssf;


    
forAll(mesh.boundary(), patchi)
    {
        const 
unallocLabelListpFaceCells mesh.boundary()[patchi].faceCells();
        const 
vectorFieldpSf mesh.Sf().boundaryField()[patchi];
        const 
fvsPatchField<Type>& pssf ssf.boundaryField()[patchi];

        
forAll(pFaceCellsfacei)
        {
            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.

Thanks in advance.

Yong


All times are GMT -4. The time now is 01:30.