Hi, after importing
import dolfin as dol
import meshio
import numpy as np
I convert a .msh file to XDMF using
msh = meshio.read('device.msh')
volume_cell_type = 'triangle'
volume_cells = []
for cell in msh.cells:
if cell.type == volume_cell_type:
if len(volume_cells) == 0:
volume_cells = cell.data
else:
volume_cells = np.vstack([volume_cells, cell.data])
for key in msh.cell_data_dict['gmsh:physical'].keys():
if key == volume_cell_type:
volume_data = msh.cell_data_dict['gmsh:physical'][key]
volume_mesh = meshio.Mesh(points = msh.points[:,:2],
cells = [(volume_cell_type, volume_cells)],
cell_data = {'marker' : [volume_data]})
meshio.write('device_2D_mesh.xdmf', volume_mesh)
I then open the file, read the mesh and the marker, and define the measure.
mesh = dol.Mesh()
with dol.XDMFFile('device_2D_mesh.xdmf') as infile:
infile.read(mesh)
mvc = dol.MeshValueCollection('size_t', mesh = mesh, dim = 2)
with dol.XDMFFile('device_2D_mesh.xdmf') as infile:
infile.read(mvc, 'marker')
volume_marker = dol.cpp.mesh.MeshFunctionSizet(mesh, mvc)
del(mvc)
dx = dol.Measure('dx', domain = mesh, subdomain_data = volume_marker)
I plotted volume_marker
using dolfin plot function and it is correct,
dol.assemble(dol.Constant(1) * dx )
does give the total area (5.75)
but
dol.assemble(dol.Constant(1) * dx(1))
dol.assemble(dol.Constant(1) * dx(2))
Both return 0 instead of 4.5 and 1.25.
I am using
dolfin 2019.1.0
meshio 4.2.0
gmsh 4.5.5 for producing the msh file
For completeness I also attach the geometry file I used to produce the .msh one.
SetFactory("OpenCASCADE");
lc = .1;
Point(1) = {0, 0, 0, lc};
Point(2) = {4, 0, 0, lc};
Point(3) = {3, 2, 0, lc/2};
Point(4) = {1, 1, 0, lc/2};
Point(5) = {0.5, 0.5, 0, lc};
Line(1) = {1,2};
Line(2) = {2,3};
Line(3) = {3,4};
Line(4) = {4,5};
Line(5) = {5,1};
Line Loop(1) = {1,2,3,4,5};
Plane Surface(1) = {1};
Point(6) = {1, 2, 0, lc};
Point(7) = {0, 2, 0, lc};
Point(8) = {0, 1, 0, lc};
Line(6) = {4,6};
Line(7) = {6,7};
Line(8) = {7,8};
Line(9) = {8,5};
Line Loop(2) = {4,6,7,8,9};
Plane Surface(2) = {2};
Point(9) = {2, 1, 0, lc / 5};
Point(10) = {3, 0.5, 0, lc / 5};
Line(10) = {9,10};
Line{10} In Surface {1};
v() = BooleanFragments{Surface{1}; Delete;}{ Surface{2}; Delete; };
Physical Surface('blg', 1) = {1};
Physical Surface('slg', 2) = {2};
Physical Line('source', 1) = {7,8};
Physical Line('drain', 2) = {2};
Physical Line('wall', 3) = {10};