CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

[Fortran]Transform ICEM mesh file format to Fortran use

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree3Likes
  • 1 Post By sbaffini
  • 1 Post By sbaffini
  • 1 Post By sbaffini

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 18, 2022, 22:23
Default [Fortran]Transform ICEM mesh file format to Fortran use
  #1
New Member
 
XIE JIN
Join Date: Apr 2022
Location: Sydney AU
Posts: 13
Rep Power: 2
JINXIE is on a distinguished road
Hello everyone,


Do you know how to transform mesh file generated by ICEM to the data format that can be used by Fortran, Coding a complex geometry is very difficult for me. Thanks in advance.


Best



Jin
JINXIE is offline   Reply With Quote

Old   September 19, 2022, 05:20
Default
  #2
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 1,943
Blog Entries: 29
Rep Power: 36
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
Fortran is a general, low level, programming language that can read any binary or text file.

However, the concept of having some command that will automagically read a full mesh file in an arbitrary format is just wrong, such thing doesn't exist in Fortran or any other programming language. Not even MATLAB (where the availability of several advanced functions might have led you to think so), because would be too specific even for it.

What you're looking for is some actual piece of code that would do exactly that, read the mesh file record by record and store that information.

I have no idea if there is any such piece of code out there, publicly available.

Let me also add that, while I don't specifically know ICEM, it is very likely that it actually outputs its mesh in a number of formats used in several solvers. So, for example, you might find a Fortran code that reads a certain mesh format that is among the ones allowed in output for ICEM.

But even in that case, my experience is that you never find full fledged mesh reader out in the wild. Typically, they are either outdated or too simple for several practical cases. So, depending on your needs, you might have to write that code yourself.
JINXIE likes this.
sbaffini is offline   Reply With Quote

Old   September 19, 2022, 07:28
Default
  #3
New Member
 
XIE JIN
Join Date: Apr 2022
Location: Sydney AU
Posts: 13
Rep Power: 2
JINXIE is on a distinguished road
Quote:
Originally Posted by sbaffini View Post
Fortran is a general, low level, programming language that can read any binary or text file.

However, the concept of having some command that will automagically read a full mesh file in an arbitrary format is just wrong, such thing doesn't exist in Fortran or any other programming language. Not even MATLAB (where the availability of several advanced functions might have led you to think so), because would be too specific even for it.

What you're looking for is some actual piece of code that would do exactly that, read the mesh file record by record and store that information.

I have no idea if there is any such piece of code out there, publicly available.

Let me also add that, while I don't specifically know ICEM, it is very likely that it actually outputs its mesh in a number of formats used in several solvers. So, for example, you might find a Fortran code that reads a certain mesh format that is among the ones allowed in output for ICEM.

But even in that case, my experience is that you never find full fledged mesh reader out in the wild. Typically, they are either outdated or too simple for several practical cases. So, depending on your needs, you might have to write that code yourself.

Thank you very much for your opinion. Your understanding is right and I need some lines of codes that can be used to transform formats that I can use. I opened the .msh file generated by ICEM and found they are data like coordinates of nodes and I'm trying to find some methods to number these nodes and use some statements to read them.
Attached Images
File Type: png WeChat Image_20220919202607.png (61.7 KB, 14 views)
JINXIE is offline   Reply With Quote

Old   September 19, 2022, 09:53
Default
  #4
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 1,943
Blog Entries: 29
Rep Power: 36
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
Looks like a Fluent mesh file in ascii format. Is it so? It shouldn't be difficult to read but, your comment on "finding some method to number them" indicates you need to first understand better how these files are written and that it won't be exactly easy or fast, given the point where you are (as, for example, the nodes are numbered, and referred to in the rest of the file, following the order they are written to file; same for faces and cells).

What is your end goal? Why do you want to read such a mesh file in Fortran?
JINXIE likes this.
sbaffini is offline   Reply With Quote

Old   September 19, 2022, 21:42
Default
  #5
New Member
 
XIE JIN
Join Date: Apr 2022
Location: Sydney AU
Posts: 13
Rep Power: 2
JINXIE is on a distinguished road
Quote:
Originally Posted by sbaffini View Post
Looks like a Fluent mesh file in ascii format. Is it so? It shouldn't be difficult to read but, your comment on "finding some method to number them" indicates you need to first understand better how these files are written and that it won't be exactly easy or fast, given the point where you are (as, for example, the nodes are numbered, and referred to in the rest of the file, following the order they are written to file; same for faces and cells).

