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

Getting cell ID from Patches

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 1 Post By Anne Lincke
  • 1 Post By Anne Lincke
  • 1 Post By vonboett
  • 1 Post By Anne Lincke
  • 1 Post By gschaider

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 29, 2010, 10:04
Red face Getting cell ID from Patches
  #1
Senior Member
 
Anne Gerdes
Join Date: Aug 2010
Location: Hamburg
Posts: 168
Rep Power: 15
Anne Lincke is on a distinguished road
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
Anne Lincke is offline   Reply With Quote

Old   April 13, 2012, 11:46
Default
  #2
New Member
 
Darío López
Join Date: Oct 2011
Location: Vigo, Spain
Posts: 10
Rep Power: 14
darlopez is on a distinguished road
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.
darlopez is offline   Reply With Quote

Old   April 16, 2012, 05:44
Default
  #3
Senior Member
 
Anne Gerdes
Join Date: Aug 2010
Location: Hamburg
Posts: 168
Rep Power: 15
Anne Lincke is on a distinguished road
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.
Anne Lincke is offline   Reply With Quote

Old   November 16, 2012, 13:19
Default
  #4
Member
 
Jamal
Join Date: May 2012
Location: Freiburg
Posts: 54
Rep Power: 12
aujamal20 is an unknown quantity at this point
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
aujamal20 is offline   Reply With Quote

Old   December 11, 2012, 05:30
Default
  #5
Senior Member
 
Anne Gerdes
Join Date: Aug 2010
Location: Hamburg
Posts: 168
Rep Power: 15
Anne Lincke is on a distinguished road
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
Anne Lincke is offline   Reply With Quote

Old   May 9, 2013, 09:30
Default
  #6
Senior Member
 
Mojtaba.a's Avatar
 
Mojtaba Amiraslanpour
Join Date: Jun 2011
Location: Tampa, US
Posts: 308
Rep Power: 15
Mojtaba.a is on a distinguished road
Send a message via Skype™ to Mojtaba.a
Quote:
Originally Posted by Anne Lincke View Post
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
__________________
Learn OpenFOAM in Persian
SFO (StarCCM+ FLUENT OpenFOAM) Project Team Member
Complex Heat & Flow Simulation Research Group
If you can't explain it simply, you don't understand it well enough. "Richard Feynman"
Mojtaba.a is offline   Reply With Quote

Old   May 10, 2013, 07:53
Default
  #7
Member
 
Jamal
Join Date: May 2012
Location: Freiburg
Posts: 54
Rep Power: 12
aujamal20 is an unknown quantity at this point
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
aujamal20 is offline   Reply With Quote

Old   May 10, 2013, 13:21
Default
  #8
Senior Member
 
Mojtaba.a's Avatar
 
Mojtaba Amiraslanpour
Join Date: Jun 2011
Location: Tampa, US
Posts: 308
Rep Power: 15
Mojtaba.a is on a distinguished road
Send a message via Skype™ to Mojtaba.a
Quote:
Originally Posted by aujamal20 View Post
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
Dear Jamal, thanks for your reply.
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
__________________
Learn OpenFOAM in Persian
SFO (StarCCM+ FLUENT OpenFOAM) Project Team Member
Complex Heat & Flow Simulation Research Group
If you can't explain it simply, you don't understand it well enough. "Richard Feynman"
Mojtaba.a is offline   Reply With Quote

Old   May 13, 2013, 03:23
Default
  #9
Senior Member
 
Anne Gerdes
Join Date: Aug 2010
Location: Hamburg
Posts: 168
Rep Power: 15
Anne Lincke is on a distinguished road
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.
Anne Lincke is offline   Reply With Quote

Old   May 13, 2013, 12:09
Default
  #10
Senior Member
 
Mojtaba.a's Avatar
 
Mojtaba Amiraslanpour
Join Date: Jun 2011
Location: Tampa, US
Posts: 308
Rep Power: 15
Mojtaba.a is on a distinguished road
Send a message via Skype™ to Mojtaba.a
Quote:
Originally Posted by Anne Lincke View Post
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?
__________________
Learn OpenFOAM in Persian
SFO (StarCCM+ FLUENT OpenFOAM) Project Team Member
Complex Heat & Flow Simulation Research Group
If you can't explain it simply, you don't understand it well enough. "Richard Feynman"
Mojtaba.a is offline   Reply With Quote

Old   May 14, 2013, 04:14
Default Getting cell IDs from patches
  #11
Senior Member
 
Albrecht vBoetticher
Join Date: Aug 2010
Location: Zürich, Swizerland
Posts: 237
Rep Power: 16
vonboett is on a distinguished road
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<numNodes;i++){
nodeCoords[j ] = patchPoints[i].x();
nodeCoords[j+1] = patchPoints[i].y();
nodeCoords[j+2] = patchPoints[i].z();
j=j+3;
}

