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

How to access to faces of a patch

Register Blogs Community New Posts Updated Threads Search

Like Tree23Likes
  • 3 Post By jaswi
  • 12 Post By jaswi
  • 2 Post By shivasub
  • 1 Post By Marshak
  • 2 Post By fumiya
  • 3 Post By PEM_GUY

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 30, 2007, 19:05
Default Dear OpenFOAMers Greetings
  #1
Senior Member
 
Join Date: Mar 2009
Posts: 248
Rep Power: 18
jaswi is on a distinguished road
Dear OpenFOAMers

Greetings

I need the face list of faces belonging to a boundary patch. This is what I am doing:


label patchID = mesh.boundaryMesh().findPatchID("cylinder");
const polyPatch& cPatch = mesh.boundaryMesh()[patchID];


With the above code lines I can create a polyPatch and assign it equal to the boundary patch i need.

Please give me a clue on how to access the faces of this patch as I need to loop over these faces.



Thanks in advance

Best Regards
Jaswinder

PS: I am searching the posts simultaneously
jaswi is offline   Reply With Quote

Old   December 30, 2007, 21:16
Default Hi Forum Good Evening once
  #2
Senior Member
 
Join Date: Mar 2009
Posts: 248
Rep Power: 18
jaswi is on a distinguished road
Hi Forum

Good Evening once again

I wanted to calculate the surface area of a patch. This is how I achieved the result :

label patchID = mesh.boundaryMesh().findPatchID("walls");

const polyPatch& cPatch = mesh.boundaryMesh()[patchID];

const surfaceScalarField& magSf = mesh.magSf();

scalar patchArea = 0.0;
forAll(cPatch, facei)
{
patchArea += magSf.boundaryField()[patchID][facei];
}

Info << "Patch Area " << patchArea << endl;

I checked it for a cylinder and it gives accurate result. I am sure that it can be done in a more elegant way. Experts please suggest.

Now the next step is to iterate over the faces of this patch and sum the area of only those faces where value of volume fraction gamma is positive.

Any suggestions are highly appreciated.

Wish you all a successful year ahead
Best Regards
Jaswinder
jaswi is offline   Reply With Quote

Old   December 30, 2007, 21:19
Default Jaswinder, you can access e
  #3
New Member
 
Shivasubramanian Gopalakrishnan
Join Date: Mar 2009
Location: Amherst, Massachusetts, USA
Posts: 15
Rep Power: 17
shivasub is on a distinguished road
Jaswinder,

you can access each of the faces in this manner after getting specific patch.

forAll(cPatch, faceI)
{
//whatever you need to access here

}

regards
Shiva
meshman and Luttappy like this.
shivasub is offline   Reply With Quote

Old   December 30, 2007, 21:55
Default Thanks Shiva Your profile s
  #4
Senior Member
 
Join Date: Mar 2009
Posts: 248
Rep Power: 18
jaswi is on a distinguished road
Thanks Shiva

Your profile shows that you work with Multiphase Flows. That's a good news for me as I am a novice in this field and have been looking out for people who are experienced, especially within OpenFOAM community.

Kind Regards
Jaswinder
jaswi is offline   Reply With Quote

Old   December 31, 2007, 12:14
Default Hi Jaswinder, good to know
  #5
New Member
 
Shivasubramanian Gopalakrishnan
Join Date: Mar 2009
Location: Amherst, Massachusetts, USA
Posts: 15
Rep Power: 17
shivasub is on a distinguished road
Hi Jaswinder,

good to know you are working in multiphase flows as well. I am still learning a lot about this.

you can use an if test in the for loop for checking faces with gamma > 0 .

forAll(cPatch,faceI)

{
if (gamma.boundaryField()[patchID][faceI] > 0)
//whatever you need to do.
}

This works, but am not sure how efficient this is and whether there is any other elegant workaround.

regards
Shiva
shivasub is offline   Reply With Quote

Old   January 6, 2008, 06:04
Default Thanks Shiva It works.
  #6
Senior Member
 
Join Date: Mar 2009
Posts: 248
Rep Power: 18
jaswi is on a distinguished road
Thanks Shiva

It works.


Happy New year
Jaswinder
jaswi is offline   Reply With Quote

Old   March 2, 2013, 21:43
Default sum of areas of all faces of a cell
  #7
New Member
 
Join Date: Feb 2012
Posts: 25
Rep Power: 14
Marshak is on a distinguished road
I have a similar problem to solve. I want to calculate, for each given cell in the domain :

