CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   All cells connected via edge to cell. (https://www.cfd-online.com/Forums/openfoam-programming-development/140734-all-cells-connected-via-edge-cell.html)

sebastien_F1 August 21, 2014 18:01

All cells connected via edge to cell.
 
Hi everyone,

I would like to calculate the average of neighbour cells connected by edge. I already know how to do the average of neighbour cells connected by face:

labelListList neighbour = this->mesh().cellCells();

However, I cannot find those connected by edge.

Let me know if you have any hint.
Best,
Sebastien

kmooney August 21, 2014 21:05

Quote:

Originally Posted by sebastien_F1 (Post 507140)
Hi everyone,

I would like to calculate the average of neighbour cells connected by edge. I already know how to do the average of neighbour cells connected by face:

labelListList neighbour = this->mesh().cellCells();

However, I cannot find those connected by edge.

Let me know if you have any hint.
Best,
Sebastien

Hi Sebastien,

You could start by taking a look at /src/OpenFOAM/lnInclude/primitiveMesh.H

There you should be able to spot a lot of useful connectivity information, including the cellCells function which you seem to have already discovered.

With a combination of edgeCells and cellEdges you should be able to assemble a data structure which suits your needs.

I hope that helps!
Cheers,
Kyle

sebastien_F1 August 27, 2014 12:22

Hi Kyle,

Thanks for the advice. I have already explored this class. But I was wondering if someone already put all the piece together and do a smart filtering to not count for duplicate cells.

I did it. Here is my piece of code to calculate average with cells connected by edge or points.

Quote:

/****Calculate an average temperature with neighboor cells****/

avgT_ = dimensionedScalar("b",dimTemperature,0.0);

forAll(T_tilde_.internalField(),celli)
{
// Construct cellEdges
DynamicList<label> cellStorage;
//labelList neighborEdge = this->mesh().cellEdges()[celli];
labelList neighborEdge = this->mesh().cellPoints()[celli];

cellStorage.clear();

//Do quadratic insertion
forAll(neighborEdge, edgej)
{
//labelList neighborCell = this->mesh().edgeCells()[neighborEdge[edgej]];
labelList neighborCell = this->mesh().pointCells()[neighborEdge[edgej]];

forAll(neighborCell, cellj)
{
label ownCellI = neighborCell[cellj];

//Check if not already in storage
forAll(cellStorage, j)
{
if(cellStorage[j] == ownCellI)
{
ownCellI = -1;
break;
}
}
//if not, add to the storage list
if (ownCellI != -1)
{
cellStorage.append(ownCellI);
}
}
}
// Calculate the average of cells connected via edge or points
forAll(cellStorage, cellk)
{
avgT_[celli] += T_tilde_[cellStorage[cellk]];
}
avgT_[celli] /= cellStorage.size();
//Info << "Cell neighboor = " << cellStorage.size() << endl;
//Info << "Cell = " << celli << endl;
}
/************************************************** ******/
Best
Sebastien

ngj August 27, 2014 13:27

Hi Sebastian,

A small word of warning:

Your averaging is based on the number of cells with a uniform weighting. You might want to perform a weighting by cell volumes on non-equidistant meshes.

You can also find the volume in the primitive mesh class, which Kyle pointed to.

Kind regards,

Niels


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