# How to calculate the gradient in the boundary cells

 User Name Remember Me Password
 Register Blogs Members List Search Today's Posts Mark Forums Read

 August 15, 2011, 17:04 How to calculate the gradient in the boundary cells #1 Member   Yong Wang Join Date: Apr 2009 Posts: 34 Rep Power: 10 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.

 August 18, 2011, 14:56 #2 Senior Member   Steven van Haren Join Date: Aug 2010 Location: The Netherlands Posts: 149 Rep Power: 9 Maybe take a look at the wallGradU utility? Is that helpful for you?

August 18, 2011, 16:50
#3
Member

Yong Wang
Join Date: Apr 2009
Posts: 34
Rep Power: 10
Quote:
 Originally Posted by stevenvanharen 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?

 August 19, 2011, 01:55 #4 Senior Member   Steven van Haren Join Date: Aug 2010 Location: The Netherlands Posts: 149 Rep Power: 9 because u use: U.boundaryField()[patchi] only the faces on this patch are calculated

 August 19, 2011, 04:27 #5 Senior Member   Eugene de Villiers Join Date: Mar 2009 Posts: 725 Rep Power: 14 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.

August 19, 2011, 04:56
#6
Senior Member

Steven van Haren
Join Date: Aug 2010
Location: The Netherlands
Posts: 149
Rep Power: 9
Quote:
 Originally Posted by eugene 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.

August 19, 2011, 14:27
#7
Member

Yong Wang
Join Date: Apr 2009
Posts: 34
Rep Power: 10
Quote:
 Originally Posted by eugene 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.

August 19, 2011, 14:30
#8
Member

Yong Wang
Join Date: Apr 2009
Posts: 34
Rep Power: 10
Quote:
 Originally Posted by stevenvanharen Ah ok, I missed the fact that cell-center gradients were required.
It's ok. I noticed it. Thanks very much .

 August 30, 2011, 03:39 #9 Member   Yong Wang Join Date: Apr 2009 Posts: 34 Rep Power: 10 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& igGrad = gGrad;     const Field& 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& 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& igGrad = gGrad;     const Field& issf = ssf;     forAll(mesh.boundary(), patchi)     {         const unallocLabelList& pFaceCells = mesh.boundary()[patchi].faceCells();         const vectorField& pSf = mesh.Sf().boundaryField()[patchi];         const fvsPatchField& 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. Thanks in advance. Yong

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Saturn CFX 48 October 25, 2017 06:07 HMR CFX 5 October 10, 2016 05:57 kaka OpenFOAM Mesh Utilities 2 November 26, 2009 05:17 Karl FLUENT 7 May 11, 2002 22:12 Haris Maharana Siemens 1 August 2, 2000 19:31

All times are GMT -4. The time now is 03:50.

 Contact Us - CFD Online - Privacy Statement - Top