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

[mesh manipulation] How to create a cellZone from a list of cells?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 16, 2011, 15:43
Default How to create a cellZone from a list of cells?
  #1
Member
 
Alex
Join Date: Jun 2010
Location: Planet Earth
Posts: 43
Rep Power: 16
bigbang is on a distinguished road
So I've extracted a list of cell IDs from paraview after meshing. I want to create a cellZones file that contains a list of all these cells for use in simplePorousFoam.

Any ideas?
bigbang is offline   Reply With Quote

Old   September 17, 2011, 08:49
Default
  #2
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
Quote:
Originally Posted by bigbang View Post
So I've extracted a list of cell IDs from paraview after meshing. I want to create a cellZones file that contains a list of all these cells for use in simplePorousFoam.

Any ideas?
Here's an idea:

Code:
      // Define a cellZoneMesh of size 0.

    cellZoneMesh zones
    (
        IOobject
        (
            "zones",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ
        ),
        mesh, 
        0
    );

    // Bogus label list definition, replace with your ID list here:
    // if you have created it from some outside app and written it 
    // onto the HDD, you will need to read and register it using a
    // LabelLiist<T> constructor.

        // Bogus label list of ten elements.  
    labelList selectCells (10,0);

        // Bogus selection, just for this example: select cells with
        // labels 0-9.
    forAll (selectCells, I)
    {
        selectCells[I] = I;
    }

    // Define a cellZone from the selectCells label list (not a cell list, a list of IDs is not 
    // a cell list, it's a label list :) )
    cellZone myZone
    (
        "myZone",
        selectCells, 
        0,
        zones
    );

    // Brute force write.
    OFstream outFile("myZone");
    myZone.write(outFile);
This is just the first thing I thought of. You probably won't be happy with the myZone.write(IOstream) approach.

What i find interesting is that the
Code:
cellZone
constructor requires a const reference to the
Code:
cellZoneMesh
which is a list of
Code:
cellZone
basically.

Hope this is of any help...

T.
tomislav_maric is offline   Reply With Quote

Old   September 19, 2011, 12:11
Default
  #3
Member
 
Alex
Join Date: Jun 2010
Location: Planet Earth
Posts: 43
Rep Power: 16
bigbang is on a distinguished road
Hi T,

Thanks for this reply.

I'm still relatively new to programming in openFoam.

I tried to splice your code into some tutorials that I've done, but when I compile I get the following error:

Code:
myZones.C:42:30: error: createFields.H: No such file or directory
myZones.C: In function ‘int main(int, char**)’:
myZones.C:88: error: ‘OFstream’ was not declared in this scope
myZones.C:88: error: expected ‘;’ before ‘outFile’
myZones.C:89: error: ‘outFile’ was not declared in this scope
/opt/openfoam201/src/finiteVolume/lnInclude/initContinuityErrs.H:37: warning: unused variable ‘cumulativeContErr’
make: *** [Make/linux64GccDPOpt/myZones.o] Error 1
alexander@alexander-G50VT:~/OpenFOAM/alexander-2.0.1/applications/myZones$ gedit myZones.C
Basically, what do I need to include to run your code?

Thanks for helping out a newbie.
bigbang is offline   Reply With Quote

Old   September 19, 2011, 17:01
Default
  #4
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
Quote:
Originally Posted by bigbang View Post
Hi T,

Thanks for this reply.

I'm still relatively new to programming in openFoam.

I tried to splice your code into some tutorials that I've done, but when I compile I get the following error:

Code:
myZones.C:42:30: error: createFields.H: No such file or directory
myZones.C: In function ‘int main(int, char**)’:
myZones.C:88: error: ‘OFstream’ was not declared in this scope
myZones.C:88: error: expected ‘;’ before ‘outFile’
myZones.C:89: error: ‘outFile’ was not declared in this scope
/opt/openfoam201/src/finiteVolume/lnInclude/initContinuityErrs.H:37: warning: unused variable ‘cumulativeContErr’
make: *** [Make/linux64GccDPOpt/myZones.o] Error 1
alexander@alexander-G50VT:~/OpenFOAM/alexander-2.0.1/applications/myZones$ gedit myZones.C
Basically, what do I need to include to run your code?

Thanks for helping out a newbie.
Can you post the whole app here and I can try to plug the code in? I have tried to attach the .zip of my app to this post. If it doesn't help, post your code and we'll figure it out.

Btw, don't worry about being new to the code, without proper documentation everybody is new to the code, especially if they step out of their "comfort zone".

Best regards,
Tomislav
Attached Files
File Type: zip myCellZone.zip (1.8 KB, 45 views)
tomislav_maric is offline   Reply With Quote

