[Gmsh] Generating 2nd order mesh via Python API

Felix Eriksson erfelix at student.chalmers.se
Tue Mar 26 10:34:37 CET 2019


Dear Christophe,


Thank you for your quick answer. My STEP-file is in meters, so I added the code line you gave me before I import the STEP-file. Just a small remark, it has to be gmsh.option.setString("Geometry.OCCTargetUnit", "M") with a capital M to work.


Now I can make a linear element mesh with GMSH 4.2, but it still fails when I try to make a mesh with second order elements. I've tried both:

gmsh.model.mesh.setOrder(2) and

gmsh.option.setNumber("Mesh.ElementOrder", 2)


When I use the setOrder()-method before generate(), it does not change the result (mesh still has linear elements). If I use setOrder() after generate(), I now get the following error message (in GMSH 4.1 it just restarted the shell):


File "C:\PythonSpringGen\gmsh-4.2.2-Windows64-sdk\lib\gmsh.py", line 1158, in setOrder
    byref(ierr))
OSError: exception: access violation writing 0x00000000100A0000


For the setNumber()-method, when I put that before generate(), I instead get the same type of error when it reaches generate():

File "C:\PythonSpringGen\gmsh-4.2.2-Windows64-sdk\lib\gmsh.py", line 1104, in generate
    byref(ierr))
OSError: exception: access violation writing 0x0000000030530000

and when I put setNumber() after generate(), nothing happens (still linear elements). It seems to me that the API is trying to write something to a place in memory that isn't allowed, but my knowledge of exactly how this works is yet too limited to understand this.

I would be very grateful for assistance in this matter, I really appreciate you taking the time to answer my question.

Kind regards,
Felix Eriksson

________________________________
Från: Christophe Geuzaine <cgeuzaine at uliege.be>
Skickat: den 25 mars 2019 19:44
Till: Felix Eriksson
Kopia: gmsh at onelab.info
Ämne: Re: [Gmsh] Generating 2nd order mesh via Python API


Dear Felix,

Can you try again with version 4.2.2, but by making sur that you match the mesh size with the size of the model?

Gmsh 4.2 changed the default setting for importing STEP files to keep the coordinates without unit conversion. For example, if you file is in mm, you should multiply your mesh size by 1000 compared to Gmsh 4.1. Or else use gmsh.option.setString("Geometry.OCCTargetUnit", "m") to convert the geometry to meters, as was done in Gmsh 4.1. (This was disabled by default as it sometimes leads to conversion inaccuracies.)

Christophe

> On 25 Mar 2019, at 16:47, Felix Eriksson <erfelix at student.chalmers.se> wrote:
>
> Hi!
>
> I'm writing a Python program for parameter optimization as part of my Master's thesis. In this program, I'm using GMSH for meshing a STEP-file that has been generated in Autodesk Inventor. It has been working very nicely, and I'm impressed by the capabilities of the software.
>
> However, I've run into some problems now, which I can't seem to figure out the cause of. I've realized that I need to use second order elements for my problem, as shear locking is causing large errors when I use linear elements. I can successfully generate a mesh of tetrahedrons with my desired fineness, so the only thing I need to change is the order of the elements. In the graphical interface, this works fine by just clicking "Set order 2". Looking at the documentation, the appropriate command for setting the element order to 2 is:
> gmsh.model.mesh.setOrder(2)
>
> But when I add this line to my Python code, it either doesn't do anything (elements still turn out linear), or makes Python crash (the shell is restarted without any message), depending on if I add the line before or after gmsh.model.mesh.generate(3). I've tried getting log messages, to figure out what is going on, using gmsh.logger.start() after initializing GMSH, but when I add that command GMSH crashes with the following message, once it reaches gmsh.model.mesh.generate(3):
>
> File "C:\PythonSpringGen\gmshSDK\lib\gmsh.py", line 1007, in generate
>     byref(ierr))
> OSError: exception: access violation writing 0x00007FF80125DD40
>
> I've also tried looking for some kind of log file, which, to my understanding, should be saved in case GMSH crashes, but I don't know where to find it.
>
> My code looks like this:
>
> gmsh.initialize()
>         gmsh.open(stepPath)
>         #gmsh.logger.start()
>         ent = gmsh.model.getEntities(0)
>         gmsh.model.mesh.setSize(ent, elemSize)
>
>         # for some reason it doesn't work with ElmerGrid if you use the new version 4 for GMSH mesh file format, so choose v2 (previous)
>         gmsh.option.setNumber("Mesh.MshFileVersion", 2)
>
>         gmsh.model.mesh.generate(3) # Generate mesh with 3 dimensions
>
>         gmsh.model.mesh.setOrder(2) # <--------------- it crashes here
>
>         #print(gmsh.logger.get())
>
>         gmsh.write(meshPath)
>
> nodeTags, self.nodeCoords, parametricCoord = gmsh.model.mesh.getNodes()
>
> gmsh.finalize()
>
> I'm using GMSH SDK 4.1.4. I tried using the latest version (4.2.2), but then my program always hangs at gmsh.model.mesh.generate(3), even if I don't set the mesh order to 2.
>
> So, to sum up my questions:
> - Am I doing something wrong in my code when trying to implement 2nd order mesh generation?
> - How do I access GMSH log messages when I run it from the Python API?
>
> Any help or pointers would be greatly appreciated!
>
> Sunny greetings from Gothenburg,
> Felix Eriksson
>
> _______________________________________________
> gmsh mailing list
> gmsh at onelab.info
> http://onelab.info/mailman/listinfo/gmsh

—
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science
http://www.montefiore.ulg.ac.be/~geuzaine



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://onelab.info/pipermail/gmsh/attachments/20190326/703af1ef/attachment-0001.html>


More information about the gmsh mailing list