meshio icon indicating copy to clipboard operation
meshio copied to clipboard

round-tripping a med file results in losing group names (tags)

Open Jesusbill opened this issue 4 years ago • 3 comments

I would like to make sure that I can round-trip (read, modify and write) a med file without losing information. Doing some tests I see that the names of the point tags and cell tags are not written (checked with older versions as well).

I am using this simple snippet

import meshio

file = meshio.read("path/to/med/file", file_format="med")

meshio.Mesh(
    file.points,
    file.cells_dict,
    # Optionally provide extra data on points, cells, etc.
    point_data=file.point_data,
    cell_data=file.cell_data,
    # field_data=file.field_data
).write(
    "path/to/new/med/file",
    file_format="med"
)

With the file attached for example I can get from the original file the correct point and cell tags

"point_tags": {
        "2": [
            "base_columns"
        ],
        "1": [
            "base_plates"
        ],
        "3": [
            "point_masses"
        ]
    }
"cell_tags": {
        "-1": [
            "base_plates"
        ],
        "-2": [
            "columns"
        ],
        "-3": [
            "plates"
        ],
        "-4": [
            "point_masses"
        ]
    }

but with the same med file written with meshio these tag dictionaries are empty, although the tag assignments to the elements are correctly done.

I am investigating, although not of high priority right now, but I would like to have it fixed soon.

PS: Nico can we have a med label for the issues? :)

reinforcement.zip

Jesusbill avatar Mar 10 '21 13:03 Jesusbill

PS: Nico can we have a med label for the issues? :)

Added.

nschloe avatar Mar 10 '21 13:03 nschloe

Hi @nschloe I have provided a commit for this issue here; I was thinking if you wanted to review before the PR.

I have the impression that the dictionaries that hold the tag values and the corresponding names were initially named point_tags and cell_tags but then they were renamed to point_sets and cell_sets.

However, they were never updated in the med implementation and instead two try/except statements were used to overcome the AttributeError. Does this train of thought makes sense?

I have tested it now and everything looks to work fine.

Jesusbill avatar Apr 17 '21 00:04 Jesusbill

Indeed, I think that might have happened. Just PR that, it's always easier to reason there. (No need for "pre-review", we can always close the PR without merging if we come up with something better in the process.)

nschloe avatar Apr 17 '21 07:04 nschloe