CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Finding list of cells according to a condition (https://www.cfd-online.com/Forums/openfoam-solving/71199-finding-list-cells-according-condition.html)

alberto December 18, 2009 23:48

Finding list of cells according to a condition
 
Hello,

I need to find the labelList of cells that respect a certain condition in my simulation, in order to use it in setValues to exclude the equations of those cells from the matrix.

Is there any easy way to do this, excluding looping and checking?

Thanks in advance.

deepsterblue December 19, 2009 21:23

I usually use a labelHashSet to do this. You'll still have to loop through all cells to test for the condition, but when you do, add the cell index to the hashSet. At the end of the loop, you can use the toc() method in HashSet to obtain a labelList of cell indices.

Code:

labelHashSet conditionCells;

forAll(mesh.cells(), cellI)
{
    if (condition)
    {
        conditionCells.insert(cellI);
    }
}

labelList cellLabels = conditionCells.toc();

Hope this helps...

alberto December 20, 2009 03:49

Thanks :-)

aot January 19, 2010 05:07

Quote:

Originally Posted by alberto (Post 240539)
Thanks :-)

Hi Alberto,
how do you now use your labellist with setValues? I tried it as it was shown in
http://http://www.cfd-online.com/Forums/openfoam-solving/59266-how-force-fixed-value-variable-one-cell-2.html#post196058 but it didn't work.

Thanks in advance!

alberto March 24, 2010 16:55

Quote:

Originally Posted by aot (Post 243054)
Hi Alberto,
how do you now use your labellist with setValues? I tried it as it was shown in
http://http://www.cfd-online.com/Forums/openfoam-solving/59266-how-force-fixed-value-variable-one-cell-2.html#post196058 but it didn't work.

Thanks in advance!

Yes, it does not work as expected also in my case. I used flags.

Best,


All times are GMT -4. The time now is 05:25.