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.
This commit is contained in:
Chris Greenshields
2018-12-20 18:43:40 +00:00
parent 9f9576a0e7
commit 2051acedfb

View File

@ -40,6 +40,7 @@ options:
-block use blockMesh reader (uses .blockMesh extension) -block use blockMesh reader (uses .blockMesh extension)
-builtin use VTK builtin OpenFOAM reader (uses .foam extension) -builtin use VTK builtin OpenFOAM reader (uses .foam extension)
-case <dir> specify alternative case directory, default is the cwd -case <dir> specify alternative case directory, default is the cwd
-empty launch ParaView without opening any data files
-region <name> specify alternative mesh region -region <name> specify alternative mesh region
-touch only create the file (eg, .blockMesh, .OpenFOAM, etc) -touch only create the file (eg, .blockMesh, .OpenFOAM, etc)
-touchAll create .blockMesh, .OpenFOAM files (and for all regions) -touchAll create .blockMesh, .OpenFOAM files (and for all regions)
@ -59,6 +60,38 @@ error() {
exit 1 exit 1
} }
pvExec () {
paraview "$@" 2> /dev/null && return 0
pvFallback
paraview --mesa "$@"
}
pvFallback () {
cat <<EOF
**********************************************************
ParaView failed to open using available graphics hardware.
Trying fallback to software rendering using MESA.
**********************************************************
EOF
}
noPVReader () {
cat<<EOF
FATAL ERROR: The official reader module for OpenFOAM data does not exist on
your system. This means that the version of ParaView you are using was not
compiled with OpenFOAM, or distributed with a packaged version of OpenFOAM.
For information on packaged versions of OpenFOAM/ParaView and compilation of
OpenFOAM/ParaView, see https://openfoam.org/download
Alternatively, you might be able to view your OpenFOAM data with the reader
module provided with ParaView by running:
paraFoam -builtin
EOF
}
# We want to do nice exit when running paraview to give paraview opportunity # We want to do nice exit when running paraview to give paraview opportunity
# to clean up # to clean up
unset FOAM_ABORT unset FOAM_ABORT
@ -96,6 +129,10 @@ do
cd "$2" 2>/dev/null || error "directory does not exist: '$2'" cd "$2" 2>/dev/null || error "directory does not exist: '$2'"
shift 2 shift 2
;; ;;
-empty)
echo "Launching ParaView without opening any files."
pvExec && exit 0
;;
-region) -region)
[ "$#" -ge 2 ] || error "'$1' option requires an argument" [ "$#" -ge 2 ] || error "'$1' option requires an argument"
regionName=$2 regionName=$2
@ -125,20 +162,9 @@ do
done done
# Check that reader module has been built # Check that reader module has been built
if [ $requirePV -eq 1 -a ! -f "$PV_PLUGIN_PATH/libPVFoamReader_SM.so" ] [ $requirePV -eq 1 ] && \
then ! [ -f "$PV_PLUGIN_PATH/libPVFoamReader_SM.so" ] && \
cat<< BUILDREADER noPVReader && exit 1
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
# Check for --data=... argument # Check for --data=... argument
hasDataArg() hasDataArg()
@ -158,7 +184,6 @@ hasDataArg()
hasDataArg "$@" hasDataArg "$@"
# Get a sensible caseName from the directory name # Get a sensible caseName from the directory name
caseName=${PWD##*/} caseName=${PWD##*/}
caseFile="$caseName.$extension" caseFile="$caseName.$extension"
@ -179,7 +204,7 @@ fi
case "${optTouch:-false}" in case "${optTouch:-false}" in
all) all)
extension=OpenFOAM extension=OpenFOAM
if [ -f system/blockMeshDict -o -f constant/polyMesh/blockMeshDict ] if [ -f system/blockMeshDict ] || [ -f constant/polyMesh/blockMeshDict ]
then then
touch "$caseName.blockMesh" touch "$caseName.blockMesh"
echo "Created '$caseName.blockMesh'" echo "Created '$caseName.blockMesh'"
@ -189,12 +214,10 @@ all)
# Discover probable regions # Discover probable regions
for region in constant/* for region in constant/*
do do
if [ -d "$region" -a -d "$region"/polyMesh ] [ -d "$region" ] && [ -d "${region}/polyMesh" ] && \
then regionName=${region##*/} && \
regionName=${region##*/} touch "$caseName{$regionName}.$extension" && \
touch "$caseName{$regionName}.$extension"
echo "Created '$caseName{$regionName}.$extension'" echo "Created '$caseName{$regionName}.$extension'"
fi
done done
exit 0 exit 0
;; ;;
@ -217,7 +240,7 @@ if [ "${hasData:-false}" = true ]
then then
# Has --data=.., send directly to paraview # Has --data=.., send directly to paraview
exec paraview "$@" pvExec "$@"
else else
@ -235,7 +258,8 @@ else
$blockMeshDictDir \ $blockMeshDictDir \
; ;
do do
[ -s "$parentDir/$check" ] || { [ -s "$parentDir/$check" ] || [ -s "$parentDir/$check.orig" ] ||
{
[ -n "$warn" ] && echo "$warn" 1>&2 [ -n "$warn" ] && echo "$warn" 1>&2
echo " $parentDir/$check" 1>&2 echo " $parentDir/$check" 1>&2
unset warn unset warn
@ -250,7 +274,8 @@ else
$fvControls/fvSolution \ $fvControls/fvSolution \
; ;
do do
[ -s "$parentDir/$check" ] || { [ -s "$parentDir/$check" ] || [ -s "$parentDir/$check.orig" ] ||
{
[ -n "$warn" ] && echo "$warn" 1>&2 [ -n "$warn" ] && echo "$warn" 1>&2
echo " $parentDir/$check" 1>&2 echo " $parentDir/$check" 1>&2
unset warn unset warn
@ -263,7 +288,7 @@ else
echo "Cannot locate OpenFOAM-format case files" echo "Cannot locate OpenFOAM-format case files"
printf "Would you like to open ParaView anyway <Y|n>:" printf "Would you like to open ParaView anyway <Y|n>:"
read open read open
[ "$open" = "" ] || echo "$open" | grep -iqE "^y" && paraview [ "$open" = "" ] || echo "$open" | grep -iqE "^y" && pvExec
exit exit
} }
@ -275,8 +300,8 @@ else
} }
# For now filter out any ld.so errors. Caused by non-system compiler? # For now filter out any ld.so errors. Caused by non-system compiler?
paraview --data="$caseFile" "$@" 2>&1 \ pvExec --data="$caseFile" "$@" 2>&1 \
| fgrep -v 'Inconsistency detected by ld.so' | grep -v -F 'Inconsistency detected by ld.so'
fi fi