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/)
-   -   Access to cellid in cellSet (https://www.cfd-online.com/Forums/openfoam-programming-development/158104-access-cellid-cellset.html)

Tobi August 15, 2015 10:49

Access to cellid in cellSet
 
Hello all,

If I read a cellSet like:
Code:

cellSet foobar(mesh, nameOfSet);
it will read the cellSet in constant/polyMesh/sets/nameOfSet.
I did not figure it out how to get access to the values of the cellSet (cellId 's)?

Any suggestion would be appreciated.

ssss August 15, 2015 12:07

As cellSet is a topoSet child class class maybe you can have a look in the way they use iterators and labels in topoSet, for example in the functions:

Foam::topoSet::invert
Foam::topoSet::updateLabels

Sorry that I cannot help you more, as my C++ knowledge is pretty basic

Tobi August 15, 2015 14:27

Thanks for the replay.
I also checked topoSet in doxygen but I did not find any function. There has to be a way :D
Foam is so awesome but I do not know the classes very well.

Tobi August 15, 2015 14:43

Solved!

As always soooo easy. I wanted to have access only to the cellSet cells in some postProcessing. Due to the fact that cellSet is inherit by a hash table.
Therefore I get it with that:
Code:


cellSet test(mesh, nameOfSet);

forAll(mesh.C(), id)
{
    if  (test[id])
    {
          //- Only get the cells which are included in the cellSet
    }
}


yehaixuan September 13, 2016 11:24

Quote:

Originally Posted by Tobi (Post 559691)
Solved!

As always soooo easy. I wanted to have access only to the cellSet cells in some postProcessing. Due to the fact that cellSet is inherit by a hash table.
Therefore I get it with that:
Code:


cellSet test(mesh, nameOfSet);

forAll(mesh.C(), id)
{
    if  (test[id])
    {
          //- Only get the cells which are included in the cellSet
    }
}


Just for completeness. Your solution will loop all the cells. In my opinion, it may not be efficient when the cellSet is only a small portion of the mesh.

I suggest to use test.toc() to access the contents of the table directly.

Code:

test.toc()

chengyu April 16, 2017 21:05

Use the native access method provided by OpenFOAM
 
Hey guys,
I am also looking for the access method to cellSet, after digging into the code, I found a native way provided by OpenFOAM in the file fvOption.C, see the lines (147-148) and lines (236-240). For convenience, I paste the code here
Code:


          cellSet selectedCells(mesh_, cellSetName_);
          cells_ = selectedCells.toc();

Code:

        V_ = 0.0;
        forAll(cells_, i)
        {
            V_ += mesh_.V()[cells_[i]];
        }



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