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.mixedgrid_from_gmsh — Function
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.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_mixedgrid — Function
gmshfile_to_mixedgrid(filename::String, Tc, Ti)

Read an msh file, create a gmsh model from it and convert it to a mixed grid.

The function then calls mod_to_mixedgrid, which is also reachable through mixedgrid_from_gmsh. Tc is the type of coordinates, Ti is the index type.

This function initializes and finalizes gmsh.

source
ExtendableGridsGmshExt.gmshfile_to_simplexgrid — Function
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_gmshfile — Function
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_indices — Function
multiply_indices(indices, n)

Expand cell indices to the indices of all their nodes in a flattened node list.

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_mixedgrid — Function
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_mod — Function
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_simplexgrid — Function
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_simplexgrid — Function
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_vta — Function
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_simplex — Function
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_direct — Function
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.decode — Function
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.encode — Function
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.assemble_bfaces — Function
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