What is your end goal? Why do you want to read such a mesh file in Fortran?
Yes you are right, it's a Fluent mesh file. Since I'm using FVM in Fortran to solve some problems, so I need to know the node order in the cell center and boundaries. I have a 2D Fortran mesh generation and solver code for a nozzle problem, and now I need to develop a 3D model, including mesh generation and solver development. Coding a 3D mesh is difficult for me, so I try to find a way to transform formats between fortran and fluent mesh file.
JINXIE is offline   Reply With Quote

Old   September 20, 2022, 13:01
Default
  #6
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 1,943
Blog Entries: 29
Rep Power: 36
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
Then, I guess, you need to delve into the structure of a Fluent mesh file. Note that, especially in ascii format, it is not very difficult to process, as long as you do not have to deal with more complicated stuff like periodic boundaries or hanging nodes. The Fluent user guide explains the format very clearly. I suggest you to start making a very simple mesh of a cube (say, 3x3x3 cells) and use that as reference to study and understand the format.

Numberings are implicit, the node number n referred to in the faces sections is the (n+1)-th (as it is C based numbering) in the list of nodes written in the file. Same for the C0-C1 cells referenced at the end of each face.

However, additional info (e.g., the nodes of a cell, the faces of a cell, etc.) must be built.

The book by Lohner has a section on such things that you may find useful.
sbaffini is offline   Reply With Quote

Old   September 21, 2022, 01:33
Default
  #7
Senior Member
 
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,121
Rep Power: 29
arjun will become famous soon enougharjun will become famous soon enough
You can download wildkatze and convert fluent file to bmsh format.

This bmsh format you can very easily read with simple c or fortran code. The format is designed for it.



https://fvus.github.io/wildkatze/ins...load-wildkatze



Here the first step you do is to convert the mesh. If you decide to use bmsh then let me know i will show you the format. (which is basically just values put into a file)
arjun is offline   Reply With Quote

Old   September 28, 2022, 21:39
Default
  #8
New Member
 
XIE JIN
Join Date: Apr 2022
Location: Sydney AU
Posts: 13
Rep Power: 2
JINXIE is on a distinguished road
Quote:
Originally Posted by arjun View Post
You can download wildkatze and convert fluent file to bmsh format.

This bmsh format you can very easily read with simple c or fortran code. The format is designed for it.



https://fvus.github.io/wildkatze/ins...load-wildkatze



Here the first step you do is to convert the mesh. If you decide to use bmsh then let me know i will show you the format. (which is basically just values put into a file)
Thank you for your reply. I do want to try bmsh and can you tell me more details about it?
JINXIE is offline   Reply With Quote

Old   September 29, 2022, 22:17
Default Installation error
  #9
New Member
 
XIE JIN
Join Date: Apr 2022
Location: Sydney AU
Posts: 13
Rep Power: 2
JINXIE is on a distinguished road
Quote:
Originally Posted by arjun View Post
You can download wildkatze and convert fluent file to bmsh format.

This bmsh format you can very easily read with simple c or fortran code. The format is designed for it.



https://fvus.github.io/wildkatze/ins...load-wildkatze



Here the first step you do is to convert the mesh. If you decide to use bmsh then let me know i will show you the format. (which is basically just values put into a file)

I followed your Youtube installation tutorial step by step, but I met an error as shown in attachment. Do you know how to solve it? I tried many ways but they don't work.
Attached Images
File Type: jpg error.jpg (126.6 KB, 8 views)
JINXIE is offline   Reply With Quote

Old   September 30, 2022, 02:25
Default
  #10
Senior Member
 
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,121
Rep Power: 29
arjun will become famous soon enougharjun will become famous soon enough
you do not need to run the gui.


mpirun -np 1 ./wildkatze -lc fluent2bmsh fluentmesh


should do the job.


I will put you a simple c++ code that loads bmsh and you can use that.
arjun is offline   Reply With Quote

Old   September 30, 2022, 02:26
Default
  #11
Senior Member
 
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,121
Rep Power: 29
arjun will become famous soon enougharjun will become famous soon enough
Quote:
Originally Posted by JINXIE View Post
I followed your Youtube installation tutorial step by step, but I met an error as shown in attachment. Do you know how to solve it? I tried many ways but they don't work.


This error is due to java. You need to google this error because some java are doing this. (some java seem to be missing awt)
arjun is offline   Reply With Quote

Old   October 3, 2022, 21:11
Default
  #12
New Member
 
XIE JIN
Join Date: Apr 2022
Location: Sydney AU
Posts: 13
Rep Power: 2
JINXIE is on a distinguished road
Quote:
Originally Posted by arjun View Post
you do not need to run the gui.


