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

how to use grad P at boundary faces

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By kk415

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 21, 2018, 03:17
Red face how to use grad P at boundary faces
  #1
Senior Member
 
krishna kant
Join Date: Feb 2016
Location: Hyderabad, India
Posts: 133
Rep Power: 10
kk415 is on a distinguished road
Hi Foamers


I have a very simple problem. I want to access grad P at boundary faces.


Code: Info<< fvc::grad(pf) << endl;


Output:

dimensions [0 1 -2 0 0 0 0];

internalField nonuniform List<vector> 4((1.92787 -1.80556 0) (1.92787 1.80538 0) (5.53881 -1.80556 0) (5.53881 1.80538 0));

boundaryField
{
movingWall
{
type extrapolatedCalculated;
value nonuniform List<vector> 2((5.53881 0 0) (5.53881 0 0));
}
fixedWalls
{
type extrapolatedCalculated;
value nonuniform List<vector> 6((0 -1.80556 0) (0 -1.80556 0) (0 1.80538 0) (0 1.80538 0) (1.92787 0 0) (1.92787 0 0));
}
frontAndback
{
type empty;
}
}



So I can access grad(P) of interior faces like:


Code:
forAll(fluidRegions[0].owner(), faceI)
{
Info<< fvc::grad(pf)()[faceI] <<endl;
}



Output:
(1.92787 -1.80556 0)
(1.92787 1.80538 0)
(5.53881 -1.80556 0)
(5.53881 1.80538 0)



Similarly I want to write a face loop for all the boundary faces and want to print grad(P). How can I do that?
kk415 is offline   Reply With Quote

Old   August 21, 2018, 18:01
Default
  #2
New Member
 
Join Date: Nov 2016
Posts: 15
Rep Power: 10
mitti is on a distinguished road
The shitty solution would be to get the patchID for every patch:

Code:
label patchLabel1 = mesh.boundaryMesh().findPatchID("boundary1")
label patchLabel2 = mesh.boundaryMesh().findPatchID("boundary2")
and then loop over the faces for every patch:

Code:
forAll (U.boundaryField()[patchLabel1], faceI) {
// code
}
forAll (U.boundaryField()[patchLabel2], faceI) {
// code
}
But when you have a lot of patches/boundary: Have fun.
mitti is offline   Reply With Quote

Old   August 23, 2018, 02:35
Red face
  #3
Senior Member
 
krishna kant
Join Date: Feb 2016
Location: Hyderabad, India
Posts: 133
Rep Power: 10
kk415 is on a distinguished road
Hey Thanks for Reply


I get how to write the boundary face loop. But I still didn't get how to get grad(p) at boundary.


I try using Info<< fvc::grad(pf).boundaryField()[faceI] <<endl;


But it gives error like boundaryField is not defined in this class. However when I simply give command like Info<< fvc::grad(pf) <<endl;


Then it give output as



dimensions [0 1 -2 0 0 0 0];

internalField nonuniform List<vector> 4((1.92787 -1.80556 0) (1.92787 1.80538 0) (5.53881 -1.80556 0) (5.53881 1.80538 0));

boundaryField
{
movingWall
{
type extrapolatedCalculated;
value nonuniform List<vector> 2((5.53881 0 0) (5.53881 0 0));
}
fixedWalls
{
type extrapolatedCalculated;
value nonuniform List<vector> 6((0 -1.80556 0) (0 -1.80556 0) (0 1.80538 0) (0 1.80538 0) (1.92787 0 0) (1.92787 0 0));
}
frontAndback
{
type empty;
}
}



This means the boundary field information is stored in grad(P). However I dont know how to use it. Can you help me with that?
kk415 is offline   Reply With Quote

Old   August 23, 2018, 04:50
Default
  #4
New Member
 
Artem
Join Date: Apr 2014
Posts: 29
Rep Power: 12
Kombinator is on a distinguished road
Hey,

If you need grad(p) on the patch, something like this should work (I didn't test it, sorry):

Code:
// Find your patch
label patchID = mesh.boundaryMesh().findPatchID("yourPatch");
  
if(patchID == -1)
  
  {
    FatalError << "patch not found!" << exit(FatalError);      
  }
    
// Print p gradient on the patch
forAll(p.boundaryFieldRef()[patchID], faceI)
{
    Info<<p.boundaryFieldRef()[patchID].snGrad()()[faceI]<<endl;
}
Regards,
Artem
Kombinator is offline   Reply With Quote

Old   August 23, 2018, 05:04
Default
  #5
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
.snGrad() gives you the surface normal gradient, which is not equal to the gradient. The surface normal gradient at the boundary is defined as the difference between the cell center value and the boundary face center value divided by the distance between the cell center and the face center. It is described in the programmer guide.
mAlletto is offline   Reply With Quote

Old   August 25, 2018, 02:45
Talking
  #6
Senior Member
 
krishna kant
Join Date: Feb 2016
Location: Hyderabad, India
Posts: 133
Rep Power: 10
kk415 is on a distinguished road
With lot of try and error I found this solution,


Code:


Info<< fvc::grad(pf)().boundaryField()[0] << endl;


Output:


type extrapolatedCalculated;
value nonuniform List<vector> 2((5.53881 0 0) (5.53881 0 0));
mitti likes this.
kk415 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
Foam::error::PrintStack almir OpenFOAM Running, Solving & CFD 92 May 21, 2024 08:56
[snappyHexMesh] sHM layer process keeps getting killed MBttR OpenFOAM Meshing & Mesh Conversion 4 August 15, 2016 04:21
[OpenFOAM.org] OF2.3.1 + OS13.2 - Trying to use the dummy Pstream library aylalisa OpenFOAM Installation 23 June 15, 2015 15:49
Radiation interface hinca CFX 15 January 26, 2014 18:11


All times are GMT -4. The time now is 04:54.