Length= cell Volume / sum of areas of all faces of a cell

Can you kindly help me how can I code this.
pearlli likes this.
Marshak is offline   Reply With Quote

Old   March 3, 2013, 01:59
Default How to loop over cell faces
  #8
Senior Member
 
fumiya's Avatar
 
Fumiya Nozaki
Join Date: Jun 2010
Location: Yokohama, Japan
Posts: 266
Blog Entries: 1
Rep Power: 18
fumiya is on a distinguished road
Hi Marshak,

I think it is better to start another thread for being easy to search later.
Regarding your question, the following is my sample code:

Code:
scalar sumA = 0.0; //Sum of areas of all faces of a cell
const cell& cFaces = mesh.cells()[yourCellIndex];

forAll(cFaces, i)
{
    sumA += mag(mesh.Sf()[cFaces[i]]); //cFaces[i]: face label of a cell
}

scalar Length = mesh.V()[yourCellIndex]/sumA;
Hopt that helps,
Fumiya
pfhan and Luttappy like this.
fumiya is offline   Reply With Quote

Old   September 28, 2013, 15:34
Default
  #9
New Member
 
David
Join Date: Mar 2010
Location: Vancouver, Canada
Posts: 13
Rep Power: 16
PEM_GUY is on a distinguished road
label patchID = mesh.boundaryMesh().findPatchID("NAME OF PATCH");

Info << "patchID = " << patchID << endl;

const polyPatch& cPatch = mesh.boundaryMesh()[patchID];

Info << "cPATCH = " << nl << cPatch << endl;

const surfaceScalarField& magSf = mesh.magSf();

scalar AREA = gSum(magSf.boundaryField()[patchID]);

Info << "AREA = " << nl << AREA << endl;

You might find it more efficient to do the following, it will avoid the need for additional looping. There is also the Foam::max and Foam::min function when needed to only sum more or less than a given value.

Cheers

DH
arvindpj, Luttappy and JulioPieri like this.
PEM_GUY is offline   Reply With Quote

Old   October 1, 2013, 05:06
Default
  #10
New Member
 
Join Date: Feb 2012
Posts: 25
Rep Power: 14
Marshak is on a distinguished road
Is this the procedure for boundary patches only? if yes then how about finding surface area of each internal mesh cell?
Marshak is offline   Reply With Quote

Old   December 4, 2013, 04:37
Default
  #11
Member
 
Ye Zhang
Join Date: Dec 2009
Location: Delft,Netherland
Posts: 92
Rep Power: 16
kiddmax is on a distinguished road
Dear DH,

should I add this code into controlDict file? or the solver code?
kiddmax is offline   Reply With Quote

Old   December 4, 2013, 14:01
Default Faces... faces... everywhere...
  #12
New Member
 
David
Join Date: Mar 2010
Location: Vancouver, Canada
Posts: 13
Rep Power: 16
PEM_GUY is on a distinguished road
The routine above works for addressable patches, i.e. ones that have been created in blockmesh or are created upon splitting a mesh for multi-region. This code would be included in the solver, not in controlDict.

If you wanted to do a loop over all faces in a domain, there are examples of this in the grad calc function in OpenFoam's source guide. I do have code for this and will try to post a "how" later on today.

Cheers,
DH
PEM_GUY is offline   Reply With Quote

Old   September 19, 2014, 05:20
Default surface area of boundary
  #13
New Member
 
Caro
Join Date: Jul 2014
Posts: 15
Rep Power: 11
will_ca is on a distinguished road
I solved my problem below. It is working.


Hello,

I am using the coldEngine solver and I wanted to get the area of the cylinderwalls. The walls of the cylinder are definded as walls in a boundary patch called 'liner'. The mesh is changing over time and so is the surface of the liner.
This is the code I used:

#include "fvCFD.H"
#include "fvCFD.H"
#include "wallFvPatch.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:

int main(int argc, char *argv[])
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
timeSelector::addOptions();
#include "addRegionOption.H"
#include "setRootCase.H"
#include "createTime.H"
instantList timeDirs = timeSelector::select0(runTime, args);
#include "createNamedMesh.H"

forAll(timeDirs, timeI)
{
runTime.setTime(timeDirs[timeI], timeI);
Info<< "Time = " << runTime.timeName() << endl;
mesh.readUpdate();

label patchID = mesh.boundaryMesh().findPatchID("liner");

Info<<"\nsurface of liner "
<< gSum(mesh.magSf().boundaryField()[patchID])
<< endl;

}
Info<< "\nEnd\n" << endl;
return 0;
};


