CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Write out labelListList cellCells() (https://www.cfd-online.com/Forums/openfoam-programming-development/236398-write-out-labellistlist-cellcells.html)

Tallac May 28, 2021 01:20

Write out labelListList cellCells()
 
Hello all,

I am attempting to write out cell center connectivity to a file. I started with the foamToFluent utility and modified it according to my needs. However, my C++ and research skills are rapidly running out.

From https://www.cfd-online.com/Forums/op...edge-cell.html and https://jibranhaider.com/blog/mesh-i...connectivities I know that I need to access cellCells() and that it is a labelListList. My understanding is that this is a list of lists, which makes sense. The section of my code indented to write this information to file is below.

When compiling I am getting an error relating to, I believe, a mismatch in expected data type for the ```edge_list << neighbour[celli] ``` command. This error message is shown below.

I think my lack of understanding of labelListList is the root cause of this error. And after some exhaustive searching I am not sure of where to go from here. I would greatly appreciate help in understanding what I am doing wrong. I can easily imagine that naively calling cellCells()[celli] is not how I should go about this, but without knowing the structure of cellCells I am left to guess.

Any help is greatly appreciated, thank you,


- Sam





Compiler error message:


Code:

error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘const Foam::List<int>’)
        edge_list << " " << neighbour[celli];

Code:



Code:

    // Open a file for the edges
    std::ofstream edge_list
    (
        time().rootPath()
      / time().caseName()
      / "graph"
      / "edges.txt"
    );

    Info<< "Writing edges.txt" << endl;

    // Writing cells based on neighbors
    const labelListList neighbour = this->mesh.cellCells();

    // Writing number of cells
    edge_list
        << "("
        << nCells() << ")" << std::endl;
    edge_list << "(";
 
    forAll(neighbour, celli)
    {
        edge_list << " " << neighbour[celli];
        edge_list << "\n";
    }

    edge_list << ")" << std::endl;


olesen May 31, 2021 01:55

Using OFstream instead of std :: ofstream will work better.
BTW you should not be taking a copy when you obtain the cellCells() - use a const ref instead.

The structure of labelListList is in the name - a list of lists of labels.


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