<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<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">
<p style="margin-top:0;margin-bottom:0"></p>
<div>Hi!</div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>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:</div>
<div>gmsh.model.mesh.setOrder(2)</div>
<div><br>
</div>
<div>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):</div>
<div><br>
</div>
<div>File "C:\PythonSpringGen\gmshSDK\lib\gmsh.py", line 1007, in generate</div>
<div> byref(ierr))</div>
<div>OSError: exception: access violation writing 0x00007FF80125DD40</div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>My code looks like this:</div>
<div><br>
</div>
<div><span style="white-space:pre"></span>gmsh.initialize()</div>
<div> gmsh.open(stepPath)</div>
<div> #gmsh.logger.start()</div>
<div> ent = gmsh.model.getEntities(0)</div>
<div> gmsh.model.mesh.setSize(ent, elemSize)</div>
<div><br>
</div>
<div> # 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)</div>
<div> gmsh.option.setNumber("Mesh.MshFileVersion", 2) </div>
<div> </div>
<div> gmsh.model.mesh.generate(3) # Generate mesh with 3 dimensions</div>
<div><br>
</div>
<div> gmsh.model.mesh.setOrder(2) # <--------------- it crashes here</div>
<div> </div>
<div> #print(gmsh.logger.get()) </div>
<div><br>
</div>
<div> gmsh.write(meshPath)</div>
<div><br>
</div>
<div><span style="white-space:pre"></span>nodeTags, self.nodeCoords, parametricCoord = gmsh.model.mesh.getNodes()</div>
<div><br>
</div>
<div><span style="white-space:pre"></span>gmsh.finalize()</div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>So, to sum up my questions:</div>
<div>- Am I doing something wrong in my code when trying to implement 2nd order mesh generation?</div>
<div>- How do I access GMSH log messages when I run it from the Python API?</div>
<div><br>
</div>
<div>Any help or pointers would be greatly appreciated!</div>
<div><br>
</div>
<div>Sunny greetings from Gothenburg,</div>
<div>Felix Eriksson</div>
<br>
<p></p>
</div>
</body>
</html>