Commit 98b5a154 authored by Baptiste Durand's avatar Baptiste Durand

Accommodating a breaking change of convention in meshio from version 4.0.0.

Details: https://github.com/nschloe/meshio/blob/master/CHANGELOG.md
parent 47bc54f1
......@@ -41,34 +41,17 @@ except ImportError:
try:
from . import full_scale_pb, homog2d, part, toolbox_FEniCS
except ImportError:
pckg_logger.warning("One of the following submodule imports fails : full_scale_pb, homog2d, part, toolbox_FEniCS")
try:
from . import geometry, mesh_tools, mesh_generate
except ImportError:
pckg_logger.warning("Import of geometry and mesh generating submodules fails")
try:
from . import materials
except ImportError:
pckg_logger.warning("Import of material submodule fails")
try:
from . import periodicity
from . import toolbox_gmsh
except ImportError:
pckg_logger.warning("Import of periodicity submodule fails")
pckg_logger.warning("Import of toolbox_gmsh submodule fails")
try:
from . import full_scale_pb, homog2d, part, toolbox_FEniCS
except ImportError:
pckg_logger.warning("One of the following submodule imports fails : full_scale_pb, homog2d, part, toolbox_FEniCS")
pckg_logger.warning(
"One of the following submodule imports fails : full_scale_pb, homog2d, part, toolbox_FEniCS"
)
def set_log_handlers(level: int = log_level, path=log_path):
......
......@@ -9,7 +9,13 @@ Collection of tools designed to help users working with gmsh python API.
import logging
from pathlib import Path
import meshio
from . import pckg_logger
try:
import meshio
except ImportError:
pckg_logger.warning("Import of meshio fails.")
from subprocess import run
import gmsh
......@@ -61,31 +67,57 @@ def conversion_to_xdmf(i_path, o_path, cell_reg, facet_reg, dim, subdomains=Fals
subdomains : bool, optional
If True, extra files are created to store information about subdomains.
(default: False)
Source
------
https://fenicsproject.discourse.group/t/transitioning-from-mesh-xml-to-mesh-xdmf-from-dolfin-convert-to-meshio/412/79?u=bd1747 #noqa
"""
m = meshio.read(str(i_path))
m = meshio.read(i_path)
if dim == 2:
m.points = m.points[:, :2]
geo_only = meshio.Mesh(points=m.points, cells={"triangle": m.cells["triangle"]})
cell = "triangle"
face = "line"
triangles_cells = list()
for cell in m.cells:
if cell.type == "triangle":
triangles_cells.append(("triangle", cell.data))
geo_only = meshio.Mesh(points=m.points, cells=triangles_cells)
cell_key = "triangle"
face_key = "line"
elif dim == 3:
raise NotImplementedError("3D meshes are not supported yet.")
# * INFO :
else:
ValueError
meshio.write(str(o_path), geo_only)
meshio.write(o_path, geo_only)
if subdomains:
# TODO : à tester !
cell_data, facet_data = list(), list()
for key, data in m.cell_data_dict["gmsh:physical"].items():
if key == cell_key:
cell_data.append(data)
elif key == face_key:
facet_data.append(data)
cell_mesh, facet_mesh = list(), list()
for cell in m.cells:
if cell.type == cell_key:
cell_mesh.append((cell_key, cell.data))
if cell.type == face_key:
facet_mesh.append((face_key, cell.data))
cell_funct = meshio.Mesh(
points=m.points,
cells={cell: m.cells[cell]},
cell_data={cell: {"cell_data": m.cell_data[cell]["gmsh:physical"]}},
points=m.points, cells=cell_mesh, cell_data={"cell_data": cell_data},
)
meshio.write(str(cell_reg), cell_funct)
facet_funct = meshio.Mesh(
points=m.points,
cells={face: m.cells[face]},
cell_data={face: {"facet_data": m.cell_data[face]["gmsh:physical"]}},
points=m.points, cells=facet_mesh, cell_data={"facet_data": facet_data},
)
meshio.write(str(facet_reg), facet_funct)
# TODO : Regarder, si on se sert des sous-domaines de gmsh, si on peut mettre les cell data et les facet data dans le même fichier
# TODO : c.à.d cell_data = {"cell_data": cell_data, "facet_data":facet_data}
meshio.write(cell_reg, cell_funct)
meshio.write(facet_reg, facet_funct)
return True
......
......@@ -37,5 +37,6 @@ install_requires =
numpy
gmsh
meshio
h5py # pour meshio
include_package_data = True
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment