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

Exporting mesh connectivity data to file

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 23, 2020, 21:13
Default Exporting mesh connectivity data to file
  #1
New Member
 
Join Date: Nov 2020
Posts: 5
Rep Power: 5
alessandro_92 is on a distinguished road
Hello everyone,


This is my first post here. I am a complete beginner in OpenFOAM. I need such software to extract several mesh related data (e.g. face connectivity etc...).



Basically I do my mesh in Salome and then convert it into OpenFOAM. I am able to successfully extract the txt files: points.txt, boundary.txt, neighbour.txt and owner.txt.


However, I would also need other connectivity information such as cell to node connectivity.


I found this website which clarifies exactly what I need: https://jibranhaider.com/blog/mesh-i...sh-coordinates


Being a complete beginner in OpenFOAM, is anybody here willing to give me some advice on where and how exactly I need to implement those commands? Do I need to modify the controlDict file o I need to write a separate C code?



Any help would be greatly appreciated,


Alessandro
alessandro_92 is offline   Reply With Quote

Old   November 25, 2020, 11:17
Default
  #2
New Member
 
Join Date: Nov 2020
Posts: 5
Rep Power: 5
alessandro_92 is on a distinguished road
This is the piece of code that I've written so far.


#include "fvCFD.H"

int main(int argc, char *argv[])
{

#include "setRootCase.H" // Checks if there is an appropriate system/controlDict
#include "createTime.H" // Constructs the class runTime object of the class time

Foam::Info
<< "Create mesh for time = "
<< runTime.timeName() << Foam::nl << Foam::endl;
Foam::fvMesh mesh
(
Foam::IOobject
(
Foam::fvMesh::defaultRegion,
runTime.timeName(),
runTime,
Foam::IOobject::MUST_READ
)
);


// Mesh connectivities

// Cells
const labelListList& cellPoints = mesh.cellPoints(); // Cell to node
const labelListList& cellEdges = mesh.cellEdges(); // Cell to edge
const cellList& cells = mesh.cells(); // Cell to face
const labelListList& cellCells = mesh.cellCells(); // Cell to cell

return 0;
}




And these are the errors that I get:


ExportMesh.C: In function ‘int main(int, char**)’:
ExportMesh.C:90:23: warning: unused variable ‘cellPoints’ [-Wunused-variable]
const labelListList& cellPoints = mesh.cellPoints(); // Cell to node
^~~~~~~~~~
ExportMesh.C:91:26: warning: unused variable ‘cellEdges’ [-Wunused-variable]
const labelListList& cellEdges = mesh.cellEdges(); // Cell to edge
^~~~~~~~~
ExportMesh.C:92:21: warning: unused variable ‘cells’ [-Wunused-variable]
const cellList& cells = mesh.cells(); // Cell to face
^~~~~
ExportMesh.C:93:26: warning: unused variable ‘cellCells’ [-Wunused-variable]
const labelListList& cellCells = mesh.cellCells(); // Cell to cell





How do I write these variables to .txt files in the "constant" folder?


I do not need to run any "case", I just want to use OpenFOAM as a preprocessor.



Alessandro
alessandro_92 is offline   Reply With Quote

Old   November 27, 2020, 21:20
Default
  #3
New Member
 
Join Date: Nov 2020
Posts: 5
Rep Power: 5
alessandro_92 is on a distinguished road
UP.


Any suggestions?
alessandro_92 is offline   Reply With Quote

Old   November 28, 2020, 07:03
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 alessandro_92 View Post
UP.
Any suggestions?
If you want to load an OpenFOAM mesh, you do need at least a system/controlDict, it can reasonably small since many of the entries can use their default values. Be certain, however, to create a polyMesh, not an fvMesh or you will need some dummy fvSchemes and fvSolution too.
You are completely free how you write to txt files and where. Use std:: ofstream, OFstream, whatever you like. Just remember to create the output directory if it does not already exist.

Last edited by olesen; November 28, 2020 at 07:04. Reason: Space to avoid automatic emoji
olesen is offline   Reply With Quote

Old   November 28, 2020, 18:23
Default
  #5
New Member
 
Join Date: Nov 2020
Posts: 5
Rep Power: 5
alessandro_92 is on a distinguished road
Quote:
Originally Posted by olesen View Post
If you want to load an OpenFOAM mesh, you do need at least a system/controlDict, it can reasonably small since many of the entries can use their default values. Be certain, however, to create a polyMesh, not an fvMesh or you will need some dummy fvSchemes and fvSolution too.
You are completely free how you write to txt files and where. Use std:: ofstream, OFstream, whatever you like. Just remember to create the output directory if it does not already exist.

Thanks for the reply.


Here is the structure of my folders:
- constant
- --> polyMesh (created once I convert my mesh from Salome to Foam)

