# Getting cell ID from Patches

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

 November 29, 2010, 11:04 Getting cell ID from Patches #1 Senior Member   Anne Gerdes Join Date: Aug 2010 Location: Hamburg Posts: 168 Rep Power: 8 Hey to all, I need a little help. I have written a little postProcessing Tool which works similar to WallShearStress, i.e. it computes a gradient at the wall. Now I need to treat these gradients which are computed at each node of the boundary as a n-dimensional vector which has to me multiplied by a 3xn matrix (!) which I get from another program (ANSA). I have not yet computed this matrix but I ask how shall I compute the vector with the matrix if I do not know how my vector is sorted. So my question is: How do I get the cellID for each value in order to be able to sort it? Cell ID is just the first which came to my mind, any criteria how to sort this vector would help me because I need it to be sorted if I want to multiply it with the matrix. Do you have any ideas? Thank you very much in advance. Anne

 April 13, 2012, 11:46 #2 New Member   Darío López Join Date: Oct 2011 Location: Vigo, Spain Posts: 10 Rep Power: 6 Hi Anne. Have you resolved your problem?? I am interesting in find the cellID's from Patches in order to program a Simpson rule. Do you have any suggestion? Regards. Darío.

 April 16, 2012, 05:44 #3 Senior Member   Anne Gerdes Join Date: Aug 2010 Location: Hamburg Posts: 168 Rep Power: 8 Hey Dario, I solved my problem by outputting the x-y-and z- coordinate of each cell. Then I sorted the cells in the unix shell with sort -k1 -k2 -k3. The result is a sorted vector, first sort criteria x-coordinate, second one y-coordinate and third one z-coordinate so that it is a clear order. You can also look at the sample-utility of OpenFOAM, maybe this can help. So far, I do not know another solution. darlopez likes this.

 November 16, 2012, 14:19 #4 Member   Jamal Join Date: May 2012 Location: Freiburg Posts: 54 Rep Power: 5 Dear I am a new user to OF. I am facing a problem to get Cell ID or cell coordinates so that i can get field values at prescribed locations. I need to know what to use and where to use a code/file to get this. Thanks aujamal

 December 11, 2012, 06:30 #5 Senior Member   Anne Gerdes Join Date: Aug 2010 Location: Hamburg Posts: 168 Rep Power: 8 Hey Aujamal, you can output the data with Paraview. For my result-analysis I did the following steps 1.) In time folder delete all properties which are not needed (k, epsilon, whatever) 2.) Run foamToVTK 3.) Open the VTK-folder with paraview. 4.) Extract the regions, which you would like to analyze, with slice/clip or other filter tools. 5.) Output the data with File -> Save Data -> Points as .csv - File. 6.) In the csv-File you will find the x,y and z-coorindates and the respective values for velocity, pressure 7.) You can now sort the data, plot it, analyze it, whatever. I hope this helped? Kind Regards Anne

May 9, 2013, 09:30
#6
Senior Member

Mojtaba Amiraslanpour
Join Date: Jun 2011
Location: Zanjan, Iran
Posts: 287
Rep Power: 8
Quote:
 Originally Posted by Anne Lincke Hey Aujamal, you can output the data with Paraview. For my result-analysis I did the following steps ...
Dear Anne,

Hi, do you have any idea in how to get cell IDs of the cells (face cells) which are located in a specific region (which is extracted using slice/clip tools)?
I want to use these cell IDs to be able to use nonUniform BC.
for example I have a large domain. in a specific region of this domain I want x_value to be 0.1 and for the rest of the domain I want x_value to be 0.2.
Do you have any idea how can I achieve this? I am trying to know cell IDs of the specific region in order to assign these cells my desired values, later.

Thank you,
Mojtaba
__________________
Complex Heat & Flow Simulation Research Group
If you can't explain it simply, you don't understand it well enough. "Richard Feynman"

 May 10, 2013, 07:53 #7 Member   Jamal Join Date: May 2012 Location: Freiburg Posts: 54 Rep Power: 5 Hello Mojtaba, I am not sure what you really want to do, but the utility setFieldsDict might help you in this regard to set the particular values of the field variable at different locations/(set of cells) within the domain. Please let me know if find any alternate. Thanks

May 10, 2013, 13:21
#8
Senior Member

Mojtaba Amiraslanpour
Join Date: Jun 2011
Location: Zanjan, Iran
Posts: 287
Rep Power: 8
Quote:
 Originally Posted by aujamal20 Hello Mojtaba, I am not sure what you really want to do, but the utility setFieldsDict might help you in this regard to set the particular values of the field variable at different locations/(set of cells) within the domain. Please let me know if find any alternate. Thanks
