From: Nabil Ghodbane Date: Thu, 1 Aug 2024 14:26:43 +0000 (+0200) Subject: spns #42665: MeshIO: GMSH and ANSYS X-Git-Tag: V9_13_0~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ab0e69f478eae2a28f85e56d58702e98c4985d07;p=tools%2Fsat_salome.git spns #42665: MeshIO: GMSH and ANSYS --- diff --git a/applications/SALOME-9.13.0-native.pyconf b/applications/SALOME-9.13.0-native.pyconf index 37d4212..c7d2097 100644 --- a/applications/SALOME-9.13.0-native.pyconf +++ b/applications/SALOME-9.13.0-native.pyconf @@ -237,7 +237,7 @@ __overwrite__ : 'APPLICATION.products.cmake' : 'native' # TTK requires cmake > 3.21 'APPLICATION.products.cftime' : 'native' 'APPLICATION.products.h5py' : 'native' - 'APPLICATION.products.meshio' : 'native' + 'APPLICATION.products.meshio' : {tag: '5.3.5' , base: 'no', section: 'version_5_3_5_no_pip' } 'APPLICATION.products.netCDF4' : 'native' 'APPLICATION.products.rich' : 'native' 'APPLICATION.products.cminpack' : 'native' @@ -292,7 +292,7 @@ __overwrite__ : 'APPLICATION.products.h5py' : 'native' 'APPLICATION.products.markdown_it_py' : 'native' 'APPLICATION.products.mdurl' : 'native' - 'APPLICATION.products.meshio' : 'native' + 'APPLICATION.products.meshio' : {tag: '5.3.5', base: 'no', section: 'version_5_3_5_no_pip'} 'APPLICATION.products.netCDF4' : 'native' 'APPLICATION.products.rich' : 'native' 'APPLICATION.products.opencv' : {tag: '3.2.0', base: 'no', section: 'version_3_2_0_DB12'} diff --git a/applications/SALOME-master-native.pyconf b/applications/SALOME-master-native.pyconf index 1c9df31..87c23ab 100644 --- a/applications/SALOME-master-native.pyconf +++ b/applications/SALOME-master-native.pyconf @@ -292,7 +292,7 @@ __overwrite__ : 'APPLICATION.products.h5py' : 'native' 'APPLICATION.products.markdown_it_py' : 'native' 'APPLICATION.products.mdurl' : 'native' - 'APPLICATION.products.meshio' : 'native' + 'APPLICATION.products.meshio' : {tag: '5.3.4', base: 'no', section: 'version_5_3_4_no_pip'} 'APPLICATION.products.netCDF4' : 'native' 'APPLICATION.products.rich' : 'native' 'APPLICATION.products.opencv' : {tag: '3.2.0', base: 'no', section: 'version_3_2_0_DB12'} diff --git a/products/compil_scripts/meshio-4.3.13.sh b/products/compil_scripts/meshio-4.3.13.sh index 94551a5..1f9bf39 100755 --- a/products/compil_scripts/meshio-4.3.13.sh +++ b/products/compil_scripts/meshio-4.3.13.sh @@ -15,7 +15,9 @@ cd $BUILD_DIR export PYTHONPATH=${PRODUCT_INSTALL}/lib/python${PYTHON_VERSION}/site-packages:$PYTHONPATH export PATH=${PRODUCT_INSTALL}/bin:$PATH -WHEELS=('cached_property-1.5.2-py2.py3-none-any.whl' 'meshio-4.3.13-py3-none-any.whl') +WHEELS=('cached_property-1.5.2-py2.py3-none-any.whl' + 'meshio-4.3.13-py3-none-any.whl' + ) for WHEEL in "${WHEELS[@]}"; do ${PYTHONBIN} -m pip install --cache-dir=$BUILD_DIR/cache/pip $SOURCE_DIR/$WHEEL --prefix=$PRODUCT_INSTALL if [ $? -ne 0 ]; then @@ -24,5 +26,40 @@ for WHEEL in "${WHEELS[@]}"; do fi done +# bos #42618 - https://github.com/nschloe/meshio/issues/1484 +fPy=$PRODUCT_INSTALL/lib/python${PYTHON_VERSION}/site-packages/meshio/gmsh/main.py +if [ -f $fPy ]; then + sed -i 's/"gmsh": lambda f, m, \*\*kwargs: write(f, m, "4.1", \*\*kwargs)/"gmsh40": lambda f, m, \*\*kwargs: write(f, m, "4.0", \*\*kwargs)/g' $fPy + if [ $? -ne 0 ]; then + echo "FATAL: could not apply fixes to GMSH MeshIO driver" + exit 1 + fi +else + echo "FATAL: could not find GMSH MeshIO driver!" + exit 1 +fi + +# spns #42665 +fPy=$PRODUCT_INSTALL/lib/python${PYTHON_VERSION}/site-packages/meshio/ansys/_ansys.py +if [ -f $fPy ]; then + statusCode=0 + # retrieve line number + l=$(grep -nA0 "raise KeyError" $fPy|cut -d':' -f1) + L=$(($l+2)) + sed -i 's/raise KeyError(/warn(/g' $fPy + statusCode=$(($statusCode+$?)) + sed -i "${L}s/)/)\n continue/g" $fPy + statusCode=$(($statusCode+$?)) + sed -i 's/(legal: {legal_keys})/(legal: {legal_keys}). Cell will be skipped!/g' $fPy + statusCode=$(($statusCode+$?)) + if [ $statusCode -ne 0 ]; then + echo "FATAL: could not apply fixes to ANSYS MeshIO driver" + exit 1 + fi +else + echo "FATAL: could not find ANSYS MeshIO driver!" + exit 1 +fi + echo echo "########## END" diff --git a/products/compil_scripts/meshio-5.3.4.sh b/products/compil_scripts/meshio-5.3.4.sh index 19ec707..756844b 100755 --- a/products/compil_scripts/meshio-5.3.4.sh +++ b/products/compil_scripts/meshio-5.3.4.sh @@ -34,5 +34,54 @@ case $LINUX_DISTRIBUTION in ;; esac +pyVersionMajor=python$($PYTHONBIN -c 'import sys; print(".".join(map(str, sys.version_info[0:1])))') +if [ $? -ne 0 ]; then + echo ERROR: Failed to extract major Python version - assuming Python version equal to 3... + pyVersionMajor=python3 +fi + +echo INFO: Python version major: ${pyVersionMajor} +if [ -f $PRODUCT_INSTALL/lib/python${PYTHON_VERSION}/site-packages/bin/meshio ]; then + sed -i "s%#\!.*python[0-9]*%#\!/usr/bin/env ${pyVersionMajor}%#g" $PRODUCT_INSTALL/lib/python${PYTHON_VERSION}/site-packages/bin/meshio +else + echo "FATAL: could not find meshio runner!" + exit 1 +fi + +# bos #42618 - https://github.com/nschloe/meshio/issues/1484 +fPy=$PRODUCT_INSTALL/lib/python${PYTHON_VERSION}/site-packages/meshio/gmsh/main.py +if [ -f $fPy ]; then + sed -i 's/"gmsh": lambda f, m, \*\*kwargs: write(f, m, "4.1", \*\*kwargs)/"gmsh40": lambda f, m, \*\*kwargs: write(f, m, "4.0", \*\*kwargs)/g' $fPy + if [ $? -ne 0 ]; then + echo "FATAL: could not apply fixes to GMSH MeshIO driver" + exit 1 + fi +else + echo "FATAL: could not find GMSH MeshIO driver!" + exit 1 +fi + +# spns #42665 +fPy=$PRODUCT_INSTALL/lib/python${PYTHON_VERSION}/site-packages/meshio/ansys/_ansys.py +if [ -f $fPy ]; then + statusCode=0 + # retrieve line number + l=$(grep -nA0 "raise KeyError" $fPy|cut -d':' -f1) + L=$(($l+2)) + sed -i 's/raise KeyError(/warn(/g' $fPy + statusCode=$(($statusCode+$?)) + sed -i "${L}s/)/)\n continue/g" $fPy + statusCode=$(($statusCode+$?)) + sed -i 's/(legal: {legal_keys})/(legal: {legal_keys}). Cell will be skipped!/g' $fPy + statusCode=$(($statusCode+$?)) + if [ $statusCode -ne 0 ]; then + echo "FATAL: could not apply fixes to ANSYS MeshIO driver" + exit 1 + fi +else + echo "FATAL: could not find ANSYS MeshIO driver!" + exit 1 +fi + echo echo "########## END" diff --git a/products/compil_scripts/meshio-5.3.5.sh b/products/compil_scripts/meshio-5.3.5.sh index 898f73e..02ae829 100755 --- a/products/compil_scripts/meshio-5.3.5.sh +++ b/products/compil_scripts/meshio-5.3.5.sh @@ -28,9 +28,10 @@ done pyVersionMajor=python$($PYTHONBIN -c 'import sys; print(".".join(map(str, sys.version_info[0:1])))') if [ $? -ne 0 ]; then - echo ERROR: Failed to extract major Python version - assuming Python version equal to 3... - pyVersionMajor=python3 + echo ERROR: Failed to extract major Python version - assuming Python version equal to 3... + pyVersionMajor=python3 fi + echo INFO: Python version major: ${pyVersionMajor} if [ -f $PRODUCT_INSTALL/lib/python${PYTHON_VERSION}/site-packages/bin/meshio ]; then sed -i "s%#\!.*python[0-9]*%#\!/usr/bin/env ${pyVersionMajor}%#g" $PRODUCT_INSTALL/lib/python${PYTHON_VERSION}/site-packages/bin/meshio @@ -39,5 +40,40 @@ else exit 1 fi +# bos #42618 - https://github.com/nschloe/meshio/issues/1484 +fPy=$PRODUCT_INSTALL/lib/python${PYTHON_VERSION}/site-packages/meshio/gmsh/main.py +if [ -f $fPy ]; then + sed -i 's/"gmsh": lambda f, m, \*\*kwargs: write(f, m, "4.1", \*\*kwargs)/"gmsh40": lambda f, m, \*\*kwargs: write(f, m, "4.0", \*\*kwargs)/g' $fPy + if [ $? -ne 0 ]; then + echo "FATAL: could not apply fixes to GMSH MeshIO driver" + exit 1 + fi +else + echo "FATAL: could not find GMSH MeshIO driver!" + exit 1 +fi + +# spns #42665 +fPy=$PRODUCT_INSTALL/lib/python${PYTHON_VERSION}/site-packages/meshio/ansys/_ansys.py +if [ -f $fPy ]; then + statusCode=0 + # retrieve line number + l=$(grep -nA0 "raise KeyError" $fPy|cut -d':' -f1) + L=$(($l+2)) + sed -i 's/raise KeyError(/warn(/g' $fPy + statusCode=$(($statusCode+$?)) + sed -i "${L}s/)/)\n continue/g" $fPy + statusCode=$(($statusCode+$?)) + sed -i 's/(legal: {legal_keys})/(legal: {legal_keys}). Cell will be skipped!/g' $fPy + statusCode=$(($statusCode+$?)) + if [ $statusCode -ne 0 ]; then + echo "FATAL: could not apply fixes to ANSYS MeshIO driver" + exit 1 + fi +else + echo "FATAL: could not find ANSYS MeshIO driver!" + exit 1 +fi + echo echo "########## END" diff --git a/products/meshio.pyconf b/products/meshio.pyconf index 390a75d..6d87618 100644 --- a/products/meshio.pyconf +++ b/products/meshio.pyconf @@ -49,6 +49,7 @@ version_5_3_5_win : { compil_script: "meshio-5.3.5.bat" archive_info : {archive_name : "meshio-5.3.5.tar.gz"} + patches : ['meshio-5.3.5.p01.gmsh_ansys.patch'] properties : { incremental : "yes" diff --git a/products/patches/meshio-5.3.5.p01.gmsh_ansys.patch b/products/patches/meshio-5.3.5.p01.gmsh_ansys.patch new file mode 100644 index 0000000..ade25ef --- /dev/null +++ b/products/patches/meshio-5.3.5.p01.gmsh_ansys.patch @@ -0,0 +1,25 @@ +--- meshio-5.3.5_ref/src/meshio/gmsh/main.py 2023-06-26 21:18:18.000000000 +0200 ++++ meshio-5.3.5_dev/src/meshio/gmsh/main.py 2024-08-02 10:20:16.667483402 +0200 +@@ -108,6 +108,6 @@ + read, + { + "gmsh22": lambda f, m, **kwargs: write(f, m, "2.2", **kwargs), +- "gmsh": lambda f, m, **kwargs: write(f, m, "4.1", **kwargs), ++ "gmsh40": lambda f, m, **kwargs: write(f, m, "4.0", **kwargs), + }, + ) +--- meshio-5.3.5_ref/src/meshio/ansys/_ansys.py 2024-01-31 16:09:01.000000000 +0100 ++++ meshio-5.3.5_dev/src/meshio/ansys/_ansys.py 2024-08-02 10:20:57.619917526 +0200 +@@ -446,9 +446,10 @@ + ansys_cell_type = meshio_to_ansys_type[cell_type] + except KeyError: + legal_keys = ", ".join(meshio_to_ansys_type.keys()) +- raise KeyError( +- f"Illegal ANSYS cell type '{cell_type}'. (legal: {legal_keys})" ++ warn( ++ f"Illegal ANSYS cell type '{cell_type}'. (legal: {legal_keys}). Skipping cell!" + ) ++ continue + fh.write( + f"({key} (1 {first_index:x} {last_index:x} 1 {ansys_cell_type})(\n".encode() + )