nschloe / meshio

:spider_web: input/output for many mesh formats
MIT License
1.96k stars 402 forks source link

hexahedron20. Incorrect convertation into vtu file #1431

Open Mike637 opened 1 year ago

Mike637 commented 1 year ago

Code: ` import sys, numpy, os BASE_DIR = os.getcwd() import meshio hex20_mesh = meshio.Mesh( [ [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 1.0], [0.0, 1.0, 1.0],

    [0.5, 0.0, 0.0],
    [1.0, 0.5, 0.0],
    [0.5, 1.0, 0.0],
    [0.0, 0.5, 0.0],

    [0.0, 0.0, 0.5],
    [1.0, 0.0, 0.5],
    [1.0, 1.0, 0.5],
    [0.0, 1.0, 0.5],

    [0.5, 0.0, 1.0],
    [1.0, 0.5, 1.0],
    [0.5, 1.0, 1.0],
    [0.0, 0.5, 1.0],
],
[("hexahedron20", [numpy.arange(20)])],

) hex20_mesh.write( os.path.join(BASE_DIR ,"result123.vtu"),
) ` After covertation I opened vtu file in paraview and saw wrong view of hexahedron. image

kaiserls commented 8 months ago

The definition of the hexahedron20 requires a specific order of nodes or adapted node connectivity. https://vtk.org/doc/nightly/html/classvtkQuadraticHexahedron.html#details

It should be:

import meshio
import numpy
import os

BASE_DIR = os.getcwd()

hex20_corrected = meshio.Mesh(
    [
        [0.0, 0.0, 0.0],
        [1.0, 0.0, 0.0],
        [1.0, 1.0, 0.0],
        [0.0, 1.0, 0.0],
        [0.0, 0.0, 1.0],
        [1.0, 0.0, 1.0],
        [1.0, 1.0, 1.0],
        [0.0, 1.0, 1.0],
        [0.5, 0.0, 0.0],
        [1.0, 0.5, 0.0],
        [0.5, 1.0, 0.0],#10
        [0.0, 0.5, 0.0],
        [0.5, 0.0, 1.0],# first wrong node
        [1.0, 0.5, 1.0],
        [0.5, 1.0, 1.0],
        [0.0, 0.5, 1.0],
        [0.0, 0.0, 0.5],
        [1.0, 0.0, 0.5],
        [1.0, 1.0, 0.5],
        [0.0, 1.0, 0.5],
    ],
    [("hexahedron20", [numpy.arange(20)])],
)

hex20_corrected.write(
    os.path.join(BASE_DIR, "result_corrected.vtu"),
)