Introduction
This is a design document for creating an extension that enables the use of the open-source mesh generation library gmsh
in Morpho.
The extension is available here and works with Morpho version 0.6.0. The version of Gmsh used at the time of writing is 4.12.2.
Example use
Here is an example of how the gmsh
module can be used.
import gmsh
var gm = GmshLoader("t1.msh") // Load a .msh (gmsh's format) file in Gmsh
gm.launch() // Launch the Gmsh app, where the mesh can now be modified
gm.exportToMorpho("t1Modified.mesh") // Save the modified mesh in Morpho's .mesh format
Excerpt from examples/fromFile.morpho
The Morpho Gmsh API itself can be used by importing the gmshapi
module:
import gmshapi
import plot
gmshInitialize(0,0,0)
var coneHeight = 1
var coneRadius = 1
var coneTag = gmshModelOccAddCone(0,0,0, 0,0,coneHeight, coneRadius,0, -1, 2*Pi)
gmshModelOccSynchronize()
gmshOptionSetNumber("Mesh.MeshSizeMax", 0.2)
gmshModelMeshGenerate(3)
var m = GmshLoader().buildMorphoMesh()
Show(plotmesh(m, grade=1))
gmshFinalize()
Excerpt from examples/occ.morpho
This allows for a different implementation of the gmsh
module or other functionalities.
Organization
The installation instructions are in Chapter 2. A simple example of a Morpho wrapper extension is discussed in Chapter 3. The structure of the Gmsh API is discussed in Chapter 4. The creation of Morpho bindings for the Gmsh API is discussed in Chapter 5. In Chapter 6, we will discuss the implementation of the gmsh
module in Morpho, which will use the Morpho Gmsh API to generate higher-level functionality. While this could also have been auto-generated similar to the Python API, we create this manually in a "Morphonic" object-oriented style. We document some to-do's in Chapter 7.
Acknowledgements
The design of this Morpho-specific binding was improved by inspirations from a Haskell Binding to the Gmsh API by Antero Marjamäki.
This is a pretty unusual piece of code for me, which required understanding the organization of the parent gmsh
codebase. This document is rather verbose, and is mostly so for my own benefit. Apologies if it beats around the bush too much!