CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Meshing & Mesh Conversion (https://www.cfd-online.com/Forums/openfoam-meshing/)
-   -   [Technical] How to identify cell neighbours (https://www.cfd-online.com/Forums/openfoam-meshing/61906-how-identify-cell-neighbours.html)

su_junwei December 11, 2010 23:02

Quote:

Originally Posted by yashar.afarin (Post 287030)
Hi Su

how I could export my data so that I could specify and link for each point(cell centre) , the position(x,y,z) and velocity(u,v,w) variables of that point as a same file?

// include the head file
#include"OFstream.H"

//declare a object and out the variable you want. file.dat is the name of the //file you need.

OFstream os("file.dat");

forAll(mesh.C(), i)
{
os<<mesh.C()[i] <<" " <<u[i]<<endl;
}

yashar.afarin January 17, 2011 05:10

Hi SU

thank you very much for all of your helps.
I would appreciate if you could answer my question.
I have calculated Umean by introducing a function at system/controlDict of my case and I can see its contour with paraFoam.
how I could export it (UMean) to a .dat file, similar to my last question about U ?

su_junwei January 17, 2011 05:56

Quote:

Originally Posted by yashar.afarin (Post 290709)
Hi SU

thank you very much for all of your helps.
I would appreciate if you could answer my question.
I have calculated Umean by introducing a function at system/controlDict of my case and I can see its contour with paraFoam.
how I could export it (UMean) to a .dat file, similar to my last question about U ?

You don't have to process UMean. It should be in the time dir in your case.

yashar.afarin January 17, 2011 07:02

Quote:

Originally Posted by su_junwei (Post 290720)
You don't have to process UMean. It should be in the time dir in your case.

yes, it's there but I want to export it to a file.dat. according to your reply I export U of each point but I don't know how I could do that again for UMean?
I would appreciate if you could help me.

su_junwei January 17, 2011 07:55

Quote:

Originally Posted by yashar.afarin (Post 290732)
yes, it's there but I want to export it to a file.dat. according to your reply I export U of each point but I don't know how I could do that again for UMean?
I would appreciate if you could help me.

Just copy the internalField to a seperate file name *.dat

If you want to do it using a program, Just write a small tool for post processing. Read the file and write the internalField to a file

OFstream os("file.dat");

forAll(UMean.C(), i)
{
os<<mesh.C()[i] <<" " <<UMean[i]<<endl;
}

yashar.afarin January 17, 2011 08:35

Quote:

Originally Posted by su_junwei (Post 290748)
Just copy the internalField to a seperate file name *.dat

If you want to do it using a program, Just write a small tool for post processing. Read the file and write the internalField to a file

OFstream os("file.dat");

forAll(UMean.C(), i)
{
os<<mesh.C()[i] <<" " <<UMean[i]<<endl;
}

thank you very much for your reply.
I wrote the code that you sent for me in applications/solvers/incompressible/pisoFoam/pisoFoam.C
but when I compiled it, an error would be reported:
write.H:55: error: ‘UMean’ was not declared in this scope

I cant understand what is the problem, plz give me help!

yashar.afarin January 17, 2011 10:43

I am sorry. that was my silly reply. I know what you mean now. thanks for your reply.:o

daZigeiner February 22, 2011 14:53

problems with mesh.cellCells()
 
Quote:

Originally Posted by su_junwei (Post 181929)
Hi Khaled

mesh.cellCells()[cellI] gives the neighbours of cell cellI

su junwei

Hi Su

I'm just working on a possibility to refine locally on a selection of the mesh (blockMesh with refinementIterator). Since I have higher refinement levels I need to lay some buffer-layers around the selection. For this purpose I use the cellCells() function in multiple iterations.

My problem is that cellCells() does not recognize all neighbours of already refined cells (The refinement history I have implemented works fine and has no bugs) .

I'll give a little example:

- 8 cells (= refinement level 3) on the west side of a simple refined cell (= 2 cells f.e. cell A and B).
- this should give cell A as eastern neighbour for four of the tripple refined cells and cell B for the other four cells
- instead of this cellCells returns only cell A as eastern neighbour for all eight cells!!

And now the really big problem:

This bug is not reproduceable, since the correct recognition of all neighbours works fine in the mesh of forwardStep (tutorials/compressible/rhoCentralFo...), but not in the mesh of counterFlow2D (tutorials/combustion/reactingFoam...) :mad:

maysmech May 22, 2011 20:22

Quote:

Originally Posted by su_junwei (Post 287070)
// include the head file
#include"OFstream.H"

//declare a object and out the variable you want. file.dat is the name of the //file you need.

OFstream os("file.dat");

forAll(mesh.C(), i)
{
os<<mesh.C()[i] <<" " <<u[i]<<endl;
}

Hi Su,
Is it possible describe it more for me?
Where should be written this code and how should it be compiled?

su_junwei May 22, 2011 22:38

just write it in the time cycle. os declaration can be written in creatFields. H

You can write it like the following code

if(runTime.outputTime()) //only write at outputTime point
{
forAll(mesh.C(), i)
{
os<<mesh.C()[i] <<" " <<u[i]<<endl;
}
}

robingilbert January 7, 2012 18:24

Quote:

Originally Posted by kathrin_kissling (Post 283720)
Hi Pascal,

alternatively you can use

label labelOfClosestCell mesh.findCell(c y z);


Best Kathrin

Kathrin,

I am getting the following error when I use this:

Code:

transientSimpleFoam.C: In function ‘int main(int, char**)’:
transientSimpleFoam.C:123: error: expected initializer before ‘mesh’
transientSimpleFoam.C:124: error: ‘labelOfClosestCell’ was not declared in this scope

Any ideas why this is happening?

Thank you.

kathrin_kissling January 8, 2012 12:08

I think something is wrong with my formatting:
const point& location = (x,y,z); //your coordinates
label labelOfClosestCell=mesh.findCell(location);

Can you post your code?

Thanks!

Kathrin

robingilbert January 8, 2012 15:52

Kathrin,

Thanks for your reply. It was indeed the problem with the way I specified my location. I got it working.
Thank you.

impecca May 23, 2012 07:18

Hi, Junwei

I am trying to access the neighbour cells with parallel computing but it seems the cell which is placed adjacent to the interface between sub-domains does not recognize all neighbour cells.
I followed the same as you mentioned which is briefly (I am using OF-2.1.x),

mesh.cellCells()[cellI]

So I am wondering that you have a similar experience and is there any possible solution on this?

I also posted the question on this issue but I haven't got respose so far.

http://www.cfd-online.com/Forums/ope...computing.html


Thanks in advance.
Yusik

mathslw August 14, 2012 10:56

Quote:

Originally Posted by su_junwei (Post 283714)
Hi Pascal
you can use the following code

meshSearch ms(mesh);
label nearestCellIndex = ms.findNearestCell(p);

p is your point for searching nearest cell. nearestCellIndex is the cell index that you want.
Don't forget to include "meshSearch.H"

Junwei

Hi Junwei,

Could the p be a face in the internal field. If it could be, how can I define it?
Many thanks!

Wei

hawkeye321 October 2, 2012 12:39

X, Y and Z of each cell
 
hey, does anyone know how can I get the x, y and z of each cell?

mathslw September 23, 2013 20:44

Hi Junwei

As I see, the cellCells gives the list of index, my question is how could distinguish them?
thanks

Wei

Quote:

Originally Posted by su_junwei (Post 181929)
Hi Khaled

mesh.cellCells()[cellI] gives the neighbours of cell cellI

su junwei


su_junwei September 25, 2013 02:31

The return value is a list of index of neighbor cells. cells can be distinguished from another from cell index, cell center, etc.

CHARLES May 5, 2014 15:38

I'm confused about how to access a specific cell using cellCells. For example, how can I use cellCells to access the NORTH cell of each cell in my domain?

Here's an example of what I would like to do... I know that the code may not compile, I'm just trying to explain what I'm doing.

Code:

V=value; //V is a boundary field ('value' is calculated and varies across the domain)

forAll(U, celli)
{
U[celli]=V[celli];
U[NORTH of celli] = U[celli];
}


babakflame December 19, 2014 01:58

Quote:

Originally Posted by su_junwei (Post 283714)
Hi Pascal
you can use the following code

meshSearch ms(mesh);
label nearestCellIndex = ms.findNearestCell(p);

p is your point for searching nearest cell. nearestCellIndex is the cell index that you want.
Don't forget to include "meshSearch.H"

Junwei


Greeting Su

Is it possible to detail your hint more clearly?
I guess that the meshSearch.H should be added to the main code for instance reactingFoam.C . But what about

Code:

meshSearch ms(mesh);
    label nearestCellIndex = ms.findNearestCell(p);

Where should I add these lines?

Thanks for your hints.


Best,
Bobi


All times are GMT -4. The time now is 18:33.