Well I am trying to define a nonUniform boundary condition. as you know nonUniform boundary condition has a form like this:

value nonuniform List<scalar>
'No.ofOverallCells'
(
//data entered here
);

Unfortunately In OF I couldn't find any order for numbering of the cells and thus I don't know how to write the list. For instance I have a nonUniform boundary like this:

value nonuniform List<scalar>
5
(
1
2
3
4
5
);

How can I know that which cell in boundary has the value of '1' or any other values? actually I have found the solution to this particular issue, and that's by using paraview, but it is not applicable for boundaries with large number of cells. Do you have any idea how I can set value for each cell in a boundary?

In addition I haven't used setFields utility yet, I don't know if it is capable of selecting my desired group of cells. my cell region is not a common shape like rectangular or circle to define it easily. Therefor I don't know how to define it using setFields.

Thank you,
Mojtaba
__________________
Complex Heat & Flow Simulation Research Group
If you can't explain it simply, you don't understand it well enough. "Richard Feynman"

 May 13, 2013, 03:23 #9 Senior Member   Anne Gerdes Join Date: Aug 2010 Location: Hamburg Posts: 168 Rep Power: 8 Hey Mojtaba, I set the values with setFieldsDict concerning the internal Field. So far I have not used a non-uniform condition on the boundary itself. I got the numbers of the cells with paraview as I wrote before.... why doesn't this work in your case? Here is an example of a setFieldsDict. It sets alpha equal to 200 on the cellSet face_hole_1 and zero elsewhere. You can generate the cellSet from a cellZone in polyMesh/cellZones where you define it with the numbers obtained from paraview. I hope this helps.... Kind Regards Anne HTML Code: ```/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 1.7.0 | | \\ / A nd | Web: www.OpenFOAM.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location "system"; object setFieldsDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // defaultFieldValues ( volScalarFieldValue alpha 0 ) ; regions ( cellToCell { set face_hole_1; fieldValues ( volScalarFieldValue alpha 200 ); } )``` Mojtaba.a likes this.

May 13, 2013, 12:09
#10
Senior Member

Mojtaba Amiraslanpour
Join Date: Jun 2011
Location: Zanjan, Iran
Posts: 287
Rep Power: 8
Quote:
 Originally Posted by Anne Lincke Hey Mojtaba, I set the values with setFieldsDict concerning the internal Field. So far I have not used a non-uniform condition on the boundary itself. I got the numbers of the cells with paraview as I wrote before.... why doesn't this work in your case?
Thank you Anne,
Well this really helped. My problem is a little bit different.
Here is the boundary I am trying to define in nut boundary condition file.

ground
{
type nutkAtmRoughWallFunction;
z0 \$z0;
value uniform 0.0;
}

I have different z0 values for different cellSets. As far as z0 is not directly a field (correct me if I am wrong about this), I can not use setFields utility to set values for it. Therefore I am trying to use nonUniform BC which I got to know cell positions.
As you mentioned I can find cell numbers in paraview, but I need to sort the list manually for nonUniform BC.
Do you have any idea that how can I set this?
__________________
Complex Heat & Flow Simulation Research Group
If you can't explain it simply, you don't understand it well enough. "Richard Feynman"

 May 14, 2013, 04:14 Getting cell IDs from patches #11 Senior Member   Albrecht vBoetticher Join Date: Aug 2010 Location: Zürich, Swizerland Posts: 211 Rep Power: 9 Maybe this code snippet helps, I once had to implement fludi structure interaction between InderDyMFoam and a DEM code so I needed the nodes of the boundary. I define the Patch name in a couplingProperties dictionary in constant folder and write the node coordinates to a file. The advantage is that it allows you to adress more things than yust coordinates once you added the code. Part of the code was written at the chair of structural analysis at TU Munich (TUM) //open dictionary couplingProperties in directory: casename/constant IOdictionary couplingProperties ( IOobject ( "couplingProperties", runTime.constant(), mesh, IOobject::MUST_READ, IOobject::NO_WRITE ) ); word coupledPatchName = couplingProperties.lookup("coupledPatchName"); label coupledPatchID=mesh.boundaryMesh().findPatchID(cou pledPatchName); scalar interval = readScalar(couplingProperties.lookup("interactionI nterval")); //pointer to points and faces const pointField& patchPoints = mesh.boundaryMesh()[coupledPatchID].localPoints(); //const faceList& patchFaces = mesh.boundaryMesh()[coupledPatchIDs].localFaces(); //typeFace[patchI]=patchFaces[0].size(); int numNodes = patchPoints.size(); nodeCoords = new double[3*numNodes]; int j=0; for(int i=0;i

 May 15, 2013, 03:50 #12 Senior Member   Anne Gerdes Join Date: Aug 2010 Location: Hamburg Posts: 168 Rep Power: 8 I think "setFields" will work, as is sets values depending on the cellZones/cellSets that you define. But the problem will be to define those cellZones. What do you mean with different values for z0? What is z0? There are possibilities in OpenFoam to define cellZones with "cellSet" and a proper cellSetDict for example all cells inside a defined box. How do the cellZones that you want to generate look like? Kind Regards Anne Mojtaba.a likes this.

