CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   Getting cell ID from Patches (http://www.cfd-online.com/Forums/openfoam/82547-getting-cell-id-patches.html)

Anne Lincke November 29, 2010 11:04

Getting cell ID from Patches
 
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

darlopez April 13, 2012 11:46

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.

Anne Lincke April 16, 2012 05:44

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.

aujamal20 November 16, 2012 14:19

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

Anne Lincke December 11, 2012 06:30

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

Mojtaba.a May 9, 2013 09:30

Quote:

Originally Posted by Anne Lincke (Post 396869)
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

aujamal20 May 10, 2013 07:53

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

Mojtaba.a May 10, 2013 13:21

Quote:

Originally Posted by aujamal20 (Post 426511)
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

Anne Lincke May 13, 2013 03:23

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 May 13, 2013 12:09

Quote:

Originally Posted by Anne Lincke (Post 427088)
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?

vonboett May 14, 2013 04:14

Getting cell IDs from patches
 
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;

Anne Lincke May 15, 2013 03:50

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 May 15, 2013 09:21

Quote:

Originally Posted by vonboett (Post 427348)
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 (Post 427636)
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

Anne Lincke May 15, 2013 09:36

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?

gschaider May 15, 2013 19:41

Quote:

Originally Posted by Mojtaba.a (Post 427742)
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

Mojtaba.a May 16, 2013 05:15

Quote:

Originally Posted by Anne Lincke (Post 427748)
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 (Post 427855)
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

gschaider May 16, 2013 05:45

Quote:

Originally Posted by Mojtaba.a (Post 427946)
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 May 16, 2013 14:28

Quote:

Originally Posted by gschaider (Post 427960)
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


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