Problem while loading .msh mesh using GMSH api

344 views
Skip to first unread message

Pratik Pophali

unread,
Aug 2, 2021, 7:38:45 AM8/2/21
to sparselizardforum
Hi all,
I have a "rect2.msh" file with me. I am trying to load it using
mesh mymesh("gmsh:rect2.msh");
but it is giving me this error. " Error in 'gmshinterface' namespace: GMSH API is not available"

When I tried this method, 
...
#include "gmsh.h"
...
gmsh:: initialize ();
gmsh::open("rect2.msh");
mesh mymesh("gmsh:api");
gmsh:: finalize ();

I downloaded gmsh.h file from the internet and saved in the headers folder. But it is giving me this error.

/tmp/ccMCHSju.o: In function `main':
main.cpp:(.text.startup+0x36): undefined reference to `gmsh::initialize(int, char**, bool)'
main.cpp:(.text.startup+0x4d): undefined reference to `gmsh::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
main.cpp:(.text.startup+0x9f): undefined reference to `gmsh::finalize()'
collect2: error: ld returned 1 exit status

Please help. Thank you

Alexandre Halbach

unread,
Aug 2, 2021, 8:46:58 AM8/2/21
to Pratik Pophali, sparselizardforum
Hi Pratik,

It seems you have not compiled sparselizard with the gmsh api (placing just the header in a folder is not enough, you need the .h header, the .so library and also you meed to tell the compiler where these two are). Don't use the default "makefile" in the folder but use instead cmake to compile sparselizard with gmsh. You just have to run the ./optional_install_gmsh.sh script to download the right gmsh api version to your home/SLlibs. Then cmake will automatically find it.

Alternatively you can also load .msh ascii format 2 natively in sparselizard with

mesh mymesh("rect2.msh"); 

For that you can open the msh file in gmsh, and file->export and export as .msh ascii version 2 format.

or try your luck with

mesh mymesh("petsc:rect2.msh");

in case the petsc reader can read it (it does not always work and I can t do anything about it sonce it is a third party library).

Alex



--
You received this message because you are subscribed to the Google Groups "sparselizardforum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sparselizardfo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sparselizardforum/a7a76ee4-58d0-47c0-94b2-3fb7736081d4n%40googlegroups.com.

Pratik Pophali

unread,
Aug 3, 2021, 1:59:12 AM8/3/21
to sparselizardforum
Hello sir, I want to solve the pressure equation problem.(Please find the attached jpg image). As told by you I tried the command " ./optional_install_gmsh.sh  ". But it is saying "No command found".
As per your other method, I created  .msh ascii version 2 format (Please find the given .msh file). But it gave me this error.

Loading mesh from 'rect2_ascii.msh' with the native mesh reader
terminate called after throwing an instance of 'std::length_error'
  what():  vector::_M_default_append
Aborted (core dumped)

I have solved the same problem with the mesh with triangular elements and got the correct ans too. There I load the mesh using petsc reader. But this mesh is of rectangular elements and petsc reader don't read such mesh. That's why I tried the methods told by you. 


Please help. Thank you




main.cpp
rect2_ascii.msh
Capture.JPG

alexandr...@gmail.com

unread,
Aug 12, 2021, 2:17:08 AM8/12/21
to sparselizardforum
Hi Pratik,

The gmsh 2 format .msh file you attach has a section $ParametricNodes. This should be instead $Nodes. Did you export to gmsh 2 format with ticking the "Save parameteric coordinates" box? You should not tick any box during the export.

After this the other issue remaining is that you have not defined any physical region (in the gmsh gui click on tools -> visibility and you will see there is none). This is needed. It might have been lost during the .inp to gmsh importing. There must be a way to fix this but I never loaded inp before.
Gmsh support can help you for that.

Alex
Reply all
Reply to author
Forward
0 new messages