May 15, 2013, 09:21
#13
Senior Member

Mojtaba Amiraslanpour
Join Date: Jun 2011
Location: Zanjan, Iran
Posts: 287
Rep Power: 8
Quote:
 Originally Posted by vonboett Maybe this code snippet helps, I once had to implement fludi structure interaction between InderDyMFoam and a DEM code so I needed the nodes of the boundary. I define the Patch name in a couplingProperties dictionary in constant folder and write the node coordinates to a file. The advantage is that it allows you to adress more things than yust coordinates once you added the code. Part of the code was written at the chair of structural analysis at TU Munich (TUM)
Thank you Albrecht.
This is interesting. Let me compile the code to see if it can help me solve my problem.

Quote:
 Originally Posted by Anne Lincke I think "setFields" will work, as is sets values depending on the cellZones/cellSets that you define. But the problem will be to define those cellZones. What do you mean with different values for z0? What is z0? There are possibilities in OpenFoam to define cellZones with "cellSet" and a proper cellSetDict for example all cells inside a defined box. How do the cellZones that you want to generate look like? Kind Regards Anne
Thank you Anne,
Well z0 is the roughness parameter for any wall type BC. this roughness values are defined in nut file.
Maybe I was not clear in my last post. The BC is something like this:

nut
----------
ground
{
type nutkAtmRoughWallFunction;
z0 uniform 0.1;
value uniform 0.0;
}

Or if I want a nonUniform distribution of z0, I have something like this:

ground
{
type nutkAtmRoughWallFunction;
z0 nonuniform List<scalar>
5
(
0.1
0.1
0.2
0.3
0.3
);
value uniform 0.0;
}

I am new to setFields utility. my region is surrounded by straight lines. For example a region which is surrounded by:

y=0
x=0
y=-x+1

In this post:
non-uniform internalField

gschaider has solved this problem for me. As he says:

Quote:
 That can be easily done with a condition like this in funkySetFields: Code: `(pos().y>0) && (pos().x>0) && ((pos().x+pos().y)<1)` Either you use it in a condition if you want the rest of the field unchanged Code: `funkySetFields -time 0 -field alpha -keepPatches -expression "1" -condition ""` (for insert the above expression)
As you see in this code, field of alpha will be set to values of 1 in the specified region.
In my case (to set values of z0) what will be the replacement for alpha?
Or generally how this code will work for me to set values of z0 in nut file?

Warmest Wishes,
Mojtaba
__________________
Complex Heat & Flow Simulation Research Group
If you can't explain it simply, you don't understand it well enough. "Richard Feynman"

 May 15, 2013, 09:36 #14 Senior Member   Anne Gerdes Join Date: Aug 2010 Location: Hamburg Posts: 168 Rep Power: 8 I am not familiar with funkySetFields. But if it is possible to apply this to a field alpha, you can also run it for a field z0 and then transfer the z0 to the nut-environment (simplest but not very elegant way: just copy the non-uniform list to the nut-environment. But there have to be other possibilities). The z0 has different values in your case (0.1, 0.2,...). Is there a function how this z0 is computed? Is it related for example to "x"- or "y"-coordinates?

May 15, 2013, 19:41
#15
Assistant Moderator

Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,934
Rep Power: 41
Quote:
 Originally Posted by Mojtaba.a Thank you Anne, Well z0 is the roughness parameter for any wall type BC. this roughness values are defined in nut file. Maybe I was not clear in my last post. The BC is something like this: nut ---------- ground { type nutkAtmRoughWallFunction; z0 uniform 0.1; value uniform 0.0; } Or if I want a nonUniform distribution of z0, I have something like this: ground { type nutkAtmRoughWallFunction; z0 nonuniform List 5 ( 0.1 0.1 0.2 0.3 0.3 ); value uniform 0.0; } I am new to setFields utility. my region is surrounded by straight lines. For example a region which is surrounded by: y=0 x=0 y=-x+1 In this post: non-uniform internalField gschaider has solved this problem for me. As he says: As you see in this code, field of alpha will be set to values of 1 in the specified region. In my case (to set values of z0) what will be the replacement for alpha? Or generally how this code will work for me to set values of z0 in nut file? Warmest Wishes, Mojtaba
