Newer
Older
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\/ M anipulation | Copyright (C) 2018 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
# foamExec
#
# Description
# Usage: foamExec [-version=foamVersion] <foamCommand> ...
#
# Runs the <foamVersion> version of executable <foamCommand>
# with the rest of the arguments.
#
# Can also be used for parallel runs. For example,
# \code
# mpirun -np <nProcs> \
# foamExec -version=VERSION <foamCommand> ... -parallel
# \endcode
#
# Note
# This script must exist in $WM_PROJECT_INST_DIR/OpenFOAM-<VERSION>/bin
# or $WM_PROJECT_INST_DIR/openfoam<VERSION>/bin (debian)
# foamEtcFile located in the same directory as this script
#------------------------------------------------------------------------------
usage() {
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
Usage: ${0##*/} [OPTION] <application> ...
-mode=MODE Any combination of u(user), g(group), o(other)
-prefix=DIR Specify an alternative installation prefix
pass through to foamEtcFile
-version=VER Specify alternative OpenFOAM version (eg, 3.0, 1612, ...)
Run a particular OpenFOAM version of <APPLICATION>
exit 1
#-------------------------------------------------------------------------------
binDir="${0%/*}" # The bin dir
projectDir="${binDir%/bin}" # The project dir
# prefixDir="${projectDir%/*}" # The prefix dir (same as $WM_PROJECT_INST_DIR)
projectVersion="${WM_PROJECT_VERSION:-unknown}"
# parse options
while [ "$#" -gt 0 ]
do
case "$1" in
usage
;;
-mode=*)
etcOpts="$etcOpts $1" # pass-thru to foamEtcFile
;;
-prefix=/*)
etcOpts="$etcOpts $1" # pass-thru to foamEtcFile
;;
-version=*)
etcOpts="$etcOpts $1" # pass-thru to foamEtcFile
projectVersion="${1#*=}" # for reporting
-m | -mode)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile
shift
;;
-p | -prefix)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile
shift
;;
-v | -version)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile
projectVersion="$2" # for reporting
;;
--)
shift
break
;;
-*)
usage "invalid option '$1'"
;;
*)
break
;;
esac
# Find and source the OpenFOAM <etc/bashrc>
# placed in function to preserve command-line arguments
sourceBashrc()
rcFile="$($binDir/foamEtcFile $etcOpts bashrc)" || {
echo "Error: bashrc file could not be found for OpenFOAM-$projectVersion" 1>&2
exit 2
[ "$#" -ge 1 ] || usage "no application specified"
sourceBashrc
#------------------------------------------------------------------------------