Old   September 20, 2011, 09:10
Default
  #5
Member
 
Alex
Join Date: Jun 2010
Location: Planet Earth
Posts: 43
Rep Power: 16
bigbang is on a distinguished road
Thanks again T.

When I compile your application (wmake) from my $FOAM_RUN/myCellZone,
I get the following error:
Code:
Making dependency list for source file myCellZone.C
SOURCE=myCellZone.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam201/src/finiteVolume/lnInclude -IlnInclude -I. -I/opt/openfoam201/src/OpenFOAM/lnInclude -I/opt/openfoam201/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/myCellZone.o
myCellZone.C: In function ‘int main(int, char**)’:
myCellZone.C:85: error: ‘OFstream’ was not declared in this scope
myCellZone.C:85: error: expected ‘;’ before ‘outFile’
myCellZone.C:86: error: ‘outFile’ was not declared in this scope
make: *** [Make/linux64GccDPOpt/myCellZone.o] Error 1
alexander@alexander-G50VT:~/OpenFOAM/alexander-2.0.1/applications/myCellZone$
bigbang is offline   Reply With Quote

Old   September 20, 2011, 09:15
Default
  #6
Member
 
Alex
Join Date: Jun 2010
Location: Planet Earth
Posts: 43
Rep Power: 16
bigbang is on a distinguished road
And then if I add: #include "OFstream.H" in the main, I get this error:

Code:
Making dependency list for source file myCellZone.C
SOURCE=myCellZone.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam201/src/finiteVolume/lnInclude -IlnInclude -I. -I/opt/openfoam201/src/OpenFOAM/lnInclude -I/opt/openfoam201/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/myCellZone.o
In file included from /usr/include/c++/4.4/fstream:42,
                 from /opt/openfoam201/src/OpenFOAM/lnInclude/OFstream.H:42,
                 from myCellZone.C:42:
/usr/include/c++/4.4/bits/codecvt.h: In function ‘int main(int, char**)’:
/usr/include/c++/4.4/bits/codecvt.h:42: error: expected ‘=’ before ‘__attribute__’
/usr/include/c++/4.4/bits/codecvt.h:42: error: expected identifier before ‘__attribute__’
/usr/include/c++/4.4/bits/codecvt.h:42: error: expected ‘;’ before ‘__attribute__’
/usr/include/c++/4.4/bits/codecvt.h:42: error: expected primary-expression before ‘__attribute__’
/usr/include/c++/4.4/bits/codecvt.h:42: error: expected ‘;’ before ‘__attribute__’
myCellZone.C:95: error: expected ‘}’ at end of input
make: *** [Make/linux64GccDPOpt/myCellZone.o] Error 1
bigbang is offline   Reply With Quote

Old   September 20, 2011, 09:44
Default
  #7
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
Which OF version are you using? I'm on 1.6-ext.

Quote:
Originally Posted by bigbang View Post
And then if I add: #include "OFstream.H" in the main, I get this error:

Code:
Making dependency list for source file myCellZone.C
SOURCE=myCellZone.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam201/src/finiteVolume/lnInclude -IlnInclude -I. -I/opt/openfoam201/src/OpenFOAM/lnInclude -I/opt/openfoam201/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/myCellZone.o
In file included from /usr/include/c++/4.4/fstream:42,
                 from /opt/openfoam201/src/OpenFOAM/lnInclude/OFstream.H:42,
                 from myCellZone.C:42:
/usr/include/c++/4.4/bits/codecvt.h: In function ‘int main(int, char**)’:
/usr/include/c++/4.4/bits/codecvt.h:42: error: expected ‘=’ before ‘__attribute__’
/usr/include/c++/4.4/bits/codecvt.h:42: error: expected identifier before ‘__attribute__’
/usr/include/c++/4.4/bits/codecvt.h:42: error: expected ‘;’ before ‘__attribute__’
/usr/include/c++/4.4/bits/codecvt.h:42: error: expected primary-expression before ‘__attribute__’
/usr/include/c++/4.4/bits/codecvt.h:42: error: expected ‘;’ before ‘__attribute__’
myCellZone.C:95: error: expected ‘}’ at end of input
make: *** [Make/linux64GccDPOpt/myCellZone.o] Error 1
tomislav_maric is offline   Reply With Quote

Old   September 20, 2011, 10:21
Default
  #8
Member
 
Alex
Join Date: Jun 2010
Location: Planet Earth
Posts: 43
Rep Power: 16
bigbang is on a distinguished road
Hmmm,

I'm on 2.0.1. Don't know why I keep upgrading.. it's nothing but trouble
bigbang is offline   Reply With Quote

