CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Extract cells from multiple cell zones

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 2, 2012, 22:18
Post Extract cells from multiple cell zones
  #1
New Member
 
deok-kyu choi
Join Date: Feb 2012
Location: Rep. of Korea
Posts: 12
Rep Power: 14
ggoggodak85 is on a distinguished road
is it possible to extract cells from multiple cell zones?

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


regards,
ggoggodak85 is offline   Reply With Quote

Old   May 3, 2012, 02:30
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,685
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by ggoggodak85 View Post
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]
            }
        }
olesen is offline   Reply With Quote

Old   May 4, 2012, 05:46
Default
  #3
New Member
 
deok-kyu choi
Join Date: Feb 2012
Location: Rep. of Korea
Posts: 12
Rep Power: 14
ggoggodak85 is on a distinguished road
Quote:
Originally Posted by olesen View Post
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!
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,
Attached Images
File Type: jpg Screenshot.jpg (43.6 KB, 42 views)
ggoggodak85 is offline   Reply With Quote

Old   May 4, 2012, 06:39
Default
  #4
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,685
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by ggoggodak85 View Post
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.
mm.abdollahzadeh likes this.
olesen is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to set periodic boundary conditions Ganesh FLUENT 15 November 18, 2020 06:09
Cells with t below lower limit Purushothama Siemens 2 May 31, 2010 21:58
Warning 097- AB Siemens 6 November 15, 2004 04:41
two adjacent cell zones. Thejasvi FLUENT 3 November 26, 2001 08:35
Tracking/Modifying Cell Zones Greg Perkins FLUENT 1 November 6, 2000 23:35


All times are GMT -4. The time now is 10:45.