mpirun -np 1 ./wildkatze -lc fluent2bmsh fluentmesh


should do the job.


I will put you a simple c++ code that loads bmsh and you can use that.

I kindly appreciate your help. The command "solver.sh lc fluent2bmsh sample" works fine and I can follow the tutorial to run the sample calculation, but if I use "mpirun -np 1 ./wildkatze -lc fluent2bmsh sample", it gives mpirun was unable to launch the specified application as it could not access or execute an executable:

Executable: ./wildkatze
Node: xiejin

while attempting to start process rank 0."


Is it okay that I use the command "solver.sh lc fluent2bmsh sample" to transform mesh?



In addition, could you plz tell me your mentioned c++ code to transform the mesh that I can use. Thank you so much.
JINXIE is offline   Reply With Quote

Old   October 4, 2022, 08:26
Default
  #13
Senior Member
 
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,121
Rep Power: 29
arjun will become famous soon enougharjun will become famous soon enough
I attach you a simple C++ class that loads the bmsh file and store it at region object.


You can retrive the data from it.

JUST NOTE that following the fluent file format the cells are indexed from 1, ... NCells. The boundaries shall have 0 as right cell index.
Attached Files
File Type: zip bmsh.zip (4.0 KB, 4 views)
arjun is offline   Reply With Quote

Old   October 10, 2022, 06:43
Default How to use the c++ codes
  #14
New Member
 
XIE JIN
Join Date: Apr 2022
Location: Sydney AU
Posts: 13
Rep Power: 2
JINXIE is on a distinguished road
Quote:
Originally Posted by arjun View Post
I attach you a simple C++ class that loads the bmsh file and store it at region object.


You can retrive the data from it.

JUST NOTE that following the fluent file format the cells are indexed from 1, ... NCells. The boundaries shall have 0 as right cell index.

I really appreciate your time and the codes. I am really new in c++ and I don't know how to properly run the codes. I transformed the mesh from Fluent to bmsh by Wildkatze, and now I try to use Microsoft Visual c++ 6.0 to run the codes. I put sample.bmsh and sample.info.bmsh into file folder containing c++ codes you shared. After compiling the cpp codes, it gives the following errors, what should I do? Should I modify some codes in the cpp codes?


--------------------Configuration: BMeshObject - Win32 Debug--------------------
Compiling...
BMeshObject.cpp
C:\Users\z5345552\OneDrive - UNSW\Desktop\Meshtrans\bmsh\BMeshObject.cpp(21) : error C2664: 'void __thiscall std::basic_fstream<char,struct std::char_traits<char> >:pen(const char *,int)' : cannot convert parameter 1 from 'class std::basic_string<
char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\Users\z5345552\OneDrive - UNSW\Desktop\Meshtrans\bmsh\BMeshObject.cpp(293) : error C2039: 'data' : is not a member of 'vector<double,class std::allocator<double> >'
C:\Users\z5345552\OneDrive - UNSW\Desktop\Meshtrans\bmsh\BMeshObject.cpp(294) : error C2039: 'data' : is not a member of 'vector<double,class std::allocator<double> >'
C:\Users\z5345552\OneDrive - UNSW\Desktop\Meshtrans\bmsh\BMeshObject.cpp(295) : error C2039: 'data' : is not a member of 'vector<double,class std::allocator<double> >'
C:\Users\z5345552\OneDrive - UNSW\Desktop\Meshtrans\bmsh\BMeshObject.cpp(297) : error C2039: 'data' : is not a member of 'vector<int,class std::allocator<int> >'
C:\Users\z5345552\OneDrive - UNSW\Desktop\Meshtrans\bmsh\BMeshObject.cpp(298) : error C2039: 'data' : is not a member of 'vector<int,class std::allocator<int> >'
C:\Users\z5345552\OneDrive - UNSW\Desktop\Meshtrans\bmsh\BMeshObject.cpp(393) : error C2374: 'r' : redefinition; multiple initialization
C:\Users\z5345552\OneDrive - UNSW\Desktop\Meshtrans\bmsh\BMeshObject.cpp(134) : see declaration of 'r'
C:\Users\z5345552\OneDrive - UNSW\Desktop\Meshtrans\bmsh\BMeshObject.cpp(404) : error C2374: 'r' : redefinition; multiple initialization
C:\Users\z5345552\OneDrive - UNSW\Desktop\Meshtrans\bmsh\BMeshObject.cpp(134) : see declaration of 'r'
Error executing cl.exe.

BMeshObject.obj - 8 error(s), 0 warning(s)