// write nodeCoords to file named 'nodeCoord'
OFstream nodeCoordFile(runTime.path()/"nodeCoord");
j=0;
for(int i=0;i<numNodes;i++)
{
nodeCoordFile << nodeCoords[j ] <<'\t'
<< nodeCoords[j+1] <<'\t'
<< nodeCoords[j+2] << endl;
j=j+3;
}


the cells of the patch you get with:
const labelList& patchCells = mesh.boundaryMesh()[coupledPatchID].faceCells();



If it is to find cells within the mesh due to the space they lie in:

// Loop over all the cells in the mesh:
forAll(mesh.cells(), cellI)
const vector& cellCenter = mesh.C()[cellI];
const scalar x = cellCenter[0];
const scalar y = cellCenter[1];
const scalar z = cellCenter[2];
if ( x < //... && y ... && z ... all your restrictions where the cells you need are situated)
label selectedCellID = cellI;
Mojtaba.a likes this.

Last edited by vonboett; May 14, 2013 at 04:37.
vonboett is offline   Reply With Quote

Old   May 15, 2013, 03:50
Default
  #12
Senior Member
 
Anne Gerdes
Join Date: Aug 2010
Location: Hamburg
Posts: 168
Rep Power: 15
Anne Lincke is on a distinguished road
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.
Anne Lincke is offline   Reply With Quote

Old   May 15, 2013, 09:21
Default
  #13
Senior Member
 
Mojtaba.a's Avatar
 
Mojtaba Amiraslanpour
Join Date: Jun 2011
Location: Tampa, US
Posts: 308
Rep Power: 15
Mojtaba.a is on a distinguished road
Send a message via Skype™ to Mojtaba.a
Quote:
Originally Posted by vonboett View Post
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 View Post
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:
http://www.cfd-online.com/Forums/ope...tml#post427038

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 "<cond>"
(for <cond> 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
__________________
Learn OpenFOAM in Persian
SFO (StarCCM+ FLUENT OpenFOAM) Project Team Member
Complex Heat & Flow Simulation Research Group
If you can't explain it simply, you don't understand it well enough. "Richard Feynman"
Mojtaba.a is offline   Reply With Quote

Old   May 15, 2013, 09:36
Default
  #14
Senior Member
 
Anne Gerdes
Join Date: Aug 2010
Location: Hamburg
Posts: 168
Rep Power: 15
Anne Lincke is on a distinguished road
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?
Anne Lincke is offline   Reply With Quote

Old   May 15, 2013, 19:41
Default
  #15
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Mojtaba.a View Post
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:
http://www.cfd-online.com/Forums/ope...tml#post427038

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
gschaider is offline   Reply With Quote

Old   May 16, 2013, 05:15
Default
  #16
Senior Member
 
Mojtaba.a's Avatar
 
Mojtaba Amiraslanpour
Join Date: Jun 2011
Location: Tampa, US
Posts: 308
Rep Power: 15
Mojtaba.a is on a distinguished road
Send a message via Skype™ to Mojtaba.a
Quote:
Originally Posted by Anne Lincke View Post
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 View Post
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?

Thanks for your valuable time,

Best wishes,
Mojtaba
__________________
Learn OpenFOAM in Persian
SFO (StarCCM+ FLUENT OpenFOAM) Project Team Member
Complex Heat & Flow Simulation Research Group
If you can't explain it simply, you don't understand it well enough. "Richard Feynman"
Mojtaba.a is offline   Reply With Quote

Old   May 16, 2013, 05:45
Default
  #17
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Mojtaba.a View Post
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)
Mojtaba.a likes this.
__________________
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
gschaider is offline   Reply With Quote

Old   May 16, 2013, 14:28
Default
  #18
Senior Member
 
Mojtaba.a's Avatar
 
Mojtaba Amiraslanpour
Join Date: Jun 2011
Location: Tampa, US
Posts: 308
Rep Power: 15
Mojtaba.a is on a distinguished road
Send a message via Skype™ to Mojtaba.a
Quote:
Originally Posted by gschaider View Post
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
__________________
Learn OpenFOAM in Persian
SFO (StarCCM+ FLUENT OpenFOAM) Project Team Member
Complex Heat & Flow Simulation Research Group
If you can't explain it simply, you don't understand it well enough. "Richard Feynman"
Mojtaba.a 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
How to determine the direction of cell face vectors on processor patches sebastian_vogl OpenFOAM Programming & Development 1 October 11, 2016 13:17
Cells with t below lower limit Purushothama Siemens 2 May 31, 2010 21:58
How to determine the direction of cell face vectors on processor patches sebastian_vogl OpenFOAM Running, Solving & CFD 0 October 27, 2009 08:47
[Commercial meshers] Trimmed cell and embedded refinement mesh conversion issues michele OpenFOAM Meshing & Mesh Conversion 2 July 15, 2005 04:15
Warning 097- AB Siemens 6 November 15, 2004 04:41


All times are GMT -4. The time now is 09:42.