Posts

Showing posts from 2021

FEniCS: Read mesh from msh (XDMF) with subdomains

The overall procedure is generating Mesh() , MeshValueCollection objects first, and reading information into them. Then generating MeshFunctionSizet accordingly to define dx , ds ... for subdomains. Step 0. Open corresponding XDMF files; e.g.,  with XDMFFile(MPI.comm_world, "mesh.xdmf") as xdmf_infile: Step 1. Create Mesh object, using mesh = dolfin.cpp.mesh.Mesh() Step 2. Read Mesh from XDMF file, e.g.,  xdmf_infile.read(mesh) Step 3. Create MeshValueCollection object as container of subdomain information; mvc_subdomain = dolfin.MeshValueCollection("size_t", mesh, mesh.topology().dim()) Step 4. Read subdomain information, xdmf_infile.read(mvc_subdomain, "name-to-read") The "name-to-read" here is the name given in XDMF file generated by meshio . Step 5. Using step 3, 4 to read boundaries (open another file if necessary): mvc_boundaries = dolfin.MeshValueCollection("size_t", mesh, mesh.topology().dim()-1) xdmf_infile.rea