This demo explains how to use Measure
to restrict facet integration.
Hi,
sorry, I probably did not explain it well.
I wrote two functions to convert a .msh file to XDMF file using the code example provided by @dokken .
Now my first function generates from a .msh file three separated XDMF files for the mesh, the subdomains and the boundary subdomains.
At a later time I can load the files using the second functions that returns a dictionary containing the mesh, the marker functions (for volume and boundary subdomains) and the corresponding measures.
How I can generalize this code to include also internal boundary subdomains.
Should I also generate a separate xdmf file for internal boundaries?
How can I mark in gmsh an internal boundary subdomain? The command Physical surface doesn’t seem to distinguish external surfaces from internal ones.
Best.
Iacopo
Here is my code
import meshio
import dolfin as dol
def convert_to_XDMF(filename):
'''reads a .msh file and writes mesh, subdomains, and boundary subdomains
to XDMF files'''
#check if input file i in msh
if filename.split(sep = '.')[-1] != 'msh':
raise TypeError('.msh file required')
msh = meshio.read(filename)
#write mesh xdmf file
meshio.write(''.join(filename.split(sep ='.')[:-1]) + '_mesh.xdmf',
meshio.Mesh(points = msh.points,
cells = {'tetra': msh.cells['tetra']}))
#write boundary subdomains xdmf file
meshio.write(''.join(filename.split(sep ='.')[:-1]) + '_boundary_subdomains.xdmf',
meshio.Mesh(points = msh.points,
cells = {'triangle': msh.cells['triangle']},
cell_data = {'triangle': {'name_to_read' : msh.cell_data['triangle']['gmsh:physical']}}))
#write subdomains xdmf file
meshio.write(''.join(filename.split(sep ='.')[:-1]) + '_subdomains.xdmf',
meshio.Mesh(points = msh.points,
cells = {'tetra' : msh.cells['tetra']},
cell_data = {'tetra' : {'name_to_read' : msh.cell_data['tetra']['gmsh:physical']}}))
def load_XDMF_files(filename):
#create mesh from msh file
mesh = dol.Mesh()
with dol.XDMFFile(filename) as infile:
infile.read(mesh)
#create subdomain cell function
mvc = dol.MeshValueCollection('size_t', mesh, 3)
with dol.XDMFFile(''.join(filename.split(sep ='_')[:-1]) + '_subdomains.xdmf') as infile:
infile.read(mvc, 'name_to_read')
subdomain_marker = dol.cpp.mesh.MeshFunctionSizet(mesh, mvc)
#create boundary subdomain facet function
mvc = dol.MeshValueCollection('size_t', mesh, 2)
with dol.XDMFFile(''.join(filename.split(sep ='_')[:-1]) + '_boundary_subdomains.xdmf') as infile:
infile.read(mvc, 'name_to_read')
boundary_marker = dol.cpp.mesh.MeshFunctionSizet(mesh, mvc)
del(mvc)
#define measures
dx = dol.Measure('dx', domain = mesh, subdomain_data = subdomain_marker)
ds = dol.Measure('ds', domain = mesh, subdomain_data = boundary_marker)
#return dictionary
return {'mesh' : mesh,
'volume_measure' : dx,
'boundary_measure' : ds,
'subdomain_marker' : subdomain_marker,
'boundary_marker' : boundary_marker}
You can just proceed analogously as for exterior boundaries, even write everything into the same xdmf file.
For gmsh you just mark the corresponding internal boundaries as physical line or surface (depending on your dimension).
When you create your Measures with
ds = dol.Measure('ds', domain = mesh, subdomain_data = boundary_marker)
dS = dol.Measure('dS', domain=mesh, subdomain_data = boundary_marker)
everything is taken care of (as the Measures are for external and internal surfaces)
Ok, dS ignores informations on facets that are on the boundary, while ds ignores internal boundaries.
I just need to use different indicators (I cannot have an internal boundary with integration measure dS(1) and an external boundary with integration measure ds(1) ) but is probably never a good idea to use the same number for two different things.
Thanks for the super-fast reply.
I
Hi,
I not familiar with using xml or xdmf files but I used Gmsh to create a simple mesh in order to refine it later. As you explained using gmsh -3 plate.geo to generate plate.msh. and with the same code you have provided for conversion into xdmf .
Unfortuentaly I was not able to figure out how to avoid this error message:
File "Dye3D.py", line 70, in <module>
meshio.write("mesh.xdmf", meshio.Mesh(points=msh.points, cells={"tetra": msh.cells["tetra"]}))
AttributeError: module 'meshio' has no attribute 'Mesh'
here is the plate.geo file from Gmsh:
//+
Physical Line("left_line") = {4};
//+
SetFactory("OpenCASCADE");
Box(1) = {e, e, 0, 50, 100, 2};
//+
Physical Line("left_line") += {4};
//+
Physical Line("right_line") = {8};
//+
Physical Line("front_line") = {11};
//+
Physical Line("back_line") = {9};
//+
Physical Surface("left") = {1};
//+
Physical Surface("right") = {2};
//+
Physical Surface("front") = {4};
//+
Physical Surface("back") = {3};
//+
Physical Surface("bottom") = {5};
//+
Physical Surface("top") = {6};
//+
Physical Volume("domain") = {1};
//+
Field[1] = Box;
//+
Field[1].VIn = 0.7;
//+
Field[1].VOut = 5;
//+
Field[1].XMax = 50;
//+
Field[1].XMin = 45;
//+
Field[1].YMax = 100;
//+
Field[1].ZMax = 2;
//+
Background Field = 1;
Can you please advise any solution to this error and if I am using the correct way for the file generation.
Thank you!
Which version of meshio
are you using?
I have no issues with the following code with meshio 4.0.8:
import meshio
msh = meshio.read("mesh.msh")
meshio.write("mesh.xdmf",
meshio.Mesh(points = msh.points,
cells = {'tetra': msh.cells_dict['tetra']}))
thanks for reply
It is meshio-2.3.10
I have checked for the version 4.0.8. but could not install it!
Have you tried pip3 install meshio --upgrade
I tried this with meshio-4.0.8:
import meshio
msh = meshio.read("Monopole2.msh")
for cell in msh.cells:
if cell.type == "tetra":
tet_cells = cell.data
for key in msh.cell_data_dict["gmsh:physical"].keys():
if key == "tetra":
tetra_data = msh.cell_data_dict["gmsh:physical"][key]
tet_mesh = meshio.Mesh(points=msh.points, cells={"tetra": tet_cells})
meshio.write("mesh.xdmf", tet_mesh)
and it dies with the following error message:
Traceback (most recent call last):
File "Monopole2.py", line 10, in <module>
meshio.write("mesh.xdmf", tet_mesh)
File "/home/bill/.local/lib/python3.6/site-packages/meshio/_helpers.py", line 119, in write
file_format = _filetype_from_path(path)
File "/home/bill/.local/lib/python3.6/site-packages/meshio/_helpers.py", line 33, in _filetype_from_path
raise ReadError("Could not deduce file format from extension '{}'.".format(ext))
meshio._exceptions.ReadError: Could not deduce file format from extension '.xdmf'.
How can I make this work?
My full 3D GMSH mesh file found here. It is a bit big to post as code for E-Z copy paste.
PS- Just tried this code posted by @dokken earlier. It gives the same error.
import meshio
msh = meshio.read("Monopole2.msh")
meshio.write("mesh.xdmf",
meshio.Mesh(points = msh.points,
cells = {'tetra': msh.cells_dict['tetra']}))
You have to install h5py. pip3 install h5py
.
@dokken That fixed it! Thanks!
Thanks, it is updated now.
I have read this thread and tried to use the generated files but it did not work.
I want to use the physical_groups names for Dirichlet and Neumann boundary conditions (this may include boundaries on edge lines).
The problem that I want to solve will include a Mixed finite element. Here is a simple version with heat diffusion as it was possible to generate the xdmf files:
Edit: best what I was able to achieve is to use from mf.xdmf file.
I could not create the cf.xdmf file in order to use it in the volume measure.
Now the minimal code is
import meshio
msh = meshio.read("plate.msh")
for cell in msh.cells:
if cell.type == "triangle":
triangle_cells = cell.data
elif cell.type == "tetra":
tetra_cells = cell.data
for key in msh.cell_data_dict["gmsh:physical"].keys():
if key == "triangle":
triangle_data = msh.cell_data_dict["gmsh:physical"][key]
elif key == "tetra":
tetra_data = msh.cell_data_dict["gmsh:physical"][key]
tetra_mesh = meshio.Mesh(points=msh.points, cells={"tetra": tetra_cells})
triangle_mesh =meshio.Mesh(points=msh.points,
cells=[("triangle", triangle_cells)],
cell_data={"name_to_read":[triangle_data]})
meshio.write("plate.xdmf", tetra_mesh)
meshio.write("mf.xdmf", triangle_mesh)
from dolfin import *
import numpy
import time
import matplotlib.pyplot as plt
set_log_level(LogLevel.ERROR)
mesh = Mesh()
with XDMFFile("plate.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)
'''mvc = MeshValueCollection("size_t", mesh, 3)
with XDMFFile("cf.xdmf") as infile:
infile.read(mvc, "name_to_read")
cf = cpp.mesh.MeshFunctionSizet(mesh, mvc)'''
ds_top = Measure("ds", domain=mesh, subdomain_data=mf, subdomain_id=11)
ds_right = Measure("ds", domain=mesh, subdomain_data=mf, subdomain_id=7)
dx_volume = Measure("dx", domain=mesh, subdomain_data=mf, subdomain_id=12) # cf, need to create cf.xdmf
print('assemble(1*ds_top)',assemble(1*ds_top))
print('assemble(1*ds_right)',assemble(1*ds_right))
Tref = 298 #300. # in K
Tamb = Tref
Ts = Constant(1273.) # Solid temp
Tl = Constant(1514.) # Liquid temp
Tm = Constant(1514.) # Melting temperature (K)
rho = 7737.0e-12 # in tonne/mm3
kappa = 28. # mJ/(smmK)
Cp = 600.0e6 # mJ/(tonK)
h = 35.0e-3 # mJ/(smm^2K)
t = 0.0
tMax = 50 #
Dt = 1 # time step
WIDTH, LENGTH, thickness = 50., 100., 2. # width, length and thickness (mm)
xMin, xMax = 0.0, WIDTH
yMin, yMax = 0.0, LENGTH
zMin, zMax = 0.0, thickness
##mesh = BoxMesh(Point(xMin,yMin,zMin), Point(xMax,yMax,zMax),20, 60, 3)
# Define space function
Space = FunctionSpace(mesh,'P',1)
#cells = MeshFunction('size_t',mesh, 3, 0)
#facets = MeshFunction('size_t',mesh, 2, 0)
#dA = Measure('ds', domain=mesh, subdomain_data=facets, metadata={'quadrature_degree':2})
#dV = Measure('dx', domain=mesh, subdomain_data=cells, metadata={'quadrature_degree':2})
#boundaries
#bc1 = DirichletBC(Space,Constant(1000.),right)
bc = []#[bc1]
# define functions
dT = TrialFunction(Space)
delT = TestFunction(Space)
T = Function(Space)
T0 = Function(Space)
T_init = Expression(('Tini'),Tini=Tref, degree=1) #degree=2
T = interpolate(T_init,Space)
T0.assign(T)
cutoff_Tc = 113.2 ##
Sour_surface = Expression( "t <= tc ? eta *Q_app/(pi*a*a)*exp(- (pow((x[0]-x0),2)+ pow((x[1]-y0-v*t),2))/(2.*a*a) ): 0",
t=t, tc=cutoff_Tc, eta=0.57, a=4 , Q_app =Constant(580e3),v=1.59, x0=0,y0=LENGTH*0.05, degree=2)
qHat = h*(T-Tref) # heat losses
F = rho*Cp*(T-T0)/Dt*delT*dx_volume +kappa*dot(grad(T),grad(delT))*dx_volume\
-1.0*Sour_surface*delT*ds_top +qHat*delT*(ds_top+ds_right) #1.0*Sour_surface*delT*dA(6)
J = derivative(F, T, dT)
file_results = XDMFFile("Results.xdmf")
file_results.parameters["flush_output"] = True
file_results.parameters["functions_share_mesh"] = True
it= 0 #
while t < tMax:
it +=1
print('iteration_No:',it)
Sour_surface.t= t
solve(F==0, T, bc, J=J,
solver_parameters={'newton_solver':{'linear_solver': 'mumps', 'relative_tolerance':1e-5}}, \
form_compiler_parameters={'cpp_optimize':True, 'representation': 'uflacs'})
T0.assign(T)
file_results.write(T, t)
t+= Dt
and the msh file with smaller dimensions:
$MeshFormat
2.2 0 8
$EndMeshFormat
$PhysicalNames
11
1 1 "left_line"
1 3 "right_line"
1 4 "front_line"
1 5 "back_line"
2 6 "left"
2 7 "right"
2 8 "front"
2 9 "back"
2 10 "bottom"
2 11 "top"
3 12 "domain"
$EndPhysicalNames
$Nodes
138
1 0 0 2
2 0 0 0
3 0 100 2
4 0 100 0
5 50 0 2
6 50 0 0
7 50 100 2
8 50 100 0
9 0 9.090909090909093 2
10 0 18.1818181818182 2
11 0 27.27272727272728 2
12 0 36.36363636363636 2
13 0 45.45454545454547 2
14 0 54.54545454545461 2
15 0 63.63636363636373 2
16 0 72.72727272727286 2
17 0 81.81818181818193 2
18 0 90.90909090909096 2
19 0 9.090909090909093 0
20 0 18.1818181818182 0
21 0 27.27272727272728 0
22 0 36.36363636363636 0
23 0 45.45454545454547 0
24 0 54.54545454545461 0
25 0 63.63636363636373 0
26 0 72.72727272727286 0
27 0 81.81818181818193 0
28 0 90.90909090909096 0
29 50 19.99999999999998 2
30 50 39.99999999999994 2
31 50 60.00000000000001 2
32 50 80.0000000000001 2
33 50 19.99999999999998 0
34 50 39.99999999999994 0
35 50 60.00000000000001 0
36 50 80.0000000000001 0
37 8.203888358544519 0 0
38 18.58995430667013 0 0
39 32.45354968026022 0 0
40 8.203888358544519 0 2
41 18.58995430667013 0 2
42 32.45354968026022 0 2
43 8.203888358544519 100 0
44 18.58995430667013 100 0
45 32.45354968026022 100 0
46 8.203888358544519 100 2
47 18.58995430667013 100 2
48 32.45354968026022 100 2
49 0 50.00000000000004 1
50 0 59.09090909090917 1
51 0 40.90909090909092 1
52 0 68.1818181818183 1
53 0 13.63636363636365 1
54 0 4.545454545454547 1
55 0 22.72727272727274 1
56 0 31.81818181818182 1
57 0 77.27272727272739 0.9999999999999999
58 0 95.45454545454548 0.9999999999999991
59 0 86.36363636363645 1
60 50 70.00000000000006 1
61 50 49.99999999999998 1
62 50 9.999999999999989 1
63 50 29.99999999999996 1
64 50 90.00000000000004 1
65 41.2267748401301 0 1
66 25.52175199346517 0 1
67 13.39692133260732 0 1
68 4.10194417927226 0 1
69 41.2267748401301 100 1
70 25.52175199346517 100 1
71 13.39692133260732 100 0.9999999999999999
72 4.10194417927226 100 1
73 22.72860372753073 22.04489450003192 0
74 22.72860372753068 77.95510549996806 0
75 25.79338842975206 50.00000000000006 0
76 14.95260566232091 40.76508501685723 0
77 14.9526056623209 59.23491498314284 0
78 14.17360865121047 13.64395718364123 0
79 14.17360865121042 86.35604281635878 0
80 9.579488176010722 22.72727272727274 0
81 9.579488176010612 77.27272727272738 0
82 25.52730874663839 90.312863896919 0
83 25.52730874663841 9.687136103080924 0
84 33.86662155275111 64.75544035319339 0
85 34.18819030421103 32.58083911054511 0
86 9.381245345831953 50.00000000000004 0
87 8.090470349106848 32.56726295315534 0
88 8.09047034910683 67.43273704684475 0
89 34.66986177341006 80.92544477471404 0
90 34.73417552370205 18.54181111803364 0
91 18.71711481913258 31.7328142159387 0
92 18.50536487000291 68.05563363549513 0
93 7.521945716656088 7.631758733316776 0
94 7.521945716656008 92.36824126668328 0
95 37.64494649996119 47.74868420106803 0
96 25.70298890304702 40.35738906797691 0
97 24.0434807503234 60.25360539347754 0
98 6.484864271451944 41.03010595763889 0
99 6.484864271451936 58.9698940423612 0
100 39.8509427992789 90.91189963922278 0
101 39.85750542685971 9.033738717179981 0
102 6.255008508775456 14.25514318339161 0
103 6.255008508775408 85.74485681660848 0
104 14.80334115594389 93.80742959599222 0
105 14.80334115594392 6.192570404007786 0
106 22.72860372753073 22.04489450003193 2
107 22.72860372753068 77.95510549996807 2
108 25.79338842975206 50.00000000000006 2
109 14.95260566232092 40.76508501685723 2
110 14.95260566232091 59.23491498314284 2
111 14.17360865121047 13.64395718364123 2
112 14.17360865121042 86.35604281635878 2
113 9.57948817601072 22.72727272727274 2
114 9.579488176010612 77.27272727272738 2
115 25.52730874663839 90.312863896919 2
116 25.52730874663841 9.687136103080931 2
117 33.86662155275111 64.75544035319339 2
118 34.18819030421102 32.58083911054511 2
119 9.76161684436936 50.00000000000004 2
120 8.090470349106846 32.56726295315534 2
121 8.09047034910683 67.43273704684475 2
122 34.66986177341006 80.92544477471404 2
123 34.73417552370205 18.54181111803365 2
124 18.50536487000291 68.05563363549514 2
125 18.71711481913258 31.7328142159387 2
126 7.521945716656091 7.631758733316778 2
127 7.521945716656008 92.36824126668328 2
128 37.64494649996119 47.74868420106803 2
129 25.70298890304703 40.35738906797692 2
130 24.04348075032341 60.25360539347756 2
131 6.560938571159426 41.03010595763889 2
132 6.56093857115942 58.9698940423612 2
133 39.8509427992789 90.91189963922278 2
134 39.85750542685971 9.03373871717999 2
135 6.255008508775457 14.25514318339161 2
136 6.255008508775408 85.74485681660848 2
137 14.80334115594389 93.80742959599223 2
138 14.80334115594392 6.192570404007788 2
$EndNodes
$Elements
631
1 1 2 1 4 2 19
2 1 2 1 4 19 20
3 1 2 1 4 20 21
4 1 2 1 4 21 22
5 1 2 1 4 22 23
6 1 2 1 4 23 24
7 1 2 1 4 24 25
8 1 2 1 4 25 26
9 1 2 1 4 26 27
10 1 2 1 4 27 28
11 1 2 1 4 28 4
12 1 2 3 8 6 33
13 1 2 3 8 33 34
14 1 2 3 8 34 35
15 1 2 3 8 35 36
16 1 2 3 8 36 8
17 1 2 5 9 2 37
18 1 2 5 9 37 38
19 1 2 5 9 38 39
20 1 2 5 9 39 6
21 1 2 4 11 4 43
22 1 2 4 11 43 44
23 1 2 4 11 44 45
24 1 2 4 11 45 8
25 2 2 6 1 2 1 54
26 2 2 6 1 54 1 9
27 2 2 6 1 19 2 54
28 2 2 6 1 58 3 4
29 2 2 6 1 18 3 58
30 2 2 6 1 58 4 28
31 2 2 6 1 53 9 10
32 2 2 6 1 19 9 53
33 2 2 6 1 54 9 19
34 2 2 6 1 55 10 11
35 2 2 6 1 53 10 20
36 2 2 6 1 20 10 55
37 2 2 6 1 56 11 12
38 2 2 6 1 55 11 21
39 2 2 6 1 21 11 56
40 2 2 6 1 51 12 13
41 2 2 6 1 22 12 51
42 2 2 6 1 56 12 22
43 2 2 6 1 49 13 14
44 2 2 6 1 23 13 49
45 2 2 6 1 51 13 23
46 2 2 6 1 50 14 15
47 2 2 6 1 49 14 24
48 2 2 6 1 24 14 50
49 2 2 6 1 52 15 16
50 2 2 6 1 50 15 25
51 2 2 6 1 25 15 52
52 2 2 6 1 57 16 17
53 2 2 6 1 52 16 26
54 2 2 6 1 26 16 57
55 2 2 6 1 59 17 18
56 2 2 6 1 57 17 27
57 2 2 6 1 27 17 59
58 2 2 6 1 28 18 58
59 2 2 6 1 59 18 28
60 2 2 6 1 20 19 53
61 2 2 6 1 21 20 55
62 2 2 6 1 22 21 56
63 2 2 6 1 23 22 51
64 2 2 6 1 24 23 49
65 2 2 6 1 25 24 50
66 2 2 6 1 26 25 52
67 2 2 6 1 27 26 57
68 2 2 6 1 28 27 59
69 2 2 7 2 62 5 6
70 2 2 7 2 29 5 62
71 2 2 7 2 62 6 33
72 2 2 7 2 8 7 64
73 2 2 7 2 64 7 32
74 2 2 7 2 36 8 64
75 2 2 7 2 30 29 63
76 2 2 7 2 33 29 62
77 2 2 7 2 63 29 33
78 2 2 7 2 31 30 61
79 2 2 7 2 61 30 34
80 2 2 7 2 34 30 63
81 2 2 7 2 32 31 60
82 2 2 7 2 60 31 35
83 2 2 7 2 35 31 61
84 2 2 7 2 36 32 60
85 2 2 7 2 64 32 36
86 2 2 7 2 63 33 34
87 2 2 7 2 61 34 35
88 2 2 7 2 60 35 36
89 2 2 9 3 68 1 2
90 2 2 9 3 40 1 68
91 2 2 9 3 68 2 37
92 2 2 9 3 6 5 65
93 2 2 9 3 65 5 42
94 2 2 9 3 39 6 65
95 2 2 9 3 67 37 38
96 2 2 9 3 40 37 67
97 2 2 9 3 68 37 40
98 2 2 9 3 66 38 39
99 2 2 9 3 41 38 66
100 2 2 9 3 67 38 41
101 2 2 9 3 42 39 65
102 2 2 9 3 66 39 42
103 2 2 9 3 41 40 67
104 2 2 9 3 42 41 66
105 2 2 8 4 4 3 72
106 2 2 8 4 72 3 46
107 2 2 8 4 43 4 72
108 2 2 8 4 69 7 8
109 2 2 8 4 48 7 69
110 2 2 8 4 69 8 45
111 2 2 8 4 44 43 71
112 2 2 8 4 71 43 46
113 2 2 8 4 46 43 72
114 2 2 8 4 45 44 70
115 2 2 8 4 70 44 47
116 2 2 8 4 47 44 71
117 2 2 8 4 69 45 48
118 2 2 8 4 48 45 70
119 2 2 8 4 71 46 47
120 2 2 8 4 70 47 48
121 2 2 10 5 93 2 19
122 2 2 10 5 37 2 93
123 2 2 10 5 28 4 94
124 2 2 10 5 94 4 43
125 2 2 10 5 33 6 101
126 2 2 10 5 101 6 39
127 2 2 10 5 100 8 36
128 2 2 10 5 45 8 100
129 2 2 10 5 102 19 20
130 2 2 10 5 93 19 102
131 2 2 10 5 80 20 21
132 2 2 10 5 102 20 80
133 2 2 10 5 87 21 22
134 2 2 10 5 80 21 87
135 2 2 10 5 98 22 23
136 2 2 10 5 87 22 98
137 2 2 10 5 86 23 24
138 2 2 10 5 98 23 86
139 2 2 10 5 99 24 25
140 2 2 10 5 86 24 99
141 2 2 10 5 88 25 26
142 2 2 10 5 99 25 88
143 2 2 10 5 81 26 27
144 2 2 10 5 88 26 81
145 2 2 10 5 103 27 28
146 2 2 10 5 81 27 103
147 2 2 10 5 103 28 94
148 2 2 10 5 34 33 85
149 2 2 10 5 85 33 90
150 2 2 10 5 90 33 101
151 2 2 10 5 35 34 95
152 2 2 10 5 95 34 85
153 2 2 10 5 36 35 84
154 2 2 10 5 84 35 95
155 2 2 10 5 89 36 84
156 2 2 10 5 100 36 89
157 2 2 10 5 38 37 105
158 2 2 10 5 105 37 93
159 2 2 10 5 39 38 83
160 2 2 10 5 83 38 105
161 2 2 10 5 101 39 83
162 2 2 10 5 104 43 44
163 2 2 10 5 94 43 104
164 2 2 10 5 82 44 45
165 2 2 10 5 104 44 82
166 2 2 10 5 82 45 100
167 2 2 10 5 80 73 78
168 2 2 10 5 78 73 83
169 2 2 10 5 91 73 80
170 2 2 10 5 83 73 90
171 2 2 10 5 90 73 85
172 2 2 10 5 85 73 91
173 2 2 10 5 79 74 81
174 2 2 10 5 82 74 79
175 2 2 10 5 81 74 92
176 2 2 10 5 89 74 82
177 2 2 10 5 84 74 89
178 2 2 10 5 92 74 84
179 2 2 10 5 86 75 76
180 2 2 10 5 76 75 96
181 2 2 10 5 77 75 86
182 2 2 10 5 97 75 77
183 2 2 10 5 95 75 84
184 2 2 10 5 84 75 97
185 2 2 10 5 96 75 95
186 2 2 10 5 86 76 98
187 2 2 10 5 87 76 91
188 2 2 10 5 98 76 87
189 2 2 10 5 91 76 96
190 2 2 10 5 99 77 86
191 2 2 10 5 92 77 88
192 2 2 10 5 88 77 99
193 2 2 10 5 97 77 92
194 2 2 10 5 80 78 102
195 2 2 10 5 105 78 83
196 2 2 10 5 102 78 93
197 2 2 10 5 93 78 105
198 2 2 10 5 103 79 81
199 2 2 10 5 82 79 104
200 2 2 10 5 94 79 103
201 2 2 10 5 104 79 94
202 2 2 10 5 91 80 87
203 2 2 10 5 88 81 92
204 2 2 10 5 89 82 100
205 2 2 10 5 101 83 90
206 2 2 10 5 92 84 97
207 2 2 10 5 96 85 91
208 2 2 10 5 95 85 96
209 2 2 11 6 9 1 126
210 2 2 11 6 126 1 40
211 2 2 11 6 127 3 18
212 2 2 11 6 46 3 127
213 2 2 11 6 134 5 29
214 2 2 11 6 42 5 134
215 2 2 11 6 32 7 133
216 2 2 11 6 133 7 48
217 2 2 11 6 10 9 135
218 2 2 11 6 135 9 126
219 2 2 11 6 11 10 113
220 2 2 11 6 113 10 135
221 2 2 11 6 12 11 120
222 2 2 11 6 120 11 113
223 2 2 11 6 13 12 131
224 2 2 11 6 131 12 120
225 2 2 11 6 14 13 119
226 2 2 11 6 119 13 131
227 2 2 11 6 15 14 132
228 2 2 11 6 132 14 119
229 2 2 11 6 16 15 121
230 2 2 11 6 121 15 132
231 2 2 11 6 17 16 114
232 2 2 11 6 114 16 121
233 2 2 11 6 18 17 136
234 2 2 11 6 136 17 114
235 2 2 11 6 127 18 136
236 2 2 11 6 118 29 30
237 2 2 11 6 123 29 118
238 2 2 11 6 134 29 123
239 2 2 11 6 128 30 31
240 2 2 11 6 118 30 128
241 2 2 11 6 117 31 32
242 2 2 11 6 128 31 117
243 2 2 11 6 117 32 122
244 2 2 11 6 122 32 133
245 2 2 11 6 138 40 41
246 2 2 11 6 126 40 138
247 2 2 11 6 116 41 42
248 2 2 11 6 138 41 116
249 2 2 11 6 116 42 134
250 2 2 11 6 47 46 137
251 2 2 11 6 137 46 127
252 2 2 11 6 48 47 115
253 2 2 11 6 115 47 137
254 2 2 11 6 133 48 115
255 2 2 11 6 111 106 113
256 2 2 11 6 116 106 111
257 2 2 11 6 113 106 125
258 2 2 11 6 123 106 116
259 2 2 11 6 118 106 123
260 2 2 11 6 125 106 118
261 2 2 11 6 114 107 112
262 2 2 11 6 112 107 115
263 2 2 11 6 124 107 114
264 2 2 11 6 115 107 122
265 2 2 11 6 122 107 117
266 2 2 11 6 117 107 124
267 2 2 11 6 109 108 119
268 2 2 11 6 129 108 109
269 2 2 11 6 119 108 110
270 2 2 11 6 110 108 130
271 2 2 11 6 117 108 128
272 2 2 11 6 130 108 117
273 2 2 11 6 128 108 129
274 2 2 11 6 131 109 119
275 2 2 11 6 125 109 120
276 2 2 11 6 120 109 131
277 2 2 11 6 129 109 125
278 2 2 11 6 119 110 132
279 2 2 11 6 121 110 124
280 2 2 11 6 132 110 121
281 2 2 11 6 124 110 130
282 2 2 11 6 135 111 113
283 2 2 11 6 116 111 138
284 2 2 11 6 126 111 135
285 2 2 11 6 138 111 126
286 2 2 11 6 114 112 136
287 2 2 11 6 137 112 115
288 2 2 11 6 136 112 127
289 2 2 11 6 127 112 137
290 2 2 11 6 120 113 125
291 2 2 11 6 124 114 121
292 2 2 11 6 133 115 122
293 2 2 11 6 123 116 134
294 2 2 11 6 130 117 124
295 2 2 11 6 125 118 129
296 2 2 11 6 129 118 128
297 4 2 12 1 21 80 11 55
298 4 2 12 1 20 10 113 55
299 4 2 12 1 81 27 57 17
300 4 2 12 1 81 16 57 26
301 4 2 12 1 56 22 12 120
302 4 2 12 1 25 88 52 15
303 4 2 12 1 88 26 52 16
304 4 2 12 1 56 21 120 11
305 4 2 12 1 52 88 16 121
306 4 2 12 1 56 21 87 120
307 4 2 12 1 97 92 130 84
308 4 2 12 1 119 75 77 110
309 4 2 12 1 75 119 76 109
310 4 2 12 1 80 91 87 120
311 4 2 12 1 78 73 111 116
312 4 2 12 1 113 78 73 111
313 4 2 12 1 92 121 81 88
314 4 2 12 1 103 28 59 18
315 4 2 12 1 102 53 19 9
316 4 2 12 1 103 59 136 18
317 4 2 12 1 53 102 135 9
318 4 2 12 1 22 98 12 120
319 4 2 12 1 88 25 99 15
320 4 2 12 1 21 80 120 11
321 4 2 12 1 88 16 81 26
322 4 2 12 1 119 75 86 77
323 4 2 12 1 119 75 76 86
324 4 2 12 1 21 80 87 120
325 4 2 12 1 81 121 16 88
326 4 2 12 1 102 10 135 113
327 4 2 12 1 114 103 17 136
328 4 2 12 1 22 56 87 120
329 4 2 12 1 52 88 121 15
330 4 2 12 1 98 131 12 120
331 4 2 12 1 99 132 121 15
332 4 2 12 1 11 80 113 55
333 4 2 12 1 80 20 113 55
334 4 2 12 1 81 57 114 17
335 4 2 12 1 81 16 114 57
336 4 2 12 1 78 113 73 80
337 4 2 12 1 75 119 109 108
338 4 2 12 1 119 75 110 108
339 4 2 12 1 77 75 97 110
340 4 2 12 1 79 112 107 115
341 4 2 12 1 114 79 112 107
342 4 2 12 1 37 67 105 40
343 4 2 12 1 43 71 46 137
344 4 2 12 1 104 137 112 115
345 4 2 12 1 105 78 138 83
346 4 2 12 1 98 22 12 51
347 4 2 12 1 25 50 99 15
348 4 2 12 1 115 100 89 82
349 4 2 12 1 80 91 120 113
350 4 2 12 1 78 73 116 83
351 4 2 12 1 30 34 63 85
352 4 2 12 1 89 107 117 122
353 4 2 12 1 122 100 115 133
354 4 2 12 1 118 30 63 85
355 4 2 12 1 102 20 10 113
356 4 2 12 1 27 81 103 17
357 4 2 12 1 131 98 12 51
358 4 2 12 1 99 50 132 15
359 4 2 12 1 90 134 83 101
360 4 2 12 1 98 22 87 120
361 4 2 12 1 88 99 121 15
362 4 2 12 1 62 134 33 101
363 4 2 12 1 79 104 112 115
364 4 2 12 1 78 111 138 116
365 4 2 12 1 121 124 81 114
366 4 2 12 1 19 93 9 54
367 4 2 12 1 28 94 58 18
368 4 2 12 1 108 75 84 95
369 4 2 12 1 23 86 49 13
370 4 2 12 1 86 24 49 14
371 4 2 12 1 130 92 124 117
372 4 2 12 1 73 113 91 80
373 4 2 12 1 67 105 40 138
374 4 2 12 1 43 104 71 137
375 4 2 12 1 92 117 74 124
376 4 2 12 1 134 90 33 101
377 4 2 12 1 78 102 135 113
378 4 2 12 1 79 103 114 136
379 4 2 12 1 117 128 108 95
380 4 2 12 1 107 89 117 74
381 4 2 12 1 90 73 123 85
382 4 2 12 1 80 120 11 113
383 4 2 12 1 81 121 114 16
384 4 2 12 1 73 106 111 116
385 4 2 12 1 90 29 123 134
386 4 2 12 1 113 73 106 111
387 4 2 12 1 129 95 85 96
388 4 2 12 1 100 122 115 89
389 4 2 12 1 107 79 115 82
390 4 2 12 1 44 115 70 47
391 4 2 12 1 41 38 83 66
392 4 2 12 1 31 117 60 35
393 4 2 12 1 115 100 82 45
394 4 2 12 1 116 134 42 83
395 4 2 12 1 104 115 44 137
396 4 2 12 1 41 105 138 83
397 4 2 12 1 74 107 124 117
398 4 2 12 1 117 84 35 95
399 4 2 12 1 44 115 82 70
400 4 2 12 1 116 41 83 66
401 4 2 12 1 133 64 36 100
402 4 2 12 1 130 117 108 84
403 4 2 12 1 91 120 113 125
404 4 2 12 1 106 73 123 116
405 4 2 12 1 122 133 36 100
406 4 2 12 1 79 104 115 82
407 4 2 12 1 138 78 116 83
408 4 2 12 1 121 92 81 124
409 4 2 12 1 9 93 126 54
410 4 2 12 1 94 58 18 127
411 4 2 12 1 85 95 30 34
412 4 2 12 1 86 98 131 13
413 4 2 12 1 86 99 14 132
414 4 2 12 1 37 126 68 40
415 4 2 12 1 43 127 46 72
416 4 2 12 1 60 117 84 35
417 4 2 12 1 20 102 80 113
418 4 2 12 1 103 81 114 17
419 4 2 12 1 107 115 89 82
420 4 2 12 1 91 120 76 87
421 4 2 12 1 126 37 68 93
422 4 2 12 1 43 127 72 94
423 4 2 12 1 36 122 100 89
424 4 2 12 1 94 28 103 18
425 4 2 12 1 93 102 19 9
426 4 2 12 1 98 131 13 51
427 4 2 12 1 99 50 14 132
428 4 2 12 1 136 103 18 127
429 4 2 12 1 102 93 135 9
430 4 2 12 1 23 98 86 13
431 4 2 12 1 24 86 99 14
432 4 2 12 1 74 79 107 82
433 4 2 12 1 117 108 84 95
434 4 2 12 1 135 78 113 111
435 4 2 12 1 114 79 136 112
436 4 2 12 1 88 77 92 121
437 4 2 12 1 92 74 81 124
438 4 2 12 1 117 74 89 84
439 4 2 12 1 137 115 44 47
440 4 2 12 1 38 105 41 83
441 4 2 12 1 75 109 129 108
442 4 2 12 1 79 103 136 127
443 4 2 12 1 93 135 78 102
444 4 2 12 1 134 29 62 33
445 4 2 12 1 107 115 122 89
446 4 2 12 1 129 75 95 96
447 4 2 12 1 90 29 134 33
448 4 2 12 1 115 104 44 82
449 4 2 12 1 41 138 116 83
450 4 2 12 1 30 95 128 61
451 4 2 12 1 23 98 13 51
452 4 2 12 1 50 24 99 14
453 4 2 12 1 103 59 17 136
454 4 2 12 1 53 102 10 135
455 4 2 12 1 117 92 74 84
456 4 2 12 1 80 102 78 113
457 4 2 12 1 81 79 103 114
458 4 2 12 1 110 77 132 121
459 4 2 12 1 76 131 120 109
460 4 2 12 1 74 107 89 82
461 4 2 12 1 130 92 117 84
462 4 2 12 1 70 115 82 45
463 4 2 12 1 42 116 83 66
464 4 2 12 1 103 94 18 127
465 4 2 12 1 93 135 9 126
466 4 2 12 1 37 105 126 40
467 4 2 12 1 127 137 43 46
468 4 2 12 1 104 127 43 94
469 4 2 12 1 93 37 105 126
470 4 2 12 1 79 94 103 127
471 4 2 12 1 135 93 78 126
472 4 2 12 1 120 125 76 109
473 4 2 12 1 30 95 61 34
474 4 2 12 1 129 75 108 95
475 4 2 12 1 105 126 40 138
476 4 2 12 1 127 104 43 137
477 4 2 12 1 128 129 108 95
478 4 2 12 1 20 53 102 10
479 4 2 12 1 27 103 59 17
480 4 2 12 1 92 77 110 121
481 4 2 12 1 64 32 133 36
482 4 2 12 1 120 91 76 125
483 4 2 12 1 32 122 133 36
484 4 2 12 1 136 79 127 112
485 4 2 12 1 78 135 126 111
486 4 2 12 1 92 97 130 110
487 4 2 12 1 115 70 48 45
488 4 2 12 1 39 42 83 66
489 4 2 12 1 79 104 94 127
490 4 2 12 1 78 93 105 126
491 4 2 12 1 124 92 110 121
492 4 2 12 1 119 86 131 13
493 4 2 12 1 119 86 14 132
494 4 2 12 1 127 104 137 112
495 4 2 12 1 105 78 126 138
496 4 2 12 1 76 119 131 109
497 4 2 12 1 77 119 110 132
498 4 2 12 1 79 104 127 112
499 4 2 12 1 126 78 111 138
500 4 2 12 1 92 77 97 110
501 4 2 12 1 92 130 124 110
502 4 2 12 1 105 67 41 138
503 4 2 12 1 104 44 71 137
504 4 2 12 1 105 67 38 41
505 4 2 12 1 44 71 137 47
506 4 2 12 1 68 126 1 40
507 4 2 12 1 53 20 102 19
508 4 2 12 1 10 53 135 9
509 4 2 12 1 6 62 33 101
510 4 2 12 1 12 56 120 11
511 4 2 12 1 68 2 93 37
512 4 2 12 1 25 50 24 99
513 4 2 12 1 67 37 105 38
514 4 2 12 1 2 93 19 54
515 4 2 12 1 22 98 23 51
516 4 2 12 1 10 11 113 55
517 4 2 12 1 41 116 42 66
518 4 2 12 1 59 17 136 18
519 4 2 12 1 56 21 22 87
520 4 2 12 1 48 7 133 69
521 4 2 12 1 25 88 26 52
522 4 2 12 1 4 28 94 58
523 4 2 12 1 104 44 43 71
524 4 2 12 1 64 32 7 133
525 4 2 12 1 27 26 81 57
526 4 2 12 1 30 29 118 63
527 4 2 12 1 57 114 17 16
528 4 2 12 1 9 126 1 54
529 4 2 12 1 23 86 24 49
530 4 2 12 1 43 4 94 72
531 4 2 12 1 28 27 103 59
532 4 2 12 1 70 47 115 48
533 4 2 12 1 71 46 137 47
534 4 2 12 1 58 3 18 127
535 4 2 12 1 72 46 3 127
536 4 2 12 1 21 20 80 55
537 4 2 12 1 16 52 121 15
538 4 2 12 1 50 14 132 15
539 4 2 12 1 67 40 41 138
540 4 2 12 1 131 12 13 51
541 4 2 12 1 65 5 134 42
542 4 2 12 1 38 39 83 66
543 4 2 12 1 34 35 95 61
544 4 2 12 1 64 36 100 8
545 4 2 12 1 100 69 8 45
546 4 2 12 1 34 63 85 33
547 4 2 12 1 31 117 32 60
548 4 2 12 1 44 70 82 45
549 4 2 12 1 36 60 84 35
550 4 2 12 1 30 128 31 61
551 4 2 12 1 39 65 6 101
552 4 2 12 1 29 5 134 62
553 4 2 12 1 29 118 85 123
554 4 2 12 1 85 118 29 63
555 4 2 12 1 85 90 29 123
556 4 2 12 1 33 85 29 63
557 4 2 12 1 33 29 85 90
558 4 2 12 1 117 122 36 89
559 4 2 12 1 36 84 117 89
560 4 2 12 1 117 84 36 60
561 4 2 12 1 97 84 108 75
562 4 2 12 1 108 84 97 130
563 4 2 12 1 108 110 97 75
564 4 2 12 1 97 110 108 130
565 4 2 12 1 61 95 31 35
566 4 2 12 1 61 31 95 128
567 4 2 12 1 117 31 95 35
568 4 2 12 1 117 95 31 128
569 4 2 12 1 32 36 117 122
570 4 2 12 1 117 36 32 60
571 4 2 12 1 7 133 100 64
572 4 2 12 1 100 133 7 69
573 4 2 12 1 100 8 7 64
574 4 2 12 1 7 8 100 69
575 4 2 12 1 5 134 101 65
576 4 2 12 1 101 134 5 62
577 4 2 12 1 101 6 5 65
578 4 2 12 1 5 6 101 62
579 4 2 12 1 73 83 123 116
580 4 2 12 1 73 123 83 90
581 4 2 12 1 134 123 83 116
582 4 2 12 1 134 83 123 90
583 4 2 12 1 129 128 85 95
584 4 2 12 1 129 85 128 118
585 4 2 12 1 30 85 128 95
586 4 2 12 1 30 128 85 118
587 4 2 12 1 100 69 48 133
588 4 2 12 1 48 69 100 45
589 4 2 12 1 48 115 100 133
590 4 2 12 1 100 115 48 45
591 4 2 12 1 134 83 39 42
592 4 2 12 1 39 83 134 101
593 4 2 12 1 39 65 134 42
594 4 2 12 1 134 65 39 101
595 4 2 12 1 129 125 85 118
596 4 2 12 1 124 107 81 114
597 4 2 12 1 124 81 107 74
598 4 2 12 1 79 81 107 114
599 4 2 12 1 79 107 81 74
600 4 2 12 1 125 106 85 118
601 4 2 12 1 123 106 85 73
602 4 2 12 1 123 85 106 118
603 4 2 12 1 120 98 76 87
604 4 2 12 1 120 76 98 131
605 4 2 12 1 99 121 77 88
606 4 2 12 1 77 121 99 132
607 4 2 12 1 132 86 77 119
608 4 2 12 1 132 77 86 99
609 4 2 12 1 131 86 76 98
610 4 2 12 1 131 76 86 119
611 4 2 12 1 1 2 93 68
612 4 2 12 1 93 2 1 54
613 4 2 12 1 93 126 1 68
614 4 2 12 1 1 126 93 54
615 4 2 12 1 4 94 3 58
616 4 2 12 1 4 3 94 72
617 4 2 12 1 127 3 94 58
618 4 2 12 1 127 94 3 72
619 4 2 12 1 13 14 86 49
620 4 2 12 1 13 86 14 119
621 4 2 12 1 125 76 96 91
622 4 2 12 1 125 85 96 129
623 4 2 12 1 96 85 125 91
624 4 2 12 1 96 125 109 76
625 4 2 12 1 109 125 96 129
626 4 2 12 1 109 75 96 76
627 4 2 12 1 96 75 109 129
628 4 2 12 1 91 113 106 125
629 4 2 12 1 106 113 91 73
630 4 2 12 1 106 85 91 125
631 4 2 12 1 91 85 106 73
$EndElements
could you please help me with this issue?
With all this code, I’m not really sure what you are asking for. Especially since you do not supply any error message. However, with the following modifications to the meshio and loading to dolfin code everything seems to run smoothly. (note that i’ve renamed the input mesh to meshi.read)
import meshio
msh = meshio.read("mesh.msh")
for key in msh.cell_data_dict["gmsh:physical"].keys():
if key == "triangle":
triangle_data = msh.cell_data_dict["gmsh:physical"][key]
elif key == "tetra":
tetra_data = msh.cell_data_dict["gmsh:physical"][key]
for cell in msh.cells:
if cell.type == "tetra":
tetra_cells = cell.data
elif cell.type == "triangle":
triangle_cells = cell.data
tetra_mesh = meshio.Mesh(points=msh.points, cells={"tetra": tetra_cells},
cell_data={"name_to_read":[tetra_data]})
triangle_mesh =meshio.Mesh(points=msh.points,
cells=[("triangle", triangle_cells)],
cell_data={"name_to_read":[triangle_data]})
meshio.write("plate.xdmf", tetra_mesh)
meshio.write("mf.xdmf", triangle_mesh)
from dolfin import *
set_log_level(LogLevel.ERROR)
mesh = Mesh()
with XDMFFile("plate.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)
mvc2 = MeshValueCollection("size_t", mesh, 3)
with XDMFFile("plate.xdmf") as infile:
infile.read(mvc2, "name_to_read")
cf = cpp.mesh.MeshFunctionSizet(mesh, mvc2)
ds_top = Measure("ds", domain=mesh, subdomain_data=mf, subdomain_id=11)
ds_right = Measure("ds", domain=mesh, subdomain_data=mf, subdomain_id=7)
dx_volume = Measure("dx", domain=mesh, subdomain_data=cf, subdomain_id=12)
As you see here, you can save the cell function data along with the mesh, in a similar fashion to how it was saved for the facets
Thank you for the support and sorry that forgot to post the error message which was related to the defining cf even I tried the same way
mvc2 = MeshValueCollection("size_t", mesh, 3)
with XDMFFile("plate.xdmf") as infile:
infile.read(mvc2, "name_to_read")
cf = cpp.mesh.MeshFunctionSizet(mesh, mvc2)
Does it now work or not?
Yes it does work. Thanks
@dokken I had a quick question regarding the usage of meshio
to write meshes for subdomains
that can be loaded into dolfin
. As of now I have 2 numpy
arrays each containing the cells
for a subdomain. Something like:
import meshio, os
meshFolder = os.getcwd()
msh = meshio.read("abaqusMesh.inp")
# msh.points -- all the nodes
# msh.cells[0] -- cells corresponding to one of the subdomain
# msh.cells[1] -- cells corresponding to the other
entireMesh = meshio.Mesh(msh.points, np.vstack((msh.cells[0], msh.cells[1])))
particlesMesh = meshio.Mesh(msh.points, msh.cells[1])
# subdomainMesh = meshio.Mesh(msh.points, ...) # what could be done here?
meshio.write(os.path.join(meshFolder, "entireMesh.xdmf"), entireMesh)
meshio.write(os.path.join(meshFolder, "particles.xdmf"), particlesMesh) # -- only the second subdomain
# and consequently this...
# meshio.write(os.path.join(meshFolder, "subdomains.xdmf"), subdomainMesh)
I want to be able to assemble forms on subdomains like
from dolfin import *
msh = Mesh()
with XDMFFile("entireMesh.xdmf") as sdf:
sdf.read(msh)
subdomains = MeshFunction("size_t", msh, "subdomains.xdmf")
dx = Measure('dx')(subdomain_data=subdomains)
Could you guide me on this or point to appropriate resources?
So, first of all, you only need the entire mesh.
For the entire mesh, you should be able to save the mesh with the corresponding subdomains as shown in the post above and define the appropriate measures: Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio
I did see the above comment. I think that is based off of a premise that the mesh is read from a Gmsh
.-generated one. For instance,
import meshio
msh = meshio.read("filename.inp")
for cell in msh.cells:
if cell.type == "tetra":
tetra_cells = cell.data
wouldn’t work in my case (as I have two CellBlock
s each with type “tetra” and pointing to a separate subdomain). Also msh.cell_data_dict
is an empty dictionary in my case. That is why in order to write the entire mesh I have to do
completeMesh = meshio.Mesh(msh.points, cells = {"tetra":np.vstack((msh.cells[0].data, msh.cells[1].data)) })
meshio.write("entireMesh.xdmf", completeMesh)
But then you do not save any subdomain information, so how should you Get any data to Measure
. The code above is easily generalized to multiple cell blocks, by stacking inside the for loop.