Extracting boundaries of a 2D mesh#

There are situations, when you have a 2D domain mesh, but not the corresponding boundary meshes (e.g. when extracting a slice from a 3D model). But you need them to properly set boundary conditions. For those cases ogstools provides a function to generate the individual boundary meshes from the domain mesh or from a contiuous boundary mesh.

import ogstools as ot
from ogstools import examples

domain = examples.load_meshseries_THM_2D_PVD()[0]

We can generate the boundary meshes from the given example in the following way and get a dictionary of name and mesh pairs per edge. For details, have a look into the documentation: Meshes. from_mesh().

meshes = ot.Meshes.from_mesh(domain)
boundaries = meshes.subdomains()
for name, mesh in boundaries.items():
    print(name, mesh)
top Mesh (0x792aa017bac0)
  N Cells:    83
  N Points:   84
  X Bounds:   -1.400e+03, 8.200e+03
  Y Bounds:   4.064e+01, 8.672e+01
  Z Bounds:   6.700e+03, 6.700e+03
  N Arrays:   0
bottom Mesh (0x792aa017b640)
  N Cells:    83
  N Points:   84
  X Bounds:   -1.400e+03, 8.200e+03
  Y Bounds:   -1.403e+03, -8.125e+02
  Z Bounds:   6.700e+03, 6.700e+03
  N Arrays:   0
left Mesh (0x792aa0178a60)
  N Cells:    44
  N Points:   45
  X Bounds:   -1.400e+03, -1.400e+03
  Y Bounds:   -1.403e+03, 4.186e+01
  Z Bounds:   6.700e+03, 6.700e+03
  N Arrays:   0
right Mesh (0x792aa017b5e0)
  N Cells:    44
  N Points:   45
  X Bounds:   8.200e+03, 8.200e+03
  Y Bounds:   -8.125e+02, 6.280e+01
  Z Bounds:   6.700e+03, 6.700e+03
  N Arrays:   0

Let’s display and save them:

fig = domain.plot_contourf(ot.variables.material_id)
colors = ["black", "grey", "lime", "yellow"]
for i, (name, mesh) in enumerate(boundaries.items()):
    ot.plot.line(mesh, ax=fig.axes[0], lw=2, annotate=name, color=colors[i])
plot extract boundaries
meshes.save()  # optional provide a path
[PosixPath('/tmp/tmpx9e07ar7meshes/domain.vtu'), PosixPath('/tmp/tmpx9e07ar7meshes/top.vtu'), PosixPath('/tmp/tmpx9e07ar7meshes/bottom.vtu'), PosixPath('/tmp/tmpx9e07ar7meshes/left.vtu'), PosixPath('/tmp/tmpx9e07ar7meshes/right.vtu')]

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