CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Extract cells from multiple cell zones (http://www.cfd-online.com/Forums/openfoam-programming-development/101392-extract-cells-multiple-cell-zones.html)

ggoggodak85 May 2, 2012 22:18

Extract cells from multiple cell zones
 
is it possible to extract cells from multiple cell zones?

and how can i set the vector value to selected cells?


regards,

olesen May 3, 2012 02:30

Quote:

Originally Posted by ggoggodak85 (Post 358984)
is it possible to extract cells from multiple cell zones?

and how can i set the vector value to selected cells?


regards,

To loop through the cells, you'd need something like the following. Note that this will not work "as is", but is just a guide:


Code:

        // cellZoneIds with the IDs of your cell zones
        // mesh_ is a reference to the mesh
 
        forAll(cellZoneIds, zoneI)
        {
            const labelList& cells = mesh_.cellZones()[cellZoneIds[zoneI]];
            forAll(cells, i)
            {
                // do something for cells[i]
            }
        }


ggoggodak85 May 4, 2012 05:46

1 Attachment(s)
Quote:

Originally Posted by olesen (Post 359008)
To loop through the cells, you'd need something like the following. Note that this will not work "as is", but is just a guide:


Code:

        // cellZoneIds with the IDs of your cell zones
        // mesh_ is a reference to the mesh
 
        forAll(cellZoneIds, zoneI)
        {
            const labelList& cells = mesh_.cellZones()[cellZoneIds[zoneI]];
            forAll(cells, i)
            {
                // do something for cells[i]
            }
        }


Dear olesen,
finally I did by olesen's favor! :D
But I'd like to do something more.

Following screenshot, it seems to be calculated for every cells.

How can i apply coriolis force for selected cell zone (celltable_2) ?
zone of celltable_2 is circle area in box.

Here is my code, but is just a guide :)

forAll(mesh.cellZones(),i)
{
const cellZone& zone = mesh.cellZones()[i];

if (zone.name()=="cellTable_2")
{
const labelList& cellLabels = mesh.cellZones()[i];
Info << "Found matching zone " << zone.name() << " with " << cellLabels.size() << " cells." << endl;

forAll(cellLabels, i)
{
// Calculate the coriolis force in selected cells (cellTable_2)
volVectorField Fcoriolis = Omega ^ (mesh.C() - Origin);
Fcoriolis.write();
}
}
}

regards,

olesen May 4, 2012 06:39

Quote:

Originally Posted by ggoggodak85 (Post 359259)
How can i apply coriolis force for selected cell zone (celltable_2) ?
zone of celltable_2 is circle area in box.

Two approaches.

1. if you will only ever have a single zone:
Code:

label zoneId = mesh.cellZones().findIndex("cellTable_2");
if (zoneId != -1)
{
    const labelList& cellIds = mesh.cellZones()[zoneId];
    forAll(cellIds, i)
    {
...
    }
}

2. if you want a regex to select one or more zones:
Code:

labelList zoneIds = mesh.cellZones().findIndices("cellTable_[1-3]");
forAll(zoneIds, zoneI)
{
    const labelList& cellIds = mesh.cellZones()[zoneIds[zoneI]];
    forAll(cellIds, i)
    {
...
    }
}

As usual, the code example may not be exactly correct.


All times are GMT -4. The time now is 06:53.