Gmsh interoperability

This functionality is in beta stage. Breaking changes for this API are considered non-breaking for the package. Therefore, these functions are not exported yet.

API

These methods become available via a package extension which is loaded together with Gmsh.jl. See the general gmsh documentation, the Gmsh reference manual and the Gmsh Julia API source code for information.

ExtendableGrids.simplexgrid_from_gmshFunction
simplexgrid_from_gmsh(filename::String; incomplete=false, Tc=Float32, Ti=Int32)

The msh file is read and a SimplexGrid is created. The mesh can also contain an incomplete grid. For this, the function has to be called with $incomplete=true$. 'incomplete' means that the grid only consists of nodes and cells, it does not have a boundary. We also do not try to read the physical groups for those grids. Tc is the type of coordinates, Ti is the index type.

source
simplexgrid_from_gmsh(mod::Module; incomplete=false, Tc=Float32, Ti=Int32)

The mesh contained in the gmsh module is converted to a SimplexGrid. The mesh can also contain an incomplete grid. For this, the function has to be called with $incomplete=true$. 'incomplete' means that the grid only consists of nodes and cells, it does not have a boundary. We also do not try to read the physical groups for those grids. Tc is the type of coordinates, Ti is the index type.

source
ExtendableGrids.simplexgrid_to_gmshFunction
simplexgrid_to_gmsh(g::ExtendableGrid; filename::String="")

The SimplexGrid 'g' is loaded into a gmsh module. If a string (not "") is passed via 'filename', the mesh is written into this file.

source
ExtendableGrids.mixedgrid_from_gmshFunction
mixedgrid_from_gmsh(filename::String; Tc=Float32, Ti=Int32)

The msh file is read and an ExtendableGrid is created. This only works for dim=2 grids and the orientation may be wrong. Tc is the type of coordinates, Ti is the index type.

source
mixedgrid_from_gmsh(mod::Module; Tc=Float32, Ti=Int32)

The mesh contained in the gmsh module is converted to an ExtendableGrid. Tc is the type of coordinates, Ti is the index type.

source
ExtendableGrids.mixedgrid_to_gmshFunction
mixedgrid_to_gmsh(g::ExtendableGrid; filename::String="")

The ExtendableGrid 'g' is loaded into a gmsh module. If a string (not "") is passed via 'filename', the mesh is written into this file.

source
ExtendableGrids.seal!Function
function seal!(grid::ExtendableGrid; bfaceregions=[], encode=true, Ti=Int64)

Take an (simplex-) ExtendableGrid and compute and add the BoundaryFaces. A so called incomplete ExtendableGrid can e.g. be read from an msh file using the Gmsh.jl-extension of the ExtendableGrids package and the function $simplexgrid_from_gmsh(filename::String; incomplete=true)$. If a non empty vector is passed as bfaceregions, this vector is used for the 'BFaceRegions'. If bfaceregions is empty, all BoundaryFaces get the region number 1.

For performance reasons, the faces (=the nodes contained in the face) can be encoded (see the function $encode(x::Vector, nn::Integer)$) to Integers encoding_type. To do this, encode=true is used. But for each encoding_type there is a limit on the number of nodes:

- For Int64  and a 2d grid: 3*10^9 nodes
- For Int64  and a 3d grid: 2*10^6 nodes
- For Int128 and a 2d grid: 1.3*10^19 nodes
- For Int128 and a 3d grid: 5.5*10^12 nodes

If encode=false is passed, there is no limit (besides the MaxValue of the Integer type used).

source

Internals

Gmsh extension

ExtendableGridsGmshExt.gmshfile_to_mixedgridFunction
gmshfile_to_mixedgrid(filename::String, Tc, Ti)

This function just reads an msh file, and creates a gmsh.model and then calls the 'modtomixedgrid' function This function is called in 'mixedgridfromgmsh' Tc is the type of coordinates, Ti is the index type.

This function initalizes and finalized gmsh.

source
ExtendableGridsGmshExt.gmshfile_to_simplexgridFunction
gmshfile_to_simplexgrid(filename::String, Tc, Ti)

This function reads a .msh or a .geo file, and creates a gmsh.model If it is a .geo file, gmsh.model.mesh.generate() is called. Finally, it calls the 'modtosimplexgrid' function. This function is called in 'simplexgridfromgmsh' Tc is the type of coordinates, Ti is the index type.

The function initializes and finalized the gmsh module.

source
ExtendableGridsGmshExt.mixedgrid_to_gmshfileFunction
mixedgrid_to_gmshfile(grid::ExtendableGrid, filename::String)

This function takes a mixed grid, uses 'gridtomod' to create a corresponding gmsh module Then it writes the module to a file

grid[CellNodes] must be a VariableTargetAdjacency structure This function initializes and finalized gmsh.

source
ExtendableGridsGmshExt.multiply_indicesFunction
multiply_indices(indices, n)

