I have read that the support from dolfin-convert is almost nill and will soon be deprecated. This means I have to change the way I read the mesh file created with Gmsh in my codes, but so far I am unable to do it. My goal is to make the transition as smooth as possible.
As of now I create a file.geo with Gmsh, convert it to a file.msh using the command gmsh file.geo -format msh2 -3
. Then I use dolfin-convert file.msh file.xml
which creates 2 files I can read with dolfin, and everything is easy and fine. More precisely, I do
subdomains = MeshFunction(âsize_tâ, mesh, file_physical_region.xml)
boundary_parts = MeshFunction(âsize_tâ, mesh, file_facet_region.xml)
This is what I would like to achieve with meshio. From what I have read, meshio supports some features of dolfin-convert regarding the xml file format, but it isnât quite similar so it is impossible to reproduce what dolfin-convert does in the above example. Furthermore, XDMF is instead the suggested alternative.
So, letâs take the following file.geo:
SetFactory("OpenCASCADE");
Mesh.RandomFactor=1.0e-6;
lc=0.00017;
a = 0.002;
b = 0.001;
c = 0.00003;
Point(1) = {-a/2, -b/2, -c/2, lc};
Point(2) = {-a/2, b/2, -c/2, lc};
Point(3) = {a/2, b/2, -c/2, lc};
Point(4) = {a/2, -b/2, -c/2, lc};
Line(1) = {1,2};
Line(2) = {2,3};
Line(3) = {3,4};
Line(4) = {4,1};
Line Loop(5) = {1,2,3,4};
Point(7) = {-a/10 + a/4.4,-b/10-b/3, -c/2, lc};
Point(8) = {-a/10 + a/4.4,b/10-b/3,-c/2, lc};
Point(9) = {a/10 + a/4.4, b/10-b/3,-c/2, lc};
Point(10) = {a/10 + a/4.4,-b/10-b/3,-c/2, lc};
Line(11) = {7,8};
Line(12) = {8,9};
Line(13) = {9,10};
Line(14) = {10,7};
Line Loop(15) = {11,12,13,14};
Plane Surface(16) = {15};
Point(17) = {-a/16+a/4,-b/16+b/3.2, -c/2, lc};
Point(18) = {-a/16+a/4,b/16+b/3.2,-c/2, lc};
Point(19) = {a/16+a/4, b/16+b/3.2,-c/2, lc};
Point(20) = {a/16+a/4,-b/16+b/3.2,-c/2, lc};
Line(21) = {17,18};
Line(22) = {18,19};
Line(23) = {19,20};
Line(24) = {20,17};
Line Loop(25) = {21,22,23,24};
Plane Surface(26) = {25};
Point(27) = {-a/20-a/2.5,-b/3, -c/2, lc};
Point(28) = {-a/20-a/2.5,b/3,-c/2, lc};
Point(29) = {a/20-a/2.5, b/3,-c/2, lc};
Point(30) = {a/20-a/2.5,-b/3,-c/2, lc};
Line(31) = {27,28};
Line(32) = {28,29};
Line(33) = {29,30};
Line(34) = {30,27};
Line Loop(35) = {31,32,33,34};
Plane Surface(36) = {35};
Point(37) = {-a/4,-b/3, -c/2, lc};
Point(38) = {-a/4,b/3,-c/2, lc};
Point(39) = {-a/5, b/3,-c/2, lc};
Point(40) = {-a/5,-b/3,-c/2, lc};
Line(41) = {37,38};
Line(42) = {38,39};
Line(43) = {39,40};
Line(44) = {40,37};
Line Loop(45) = {41,42,43,44};
Plane Surface(46) = {45};
Plane Surface(47)={5,25,15,35,45};
Physical Surface("bottom")={47};
Physical Surface("bot_1")={16};
Physical Surface("bot_2")={26};
Physical Surface("bot_3")={36};
Physical Surface("bot_4")={46};
surfaceVector[] = Extrude {0, 0, c} {
Surface{47,26,16,36,46};
Layers{31};
};
Physical Surface("top") = {surfaceVector[0]};
Physical Volume("parallelepiped") = {surfaceVector[1]};
Physical Surface("left") = {surfaceVector[2]};
Physical Surface("back") = {surfaceVector[3]};
Physical Surface("right") = {surfaceVector[4]};
Physical Surface("front") = {surfaceVector[5]};
Physical Surface("top_2") = {surfaceVector[22]};
Physical Volume("stuff_2") = {surfaceVector[23]};
Physical Surface("top_1") = {surfaceVector[28]};
Physical Volume("stuff_1") = {surfaceVector[29]};
Physical Surface("top_3") = {surfaceVector[34]};
Physical Volume("stuff_3") = {surfaceVector[35]};
Physical Surface("top_4") = {surfaceVector[40]};
Physical Volume("stuff_4") = {surfaceVector[41]};
Then we create the file.msh using gmsh file.geo -3
. Then we use meshio-convert file.msh file.xdmf
. We now have a file.h5 and a file.xdmf.
And this is where I am stuck, I do not know how to read the mesh and assign the boundaries as I used to do with the file.xml that was produced with dolfin-convert.
I tried:
from dolfin import *
mesh = Mesh()
with XDMFFile("file.xdmf") as infile:
infile.read(mesh)
But this yields
RuntimeError Traceback (most recent call last)
in
8 with XDMFFile(âfile.xdmfâ) as infile:
----> 9 infile.read(mesh)
10RuntimeError:
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
*** fenics-support@googlegroups.com
*** Remember to include the error message listed below and, if possible,
*** include a minimal running example to reproduce the error.
*** -------------------------------------------------------------------------
*** Error: Unable to recognise cell type.
*** Reason: Unknown value âmixedâ.
*** Where: This error was encountered inside XDMFFile.cpp.
*** Process: 0
*** DOLFIN version: 2018.1.0
*** Git changeset: unknown
*** -------------------------------------------------------------------------
So it seems unable to recognize the cell type. I get exactly the same error if I use the deprecated -format msh2 flag in the gmsh command to produce the file.msh. Thus, overall, I do not know how to reproduce the simple commands that work with the file.xml produced with dolfin-convert, using meshio.
Note that I had posted a similiar question there but I eventually ran into errors and so this lead to no solution.