Reading gmsh files

Beginner Meshes (files with extension .geo or .msh) generated by gmsh can be imported in Metafor. This is a very easy way to define a mesh (and groups of nodes or elements) when the geometry of the model is too difficult to be modelled with the tools available in Metafor.

The “physical groups” that have been defined in gmsh (i.e. list of nodes for the boundary conditions, or list of elements for multi-material simulations) are translated into Groups in Metafor.

In practice, the gmsh file (extension .msh) must be imported in Metafor with the commands:

from toolbox.gmsh import GmshImport

importer = GmshImport(filename, domain)

importer.setOrder(order=1)   
importer.setOpti(opti=True)
importer.setAlgo(algo='default') 
 
importer.execute()

with

filename str filename including .msh or .geo extension
domain Domain domain used to store the mesh
order int order of the elements [default=1]
opti bool activate mesh optimisation [default=True]
algo str activate mesh optimisation [default='default']

If the file extension is .geo (corresponding to a gmsh script instead of a mesh), gmsh is executed automatically by Metafor and the script is read to produce a mesh file in the workspace directory.

Problems may occur if gmsh.exe is not reachable from Metafor. The easiest way to solve this problem is to manually copy gmsh.exe in the same folder as Metafor.exe (e.g. in c:\Program Files\Metafor).

Example: Element generation:

If the “Physical Group” #300 is defined in gmsh as a list of finite elements, it is converted into a Group with the same number in Metafor. This Group can be obtained from the GroupSet using the operator() member function. This Group is useful to define a FieldApplicator in Metafor.

app1 = FieldApplicator(1)
app1.push( groupset(300) )
interactionset.add( app1 )

Example: Boundary conditions:

Similarly, if the “Physical Group” #200 is defined in gmsh as a list of nodes, it is converted into a Group with the same number in Metafor. This Group can be obtained from the GroupSet using the operator() member function. This Group is useful to prescribe boundary conditions in Metafor. For example, if we want to prescribe a 0-displacement to all the nodes of this group along the x direction:

loadingset.define(groupset(200), Field1D(TX,RE))


More Examples can be found in apps.externalMeshers