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 ndimensional 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 
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. 
Hey Dario,
I solved my problem by outputting the xyand 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 xcoordinate, second one ycoordinate and third one zcoordinate so that it is a clear order. You can also look at the sampleutility of OpenFOAM, maybe this can help. So far, I do not know another solution. 
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 
Hey Aujamal,
you can output the data with Paraview. For my resultanalysis 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 VTKfolder 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 csvFile you will find the x,y and zcoorindates 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 
Quote:
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 
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 
Quote:
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 
Hey Mojtaba,
I set the values with setFieldsDict concerning the internal Field. So far I have not used a nonuniform 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++ **\ 
Quote:
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? 
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; 
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 
Quote:
This is interesting. Let me compile the code to see if it can help me solve my problem. :) Quote:
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.cfdonline.com/Forums/ope...tml#post427038 gschaider has solved this problem for me. As he says: Quote:
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 
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 nutenvironment (simplest but not very elegant way: just copy the nonuniform list to the nutenvironment. 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? 
Quote:

Quote:
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:
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 
Quote:
Code:
dropIn { 
Quote:
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 14:47. 