question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

from_meshio fails on old ex27

See original GitHub issue

I was trying to regenerate a mesh for ex27 as part of the discussion with @bhaveshshrimali on the speed of pypardiso relative to scipy.sparse in #690 so that the number of elements could be varied but the old make_mesh(make_geom(...)) code seems not to work with the new (#680 ?) skfem.io.mesh.from_meshio.

The code:

from skfem import *
from skfem.io.meshio import from_meshio

from itertools import cycle, islice

import numpy as np

from pygmsh import generate_mesh
from pygmsh.built_in import Geometry


def make_geom(length: float, lcar: float) -> Geometry:
    # Barkley et al (2002, figure 3 a - c)
    geom = Geometry()

    points = []
    for point in [
        [0, -1, 0],
        [length, -1, 0],
        [length, 1, 0],
        [-1, 1, 0],
        [-1, 0, 0],
        [0, 0, 0],
    ]:
        points.append(geom.add_point(point, lcar))

    lines = []
    for termini in zip(points, islice(cycle(points), 1, None)):
        lines.append(geom.add_line(*termini))

    for k, label in [
        ([1], "outlet"),
        ([2], "ceiling"),
        ([3], "inlet"),
        ([0, 4, 5], "floor"),
    ]:
        geom.add_physical(list(np.array(lines)[k]), label)

    geom.add_physical(geom.add_plane_surface(geom.add_line_loop(lines)), "domain")

    return geom


if __name__ == "__main__":
    from pathlib import Path

    geom = make_geom(35.0, 0.2)

    with open(Path(__file__).with_suffix(".geo"), "w") as fgeo:
        fgeo.write(geom.get_code())

    mio = generate_mesh(geom, dim=2)
    print(mio)

    mesh = from_meshio(mio)
    print(mesh)

    mesh.save(Path(__file__).with_suffix(".vtk"))

When I run this with pygmsh==6.1.1 (before the big API change in pygmsh 7), I believe that this generates a valid *.geo file, which is accepted by Gmsh (4.8.4 here) and Gmsh can write this as MSH 4.1 file which is understood by meshio, but something goes wrong in skfem.io.meshio.from_meshio:

Traceback (most recent call last):
  File "/home/gdmcbain/src/scikit-fem/docs/examples/ex27_mesh.py", line 55, in <module>
    mesh = from_meshio(mio)
  File "/home/gdmcbain/miniconda3/envs/skfem/lib/python3.9/site-packages/skfem/io/meshio.py", line 93, in from_meshio
    facets = {k: [tuple(f) for f in
  File "/home/gdmcbain/miniconda3/envs/skfem/lib/python3.9/site-packages/skfem/io/meshio.py", line 94, in <dictcomp>
    np.sort(m.cells_dict[bnd_type][v[bnd_type]])]
IndexError: index 381 is out of bounds for axis 0 with size 380

I don’t mean to suggest that we should rely upon pygmsh<7 but I believe the GEO and MSH 4.1 files are valid, as is the meshio.Mesh, but I’ll check.

The intermediate files are generated and interrogated with

python docs/examples/ex27_mesh.py  # say, depending on where the above is saved
gmsh -2 docs/examples/ex27_mesh.geo
meshio info docs/examples/ex27_mesh.msh

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
gdmcbaincommented, Aug 18, 2021

Oh, O. K., great. (I wonder what’s going on here, but I’ll sort that out later.) You should be able to change lcar, the second argument to make_geom, to get meshes of different fineness to experiment with in #690.

Are you running on scikit-fem master, i.e. with #680? There were some substantial changes to skfem.io.meshio.from_meshio in that which I don’t know have been published as a release.

0reactions
gdmcbaincommented, Aug 23, 2021

I’m not sure why this error didn’t show up earlier. I couldn’t see anything in #680 that would have triggered it. Maybe we were just lucky before and the spurious "gmsh:bounding_entities" were imbibed but happened not to contain invalid indices and so didn’t raise the IndexError and were carried around as worthless but harmless ballast?

Read more comments on GitHub >

github_iconTop Results From Across the Web

EX27 Small OHC Engine | Subaru Industrial Power Products
Subaru's EX27 9.0 horsepower small chain-driven OHC air-cooled engine is the ideal power source for blowers, log splitters, chippers and seeders .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found