nschloe / meshio

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

Patch for len of float assertion error in nastran #1437

Closed RemDelaporteMathurin closed 3 months ago

RemDelaporteMathurin commented 1 year ago

I recently tried to convert a mesh and ran into an assertion error in _float_to_nastran_string.

To reproduce the bug

from meshio.nastran._nastran import _float_to_nastran_string

_float_to_nastran_string(-1.5614246689128802e-18)
Traceback (most recent call last):
  File "/home/remidm/festim-review/comparison/achlys/convert_mesh.py", line 27, in <module>
    _float_to_nastran_string(-1.5614246689128802e-18)
  File "/home/remidm/miniconda3/envs/festim/lib/python3.11/site-packages/meshio/nastran/_nastran.py", line 416, in _float_to_nastran_string
    assert len(out) <= 16
           ^^^^^^^^^^^^^^
AssertionError

The value of out is -1.56142466891E-18 which is 18 characters long.

This PR reduces the precision argument in format_float_scientific to 9 and fixes the bug.

ping @gabriele-ferrero

RemDelaporteMathurin commented 1 year ago

@nschloe I realise this may be a duplicate of https://github.com/nschloe/meshio/pull/1350