From: Nabil Ghodbane Date: Tue, 29 Oct 2024 13:45:55 +0000 (+0100) Subject: [FORUM][Windows] nastran: handle precision issue and edges with 3 nodes. See discussi... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ac45c680ac5fc21153b511e0e451a5d7c958a914;p=tools%2Fsat_salome.git [FORUM][Windows] nastran: handle precision issue and edges with 3 nodes. See discussion on https://discourse.salome-platform.org/t/meshio-error-on-export-to-nastran-salome-9-13-windows/1512/3 --- diff --git a/products/patches/meshio-5.3.5.p02.nastran_fID_1512.patch b/products/patches/meshio-5.3.5.p02.nastran_fID_1512.patch index dcf10bb..f1e7308 100644 --- a/products/patches/meshio-5.3.5.p02.nastran_fID_1512.patch +++ b/products/patches/meshio-5.3.5.p02.nastran_fID_1512.patch @@ -1,11 +1,44 @@ ---- meshio-5.3.5_ref/src/meshio/nastran/_nastran.py 2024-01-31 16:09:01.000000000 +0100 -+++ meshio-5.3.5_dev/src/meshio/nastran/_nastran.py 2024-09-30 15:59:26.751404661 +0200 -@@ -410,7 +410,7 @@ +--- meshio-5.3.5-ref/src/meshio/nastran/_nastran.py 2024-01-31 16:09:01.000000000 +0100 ++++ meshio-5.3.5-dev/src/meshio/nastran/_nastran.py 2024-10-28 14:03:45.432868000 +0100 +@@ -17,6 +17,7 @@ + "CELAS1": "vertex", + "CBEAM": "line", + "CBUSH": "line", ++ "CBEAM3": "line3", + "CBUSH1D": "line", + "CROD": "line", + "CGAP": "line", +@@ -347,7 +348,11 @@ + for ict, cell_block in enumerate(mesh.cells): + cell_type = cell_block.type + cells = cell_block.data +- nastran_type = meshio_to_nastran_type[cell_type] ++ try: ++ nastran_type = meshio_to_nastran_type[cell_type] ++ except KeyError: ++ warn(f" Illegal ANSYS cell type '{cell_type}' => Skipping it.") ++ continue + if cell_format.endswith("-large"): + nastran_type += "*" + if cell_refs is not None: +@@ -410,10 +415,16 @@ -0.1234 --> "-1.234E-1" 3.1415926535897932 --> "3.14159265359E+0" """ - out = np.format_float_scientific(value, exp_digits=1, precision=11).replace( -+ out = np.format_float_scientific(value, exp_digits=1, precision=9).replace( - "e", "E" - ) - assert len(out) <= 16 +- "e", "E" +- ) +- assert len(out) <= 16 ++ k=0 ++ # decrease precision if needed to keep the number of characters <= length ++ # for instance, for negative numbers and two decimal exponent, we need to decrease precision to 9 ++ # e.g. value=-1.123456454678e10 ++ # out='-1.123456455E+10' ++ while k==0 or len(out)>length: ++ out = np.format_float_scientific(value, exp_digits=1, precision=11-k) ++ k+=1 ++ out = out.replace("e", "E") ++ assert len(out) <= length + return out + # The following is the manual float conversion. Keep it around for a while in case + # we still need it.