- system
- --> controlDict (obtained from existing examples)
- --> fvSchemes (obtained from existing examples)
- --> fvSolution (obtained from existing examples)


- ExportMesh (name of my custom .C program)
- --> make
----- --> files
----- --> options
- --> ExportMesh.C



The file "files" contains the following:

ExportMesh.C
EXE = $(FOAM_USER_APPBIN)/ExportMesh




The file "options" contains:


EXE_INC = \
-I../VoF \
-I$(LIB_SRC)/transportModels/twoPhaseMixture/lnInclude \
-I$(LIB_SRC)/transportModels \
-I$(LIB_SRC)/transportModels/incompressible/lnInclude \
-I$(LIB_SRC)/transportModels/interfaceProperties/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/incompressible/lnInclude \
-I$(LIB_SRC)/transportModels/immiscibleIncompressibleTwoPhaseMixture/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/dynamicFvMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/ExportMesh/lnInclude

EXE_LIBS = \
-limmiscibleIncompressibleTwoPhaseMixture \
-lturbulenceModels \
-lincompressibleTurbulenceModels \
-lfiniteVolume \
-ldynamicFvMesh \
-lfvOptions \
-lmeshTools \
-lsampling \
-lwaveModels




The ExportMesh.C file I wrote is the following (here I just extract
cellPoints):


#include "fvCFD.H"
#include "OFstream.H" // To write data to file

int main(int argc, char *argv[])
{

#include "setRootCase.H" // Checks if there is an appropriate system/controlDict
#include "createTime.H" // Constructs the class runTime object of the class time

Foam::Info
<< "Create mesh for time = "
<< runTime.timeName() << Foam::nl << Foam::endl;
Foam::fvMesh mesh
(
Foam::IOobject
(
Foam::fvMesh::defaultRegion,
runTime.timeName(),
runTime,
Foam::IOobject::MUST_READ
)
);

// --------------------

// Mesh connectivities

// Cells
const labelListList& cellPoints = mesh.cellPoints(); // Cell to node
//const labelListList& cellEdges = mesh.cellEdges(); // Cell to edge
//const cellList& cells = mesh.cells(); // Cell to face
//const labelListList& cellCells = mesh.cellCells(); // Cell to cell

std::fstream file;
file.open ("celltonode.txt", std::fstream::ut | std::fstream::app);

file << runTime.timeName() << " " << cellPoints << std::endl << "\n";
file << nl << endl; // Add new line
file.close();

return 0;
}



The above code, however, does not return anything except errors.

I need to somehow write to file without making reference to any timestep?



The first part of the long error list is:


ExportMesh.C:100:12: error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘const labelListList {aka const Foam::List<Foam::List<int> >}’)
file << runTime.timeName() << " " << cellPoints << std::endl << "\n";





I need to evaluate cellPoints as a pre-processing step i.e. without running any case.


What am I missing?


Best,


Alessandro

Last edited by alessandro_92; November 28, 2020 at 18:26. Reason: Removed emoticons
alessandro_92 is offline   Reply With Quote

Old   December 1, 2020, 12:07
Default
  #6
New Member
 
Join Date: Nov 2020
Posts: 5
Rep Power: 5
alessandro_92 is on a distinguished road
UP. Any other suggestion?
Thanks


Alessandro
alessandro_92 is offline   Reply With Quote

Old   December 2, 2020, 03:54
Default
  #7
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
It seems there is no overloaded operator << in fstream which takes cellPoints (which is a labelList) as imput


See http://www.cplusplus.com/reference/fstream/fstream/




This thread may be useful: Writing/output of simple data into an ASCII-File
mAlletto is offline   Reply With Quote

Old   December 14, 2020, 06:56
Default
  #8
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
There are numerous examples of mesh conversion within OpenFOAM, they are always a good place to start. If you are fortunate, perhaps there is something close enough to your requirements that you can hijack it and use a script to reformat the output for your purposes.

In the code snippet, you have gone off and used an std:: ifstream for whatever reason, and then been surprised that it doesn't work. If you stick to using the OpenFOAM variants for IO (eg, a OFstream) you should not experience any issues with the shift operator overloads.


Finally, note that the cellPoints() method is a relatively expensive operation.
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
Using PengRobinsonGas EoS with sprayFoam Jabo OpenFOAM Running, Solving & CFD 35 April 29, 2022 15:35
polynomial BC srv537 OpenFOAM Pre-Processing 4 December 3, 2016 09:07
[mesh manipulation] Importing Multiple Meshes thomasnwalshiii OpenFOAM Meshing & Mesh Conversion 18 December 19, 2015 18:57
[swak4Foam] swak4foam building problem GGerber OpenFOAM Community Contributions 54 April 24, 2015 16:02
Problem compiling a custom Lagrangian library brbbhatti OpenFOAM Programming & Development 2 July 7, 2014 11:32


All times are GMT -4. The time now is 17:24.