From 2051acedfb16f730ba4f68d5877ea2c9572b9b46 Mon Sep 17 00:00:00 2001 From: Chris Greenshields Date: Thu, 20 Dec 2018 18:43:40 +0000 Subject: [PATCH] paraFoam: attempts to launch ParaView with Mesa OpenGL if system OpenGL fails A new "-empty" option launches ParaView without opening any files. This enables users to run ParaView using the paraFoam script for all data (OpenFOAM or otherwise), making use of the automatic launching with Mesa if system OpenGL fails. To view OpenFOAM case files, run "paraFoam". To view other data files, run "paraFoam -empty" and open the files within ParaView. --- bin/paraFoam | 79 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/bin/paraFoam b/bin/paraFoam index 833f15d16..cc97a4a9e 100755 --- a/bin/paraFoam +++ b/bin/paraFoam @@ -40,6 +40,7 @@ options: -block use blockMesh reader (uses .blockMesh extension) -builtin use VTK builtin OpenFOAM reader (uses .foam extension) -case specify alternative case directory, default is the cwd + -empty launch ParaView without opening any data files -region specify alternative mesh region -touch only create the file (eg, .blockMesh, .OpenFOAM, etc) -touchAll create .blockMesh, .OpenFOAM files (and for all regions) @@ -59,6 +60,38 @@ error() { exit 1 } +pvExec () { + paraview "$@" 2> /dev/null && return 0 + + pvFallback + paraview --mesa "$@" +} + +pvFallback () { + cat </dev/null || error "directory does not exist: '$2'" shift 2 ;; + -empty) + echo "Launching ParaView without opening any files." + pvExec && exit 0 + ;; -region) [ "$#" -ge 2 ] || error "'$1' option requires an argument" regionName=$2 @@ -125,20 +162,9 @@ do done # Check that reader module has been built -if [ $requirePV -eq 1 -a ! -f "$PV_PLUGIN_PATH/libPVFoamReader_SM.so" ] -then - cat<< BUILDREADER - -FATAL ERROR: ParaView reader module libraries do not exist - -Please build the reader module before continuing: -cd \$FOAM_UTILITIES/postProcessing/graphics/PVReaders -./Allwclean -./Allwmake - -BUILDREADER - exit 1 -fi +[ $requirePV -eq 1 ] && \ + ! [ -f "$PV_PLUGIN_PATH/libPVFoamReader_SM.so" ] && \ + noPVReader && exit 1 # Check for --data=... argument hasDataArg() @@ -158,7 +184,6 @@ hasDataArg() hasDataArg "$@" - # Get a sensible caseName from the directory name caseName=${PWD##*/} caseFile="$caseName.$extension" @@ -179,7 +204,7 @@ fi case "${optTouch:-false}" in all) extension=OpenFOAM - if [ -f system/blockMeshDict -o -f constant/polyMesh/blockMeshDict ] + if [ -f system/blockMeshDict ] || [ -f constant/polyMesh/blockMeshDict ] then touch "$caseName.blockMesh" echo "Created '$caseName.blockMesh'" @@ -189,12 +214,10 @@ all) # Discover probable regions for region in constant/* do - if [ -d "$region" -a -d "$region"/polyMesh ] - then - regionName=${region##*/} - touch "$caseName{$regionName}.$extension" + [ -d "$region" ] && [ -d "${region}/polyMesh" ] && \ + regionName=${region##*/} && \ + touch "$caseName{$regionName}.$extension" && \ echo "Created '$caseName{$regionName}.$extension'" - fi done exit 0 ;; @@ -217,7 +240,7 @@ if [ "${hasData:-false}" = true ] then # Has --data=.., send directly to paraview - exec paraview "$@" + pvExec "$@" else @@ -235,7 +258,8 @@ else $blockMeshDictDir \ ; do - [ -s "$parentDir/$check" ] || { + [ -s "$parentDir/$check" ] || [ -s "$parentDir/$check.orig" ] || + { [ -n "$warn" ] && echo "$warn" 1>&2 echo " $parentDir/$check" 1>&2 unset warn @@ -250,7 +274,8 @@ else $fvControls/fvSolution \ ; do - [ -s "$parentDir/$check" ] || { + [ -s "$parentDir/$check" ] || [ -s "$parentDir/$check.orig" ] || + { [ -n "$warn" ] && echo "$warn" 1>&2 echo " $parentDir/$check" 1>&2 unset warn @@ -263,7 +288,7 @@ else echo "Cannot locate OpenFOAM-format case files" printf "Would you like to open ParaView anyway :" read open - [ "$open" = "" ] || echo "$open" | grep -iqE "^y" && paraview + [ "$open" = "" ] || echo "$open" | grep -iqE "^y" && pvExec exit } @@ -275,8 +300,8 @@ else } # For now filter out any ld.so errors. Caused by non-system compiler? - paraview --data="$caseFile" "$@" 2>&1 \ - | fgrep -v 'Inconsistency detected by ld.so' + pvExec --data="$caseFile" "$@" 2>&1 \ + | grep -v -F 'Inconsistency detected by ld.so' fi