CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Mesh Utilities (http://www.cfd-online.com/Forums/openfoam-meshing-utilities/)
-   -   How to create a cellZone from a list of cells? (http://www.cfd-online.com/Forums/openfoam-meshing-utilities/92531-how-create-cellzone-list-cells.html)

bigbang September 16, 2011 14:43

How to create a cellZone from a list of cells?
 
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?

tomislav_maric September 17, 2011 07:49

Quote:

Originally Posted by bigbang (Post 324451)
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. :D

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.

bigbang September 19, 2011 11:11

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.

tomislav_maric September 19, 2011 16:01

1 Attachment(s)
Quote:

Originally Posted by bigbang (Post 324699)
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

bigbang September 20, 2011 08:10

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 September 20, 2011 08:15

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 September 20, 2011 08:44

Which OF version are you using? I'm on 1.6-ext.

Quote:

Originally Posted by bigbang (Post 324850)
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 September 20, 2011 09:21

Hmmm,

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

tomislav_maric September 20, 2011 10:05

Quote:

Originally Posted by bigbang (Post 324868)
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. :D

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... :)

bigbang September 20, 2011 10:44

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 September 20, 2011 15:06

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?

tomislav_maric September 21, 2011 06:00

1 Attachment(s)
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. :D Have fun!


All times are GMT -4. The time now is 00:03.