Newer
Older
#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
#------------------------------------------------------------------------------
# Copyright (C) 2011-2016 OpenFOAM Foundation
# Copyright (C) 2016-2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# Script
# paraFoam
#
# Description
# Start paraview with OpenFOAM libraries and reader modules.
# Combining -block, -vtk, -builtin options with -region option yields
# undefined behaviour
#------------------------------------------------------------------------------
printHelp() {
# Print usage to stdout so that it can be captured for bash completion
Usage: ${0##*/} [OPTION] [--] [PARAVIEW_OPTION]
-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
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
# 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
exit 1
}
#-------------------------------------------------------------------------------
# Do a nice exit to give paraview an opportunity to clean up
unset FOAM_ABORT
# 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
# Default reader extension and plugin name
extension=OpenFOAM
plugin=foamReader
# Parse options
unset regionName optTouch
-h | -help*)
extension=blockMesh
plugin=blockReader
-vtk | -built*)
extension=foam
Mark Olesen
committed
unset plugin
[ "$#" -ge 2 ] || die "'$1' option requires an argument"
cd "$2" 2>/dev/null || die "directory does not exist: '$2'"
;;
-region)
[ "$#" -ge 2 ] || die "'$1' option requires an argument"
optTouch=true
Mark Olesen
committed
unset plugin
-touch-all | -touchAll)
optTouch=all
Mark Olesen
committed
unset plugin
-touch-proc*)
optTouch=processor
unset plugin
;;
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
pluginError="Cannot use ParaView/OpenFOAM reader modules"
Mark Olesen
committed
# Check if requested reader module exists
if [ -z "$PV_PLUGIN_PATH" ]
then
echo "The PV_PLUGIN_PATH environment variable is unset" 1>&2
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# Check for different names. For example,
# - ParaFoamReader = (paraview >= 5.7)
# - libParaFoamReader = (paraview < 5.7) and (OPENFOAM > 1912)
# - libPVFoamReader_SM = (OPENFOAM <= 1912)
case "$plugin" in
blockReader)
for libName in \
ParaFoamBlockReader \
libParaFoamBlockReader \
libPVblockMeshReader_SM \
;
do
if [ -f "$PV_PLUGIN_PATH/$libName.so" ]
then
unset pluginError
break
fi
done
;;
foamReader)
for libName in \
ParaFoamReader \
libParaFoamReader \
libPVFoamReader_SM \
;
do
if [ -f "$PV_PLUGIN_PATH/$libName.so" ]
then
unset pluginError
break
fi
done
;;
esac
if [ -n "$pluginError" ]
then
cat<< NO_PLUGIN 1>&2
=========================
$pluginError - need to build?
cd \$WM_PROJECT_DIR/modules/visualization/src/paraview-plugins
OR cd \$WM_PROJECT_DIR/applications/utilities/postProcessing/graphics/PVReaders
./Allwclean && ./Allwmake
=========================
Mark Olesen
committed
then
if [ "$plugin" = foamReader ]
then
echo "Continuing with builtin reader: paraFoam -vtk" 1>&2
echo 1>&2
extension=foam
else
echo 1>&2
exit 1
fi
unset plugin
Mark Olesen
committed
fi
Mark Olesen
committed
# 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
caseFile="$caseName.$extension"
fvControls="system"
[ -d "constant/$regionName" ] || {
Mark Olesen
committed
echo "FATAL ERROR: Region $regionName does not exist" 1>&2
}
caseFile="$caseName{$regionName}.$extension"
fvControls="$fvControls/$regionName"
case "${optTouch:-false}" in
all)
extension=OpenFOAM
if [ -f system/blockMeshDict ] || [ -f constant/polyMesh/blockMeshDict ]
then
touch "$caseName.blockMesh"
Mark Olesen
committed
echo "Created '$caseName.blockMesh'" 1>&2
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" ]
touch "$caseName{$regionName}.$extension"
Mark Olesen
committed
echo "Created '$caseName{$regionName}.$extension'" 1>&2
fi
done
exit 0
;;
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
;;
touch "$caseFile"
Mark Olesen
committed
echo "Created '$caseFile'" 1>&2
# 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
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
if [ -n "$warn" ]
then
return 0 # No warnings were triggered
else
echo 1>&2 # Emit an additional separator line
return 1
fi
}
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
Mark Olesen
committed
blockMeshDict=system/blockMeshDict
if [ -f constant/polyMesh/blockMeshDict ]
then
Mark Olesen
committed
blockMeshDict=constant/polyMesh/blockMeshDict
hasFiles system/controlDict "$blockMeshDict" || warn=true
hasFiles \
system/controlDict \
"$fvControls/fvSchemes" \
"$fvControls/fvSolution" || warn=true
[ "${warn:-false}" = false ] || {
echo -n "Would you like to open paraview anyway <Y|n>: "
case "${open:-y}" in ([Yy]*) paraview ;; esac
# Only create/remove caseFile if it did not previously exist
[ -e "$caseFile" ] || {
touch "$caseFile"
Mark Olesen
committed
echo "Created temporary '$caseFile'" 1>&2
trap "rm -f \"$caseFile\"; exit 0" EXIT TERM INT
# For now filter out any ld.so errors. Caused by non-system compiler?
paraview --data="$caseFile" "$@" 2>&1 \
| grep -F -v 'Inconsistency detected'
#------------------------------------------------------------------------------