Thank you again!
JINXIE is offline   Reply With Quote

Old   October 10, 2022, 07:12
Default
  #15
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 1,943
Blog Entries: 29
Rep Power: 36
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
If you will accept the fact that I won't be able to help you in any case and that the approach might be naive and flawed with respect to a certain number of aspects, then you might want to give a look at the attached matlab file (I had to chang the extension to upload it here). It reads (or, at least it still should) Fluent/Gambit .msh files in ASCII format.

I developed it as a student for learning purposes on ustructured FV methods, so it is naive and limited and possibly erroneous in some ways that I would be unable to tell you as of today. But it used to work and, if Fortran is what you want, this might be close enough for you to develop YOUR solution.

DO NOT just follow it row by row, use it to learn what's inside the .msh file and try to figure out by yourself how to do what you need.

Let me restate again that this is not something I'm interested in maintaining or supporting. So, if you want to use this, you are on your own.
Attached Files
File Type: txt readmsh.txt (16.8 KB, 4 views)
arjun likes this.
sbaffini is offline   Reply With Quote

Old   October 10, 2022, 07:48
Default
  #16
New Member
 
XIE JIN
Join Date: Apr 2022
Location: Sydney AU
Posts: 13
Rep Power: 2
JINXIE is on a distinguished road
Quote:
Originally Posted by sbaffini View Post
If you will accept the fact that I won't be able to help you in any case and that the approach might be naive and flawed with respect to a certain number of aspects, then you might want to give a look at the attached matlab file (I had to chang the extension to upload it here). It reads (or, at least it still should) Fluent/Gambit .msh files in ASCII format.

I developed it as a student for learning purposes on ustructured FV methods, so it is naive and limited and possibly erroneous in some ways that I would be unable to tell you as of today. But it used to work and, if Fortran is what you want, this might be close enough for you to develop YOUR solution.

DO NOT just follow it row by row, use it to learn what's inside the .msh file and try to figure out by yourself how to do what you need.

Let me restate again that this is not something I'm interested in maintaining or supporting. So, if you want to use this, you are on your own.

Thank you pretty much, I will look at it and study the idea for matlab, and I will also study the Fluent mesh file format. As you said, the idea should be similar for Fortran.
JINXIE is offline   Reply With Quote

Old   October 10, 2022, 12:33
Default
  #17
Senior Member
 
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,121
Rep Power: 29
arjun will become famous soon enougharjun will become famous soon enough
Quote:
Originally Posted by JINXIE View Post
I really appreciate your time and the codes. I am really new in c++ and I don't know how to properly run the codes. I transformed the mesh from Fluent to bmsh by Wildkatze, and now I try to use Microsoft Visual c++ 6.0 to run the codes. I put sample.bmsh and sample.info.bmsh into file folder containing c++ codes you shared. After compiling the cpp codes, it gives the following errors, what should I do? Should I modify some codes in the cpp codes?


Thank you again!


Somehow your compiler is having problem with std::vector and std::string etc. Very strange. The code that i gave you compiles fine on gnu machine and i have tested it by loading the bmsh file before i passed to you.


You can simply read the code to see that the format is simple. You can re-write it using the files i provided (its not complicated).
arjun is offline   Reply With Quote

Old   October 10, 2022, 21:35
Default
  #18
New Member
 
XIE JIN
Join Date: Apr 2022
Location: Sydney AU
Posts: 13
Rep Power: 2
JINXIE is on a distinguished road
Quote:
Originally Posted by arjun View Post
Somehow your compiler is having problem with std::vector and std::string etc. Very strange. The code that i gave you compiles fine on gnu machine and i have tested it by loading the bmsh file before i passed to you.


You can simply read the code to see that the format is simple. You can re-write it using the files i provided (its not complicated).
Thank you for your reply. I now use Ubuntu to run your codes. And I still met a problem. By the way, how can I use the commands in readme.txt? The following is the error info:
xiejin@L-C2N69K3:~/bmsh$ g++ BMeshObject.cpp -o test
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
JINXIE is offline   Reply With Quote

Reply

Tags
fortran, icem, mesh format

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 16:35
Custom Thermophysical Properties wsmith02 OpenFOAM 3 July 27, 2015 06:37
centOS 5.6 : paraFoam not working yossi OpenFOAM Installation 2 October 9, 2013 02:41
"parabolicVelocity" in OpenFoam 2.1.0 ? sawyer86 OpenFOAM Running, Solving & CFD 21 February 7, 2012 12:44
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 18:51


All times are GMT -4. The time now is 16:12.