my problem now is that the results are wrong. They are much smaller than if I calculate the surface myself. I have checked everything I could think of, but haven't found the problem. I have checked the dimension of my cylinder in paraView and there the geometry is correct.
Does anyone know what the problem could be?
I would appreciate any help.
Ca

Last edited by will_ca; September 19, 2014 at 05:53. Reason: solved
will_ca is offline   Reply With Quote

Old   September 23, 2015, 05:25
Default
  #14
Member
 
Xinguang Wang
Join Date: Feb 2015
Posts: 45
Rep Power: 11
JasonWang3 is on a distinguished road
Hi Will

Do you know how to access all faces that are parallel to a wall?

I am using the code: label cellI = patch.faceCells()[faceI]; to access the cells next to a wall.

Jason
JasonWang3 is offline   Reply With Quote

Old   August 24, 2016, 07:52
Default
  #15
Member
 
Peng Liang
Join Date: Mar 2014
Posts: 59
Rep Power: 12
tjliang is on a distinguished road
Quote:
Originally Posted by PEM_GUY View Post
label patchID = mesh.boundaryMesh().findPatchID("NAME OF PATCH");

Info << "patchID = " << patchID << endl;

const polyPatch& cPatch = mesh.boundaryMesh()[patchID];

Info << "cPATCH = " << nl << cPatch << endl;

const surfaceScalarField& magSf = mesh.magSf();

scalar AREA = gSum(magSf.boundaryField()[patchID]);

Info << "AREA = " << nl << AREA << endl;

You might find it more efficient to do the following, it will avoid the need for additional looping. There is also the Foam::max and Foam::min function when needed to only sum more or less than a given value.

Cheers

DH
Hello David,

do you know how to access patch field value for example temperature?

Thanks in advance,

Peng
tjliang is offline   Reply With Quote

Old   November 10, 2019, 09:35
Default A question on how to execute the codes mentioned?
  #16
New Member
 
Ravi
Join Date: Nov 2019
Posts: 1
Rep Power: 0
Ravi_383 is on a distinguished road
Dear all,
I am very new to OpenFOAM and sorry for this stupid question.

This is my concern here for writing. @jaswi and @shivasub seem to have suggested that we should run a given code or line of codes to be able to get the data required. However, I do not understand how do we execute that code. Any help would be much appreciated?
Ravi_383 is offline   Reply With Quote

Old   May 4, 2020, 07:33
Default
  #17
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 355
Rep Power: 8
geth03 is on a distinguished road
Quote:
Originally Posted by Ravi_383 View Post
Dear all,
I am very new to OpenFOAM and sorry for this stupid question.

This is my concern here for writing. @jaswi and @shivasub seem to have suggested that we should run a given code or line of codes to be able to get the data required. However, I do not understand how do we execute that code. Any help would be much appreciated?
this is a more advanced topic which requires deeper knowledge regarding openfoam solver / library / BC / ... - programming.
you should first start with tutorials on openfoam wiki.
things will make sense soon.
geth03 is offline   Reply With Quote

Old   October 7, 2020, 10:30
Default
  #18
New Member
 
Tian Jin
Join Date: Aug 2020
Posts: 10
Rep Power: 5
Tian Jin is on a distinguished road
Hello, I have a stupid question: where should I put these code? In what file?
Quote:
Originally Posted by shivasub View Post
Jaswinder,

you can access each of the faces in this manner after getting specific patch.

forAll(cPatch, faceI)
{
//whatever you need to access here

}

regards
Shiva
Tian Jin 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
HELP NEEDED HOW TO MAP VALUES FROM PATCH OF ONE MESH TO PATCH OF ANOTHER MESH mkraposhin OpenFOAM Running, Solving & CFD 3 September 4, 2011 09:42
how to access a variable in DPM within a UDF patrick FLUENT 13 September 15, 2010 08:38
Gradients on surfaces or how to find neighbour faces for face on a patch tehache OpenFOAM Running, Solving & CFD 21 May 25, 2010 07:08
How to access the number of faces on a boundary jam OpenFOAM Running, Solving & CFD 1 January 20, 2008 13:13
[Technical] Mapping cell faces to other cell faces doug OpenFOAM Meshing & Mesh Conversion 5 March 30, 2007 02:43


All times are GMT -4. The time now is 11:47.