openfoam/bin/paraFoam
Mark Olesen b970ba0901 ENH: minor improvements to environment
- handle sourcing bashrc with a relative path (issue #383)
- handle sourcing from bash and zsh.
  Still need manual intervention when sourcing dash, sh, or ksh.
- replace grep in etc/cshrc with sed only
- logical instead of physical path for WM_PROJECT_DIR (issue #431).
  Doesn't seem to be possible for csh/tcsh.

  * Continue using physical locations when comparing directories,
    but not for the top-level FOAM_INST_DIR, WM_PROJECT_DIR.

- relocate WM_CC, WM_CXX overrides from etc/config.*/compiler
  to etc/config.*/settings to ensure that they are left untouched
  when etc/config.sh/compiler is sourced while making third-party
  packages (eg, gcc, llvm, CGAL).

- provide fallback FOAM_TUTORIALS setting in RunFunctions

STYLE: remove "~OpenFOAM" fallback as being too rare, non-obvious
2017-03-20 08:57:12 +01:00

290 lines
7.5 KiB
Bash
Executable File

#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
#-------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM.
#
# OpenFOAM is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
#
# Script
# paraFoam
#
# Description
# start paraview with the OpenFOAM libraries
#
# Note
# combining -block or -builtin options with the -region option yields
# undefined behaviour
#------------------------------------------------------------------------------
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
Usage: ${0##*/} [OPTION] [PARAVIEW_OPTION]
options:
-block use blockMesh reader (uses .blockMesh extension)
-case <dir> specify alternative case directory, default is the cwd
-region <name> specify alternative mesh region
-touch only create the file (eg, .blockMesh, .OpenFOAM, etc)
-touchAll create .blockMesh, .OpenFOAM files (and for all regions)
-vtk | -builtin use VTK builtin OpenFOAM reader (uses .foam extension)
-help print the usage
Paraview options start with a double dashes.
* start paraview with the OpenFOAM libraries
paraview=$(command -v paraview)
USAGE
exit 1
}
# We want to do nice exit when running paraview to give paraview opportunity
# to clean up
unset FOAM_ABORT
unset regionName optTouch
# 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
# Reader extension and plugin
extension=OpenFOAM
plugin=PVFoamReader
# Parse options
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help)
usage
;;
-block | -blockMesh)
extension=blockMesh
plugin=PVblockMeshReader
shift
;;
-builtin | -vtk)
extension=foam
unset plugin
shift
;;
-case)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
cd "$2" 2>/dev/null || usage "directory does not exist: '$2'"
shift 2
;;
-region)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
regionName=$2
shift 2
;;
-touch)
optTouch=true
unset plugin
shift
;;
-touchAll)
optTouch=all
unset plugin
shift
;;
--)
shift
break # Stop here, treat balance as paraview options
;;
--*)
break # Stop here, treat this and balance as paraview options
;;
*)
usage "unknown option/argument: '$1'"
;;
esac
done
# If a reader module is needed, check that it exists
[ -z "$plugin" -o -f $PV_PLUGIN_PATH/lib${plugin}_SM.so ] || {
cat<< BUILDREADER 1>&2
ERROR: ParaView reader module library ($plugin) does not exist
Please build the reader module before continuing:
cd \$WM_PROJECT_DIR/applications/utilities/postProcessing/graphics/PVReaders
./Allwclean
./Allwmake
BUILDREADER
# Fallback to native reader, if possible
if [ "$extension" = OpenFOAM ]
then
extension=foam
echo "Using the native VTK/OpenFOAM reader instead" 1>&2
else
exit 1
fi
}
# Check for --data=... argument
hasDataArg()
{
hasData=false
while [ "$#" -gt 0 ]
do
case "$1" in
(--data=*)
hasData=true
break
;;
esac
shift
done
}
hasDataArg $@
# Get a sensible caseName from the directory name
caseName=${PWD##*/}
caseFile="$caseName.$extension"
fvControls="system"
if [ -n "$regionName" ]
then
if [ ! -d constant/$regionName ]
then
echo "FATAL ERROR: Region $regionName does not exist" 1>&2
exit 1
else
caseFile="$caseName{$regionName}.$extension"
fvControls="$fvControls/$regionName"
fi
fi
case "${optTouch:-false}" in
all)
extension=OpenFOAM
if [ -f system/blockMeshDict -o -f constant/polyMesh/blockMeshDict ]
then
touch "$caseName.blockMesh"
echo "Created '$caseName.blockMesh'" 1>&2
fi
touch "$caseName.$extension"
echo "Created '$caseName.$extension'" 1>&2
# Discover probable regions
for region in constant/*
do
if [ -d $region -a -d $region/polyMesh ]
then
regionName=${region##*/}
touch "$caseName{$regionName}.$extension"
echo "Created '$caseName{$regionName}.$extension'" 1>&2
fi
done
exit 0
;;
true)
touch "$caseFile"
echo "Created '$caseFile'" 1>&2
exit 0
;;
esac
# Parent directory for normal or parallel results
case "$caseName" in
processor*) parentDir=".." ;;
*) parentDir="." ;;
esac
if [ "${hasData:-false}" = true ]
then
# Has --data=.., send directly to paraview
exec paraview "$@"
else
# Check existence of essential files
warn="WARN file does not exist:"
case $extension in
blockMesh)
blockMeshDict=system/blockMeshDict
if [ -f constant/polyMesh/blockMeshDict ]
then
blockMeshDict=constant/polyMesh/blockMeshDict
fi
for check in \
system/controlDict \
$blockMeshDict \
;
do
[ -s "$parentDir/$check" ] || {
[ -n "$warn" ] && echo "$warn" 1>&2
echo " $parentDir/$check" 1>&2
unset warn
}
done
;;
OpenFOAM)
for check in \
system/controlDict \
$fvControls/fvSchemes \
$fvControls/fvSolution \
;
do
[ -s "$parentDir/$check" ] || {
[ -n "$warn" ] && echo "$warn" 1>&2
echo " $parentDir/$check" 1>&2
unset warn
}
done
;;
esac
[ -n "$warn" ] || {
echo "Cannot locate OpenFOAM-format case files"
echo -n "Would you like to open ParaView anyway <Y|n>:"
read open
[ "$open" = "" ] || echo $open | grep -iqE "^y" && paraview
exit
}
# Only create/remove caseFile if it didn't already exist
[ -e $caseFile ] || {
trap "rm -f $caseFile 2>/dev/null; exit 0" EXIT TERM INT
touch "$caseFile"
echo "Created temporary '$caseFile'" 1>&2
}
# 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'
fi
#------------------------------------------------------------------------------