From a77b7f13708885a6b127b0138eb9142f28eac1c0 Mon Sep 17 00:00:00 2001
From: Henry <Henry>
Date: Fri, 6 Feb 2015 10:09:13 +0000
Subject: [PATCH] Rationalize foamJob and foamExec Patches provided by Bruno
 Santos Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=231

---
 bin/foamExec           |  2 +-
 bin/foamJob            | 26 +++++++++++++++++++++++++-
 etc/config/aliases.csh |  5 ++++-
 etc/config/aliases.sh  |  3 +++
 4 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/bin/foamExec b/bin/foamExec
index 509ed5d83cb..7a93bfb6132 100755
--- a/bin/foamExec
+++ b/bin/foamExec
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #------------------------------------------------------------------------------
 # =========                 |
 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
diff --git a/bin/foamJob b/bin/foamJob
index 20793c3d520..7fa5c8174e6 100755
--- a/bin/foamJob
+++ b/bin/foamJob
@@ -40,6 +40,7 @@ options:
   -case <dir>       specify alternative case directory, default is the cwd
   -parallel         parallel run of processors
   -screen           also sends output to screen
+  -wait             wait for execution to complete (when not using -screen)
   -version <ver>    specify an alternative OpenFOAM version
   -help             print the usage
 
@@ -108,7 +109,7 @@ findExec() {
 
 # MAIN SCRIPT
 #~~~~~~~~~~~~
-unset parallelOpt screenOpt
+unset parallelOpt screenOpt waitOpt
 
 
 # parse options
@@ -131,6 +132,10 @@ do
       screenOpt=true
       shift
       ;;
+   -w | -wait)
+      waitOpt=true
+      shift
+      ;;
    -v | -version)
       [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
       version="$2"
@@ -231,6 +236,13 @@ then
                 break
             fi
         done
+
+        #
+        # Send FOAM_SETTINGS to parallel processes, so that the proper
+        # definitions are sent as well.
+        #
+        mpiopts="$mpiopts -x FOAM_SETTINGS"
+
         ;;
     esac
 
@@ -244,6 +256,12 @@ then
     else
         echo "Executing: $mpirun $mpiopts $APPLICATION $(echoArgs "$@") -parallel > log 2>&1"
         $mpirun $mpiopts $APPLICATION "$@" -parallel > log 2>&1 &
+
+        pid=$!
+        if [ "$waitOpt" = true ]
+        then
+            wait $pid
+        fi
     fi
 
 else
@@ -258,6 +276,12 @@ else
     else
         echo "Executing: $APPLICATION $(echoArgs "$@") > log 2>&1 &"
         $APPLICATION "$@" > log 2>&1 &
+
+        pid=$!
+        if [ "$waitOpt" = true ]
+        then
+            wait $pid
+        fi
     fi
 fi
 
diff --git a/etc/config/aliases.csh b/etc/config/aliases.csh
index 1d8b0e837c5..a006be18cde 100644
--- a/etc/config/aliases.csh
+++ b/etc/config/aliases.csh
@@ -38,8 +38,11 @@ alias wm32 'wmSET WM_ARCH_OPTION=32'
 alias wmSP 'wmSET WM_PRECISION_OPTION=SP'
 alias wmDP 'wmSET WM_PRECISION_OPTION=DP'
 
+# refresh the environment
+alias wmREFRESH 'wmSET $FOAM_SETTINGS'
+
 # clear env
-alias wmUNSET='source $WM_PROJECT_DIR/etc/config/unset.csh'
+alias wmUNSET 'source $WM_PROJECT_DIR/etc/config/unset.csh'
 
 # Toggle wmakeScheduler on/off
 #  - also need to set WM_HOSTS
diff --git a/etc/config/aliases.sh b/etc/config/aliases.sh
index ea5a25a82a6..6efa8e10f50 100644
--- a/etc/config/aliases.sh
+++ b/etc/config/aliases.sh
@@ -38,6 +38,9 @@ alias wm32='wmSET WM_ARCH_OPTION=32'
 alias wmSP='wmSET WM_PRECISION_OPTION=SP'
 alias wmDP='wmSET WM_PRECISION_OPTION=DP'
 
+# refresh the environment
+alias wmREFRESH='wmSET $FOAM_SETTINGS'
+
 # clear env
 alias wmUNSET='. $WM_PROJECT_DIR/etc/config/unset.sh'
 
-- 
GitLab