Hi,
I want to extract the unique set of subdomain IDs, is there any easy interface of doing that?
I am currently doing it in a rather sloppy way. For instance:
cell_domains = MeshFunction('size_t', mesh, DIM)
cell_domains.set_all(100)
subdomains = set(cell_domains.array())
Thanks in advance,
Victor
MiroK
March 1, 2019, 1:48pm
2
I don’t think this is sloppy. You might get the result slightly faster with numpy.unique
.
These methods will not work correctly in parallel.
MiroK
March 1, 2019, 3:06pm
4
Here is the parallel solution
from dolfin import *
import numpy as np
mesh = UnitSquareMesh(32, 32)
comm = mesh.mpi_comm()
f = MeshFunction('size_t', mesh, 2)
f.array()[:] = comm.rank
# Local unique
my_unique = np.unique(f.array())
all_unique = np.unique(np.hstack(comm.allgather(my_unique)))
print(all_unique)
Thanks for the reply, yes Allgather
(uppercase as I use mpi4py with an older version of dolfin) is the way to go
Another question I have right now is Meshunction('size_t', mesh, dim-1)
extracts all the subdomain IDs including those for both internal faces and boundary faces. I am wondering if you know a way to only extract boundary faces.
Thanks
Victor
MiroK
March 1, 2019, 5:26pm
6
Consider
from dolfin import *
import numpy as np
mesh = UnitSquareMesh(32, 32)
comm = mesh.mpi_comm()
f = MeshFunction('size_t', mesh, mesh.topology().dim()-1)
# Fake data
f.array()[:] = comm.rank
# Auxiliary bdry selector
bdry_f = MeshFunction('size_t', mesh, mesh.topology().dim()-1)
DomainBoundary().mark(bdry_f, 1)
# Local unique
my_unique = np.unique(f.array()[bdry_f.array() == 1])
all_unique = np.unique(np.hstack(comm.allgather(my_unique)))
print(all_unique)
So basically, there’s not a direct way to discriminate boundary faces from internal faces without preset a subdomain IDs for boundary?