for n=3: [i, j, ..., k], 3 -> [3i-2, 3i-1, 3i, 3j-1, 3j-2, 3j, ..., 3k-2, 3k-1, 3k] in general: [i, j, ..., k], n -> [ni-(n-1), ni-(n-2), ..., ni, n*j-(n-1), ...] This function can be used, if you have the indices of cells, and you want to get all their nodes, but the nodes are stored in one list for all cells: [node1ofcell1, node2ofcell1, ... nodenofcell1, node1ofcell2, ...]

source
ExtendableGridsGmshExt.mod_to_mixedgridFunction
mod_to_mixedgrid(model::Module, Tc, Ti)

Function that tries to create a (mixed-) ExtendableGrid from a gmsh.model. Model has to be a gmsh.model. (This function has to be called with an initialized gmsh environment). This function is called in 'mixedgridfromgmsh'. Tc is the type of coordinates, Ti is the index type.

source
ExtendableGridsGmshExt.simplexgrid_to_gmshfileFunction
function simplexgrid_to_gmshfile(grid::ExtendableGrid, filename::String)

This function takes a simplexgrid, uses 'gridtomod' to create a corresponding gmsh module Then it writes the module to a file.

This function initalizes and finalized gmsh.

source
ExtendableGridsGmshExt.simplexgrid_to_modFunction
grid_to_mod(grid::ExtendableGrid)

This function writes an ExtendableGrid into a gmsh module. (This function has to be called with an initialized gmsh environment) At the moment, this function can only be used from the outside via 'write_gmsh', where the newly created gmsh module is written into a msh file.

source
ExtendableGridsGmshExt.mod_to_simplexgridFunction
mod_to_grid(model::Module, Tc, Ti)

Function that tries to create an (simplex-) ExtendableGrid from a gmsh.model. Model has to be a gmsh.model. (This function has to be called with an initialized gmsh environment). This function is called in 'simplexgridfromgmsh'. Tc is the type of coordinates, Ti is the index type.

source
ExtendableGridsGmshExt.incomplete_mod_to_simplexgridFunction
incomplete_mod_to_simplexgrid(model::Module, Tc, Ti)

Loads an incomplete mesh from a msh file. Then converts into an ExtendableGrids. 'incomplete' in this context means the boundary is missing. With the 'ExtendableGrids.seal!(grid::ExtendableGrid)' the boundary can be added. Tc is the type of coordinates, Ti is the index type.

source
ExtendableGridsGmshExt.use_vtaFunction
use_vta(VTA, col_ids, num)

If VTA were a matrix, the result would be equivalent to VTA[:, col_ids]. Each column of the VTA contains the nodes of one cell.

source

seal! method

ExtendableGrids.faces_of_ndim_simplexFunction
function faces_of_ndim_simplex(x::Vector, dim::Integer, nn::Integer)

Return all faces of a n-dim simplex. The orientation is not guaranteed to be right. x contains the nodes of the simplex. nn is the total number of nodes. The faces (=the nodes contained in the face), are encoded to Integers (of nn's type).

source
ExtendableGrids.assemble_bfaces_directFunction
function assemble_bfaces_direct(simplices, dim, Ti)

Assemble the BoundaryFaces corresponding to the simplices passed. In this function, the faces are not encoded. This may make sense for grids with many nodes. For smaller grids it can lead to performance losses. simplices is a $(dim+1) x 'number cells'$ matrix and nn is the total number of nodes. We can not guarantee, that the orientation of the BoundaryFaces is correct.

source
ExtendableGrids.decodeFunction
function decode(y::Integer, nn::Integer, dim::Integer)

Decode y to the vector x. x has the length dim. The en/-decoding is similar to using the base-nn number system. For details of the encoding, see the documentation of the function encode.

source
ExtendableGrids.encodeFunction
function encode(x::Vector, nn::Integer)

Encode th vector x into an Int y. The en/-decoding is similar to using the base-nn number system. Example: $[x₁, x₂, x₃] → (x₁-1) + (x₂-1)*nn + (x₃-1)*nn²$``

source
ExtendableGrids.faces_of_ndim_simplex_directFunction
function faces_of_ndim_simplex(x::Vector, dim::Integer, nn::Integer)

Return all faces of a n-dim simplex. The orientation is not guaranteed to be right. x contains the nodes of the simplex. nn is the total number of nodes. The faces (=the nodes contained in the face), are not encoded to Integers.

source
ExtendableGrids.assemble_bfacesFunction
function assemble_bfaces(simplices, dim, nn, Ti)

Assemble the BoundaryFaces corresponding to the simplices passed. In this function, the faces are encoded for performance reasons. If a large grid with many nodes is used, Ti has to be chosen accordingly (e.g. Int128), or encode=false has to be passed to seal!. simplices is a $(dim+1) x 'number cells'$ matrix and nn is the total number of nodes. We can not guarantee, that the orientation of the BoundaryFaces is correct.

source