Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ngsPETSc/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This module contains all the functions related to wrapping NGSolve meshes to
PETSc DMPlex using the petsc4py interface.
'''
from collections import defaultdict
import warnings
import numpy as np
from petsc4py import PETSc
Expand Down Expand Up @@ -213,4 +214,17 @@ def createPETScDMPlex(ngMesh, comm, name):
V = np.empty((0, gdim), dtype=PETSc.RealType)
plex = PETSc.DMPlex().createFromCellList(tdim, T, V, comm=comm)
plex.setName(name)

codim_entity = {0: "cell", 1: "face", 2: "edge"}
for codim in range(tdim):
label_mapping = defaultdict(list)
if comm.rank == 0:
regions = ngMesh.GetRegionNames(codim=codim)
for label, rname in enumerate(regions, start=1):
label_mapping[rname].append(label)

label_mapping = comm.bcast(dict(label_mapping), root=0)
entity = codim_entity[codim]
plex.setAttr(f"{entity}_region_names", label_mapping)

return plex
Loading