Hi,
I am attempting to perform mesh-adaptation based on a given metric using the MMG platform (https://www.mmgtools.org). There is no support for XDMF file in MMG currently but only .msh
or .medit
files.
I am therefore attempting to add to a .msh
file a NodeData field via a dolfin Function. I naively attempted to convert back my xdmf solution file to msh using meshio-convert
but it fails with
raise ReadError("Unknown section '{}'.".format(c.tag))
meshio._exceptions.ReadError: Unknown section 'Grid'.
Any take on that ? Here is my MWE
plate.geo file:
Point(1) = {-0.5, 0.5, 0, 0.1};
Point(2) = {-0.5, -0.5, 0, 0.1};
Point(3) = { 0.5, -0.5, 0, 0.1};
Point(4) = { 0.5, 0.5, 0, 0.1};
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};
Curve Loop(1) = {1, 2, 3, 4};
Plane Surface(1) = {1};
Physical Surface(1) = {1};
Python script
from dolfin import *
import meshio
import subprocess
fname = "plate"
subprocess.call(["gmsh", fname+".geo", "-2", "-format", "msh2"])
subprocess.call(["meshio-convert", fname+".msh", fname+".xdmf", "-p", "-z"])
mesh = Mesh()
with XDMFFile(fname+".xdmf") as infile:
infile.read(mesh)
V = FunctionSpace(mesh, "CG", 1)
metric = Expression("0.01*(sin(10*x[0])*cos(5*x[1])+2)", degree=2)
v = Function(V)
v.interpolate(metric)
with XDMFFile("metric.xdmf") as infile:
infile.write(v, 0)
subprocess.call(["meshio-convert", "metric.xdmf", "metric.msh"])