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

How to calculate the gradient in the boundary cells

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By ywang

Reply
 
LinkBack Thread Tools Search this Thread 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: 34
Rep Power: 17
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
rajibroy likes this.
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: 16
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: 34
Rep Power: 17
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: 16
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: 21
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: 16
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: 34
Rep Power: 17
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: 34
Rep Power: 17
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: 34
Rep Power: 17
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


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wind turbine simulation Saturn CFX 60 July 17, 2024 06:45
Domain Imbalance HMR CFX 5 October 10, 2016 06:57
[mesh manipulation] How to delete selected cells from mesh and update boundary patches kaka OpenFOAM Meshing & Mesh Conversion 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 Siemens 1 August 2, 2000 20:31


All times are GMT -4. The time now is 21:26.