Hey everyone. I’ve been trying to import a .geo file generated mesh into legacy FeniCs, in order to solve a problem that concerns subdomains. However, I haven´t had any luck with defining the subdomains. I took an answer from a while ago and attempted to modify it, put I havent been able to do so.
The code looks like this:
import meshio
import numpy as np
from dolfin import *
msh = meshio.read("idea3.msh")
line_cells = []
for cell in msh.cells:
if cell.type == "triangle":
triangle_cells = cell.data
elif cell.type == "line":
if len(line_cells) == 0:
line_cells = cell.data
else:
line_cells = np.vstack([line_cells, cell.data])
line_data = []
for key in msh.cell_data_dict["gmsh:physical"].keys():
if key == "line":
if len(line_data) == 0:
line_data = msh.cell_data_dict["gmsh:physical"][key]
else:
line_data = np.vstack([line_data, msh.cell_data_dict["gmsh:physical"][key]])
elif key == "triangle":
triangle_data = msh.cell_data_dict["gmsh:physical"][key]
triangle_mesh = meshio.Mesh(points=msh.points, cells={"triangle": triangle_cells})
line_mesh =meshio.Mesh(points=msh.points,
cells=[("line", line_cells)],
cell_data={"name_to_read":[line_data]})
meshio.write("mesh.xdmf", triangle_mesh)
meshio.xdmf.write("mf.xdmf", line_mesh)
mesh = Mesh()
with XDMFFile("mesh.xdmf") as infile:
infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 2)
with XDMFFile("mf.xdmf") as infile:
infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
and the error it reads is as follows:
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to find entity in map.
*** Reason: Error reading MeshValueCollection.
*** Where: This error was encountered inside HDF5File.cpp.
*** Process: 0
***
*** DOLFIN version: 2019.2.0.dev0
*** Git changeset: fd662efc1c0ddefa341c1dac753f717f6b6292a8
The .geo file is a simple file:
SetFactory("OpenCASCADE");
//+
Point(1) = {0, 0, 0, 1.0};
//+
Point(2) = {1, 0, 0, 1.0};
Point(3) = {1, 1, 0, 1.0};
Point(4) = {0, 1, 0, 1.0};
//+
Point(5) = {0.5, 1, 0, 1.0};
//+
Point(6) = {0, 0.5, 0, 1.0};
//+
Point(7) = {1, 0.5, 0, 1.0};
//+
Point(8) = {0.5, -0, 0, 1.0};
//+
Point(9) = {0.5, 0.5, 0, 1.0};
//+
//+
Line(1) = {4, 6};
//+
Line(2) = {6, 1};
//+
Line(3) = {1, 8};
//+
Line(4) = {8, 2};
//+
Line(5) = {2, 7};
//+
Line(6) = {7, 3};
//+
Line(7) = {3, 5};
//+
Line(8) = {5, 4};
//+
Line(9) = {5, 9};
//+
Line(10) = {9, 6};
//+
Line(11) = {9, 8};
//+
Line(12) = {9, 7};
//+
Curve Loop(1) = {10, 2, 3, -11};
//+
Plane Surface(1) = {1};
//+
Curve Loop(2) = {12, -5, -4, -11};
//+
Plane Surface(2) = {2};
//+
Curve Loop(3) = {7, 9, 12, 6};
//+
Plane Surface(3) = {3};
//+
Curve Loop(4) = {8, 1, -10, -9};
//+
Plane Surface(4) = {4};
//+
Physical Curve("inlet", 10000) = {2, 1};
//+
Physical Curve("outlet", 10001) = {6, 5};
//+
Physical Curve("wall", 10002) = {7, 8, 3, 4};
//+
Physical Surface("surface1", 1) = {1};
//+
Physical Surface("surface2", 2) = {2};
//+
Physical Surface("surface3", 3) = {4};
//+
And Im working with the following versions:
dolfin: 2019.2.0.dev0
meshio: 5.3.4
Any help into how to read my .geo as a mesh, and access to its defined mesh will be highly appreciated