Note
Go to the end to download the full example code.
Remeshing with triangle elements#
Section author: Florian Zill (Helmholtz Centre for Environmental Research GmbH - UFZ)
This short example showcases the function remesh_with_tri
which allows us to
take an existing mesh and re-discretize it with triangle elements. This is
useful for models, where the underlying meshing script is not available or hard
to adapt.
from pathlib import Path
from tempfile import mkdtemp
import ogstools as ot
from ogstools import examples
mesh = examples.load_meshseries_THM_2D_PVD().mesh(1)
elements.
fig = mesh.plot_contourf(ot.variables.material_id)

Here, we do the remeshing and convert the resulting msh file to an OGS-compatible vtu file.
mesh = examples.load_meshseries_THM_2D_PVD().mesh(1)
temp_dir = Path(mkdtemp())
msh_path = temp_dir / "tri_mesh.msh"
ot.meshlib.gmsh_meshing.remesh_with_triangles(mesh, msh_path)
meshes = ot.meshes_from_gmsh(msh_path, reindex=False, log=False)
fig = meshes["domain"].plot_contourf(ot.variables.material_id)

Total running time of the script: (0 minutes 3.692 seconds)