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

How to calculate the gradient in the boundary cells

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

Reply
 
LinkBack Thread Tools Display Modes
Old   August 15, 2011, 18:04
Default How to calculate the gradient in the boundary cells
  #1
Member
 
Yong Wang
Join Date: Apr 2009
Posts: 32
Rep Power: 7
ywang is on a distinguished road
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
ywang is offline   Reply With Quote

Old   August 18, 2011, 15:56
Default
  #2
Senior Member
 
Steven van Haren
Join Date: Aug 2010
Location: The Netherlands
Posts: 149
Rep Power: 6
stevenvanharen is on a distinguished road
Maybe take a look at the wallGradU utility?

Is that helpful for you?
stevenvanharen is offline   Reply With Quote

Old   August 18, 2011, 17:50
Default
  #3
Member
 
Yong Wang
Join Date: Apr 2009
Posts: 32
Rep Power: 7
ywang is on a distinguished road
Quote:
Originally Posted by stevenvanharen View Post
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.
ywang is offline   Reply With Quote

Old   August 19, 2011, 02:55
Default
  #4
Senior Member
 
Steven van Haren
Join Date: Aug 2010
Location: The Netherlands
Posts: 149
Rep Power: 6
stevenvanharen is on a distinguished road
because u use:

U.boundaryField()[patchi]

only the faces on this patch are calculated
stevenvanharen is offline   Reply With Quote

Old   August 19, 2011, 05:27
Default
  #5
Senior Member
 
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 11
eugene is on a distinguished road
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.
eugene is offline   Reply With Quote

Old   August 19, 2011, 05:56
Default
  #6
Senior Member
 
Steven van Haren
Join Date: Aug 2010
Location: The Netherlands
Posts: 149
Rep Power: 6
stevenvanharen is on a distinguished road
Quote:
Originally Posted by eugene View Post
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.
stevenvanharen is offline   Reply With Quote

Old   August 19, 2011, 15:27
Wink
  #7
Member
 
Yong Wang
Join Date: Apr 2009
Posts: 32
Rep Power: 7
ywang is on a distinguished road
Quote:
Originally Posted by eugene View Post
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 is offline   Reply With Quote

Old   August 19, 2011, 15:30
Default
  #8
Member
 
Yong Wang
Join Date: Apr 2009
Posts: 32
Rep Power: 7
ywang is on a distinguished road
Quote:
Originally Posted by stevenvanharen View Post
Ah ok, I missed the fact that cell-center gradients were required.
It's ok. I noticed it. Thanks very much .
ywang is offline   Reply With Quote

Old   August 30, 2011, 04:39
Default
  #9
Member
 
Yong Wang
Join Date: Apr 2009
Posts: 32
Rep Power: 7
ywang is on a distinguished road
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
ywang 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
Wind turbine simulation Saturn CFX 34 October 16, 2014 06:27
Domain Imbalance HMR CFX 3 March 6, 2011 21:10
How to delete selected cells from mesh and update boundary patches kaka OpenFOAM Mesh Utilities 2 November 26, 2009 05:17
Ignore cells on partition boundary Karl FLUENT 7 May 11, 2002 23:12
Restriction on number of boundary cells !!! Haris Maharana CD-adapco 1 August 2, 2000 20:31


All times are GMT -4. The time now is 17:32.