Old   September 20, 2011, 11:05
Default
  #9
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
Quote:
Originally Posted by bigbang View Post
Hmmm,

I'm on 2.0.1. Don't know why I keep upgrading.. it's nothing but trouble

That's where the problem lies.... updates are evil.

I think the only thing differences are in the Make/options file, I haven't used some new fancy functionality or a backward incompatible class...
tomislav_maric is offline   Reply With Quote

Old   September 20, 2011, 11:44
Default
  #10
Member
 
Alex
Join Date: Jun 2010
Location: Planet Earth
Posts: 43
Rep Power: 16
bigbang is on a distinguished road
Maybe it's possible that you can just post your cellZones file created from the program and I can use it as a template and replace the values for the cell Ids?
bigbang is offline   Reply With Quote

Old   September 20, 2011, 16:06
Default
  #11
Member
 
Alex
Join Date: Jun 2010
Location: Planet Earth
Posts: 43
Rep Power: 16
bigbang is on a distinguished road
I found a whole pdf on porous Zones. Click here

It says:
"Many porous zones can be added to the case. The number of porous zones is limited to the number
of cell zones in the mesh.
1
(
<cellZoneName>
{
Defintions.
}
)
2
(
<anotherCellZoneName>
{
Defintions.
}
)
"

So my questions is how do you replace "Definitions." with a list of cell IDs to define a zone? Or can you even define a zone with a list of cell IDs?
bigbang is offline   Reply With Quote

Old   September 21, 2011, 07:00
Default
  #12
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
Here's the 2.0 app. It's in the attachment.

Look at the cellZone constructor: it needs a label list naturally, because the cellZone --> zone --> labelList (check out the doxygen). So, basically, cellZone is a kind of labelList.

Code:
class zone
: public labelList
 { 
    protected:      // Protected data
How will you populate the lists is up to you of course. Have fun!
Attached Files
File Type: zip myCellZone-2.0.zip (1.9 KB, 74 views)
tomislav_maric is offline   Reply With Quote

Old   January 22, 2024, 17:22
Default create a cellZone from a list of cells
  #13
New Member
 
Shenhui Ruan
Join Date: Nov 2021
Location: Karlsruhe
Posts: 16
Rep Power: 5
fly_light is on a distinguished road
A very delayed answer; I think the people in the post don't need the code. But I have such a problem, and I found a way to solve it. I hope it is helpful. Please contact me if anyone wants to discuss this.

Code:
   // Initialise OF case
    #include "setRootCase.H"

    // These two create the time system (instance called runTime) and fvMesh (instance called mesh).
    #include "createTime.H"
    #include "createMesh.H"

    List<label> selectCellList;

    // add your procedure to append the list
    if (xxx)
    {
          selectCellList.append(cellid)
    }


    mesh.cellZones().append
    (
        new cellZone
        (
            "selectCellZone",
            selectCellList,
            // index, the max index of original cellzones is "size-1". 
            // The value is used as only a cellzone is added  
            mesh.cellZones().size(),  
            mesh.cellZones()
        )
    );

    mesh.cellZones().write();
fly_light is offline   Reply With Quote

Old   June 28, 2024, 12:26
Default
  #14
Member
 
Zeinab
Join Date: Feb 2023
Posts: 32
Rep Power: 3
Zena27 is on a distinguished road
Hello,
Yess I need a quicker way to create the cellZone from a labelList. Thanks
Zena27 is offline   Reply With Quote

Old   June 28, 2024, 19:03
Default
  #15
New Member
 
Shenhui Ruan
Join Date: Nov 2021
Location: Karlsruhe
Posts: 16
Rep Power: 5
fly_light is on a distinguished road
Hello Zeinab,

I am sorry that I don't understand what you mean of a quicker way. I think my code is not complicated.
If you want to read a labellist from a file and then add a cellzone. I suggest you use IOList<T> to read and then modify the code I posted before.
fly_light 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
[ICEM] Error in mesh writing helios ANSYS Meshing & Geometry 21 August 19, 2021 15:18
[swak4Foam] funkyDoCalc with OF2.3 massflow NiFl OpenFOAM Community Contributions 14 November 25, 2020 04:30
how to set periodic boundary conditions Ganesh FLUENT 15 November 18, 2020 07:09
cellZone not taking all the cells inside rahulksoni OpenFOAM Running, Solving & CFD 6 January 25, 2019 01:11
[Netgen] Import netgen mesh to OpenFOAM hsieh OpenFOAM Meshing & Mesh Conversion 32 September 13, 2011 06:50


All times are GMT -4. The time now is 02:41.