2019-09-27 17:18:26 +00:00
|
|
|
#!/bin/sh
|
2010-05-12 13:27:55 +00:00
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# ========= |
|
2019-09-27 17:18:26 +00:00
|
|
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
|
|
# \\ / O peration |
|
|
|
|
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
|
|
|
# \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
|
|
|
#-------------------------------------------------------------------------------
|
2010-05-12 13:27:55 +00:00
|
|
|
# License
|
2019-09-27 17:18:26 +00:00
|
|
|
# This file is part of OpenFOAM, licensed under GNU General Public License
|
|
|
|
# <http://www.gnu.org/licenses/>.
|
2010-05-12 13:27:55 +00:00
|
|
|
#
|
|
|
|
# Script
|
|
|
|
# paraFoam
|
|
|
|
#
|
|
|
|
# Description
|
2019-09-27 17:18:26 +00:00
|
|
|
# Start paraview with OpenFOAM libraries and reader modules.
|
2010-05-12 13:27:55 +00:00
|
|
|
#
|
2019-09-27 17:18:26 +00:00
|
|
|
# Note
|
|
|
|
# Combining -block, -vtk, -builtin options with -region option yields
|
|
|
|
# undefined behaviour
|
2010-05-12 13:27:55 +00:00
|
|
|
#------------------------------------------------------------------------------
|
2019-09-27 17:18:26 +00:00
|
|
|
printHelp() {
|
|
|
|
# Print usage to stdout so that it can be captured for bash completion
|
2010-05-27 10:48:11 +00:00
|
|
|
cat<<USAGE
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2019-09-27 17:18:26 +00:00
|
|
|
Usage: ${0##*/} [OPTION] [--] [PARAVIEW_OPTION]
|
2010-05-27 10:48:11 +00:00
|
|
|
options:
|
2019-09-27 17:18:26 +00:00
|
|
|
-block Use blockMesh reader (.blockMesh extension)
|
|
|
|
-case <dir> Specify alternative case directory, default is the cwd
|
|
|
|
-region <name> Specify alternative mesh region
|
|
|
|
-touch Create the file (eg, .blockMesh, .OpenFOAM, .foam, ...)
|
|
|
|
-touch-all Create .blockMesh, .foam, .OpenFOAM files (for all regions)
|
|
|
|
-touch-proc Same as '-touch' but for each processor
|
|
|
|
-vtk Use VTK builtin OpenFOAM reader (.foam extension)
|
|
|
|
--help Display ParaView help
|
|
|
|
-help Display short help and exit
|
|
|
|
-help-full Display full help and exit
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2019-09-27 17:18:26 +00:00
|
|
|
Start paraview with the OpenFOAM libraries and reader modules.
|
|
|
|
Note that paraview options begin with double dashes.
|
|
|
|
|
|
|
|
Uses paraview=$(command -v paraview)
|
|
|
|
|
|
|
|
Equivalent options:
|
|
|
|
-touch-all -touchAll
|
|
|
|
-vtk -builtin
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
USAGE
|
2019-09-27 17:18:26 +00:00
|
|
|
exit 0 # A clean exit
|
|
|
|
}
|
|
|
|
|
|
|
|
# Report error and exit
|
|
|
|
die()
|
|
|
|
{
|
|
|
|
exec 1>&2
|
|
|
|
echo
|
|
|
|
echo "Error encountered:"
|
|
|
|
while [ "$#" -ge 1 ]; do echo " $1"; shift; done
|
|
|
|
echo
|
|
|
|
echo "See '${0##*/} -help' for usage"
|
|
|
|
echo
|
2010-05-27 10:48:11 +00:00
|
|
|
exit 1
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 17:18:26 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Do a nice exit to give paraview an opportunity to clean up
|
|
|
|
unset FOAM_ABORT
|
2010-05-27 10:48:11 +00:00
|
|
|
|
2019-09-27 17:18:26 +00:00
|
|
|
# Hack: change all locale to 'C' i.e. using '.' for decimal point. This is
|
|
|
|
# only needed temporarily until paraview is locale aware. (git version is
|
|
|
|
# already 2010-07)
|
|
|
|
export LC_ALL=C
|
2015-09-05 11:07:11 +00:00
|
|
|
|
2019-09-27 17:18:26 +00:00
|
|
|
# Reader extension and plugin
|
|
|
|
extension=OpenFOAM
|
|
|
|
plugin=PVFoamReader
|
|
|
|
|
|
|
|
# Parse options
|
|
|
|
unset regionName optTouch
|
2010-05-27 10:48:11 +00:00
|
|
|
while [ "$#" -gt 0 ]
|
|
|
|
do
|
|
|
|
case "$1" in
|
2019-09-27 17:18:26 +00:00
|
|
|
-h | -help*)
|
|
|
|
printHelp
|
|
|
|
;;
|
|
|
|
-block*)
|
|
|
|
extension=blockMesh
|
|
|
|
plugin=PVblockMeshReader
|
|
|
|
;;
|
|
|
|
-vtk | -built*)
|
|
|
|
extension=foam
|
|
|
|
unset plugin
|
2010-05-27 10:48:11 +00:00
|
|
|
;;
|
|
|
|
-case)
|
2019-09-27 17:18:26 +00:00
|
|
|
[ "$#" -ge 2 ] || die "'$1' option requires an argument"
|
|
|
|
cd "$2" 2>/dev/null || die "directory does not exist: '$2'"
|
|
|
|
shift
|
2010-05-27 10:48:11 +00:00
|
|
|
;;
|
|
|
|
-region)
|
2019-09-27 17:18:26 +00:00
|
|
|
[ "$#" -ge 2 ] || die "'$1' option requires an argument"
|
2010-05-27 10:48:11 +00:00
|
|
|
regionName=$2
|
2019-09-27 17:18:26 +00:00
|
|
|
shift
|
2010-05-27 10:48:11 +00:00
|
|
|
;;
|
|
|
|
-touch)
|
2019-09-27 17:18:26 +00:00
|
|
|
optTouch=true
|
|
|
|
unset plugin
|
|
|
|
;;
|
|
|
|
-touch-all | -touchAll)
|
|
|
|
optTouch=all
|
|
|
|
unset plugin
|
2010-05-27 10:48:11 +00:00
|
|
|
;;
|
2019-09-27 17:18:26 +00:00
|
|
|
-touch-proc*)
|
|
|
|
optTouch=processor
|
|
|
|
unset plugin
|
|
|
|
;;
|
|
|
|
--)
|
2013-07-05 15:50:12 +00:00
|
|
|
shift
|
2019-09-27 17:18:26 +00:00
|
|
|
break # Stop here, treat balance as paraview options
|
|
|
|
;;
|
|
|
|
--help) # Emit paraview help directly
|
|
|
|
exec paraview "$@"
|
|
|
|
echo "Error: could not exec paraview" 1>&2
|
|
|
|
exit 1 # This should not have happened
|
|
|
|
;;
|
|
|
|
--*)
|
|
|
|
break # Stop here, treat _this_ and balance as paraview options
|
2013-07-05 15:50:12 +00:00
|
|
|
;;
|
2010-05-27 10:48:11 +00:00
|
|
|
*)
|
2019-09-27 17:18:26 +00:00
|
|
|
die "Unknown option/argument: '$1'"
|
2010-05-27 10:48:11 +00:00
|
|
|
;;
|
|
|
|
esac
|
2019-09-27 17:18:26 +00:00
|
|
|
shift
|
2010-05-27 10:48:11 +00:00
|
|
|
done
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2019-09-27 17:18:26 +00:00
|
|
|
if [ -n "$plugin" ]
|
2013-07-05 15:50:12 +00:00
|
|
|
then
|
2019-09-27 17:18:26 +00:00
|
|
|
pluginError="Cannot use ParaView reader module library ($plugin)"
|
|
|
|
|
|
|
|
# Check if requested reader module exists
|
|
|
|
if [ -z "$PV_PLUGIN_PATH" ]
|
|
|
|
then
|
|
|
|
echo "$pluginError" 1>&2
|
|
|
|
echo "The PV_PLUGIN_PATH environment value is not set" 1>&2
|
|
|
|
elif [ -f "$PV_PLUGIN_PATH/lib${plugin}_SM.so" ]
|
|
|
|
then
|
|
|
|
unset pluginError
|
|
|
|
else
|
|
|
|
echo "$pluginError - not built?" 1>&2
|
|
|
|
cat<< NO_PLUGIN 1>&2
|
|
|
|
Consider building the reader module
|
|
|
|
cd \$WM_PROJECT_DIR/applications/utilities/postProcessing/graphics/PVReaders
|
|
|
|
./Allwclean
|
|
|
|
./Allwmake
|
|
|
|
NO_PLUGIN
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$pluginError" ]
|
|
|
|
then
|
|
|
|
# Fallback to native reader, if possible
|
|
|
|
if [ "$plugin" = PVFoamReader ]
|
|
|
|
then
|
|
|
|
echo 1>&2
|
|
|
|
echo "Continuing with builtin reader: paraFoam -vtk" 1>&2
|
|
|
|
echo 1>&2
|
|
|
|
extension=foam
|
|
|
|
else
|
|
|
|
echo 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
unset plugin
|
|
|
|
fi
|
2013-07-05 15:50:12 +00:00
|
|
|
fi
|
|
|
|
|
2013-07-05 17:01:32 +00:00
|
|
|
|
2019-09-27 17:18:26 +00:00
|
|
|
# Check for --data=... argument
|
|
|
|
unset hasData
|
|
|
|
for i
|
|
|
|
do
|
|
|
|
case "$i" in (--data=*) hasData=true; break;; esac
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# Get a sensible caseName from the directory name
|
|
|
|
caseName="${PWD##*/}"
|
|
|
|
caseFile="$caseName.$extension"
|
2010-05-27 10:48:11 +00:00
|
|
|
fvControls="system"
|
|
|
|
|
|
|
|
if [ -n "$regionName" ]
|
|
|
|
then
|
2019-09-27 17:18:26 +00:00
|
|
|
[ -d "constant/$regionName" ] || {
|
|
|
|
echo "FATAL ERROR: Region $regionName does not exist" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
caseFile="$caseName{$regionName}.$extension"
|
2010-05-27 10:48:11 +00:00
|
|
|
fvControls="$fvControls/$regionName"
|
|
|
|
fi
|
|
|
|
|
2019-09-27 17:18:26 +00:00
|
|
|
case "${optTouch:-false}" in
|
|
|
|
all)
|
|
|
|
extension=OpenFOAM
|
|
|
|
if [ -f system/blockMeshDict ] || [ -f constant/polyMesh/blockMeshDict ]
|
|
|
|
then
|
|
|
|
touch "$caseName.blockMesh"
|
|
|
|
echo "Created '$caseName.blockMesh'" 1>&2
|
|
|
|
fi
|
|
|
|
touch "$caseName.$extension" "$caseName.foam"
|
|
|
|
echo "Created '$caseName.$extension' '$caseName.foam'" 1>&2
|
|
|
|
# Discover probable regions
|
|
|
|
for region in constant/*
|
|
|
|
do
|
|
|
|
if [ -d "$region" ] && [ -d "$region/polyMesh" ]
|
|
|
|
then
|
|
|
|
regionName="${region##*/}"
|
|
|
|
touch "$caseName{$regionName}.$extension"
|
|
|
|
echo "Created '$caseName{$regionName}.$extension'" 1>&2
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
proc*)
|
|
|
|
for i in processor*
|
|
|
|
do
|
|
|
|
(
|
|
|
|
cd "$i" 2> /dev/null && touch "${caseFile%.*}#${i#processor}.$extension"
|
|
|
|
)
|
|
|
|
done
|
|
|
|
echo "Created '$caseFile' for processor directories" 1>&2
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
true)
|
2010-05-27 10:48:11 +00:00
|
|
|
touch "$caseFile"
|
2019-09-27 17:18:26 +00:00
|
|
|
echo "Created '$caseFile'" 1>&2
|
2010-05-27 10:48:11 +00:00
|
|
|
exit 0
|
2019-09-27 17:18:26 +00:00
|
|
|
;;
|
2010-05-12 13:27:55 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
|
2019-09-27 17:18:26 +00:00
|
|
|
# Check existence of some essential OpenFOAM files.
|
|
|
|
# If caseName appears to be a processor directory, check parent as fallback
|
|
|
|
hasFiles() {
|
|
|
|
local warn="Cannot locate OpenFOAM-format case files:"
|
|
|
|
local parent
|
|
|
|
case "$caseName" in (processor*) parent="../" ;; esac
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2019-09-27 17:18:26 +00:00
|
|
|
for file
|
|
|
|
do
|
|
|
|
if [ -s "$file" ]
|
|
|
|
then
|
|
|
|
continue
|
|
|
|
elif [ -n "$parent" ] && [ -s "$parent$file" ]
|
|
|
|
then
|
|
|
|
continue
|
|
|
|
else
|
|
|
|
# Not found
|
|
|
|
[ -n "$warn" ] && echo "$warn" 1>&2
|
|
|
|
unset warn
|
|
|
|
if [ -n "$parent" ]
|
|
|
|
then
|
|
|
|
echo " $file, or $parent$file" 1>&2
|
|
|
|
else
|
|
|
|
echo " $file" 1>&2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2019-09-27 17:18:26 +00:00
|
|
|
if [ -n "$warn" ]
|
|
|
|
then
|
|
|
|
return 0 # No warnings were triggered
|
|
|
|
else
|
|
|
|
echo 1>&2 # Emit an additional separator line
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
|
2019-09-27 17:18:26 +00:00
|
|
|
if [ "${hasData:-false}" = true ]
|
|
|
|
then
|
|
|
|
|
|
|
|
# Has --data=.., send directly to paraview
|
|
|
|
exec paraview "$@"
|
|
|
|
echo "Error: could not exec paraview" 1>&2
|
|
|
|
exit 1 # This should not have happened
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
# Check existence of essential files
|
|
|
|
warn=false
|
|
|
|
case "$plugin" in
|
|
|
|
PVblockMeshReader)
|
|
|
|
blockMeshDict=system/blockMeshDict
|
|
|
|
if [ -f constant/polyMesh/blockMeshDict ]
|
|
|
|
then
|
|
|
|
blockMeshDict=constant/polyMesh/blockMeshDict
|
|
|
|
fi
|
|
|
|
|
|
|
|
hasFiles system/controlDict "$blockMeshDict" || warn=true
|
|
|
|
;;
|
|
|
|
|
|
|
|
PVFoamReader)
|
|
|
|
hasFiles \
|
|
|
|
system/controlDict \
|
|
|
|
"$fvControls/fvSchemes" \
|
|
|
|
"$fvControls/fvSolution" || warn=true
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
[ "${warn:-false}" = false ] || {
|
|
|
|
echo -n "Would you like to open paraview anyway <Y|n>: "
|
|
|
|
read open
|
|
|
|
case "${open:-y}" in ([Yy]*) paraview ;; esac
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
# Only create/remove caseFile if it did not previously exist
|
|
|
|
[ -e "$caseFile" ] || {
|
2010-05-27 10:48:11 +00:00
|
|
|
trap "rm -f $caseFile 2>/dev/null; exit 0" EXIT TERM INT
|
|
|
|
touch "$caseFile"
|
2019-09-27 17:18:26 +00:00
|
|
|
echo "Created temporary '$caseFile'" 1>&2
|
2010-05-27 10:48:11 +00:00
|
|
|
}
|
|
|
|
|
2019-09-27 17:18:26 +00:00
|
|
|
# For now filter out any ld.so errors. Caused by non-system compiler?
|
|
|
|
paraview --data="$caseFile" "$@" 2>&1 \
|
|
|
|
| grep -F -v 'Inconsistency detected'
|
|
|
|
fi
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|