<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Dear Christophe,</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">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 <span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;">gmsh.option.setString("Geometry.OCCTargetUnit",
 "M") with a capital M to work.</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;"><br>
</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;">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:</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;"><span>gmsh.model.mesh.setOrder(2)
 and</span><br>
</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;"><span><span>gmsh.option.setNumber("Mesh.ElementOrder",
 2)</span><br>
</span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;"><span><span><br>
</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;"><span><span>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):</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;"><span><span><br>
</span></span></span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 14.6667px;"><span><span></p>
<div>File "C:\PythonSpringGen\gmsh-4.2.2-Windows64-sdk\lib\gmsh.py", line 1158, in setOrder</div>
<div>    byref(ierr))</div>
<div>OSError: exception: access violation writing 0x00000000100A0000</div>
<br>
</span></span></span>
<p></p>
For the setNumber()-method, when I put that before generate(), I instead get the same type of error when it reaches generate():</div>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<br>
</div>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<div>File "C:\PythonSpringGen\gmsh-4.2.2-Windows64-sdk\lib\gmsh.py", line 1104, in generate</div>
<div>    byref(ierr))</div>
<div>OSError: exception: access violation writing 0x0000000030530000</div>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<br>
</div>
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.</div>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<br>
</div>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
I would be very grateful for assistance in this matter, I really appreciate you taking the time to answer my question.</div>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<br>
</div>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
Kind regards,</div>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
Felix Eriksson</div>
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
<br>
<div style="color: rgb(0, 0, 0);">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Från:</b> Christophe Geuzaine <cgeuzaine@uliege.be><br>
<b>Skickat:</b> den 25 mars 2019 19:44<br>
<b>Till:</b> Felix Eriksson<br>
<b>Kopia:</b> gmsh@onelab.info<br>
<b>Ämne:</b> Re: [Gmsh] Generating 2nd order mesh via Python API</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText"><br>
Dear Felix,<br>
<br>
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?<br>
<br>
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.)<br>
<br>
Christophe<br>
<br>
> On 25 Mar 2019, at 16:47, Felix Eriksson <erfelix@student.chalmers.se> wrote:<br>
> <br>
> Hi!<br>
> <br>
> 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.<br>
> <br>
> 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:<br>
> gmsh.model.mesh.setOrder(2)<br>
> <br>
> 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):<br>
> <br>
> File "C:\PythonSpringGen\gmshSDK\lib\gmsh.py", line 1007, in generate<br>
>     byref(ierr))<br>
> OSError: exception: access violation writing 0x00007FF80125DD40<br>
> <br>
> 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.<br>
> <br>
> My code looks like this:<br>
> <br>
> gmsh.initialize()<br>
>         gmsh.open(stepPath)<br>
>         #gmsh.logger.start()<br>
>         ent = gmsh.model.getEntities(0)<br>
>         gmsh.model.mesh.setSize(ent, elemSize)<br>
> <br>
>         # 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)<br>
>         gmsh.option.setNumber("Mesh.MshFileVersion", 2)        <br>
>         <br>
>         gmsh.model.mesh.generate(3) # Generate mesh with 3 dimensions<br>
> <br>
>         gmsh.model.mesh.setOrder(2) # <--------------- it crashes here<br>
>         <br>
>         #print(gmsh.logger.get())        <br>
> <br>
>         gmsh.write(meshPath)<br>
> <br>
> nodeTags, self.nodeCoords, parametricCoord = gmsh.model.mesh.getNodes()<br>
> <br>
> gmsh.finalize()<br>
> <br>
> 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.<br>
> <br>
> So, to sum up my questions:<br>
> - Am I doing something wrong in my code when trying to implement 2nd order mesh generation?<br>
> - How do I access GMSH log messages when I run it from the Python API?<br>
> <br>
> Any help or pointers would be greatly appreciated!<br>
> <br>
> Sunny greetings from Gothenburg,<br>
> Felix Eriksson<br>
> <br>
> _______________________________________________<br>
> gmsh mailing list<br>
> gmsh@onelab.info<br>
> <a href="http://onelab.info/mailman/listinfo/gmsh" id="LPlnk862845" class="OWAAutoLink" previewremoved="true">
http://onelab.info/mailman/listinfo/gmsh</a><br>
<br>
— <br>
Prof. Christophe Geuzaine<br>
University of Liege, Electrical Engineering and Computer Science <br>
<a href="http://www.montefiore.ulg.ac.be/~geuzaine" id="LPlnk261550" class="OWAAutoLink" previewremoved="true">http://www.montefiore.ulg.ac.be/~geuzaine</a><br>
<br>
<br>
<br>
</div>
</span></font></div>
</div>
</div>
</div>
</body>
</html>