Load a Gmsh .msh and use it in analysis#
This tutorial shows the minimal flow to load a .msh created by Gmsh
and use it in FluxFEM analysis.
Key points#
ff.load_gmsh_meshsupports both hex and tet meshes.Boundary conditions can be selected by the Physical Surface tag ID in Gmsh.
If the
.mshlacks boundary faces (quad/tri), they are inferred from geometry.
Prerequisites#
meshiois required (already listed inpyproject.tomldependencies).Tag the faces used in analysis as Physical Surface in Gmsh.
Prepare the .msh (Gmsh side)#
Tag the faces used in analysis as Physical Surface. Example: set
dirichlet_tag=1for fixed boundary,traction_tag=2for load boundary.Export the
.msh(either v2 or v4 is OK).
These tag IDs are later used to select boundary conditions via facet_tags.
Load in FluxFEM#
import numpy as np
import jax.numpy as jnp
import fluxfem as ff
import fluxfem.helpers_wf as h_wf
mesh, facets, facet_tags = ff.load_gmsh_mesh("mesh.msh")
# Switch space by tet/hex
if isinstance(mesh, ff.TetMesh):
space = ff.make_tet_space(mesh, dim=3, intorder=2)
else:
space = ff.make_hex_space(mesh, dim=3, intorder=2)
# 3D linear elastic material matrix
E = 210_000.0
nu = 0.3
D = ff.isotropic_3d_D(E, nu)
bilinear_form = ff.BilinearForm.volume(
lambda u, v, D_mat: h_wf.ddot(v.sym_grad, h_wf.matmul_std(D_mat, u.sym_grad))
* h_wf.dOmega()
)
K = space.assemble(bilinear_form, params=D)