Sorry. It's late and I'm not going to read the whole thread. But if this is about setting z0 non-uniformly then funkySetBoundaryFields may help ... if z0 is not changing afterwards
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request

May 16, 2013, 05:15
#16
Senior Member

Mojtaba Amiraslanpour
Join Date: Jun 2011
Location: Zanjan, Iran
Posts: 287
Rep Power: 8
Quote:
 Originally Posted by Anne Lincke I am not familiar with funkySetFields. But if it is possible to apply this to a field alpha, you can also run it for a field z0 and then transfer the z0 to the nut-environment (simplest but not very elegant way: just copy the non-uniform list to the nut-environment. But there have to be other possibilities). The z0 has different values in your case (0.1, 0.2,...). Is there a function how this z0 is computed? Is it related for example to "x"- or "y"-coordinates?
Thank you Anne,
I haven't tried this method yet. Let me see if it works.
Well as I said my region is surrounded by multiple straight lines which these lines themselves have functions. For example y=-x+1 is one border.

Quote:
 Originally Posted by gschaider Sorry. It's late and I'm not going to read the whole thread. But if this is about setting z0 non-uniformly then funkySetBoundaryFields may help ... if z0 is not changing afterwards
Thank you gschaider,
Well z0 is not changing (Thanks god ). I am not familiar with this tool. is it similar to funkySetFields? can you give me a little sample on how I can use this?

Best wishes,
Mojtaba
__________________
Complex Heat & Flow Simulation Research Group
If you can't explain it simply, you don't understand it well enough. "Richard Feynman"

May 16, 2013, 05:45
#17
Assistant Moderator

Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,934
Rep Power: 41
Quote:
 Originally Posted by Mojtaba.a Thank you Anne, I haven't tried this method yet. Let me see if it works. Well as I said my region is surrounded by multiple straight lines which these lines themselves have functions. For example y=-x+1 is one border. Thank you gschaider, Well z0 is not changing (Thanks god ). I am not familiar with this tool. is it similar to funkySetFields? can you give me a little sample on how I can use this? Thanks for your valuable time, Best wishes, Mojtaba
It is quite similar to funkySetFields but is only usable with a dictionary (specifying stuff on the command line would be a nightmare). There is an example in (you won't believe it) the Examples-folder of swak4Foam. An Excerpt of that example file is
Code:
```dropIn {
field alpha1;
expressions
(
{
target inletValue;
patchName atmosphere;
variables "maxX=max(pts().x);thres1=0.4*maxX;thres2=0.6*maxX;";
expression "(pos().x>thres1 && pos().x<thres2) ? 1 : 0";
}
);
}```
Which basically say "on the patch 'atmosphere' of 'alpha1' calculate 'expression' and then set the value of 'inletValue' on that patch to the result". Mind you: it doesn't check what is actually NEEDED there (if inletValue needed a single vector you'll get errors when the solver starts)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request

May 16, 2013, 14:28
#18
Senior Member

Mojtaba Amiraslanpour
Join Date: Jun 2011
Location: Zanjan, Iran
Posts: 287
Rep Power: 8
Quote:
 Originally Posted by gschaider It is quite similar to funkySetFields but is only usable with a dictionary (specifying stuff on the command line would be a nightmare). There is an example in (you won't believe it) the Examples-folder of swak4Foam. An Excerpt of that example file is
Thank you, I think this can solve my problem.
I got to play with it a little bit to see how it works.

Thank you very much gschaider, Anne and anybody who helped me here.

Best wishes,
Mojtaba
__________________
Complex Heat & Flow Simulation Research Group
If you can't explain it simply, you don't understand it well enough. "Richard Feynman"

 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 Purushothama CD-adapco 2 May 31, 2010 21:58 sebastian_vogl OpenFOAM Running, Solving & CFD 0 October 27, 2009 09:47 sebastian_vogl OpenFOAM Programming & Development 0 October 26, 2009 13:10 michele OpenFOAM Other Meshers: ICEM, Star, Ansys, Pointwise, GridPro, Ansa, ... 2 July 15, 2005 04:15 AB CD-adapco 6 November 15, 2004 05:41

All times are GMT -4. The time now is 06:56.