CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   [Fortran]Transform ICEM mesh file format to Fortran use (https://www.cfd-online.com/Forums/main/245160-fortran-transform-icem-mesh-file-format-fortran-use.html)

JINXIE September 18, 2022 21:23

[Fortran]Transform ICEM mesh file format to Fortran use
 
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

sbaffini September 19, 2022 04:20

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 September 19, 2022 06:28

1 Attachment(s)
Quote:

Originally Posted by sbaffini (Post 836080)
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.

sbaffini September 19, 2022 08:53

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 September 19, 2022 20:42

Quote:

Originally Posted by sbaffini (Post 836097)
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.

sbaffini September 20, 2022 12:01

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.

arjun September 21, 2022 00:33

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)

JINXIE September 28, 2022 20:39

Quote:

Originally Posted by arjun (Post 836192)
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 September 29, 2022 21:17

Installation error
 
1 Attachment(s)
Quote:

Originally Posted by arjun (Post 836192)
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.

arjun September 30, 2022 01:25

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 September 30, 2022 01:26

Quote:

Originally Posted by JINXIE (Post 836720)
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)

JINXIE October 3, 2022 20:11

Quote:

Originally Posted by arjun (Post 836727)
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.

arjun October 4, 2022 07:26

1 Attachment(s)
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.

JINXIE October 10, 2022 05:43

How to use the c++ codes
 
Quote:

Originally Posted by arjun (Post 836881)
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> >::open(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!

sbaffini October 10, 2022 06:12

1 Attachment(s)
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.

JINXIE October 10, 2022 06:48

Quote:

Originally Posted by sbaffini (Post 837192)
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.

arjun October 10, 2022 11:33

Quote:

Originally Posted by JINXIE (Post 837190)
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).

JINXIE October 10, 2022 20:35

Quote:

Originally Posted by arjun (Post 837217)
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


All times are GMT -4. The time now is 09:49.