|
[Sponsors] |
November 23, 2020, 22:13 |
Exporting mesh connectivity data to file
|
#1 |
New Member
Join Date: Nov 2020
Posts: 5
Rep Power: 6 |
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 |
|
November 25, 2020, 12:17 |
|
#2 |
New Member
Join Date: Nov 2020
Posts: 5
Rep Power: 6 |
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 |
|
November 27, 2020, 22:20 |
|
#3 |
New Member
Join Date: Nov 2020
Posts: 5
Rep Power: 6 |
UP.
Any suggestions? |
|
November 28, 2020, 08:03 |
|
#4 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
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 08:04. Reason: Space to avoid automatic emoji |
|
November 28, 2020, 19:23 |
|
#5 | |
New Member
Join Date: Nov 2020
Posts: 5
Rep Power: 6 |
Quote:
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 19:26. Reason: Removed emoticons |
||
December 1, 2020, 13:07 |
|
#6 |
New Member
Join Date: Nov 2020
Posts: 5
Rep Power: 6 |
UP. Any other suggestion?
Thanks Alessandro |
|
December 2, 2020, 04:54 |
|
#7 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
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 |
|
December 14, 2020, 07:56 |
|
#8 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
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. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Using PengRobinsonGas EoS with sprayFoam | Jabo | OpenFOAM Running, Solving & CFD | 36 | July 16, 2024 04:52 |
polynomial BC | srv537 | OpenFOAM Pre-Processing | 4 | December 3, 2016 10:07 |
[mesh manipulation] Importing Multiple Meshes | thomasnwalshiii | OpenFOAM Meshing & Mesh Conversion | 18 | December 19, 2015 19:57 |
[swak4Foam] swak4foam building problem | GGerber | OpenFOAM Community Contributions | 54 | April 24, 2015 17:02 |
Problem compiling a custom Lagrangian library | brbbhatti | OpenFOAM Programming & Development | 2 | July 7, 2014 12:32 |