From dd60cfcd061e131276649df9685093c60e5676b5 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Mon, 27 Jun 2016 16:33:55 +0200
Subject: [PATCH] FIX: provide restore0Dir function to fix issue #159

- makes it easier to ensure the correct behaviour, consistently
---
 bin/tools/RunFunctions                        | 19 ++++++--
 tutorials/basic/potentialFoam/cylinder/Allrun |  2 +-
 .../basic/potentialFoam/pitzDaily/Allrun      |  2 +-
 .../flamePropagationWithObstacles/Allrun      |  3 +-
 .../XiDyMFoam/annularCombustorTurbine/Allrun  |  4 +-
 .../rhoCentralFoam/shockTube/Allclean         |  4 +-
 .../annularThermalMixer/Allrun                |  6 +--
 .../sonicFoam/laminar/shockTube/Allclean      |  4 +-
 .../hotRoom/Allrun                            |  2 +-
 .../hotRoom/Allrun                            |  2 +-
 .../buoyantPimpleFoam/hotRoom/Allclean        |  2 +-
 .../circuitBoardCooling/Allrun                |  2 +-
 .../windshieldCondensation/Allrun             |  3 +-
 .../windshieldDefrost/Allrun.pre              |  3 +-
 .../heatExchanger/Allrun.pre                  |  4 +-
 .../oscillatingInletACMI2D/Allrun.pre         |  2 +-
 .../pimpleDyMFoam/propeller/Allrun.pre        |  5 +-
 .../pimpleDyMFoam/wingMotion/Allclean         | 23 +++++----
 .../pimpleDyMFoam/wingMotion/Allrun           | 48 +++++++++++--------
 .../pimpleFoam/TJunctionFan/Allrun            |  2 +-
 .../pisoFoam/les/motorBike/Allrun             |  2 +-
 .../pisoFoam/les/motorBike/lesFiles/Allrun    | 11 +++--
 .../pisoFoam/les/motorBike/motorBike/Allrun   | 15 +++---
 .../simpleFoam/motorBike/Allrun               | 12 ++---
 .../simpleFoam/pipeCyclic/Allrun              |  3 +-
 .../simpleFoam/turbineSiting/Allrun           |  4 +-
 .../hopper/Allclean                           | 16 +++++--
 .../hopper/Allrun                             | 32 +++++++------
 .../cylinder/Allrun.pre                       |  2 +-
 .../hotBoxes/Allrun.pre                       |  2 +-
 .../rivuletPanel/Allrun.pre                   |  2 +-
 .../splashPanel/Allrun.pre                    |  2 +-
 .../reactingParcelFoam/filter/Allclean        | 11 ++---
 .../reactingParcelFoam/verticalChannel/Allrun |  4 +-
 .../verticalChannelLTS/Allrun                 |  4 +-
 .../verticalChannel/Allclean                  |  6 +--
 .../verticalChannel/Allrun                    |  5 +-
 .../mixerVessel/Allrun-simulation             |  2 +-
 .../OpenCFD/Allrun-rhoCentralFoam             |  4 +-
 tutorials/mesh/parallel/filter/Allrun         |  2 +-
 .../MPPICInterFoam/twoPhasePachuka/Allrun     |  4 +-
 .../cavitatingFoam/les/throttle3D/Allrun      |  2 +-
 .../ras/sloshingTank2D/Allrun                 |  2 +-
 .../laminar/depthCharge2D/Allrun              |  2 +-
 .../laminar/depthCharge3D/Allrun              |  2 +-
 .../laminar/damBreak4phase/Allrun             |  3 +-
 .../laminar/sloshingTank2D/Allrun             |  2 +-
 .../laminar/sloshingTank2D3DoF/Allrun         |  2 +-
 .../laminar/sloshingTank3D/Allrun             |  2 +-
 .../laminar/sloshingTank3D3DoF/Allrun         |  2 +-
 .../laminar/sloshingTank3D6DoF/Allrun         |  2 +-
 .../interDyMFoam/laminar/testTubeMixer/Allrun |  2 +-
 .../interDyMFoam/ras/DTCHull/Allrun           | 12 +----
 .../ras/damBreakWithObstacle/Allrun           |  2 +-
 .../interDyMFoam/ras/floatingObject/Allrun    |  2 +-
 .../ras/mixerVesselAMI/Allrun.pre             |  4 +-
 .../interDyMFoam/ras/motorBike/Allrun.pre     | 14 ++++--
 .../interFoam/laminar/capillaryRise/Allrun    |  2 +-
 .../interFoam/laminar/damBreak/Allrun         |  2 +-
 .../laminar/damBreak/damBreak/Allclean        |  2 +-
 .../interFoam/laminar/mixerVessel2D/Allrun    |  2 +-
 .../multiphase/interFoam/ras/DTCHull/Allrun   |  3 +-
 .../multiphase/interFoam/ras/damBreak/Allrun  |  2 +-
 .../interFoam/ras/damBreak/damBreak/Allclean  |  2 +-
 .../ras/damBreakPorousBaffle/Allclean         |  2 +-
 .../interFoam/ras/weirOverflow/Allrun         |  4 +-
 .../propeller/Allrun.pre                      |  8 +---
 .../cavitatingBullet/Allrun                   |  2 +-
 .../multiphaseEulerFoam/damBreak4phase/Allrun |  3 +-
 .../damBreak4phaseFine/Allrun                 |  3 +-
 .../laminar/mixerVesselAMI2D/Allrun           |  3 +-
 .../laminar/damBreak4phase/Allrun             |  3 +-
 .../laminar/damBreak4phaseFine/Allrun         |  2 +-
 .../oscillatingBox/Allrun                     |  2 +-
 .../oscillatingBox/Allrun                     |  3 +-
 .../twoLiquidMixingFoam/lockExchange/Allrun   |  3 +-
 76 files changed, 206 insertions(+), 191 deletions(-)

diff --git a/bin/tools/RunFunctions b/bin/tools/RunFunctions
index 407800e7917..8bd7b2f5d1a 100755
--- a/bin/tools/RunFunctions
+++ b/bin/tools/RunFunctions
@@ -41,7 +41,7 @@ isTest()
 
 getNumberOfProcessors()
 {
-    if [ -f $1 ]
+    if [ -f "$1" ]
     then
         expandDictionary $1 | sed -ne 's/^numberOfSubdomains\s*\(.*\);/\1/p'
     fi
@@ -166,7 +166,7 @@ compileApplication()
 
 cloneCase()
 {
-    if [ -d $2 ]
+    if [ -d "$2" ]
     then
         echo "Case already cloned: remove case directory $2 to clone"
     else
@@ -175,9 +175,22 @@ cloneCase()
         cpfiles="0 system constant"
         for f in $cpfiles
         do
-            cp -r $1/$f $2
+            \cp -r $1/$f $2
         done
     fi
 }
 
+# Overwrite 0/ with the contents of 0.org/ if it exists
+restore0Dir()
+{
+    echo "Restore 0/ from 0.org/"
+    if [ -d 0.org ]
+    then
+        \rm -rf 0
+        \cp -r 0.org 0 > /dev/null 2>&1
+    else
+        echo "    Warning: no 0.org/ found"
+    fi
+}
+
 #------------------------------------------------------------------------------
diff --git a/tutorials/basic/potentialFoam/cylinder/Allrun b/tutorials/basic/potentialFoam/cylinder/Allrun
index d8a1591738f..d078c47a0e8 100755
--- a/tutorials/basic/potentialFoam/cylinder/Allrun
+++ b/tutorials/basic/potentialFoam/cylinder/Allrun
@@ -6,7 +6,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 
 application=`getApplication`
 
-cp -r 0.org 0 > /dev/null 2>&1
+restore0Dir
 runApplication blockMesh
 runApplication $application -withFunctionObjects -writePhi -writep
 runApplication streamFunction
diff --git a/tutorials/basic/potentialFoam/pitzDaily/Allrun b/tutorials/basic/potentialFoam/pitzDaily/Allrun
index 3383ef1dad7..d74cf54ec0b 100755
--- a/tutorials/basic/potentialFoam/pitzDaily/Allrun
+++ b/tutorials/basic/potentialFoam/pitzDaily/Allrun
@@ -6,7 +6,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 
 application=`getApplication`
 
-cp -r 0.org 0 > /dev/null 2>&1
+restore0Dir
 runApplication blockMesh
 runApplication $application -writePhi -writep
 runApplication streamFunction
diff --git a/tutorials/combustion/PDRFoam/flamePropagationWithObstacles/Allrun b/tutorials/combustion/PDRFoam/flamePropagationWithObstacles/Allrun
index e00af435e67..5c5ee5cabff 100755
--- a/tutorials/combustion/PDRFoam/flamePropagationWithObstacles/Allrun
+++ b/tutorials/combustion/PDRFoam/flamePropagationWithObstacles/Allrun
@@ -5,8 +5,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
-rm -rf 0
-cp -r 0.org 0
+restore0Dir
 runApplication blockMesh
 runApplication changeDictionary
 runApplication topoSet
diff --git a/tutorials/combustion/XiDyMFoam/annularCombustorTurbine/Allrun b/tutorials/combustion/XiDyMFoam/annularCombustorTurbine/Allrun
index 595770a6d14..d79a59a4f59 100755
--- a/tutorials/combustion/XiDyMFoam/annularCombustorTurbine/Allrun
+++ b/tutorials/combustion/XiDyMFoam/annularCombustorTurbine/Allrun
@@ -6,12 +6,12 @@ cd ${0%/*} || exit 1
 
 ./Allrun.mesh
 
-rm -rf 0 && cp -r 0.org 0
+restore0Dir
 
 runApplication decomposePar -force
 
 runParallel potentialFoam -pName pPotential -initialiseUBCs
 
-rm -f processor*/0/phi
+\rm -f processor*/0/phi
 
 runParallel XiDyMFoam
diff --git a/tutorials/compressible/rhoCentralFoam/shockTube/Allclean b/tutorials/compressible/rhoCentralFoam/shockTube/Allclean
index 416eb9a89d9..a52c67d9c53 100755
--- a/tutorials/compressible/rhoCentralFoam/shockTube/Allclean
+++ b/tutorials/compressible/rhoCentralFoam/shockTube/Allclean
@@ -4,8 +4,8 @@ cd ${0%/*} || exit 1    # Run from this directory
 # Source tutorial clean functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
-rm -rf 0
-cp -r 0.org 0
+\rm -rf 0
+\cp -r 0.org 0
 cleanCase
 cleanSamples
 
diff --git a/tutorials/compressible/rhoPimpleDyMFoam/annularThermalMixer/Allrun b/tutorials/compressible/rhoPimpleDyMFoam/annularThermalMixer/Allrun
index 24b62374493..07492af16c3 100755
--- a/tutorials/compressible/rhoPimpleDyMFoam/annularThermalMixer/Allrun
+++ b/tutorials/compressible/rhoPimpleDyMFoam/annularThermalMixer/Allrun
@@ -9,14 +9,12 @@ runApplication surfaceFeatureExtract
 runApplication blockMesh
 runApplication snappyHexMesh -overwrite
 
-if [ -d 0 ] ; then
-   rm -rf 0
-fi
+\rm -rf 0
 
 runApplication createBaffles -overwrite
 runApplication mergeOrSplitBaffles -split -overwrite
 
-cp -r 0.org 0
+restore0Dir
 
 runApplication $(getApplication)
 
diff --git a/tutorials/compressible/sonicFoam/laminar/shockTube/Allclean b/tutorials/compressible/sonicFoam/laminar/shockTube/Allclean
index a0d99d7592b..298f96e2992 100755
--- a/tutorials/compressible/sonicFoam/laminar/shockTube/Allclean
+++ b/tutorials/compressible/sonicFoam/laminar/shockTube/Allclean
@@ -5,8 +5,8 @@ cd ${0%/*} || exit 1    # Run from this directory
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 cleanCase
-rm -rf 0
-cp -r 0.org 0
+\rm -rf 0
+\cp -r 0.org 0
 cleanSamples
 
 #------------------------------------------------------------------------------
diff --git a/tutorials/heatTransfer/buoyantBoussinesqPimpleFoam/hotRoom/Allrun b/tutorials/heatTransfer/buoyantBoussinesqPimpleFoam/hotRoom/Allrun
index 0ecf4b2d131..d0075b1529e 100755
--- a/tutorials/heatTransfer/buoyantBoussinesqPimpleFoam/hotRoom/Allrun
+++ b/tutorials/heatTransfer/buoyantBoussinesqPimpleFoam/hotRoom/Allrun
@@ -7,7 +7,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 application=`getApplication`
 
 runApplication blockMesh
-cp 0/T.org 0/T
+\cp 0/T.org 0/T
 runApplication setFields
 runApplication $application
 
diff --git a/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/hotRoom/Allrun b/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/hotRoom/Allrun
index 0ecf4b2d131..d0075b1529e 100755
--- a/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/hotRoom/Allrun
+++ b/tutorials/heatTransfer/buoyantBoussinesqSimpleFoam/hotRoom/Allrun
@@ -7,7 +7,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 application=`getApplication`
 
 runApplication blockMesh
-cp 0/T.org 0/T
+\cp 0/T.org 0/T
 runApplication setFields
 runApplication $application
 
diff --git a/tutorials/heatTransfer/buoyantPimpleFoam/hotRoom/Allclean b/tutorials/heatTransfer/buoyantPimpleFoam/hotRoom/Allclean
index 6fe57d72bb8..c61a79c8105 100755
--- a/tutorials/heatTransfer/buoyantPimpleFoam/hotRoom/Allclean
+++ b/tutorials/heatTransfer/buoyantPimpleFoam/hotRoom/Allclean
@@ -5,6 +5,6 @@ cd ${0%/*} || exit 1    # Run from this directory
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 cleanCase
-cp 0/T.org 0/T
+\cp 0/T.org 0/T
 
 #------------------------------------------------------------------------------
diff --git a/tutorials/heatTransfer/buoyantSimpleFoam/circuitBoardCooling/Allrun b/tutorials/heatTransfer/buoyantSimpleFoam/circuitBoardCooling/Allrun
index e60b87bdff8..152d9d91870 100755
--- a/tutorials/heatTransfer/buoyantSimpleFoam/circuitBoardCooling/Allrun
+++ b/tutorials/heatTransfer/buoyantSimpleFoam/circuitBoardCooling/Allrun
@@ -6,7 +6,7 @@ application=`getApplication`
 
 runApplication blockMesh
 
-cp -r 0.org 0
+restore0Dir
 
 # Create 1D and 3D baffles
 runApplication createBaffles -overwrite
diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/Allrun b/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/Allrun
index 0330f6a530d..b75fde5c9ae 100755
--- a/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/Allrun
+++ b/tutorials/heatTransfer/chtMultiRegionFoam/windshieldCondensation/Allrun
@@ -21,7 +21,6 @@ rm log.topoSet
 runApplication topoSet -region cabin -dict system/topoSetDictRegister
 
 # set the initial fields
-rm -rf 0
-cp -rf 0.org 0
+restore0Dir
 
 runApplication $(getApplication)
diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/windshieldDefrost/Allrun.pre b/tutorials/heatTransfer/chtMultiRegionFoam/windshieldDefrost/Allrun.pre
index f22237bf9d3..0818ebd1a40 100755
--- a/tutorials/heatTransfer/chtMultiRegionFoam/windshieldDefrost/Allrun.pre
+++ b/tutorials/heatTransfer/chtMultiRegionFoam/windshieldDefrost/Allrun.pre
@@ -17,5 +17,4 @@ runApplication subsetMesh c0 -patch walls -overwrite
 runApplication splitMeshRegions -cellZones -overwrite
 
 # set the initial fields
-rm -rf 0
-cp -rf 0.org 0
+restore0Dir
diff --git a/tutorials/heatTransfer/chtMultiRegionSimpleFoam/heatExchanger/Allrun.pre b/tutorials/heatTransfer/chtMultiRegionSimpleFoam/heatExchanger/Allrun.pre
index 020b201778e..9780d15756a 100755
--- a/tutorials/heatTransfer/chtMultiRegionSimpleFoam/heatExchanger/Allrun.pre
+++ b/tutorials/heatTransfer/chtMultiRegionSimpleFoam/heatExchanger/Allrun.pre
@@ -1,5 +1,4 @@
 #!/bin/sh
-
 cd ${0%/*} || exit 1    # Run from this directory
 
 # Source tutorial run functions
@@ -25,5 +24,4 @@ rm -rf constant/air/polyMesh/sets
 paraFoam -touch -region porous
 paraFoam -touch -region air
 
-
-cp -rf 0.org 0
+restore0Dir
diff --git a/tutorials/incompressible/pimpleDyMFoam/oscillatingInletACMI2D/Allrun.pre b/tutorials/incompressible/pimpleDyMFoam/oscillatingInletACMI2D/Allrun.pre
index db20559080d..c18efa4cc95 100755
--- a/tutorials/incompressible/pimpleDyMFoam/oscillatingInletACMI2D/Allrun.pre
+++ b/tutorials/incompressible/pimpleDyMFoam/oscillatingInletACMI2D/Allrun.pre
@@ -14,4 +14,4 @@ runApplication createBaffles -overwrite
 # remove zero-sized patches
 runApplication createPatch -overwrite
 
-cp -rf 0.org 0
+restore0Dir
diff --git a/tutorials/incompressible/pimpleDyMFoam/propeller/Allrun.pre b/tutorials/incompressible/pimpleDyMFoam/propeller/Allrun.pre
index e35686cce40..15491d569a9 100755
--- a/tutorials/incompressible/pimpleDyMFoam/propeller/Allrun.pre
+++ b/tutorials/incompressible/pimpleDyMFoam/propeller/Allrun.pre
@@ -11,11 +11,8 @@ cp $FOAM_TUTORIALS/resources/geometry/propellerTip.obj.gz constant/triSurface/
 # - meshing
 
 runApplication blockMesh
-
 runApplication surfaceFeatureExtract
-
 runApplication snappyHexMesh -overwrite
-
 runApplication renumberMesh -overwrite
 
 # force removal of fields generated by snappy
@@ -31,4 +28,4 @@ runApplication createPatch -overwrite
 #runApplication moveDynamicMesh -checkAMI
 
 # - set the initial fields
-cp -rf 0.org 0
+restore0Dir
diff --git a/tutorials/incompressible/pimpleDyMFoam/wingMotion/Allclean b/tutorials/incompressible/pimpleDyMFoam/wingMotion/Allclean
index f7d6ef5a87a..d01b222a10e 100755
--- a/tutorials/incompressible/pimpleDyMFoam/wingMotion/Allclean
+++ b/tutorials/incompressible/pimpleDyMFoam/wingMotion/Allclean
@@ -4,14 +4,19 @@ cd ${0%/*} || exit 1    # Run from this directory
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
-cd wingMotion_snappyHexMesh
-cleanCase
+(
+    cd wingMotion_snappyHexMesh || exit 1
+    cleanCase
+)
 
-cd ../wingMotion2D_simpleFoam
-cleanCase
-rm -rf 0
-
-cd ../wingMotion2D_pimpleDyMFoam
-cleanCase
-rm -rf 0
+(
+    cd wingMotion2D_simpleFoam || exit 1
+    cleanCase
+    rm -rf 0
+)
 
+(
+    cd wingMotion2D_pimpleDyMFoam || exit 1
+    cleanCase
+    rm -rf 0
+)
diff --git a/tutorials/incompressible/pimpleDyMFoam/wingMotion/Allrun b/tutorials/incompressible/pimpleDyMFoam/wingMotion/Allrun
index 997bdd6cfb8..0b5930fddc5 100755
--- a/tutorials/incompressible/pimpleDyMFoam/wingMotion/Allrun
+++ b/tutorials/incompressible/pimpleDyMFoam/wingMotion/Allrun
@@ -5,26 +5,36 @@ cd ${0%/*} || exit 1    # Run from this directory
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # Make 3D mesh in slab of cells.
-cd wingMotion_snappyHexMesh
-runApplication blockMesh
-runApplication snappyHexMesh -overwrite
+(
+    cd wingMotion_snappyHexMesh || exit 1
+
+    runApplication blockMesh
+    runApplication snappyHexMesh -overwrite
+)
 
 # Make a 2D mesh by extruding a patch and solve to steady state.
-cd ../wingMotion2D_simpleFoam
-runApplication extrudeMesh
-runApplication createPatch -overwrite
-cp -r 0.org 0
-runApplication simpleFoam
-
-# Copy the mesh from the steady state case and map the results to a
-# mesh motion case, then solve transient.
-cd ../wingMotion2D_pimpleDyMFoam
-cp -r ../wingMotion2D_simpleFoam/constant/polyMesh constant
-cp -r 0.org 0
-runApplication mapFields ../wingMotion2D_simpleFoam -sourceTime latestTime -consistent
-mv 0/pointDisplacement.unmapped 0/pointDisplacement
-runApplication decomposePar
-runParallel `getApplication`
-runApplication reconstructPar
+(
+    cd wingMotion2D_simpleFoam || exit 1
+
+    runApplication extrudeMesh
+    runApplication createPatch -overwrite
+    restore0Dir
+    runApplication simpleFoam
+)
+
+# Copy mesh from the steady state case, map the results to a mesh motion case,
+# then solve transient.
+(
+    cd wingMotion2D_pimpleDyMFoam || exit 1
+
+    \rm -rf constant/polyMesh
+    \cp -r ../wingMotion2D_simpleFoam/constant/polyMesh constant
+    restore0Dir
+    runApplication mapFields ../wingMotion2D_simpleFoam -sourceTime latestTime -consistent
+    \mv 0/pointDisplacement.unmapped 0/pointDisplacement
+    runApplication decomposePar
+    runParallel $(getApplication)
+    runApplication reconstructPar
+)
 
 #------------------------------------------------------------------------------
diff --git a/tutorials/incompressible/pimpleFoam/TJunctionFan/Allrun b/tutorials/incompressible/pimpleFoam/TJunctionFan/Allrun
index 628bd511a94..2a4548eb724 100755
--- a/tutorials/incompressible/pimpleFoam/TJunctionFan/Allrun
+++ b/tutorials/incompressible/pimpleFoam/TJunctionFan/Allrun
@@ -11,7 +11,7 @@ runApplication blockMesh
 # Create faceZones for baffles and fan
 runApplication topoSet
 
-cp -r 0.org 0
+restore0Dir
 
 # Create wall and cyclic baffles and the fields on them
 runApplication createBaffles -overwrite
diff --git a/tutorials/incompressible/pisoFoam/les/motorBike/Allrun b/tutorials/incompressible/pisoFoam/les/motorBike/Allrun
index 15e3932e9e0..6c45de5d874 100755
--- a/tutorials/incompressible/pisoFoam/les/motorBike/Allrun
+++ b/tutorials/incompressible/pisoFoam/les/motorBike/Allrun
@@ -31,7 +31,7 @@ then
     cloneParallelCase motorBike motorBikeLES
 
     # Do the LES case
-    cp lesFiles/Allrun motorBikeLES/
+    \cp lesFiles/Allrun motorBikeLES/
     (cd motorBikeLES && foamRunTutorials)
 fi
 
diff --git a/tutorials/incompressible/pisoFoam/les/motorBike/lesFiles/Allrun b/tutorials/incompressible/pisoFoam/les/motorBike/lesFiles/Allrun
index be0ad68bf8d..eb23f3566e0 100755
--- a/tutorials/incompressible/pisoFoam/les/motorBike/lesFiles/Allrun
+++ b/tutorials/incompressible/pisoFoam/les/motorBike/lesFiles/Allrun
@@ -4,12 +4,13 @@
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # Set-up the LES case
-cp ../lesFiles/fvS* ../lesFiles/controlDict system/
-cp ../lesFiles/turbulenceProperties constant/
+\cp ../lesFiles/fvS* ../lesFiles/controlDict system/
+\cp ../lesFiles/turbulenceProperties constant/
 
-ls -d processor* | xargs -I {} rm -rf ./{}/0 $1
-ls -d processor* | xargs -I {} mv ./{}/500 ./{}/0 $1
-ls -d processor* | xargs -I {} rm -rf ./{}/0/uniform $1
+# $1 for special test cases?
+\ls -d processor* | xargs -I {} \rm -rf ./{}/0 $1
+\ls -d processor* | xargs -I {} \mv ./{}/500 ./{}/0 $1
+\ls -d processor* | xargs -I {} \rm -rf ./{}/0/uniform $1
 
 runParallel pisoFoam
 
diff --git a/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/Allrun b/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/Allrun
index 3aa5f32e812..9d825fda182 100755
--- a/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/Allrun
+++ b/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/Allrun
@@ -5,26 +5,27 @@ cd ${0%/*} || exit 1    # Run from this directory
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # copy motorbike surface from resources directory
-cp $FOAM_TUTORIALS/resources/geometry/motorBike.obj.gz constant/triSurface/
+\cp $FOAM_TUTORIALS/resources/geometry/motorBike.obj.gz constant/triSurface/
 
 # Make dummy 0 directory
 mkdir 0
 
 runApplication blockMesh
-# cp system/decomposeParDict.hierarchical system/decomposeParDict
+# \cp system/decomposeParDict.hierarchical system/decomposeParDict
 runApplication decomposePar -decomposeParDict system/decomposeParDict.hierarchical
 
-# cp system/decomposeParDict.ptscotch system/decomposeParDict
+# \cp system/decomposeParDict.ptscotch system/decomposeParDict
 runParallel snappyHexMesh -decomposeParDict system/decomposeParDict.ptscotch -profiling -overwrite -parallel
 
 find . -type f -iname "*level*" -exec rm {} \;
 
-ls -d processor* | xargs -I {} cp -r 0.org ./{}/0 $1
+#- set the initial fields
+# $1 for special test cases?
+\ls -d processor* | xargs -I {} \rm -rf ./{}/0 $1
+\ls -d processor* | xargs -I {} \cp -r 0.org ./{}/0 $1
 
 runParallel renumberMesh -overwrite
-
 runParallel potentialFoam -initialiseUBCs
-
-runParallel `getApplication`
+runParallel $(getApplication)
 
 #------------------------------------------------------------------------------
diff --git a/tutorials/incompressible/simpleFoam/motorBike/Allrun b/tutorials/incompressible/simpleFoam/motorBike/Allrun
index 39b3f3785b7..7400dfe8c1d 100755
--- a/tutorials/incompressible/simpleFoam/motorBike/Allrun
+++ b/tutorials/incompressible/simpleFoam/motorBike/Allrun
@@ -5,7 +5,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # copy motorbike surface from resources directory
-cp $FOAM_TUTORIALS/resources/geometry/motorBike.obj.gz constant/triSurface/
+\cp $FOAM_TUTORIALS/resources/geometry/motorBike.obj.gz constant/triSurface/
 runApplication surfaceFeatureExtract
 
 runApplication blockMesh
@@ -13,12 +13,12 @@ runApplication blockMesh
 runApplication decomposePar
 runParallel snappyHexMesh -overwrite
 
-#- For non-parallel running
-#cp -r 0.org 0 > /dev/null 2>&1
+#- For non-parallel running: - set the initial fields
+# restore0Dir
 
-#- For parallel running
-ls -d processor* | xargs -I {} rm -rf ./{}/0
-ls -d processor* | xargs -I {} cp -r 0.org ./{}/0
+#- For parallel running: set the initial fields
+\ls -d processor* | xargs -I {} \rm -rf ./{}/0
+\ls -d processor* | xargs -I {} \cp -r 0.org ./{}/0
 
 runParallel patchSummary
 runParallel potentialFoam
diff --git a/tutorials/incompressible/simpleFoam/pipeCyclic/Allrun b/tutorials/incompressible/simpleFoam/pipeCyclic/Allrun
index 8d9f834d23c..2276ebb55f8 100755
--- a/tutorials/incompressible/simpleFoam/pipeCyclic/Allrun
+++ b/tutorials/incompressible/simpleFoam/pipeCyclic/Allrun
@@ -10,7 +10,8 @@ application=`getApplication`
 runApplication blockMesh
 runApplication topoSet
 runApplication refineHexMesh c0 -overwrite
-cp -r 0.org 0
+
+restore0Dir
 
 #runApplication $application
 runApplication decomposePar -cellDist
diff --git a/tutorials/incompressible/simpleFoam/turbineSiting/Allrun b/tutorials/incompressible/simpleFoam/turbineSiting/Allrun
index c8ff7fbe9db..47f3b9caf34 100755
--- a/tutorials/incompressible/simpleFoam/turbineSiting/Allrun
+++ b/tutorials/incompressible/simpleFoam/turbineSiting/Allrun
@@ -16,7 +16,9 @@ runParallel snappyHexMesh -overwrite
 
 find . -type f -iname "*level*" -exec rm {} \;
 
-ls -d processor* | xargs -I {} cp -r 0.org ./{}/0
+# - set the initial fields
+\ls -d processor* | xargs -I {} \rm -rf ./{}/0
+\ls -d processor* | xargs -I {} \cp -r 0.org ./{}/0
 
 runParallel topoSet
 runParallel `getApplication`
diff --git a/tutorials/lagrangian/icoUncoupledKinematicParcelFoam/hopper/Allclean b/tutorials/lagrangian/icoUncoupledKinematicParcelFoam/hopper/Allclean
index 7e664591376..85527724bf1 100755
--- a/tutorials/lagrangian/icoUncoupledKinematicParcelFoam/hopper/Allclean
+++ b/tutorials/lagrangian/icoUncoupledKinematicParcelFoam/hopper/Allclean
@@ -4,11 +4,17 @@ cd ${0%/*} || exit 1    # Run from this directory
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
-cd hopperInitialState
-cleanCase
+(
+    cd hopperInitialState || exit 1
 
-cd ../hopperEmptying
-cleanCase
-rm -rf 0
+    cleanCase
+)
+
+(
+    cd hopperEmptying || exit 1
+
+    cleanCase
+    rm -rf 0
+)
 
 #------------------------------------------------------------------------------
diff --git a/tutorials/lagrangian/icoUncoupledKinematicParcelFoam/hopper/Allrun b/tutorials/lagrangian/icoUncoupledKinematicParcelFoam/hopper/Allrun
index 6a0667ccb84..2beb0f03550 100755
--- a/tutorials/lagrangian/icoUncoupledKinematicParcelFoam/hopper/Allrun
+++ b/tutorials/lagrangian/icoUncoupledKinematicParcelFoam/hopper/Allrun
@@ -4,20 +4,24 @@ cd ${0%/*} || exit 1    # Run from this directory
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
-cd hopperInitialState
-runApplication blockMesh
-runApplication decomposePar
-runParallel `getApplication`
-runApplication reconstructPar -latestTime
-cd ..
+(
+    cd hopperInitialState || exit 1
 
-cd hopperEmptying
-rm -rf 0
-cp -r 0.org 0
-runApplication blockMesh
-runApplication mapFields ../hopperInitialState -sourceTime latestTime
-runApplication decomposePar
-runParallel `getApplication`
-runApplication reconstructPar
+    runApplication blockMesh
+    runApplication decomposePar
+    runParallel $(getApplication)
+    runApplication reconstructPar -latestTime
+)
+
+(
+    cd hopperEmptying || exit 1
+
+    restore0Dir
+    runApplication blockMesh
+    runApplication mapFields ../hopperInitialState -sourceTime latestTime
+    runApplication decomposePar
+    runParallel $(getApplication)
+    runApplication reconstructPar
+)
 
 #------------------------------------------------------------------------------
diff --git a/tutorials/lagrangian/reactingParcelFilmFoam/cylinder/Allrun.pre b/tutorials/lagrangian/reactingParcelFilmFoam/cylinder/Allrun.pre
index ae65df0e259..e4d467e68ee 100755
--- a/tutorials/lagrangian/reactingParcelFilmFoam/cylinder/Allrun.pre
+++ b/tutorials/lagrangian/reactingParcelFilmFoam/cylinder/Allrun.pre
@@ -1,7 +1,7 @@
 #!/bin/sh
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
-cp -rf 0.org 0
+restore0Dir
 runApplication blockMesh
 
 #runApplication setSet -batch wallFilmRegion.setSet
diff --git a/tutorials/lagrangian/reactingParcelFilmFoam/hotBoxes/Allrun.pre b/tutorials/lagrangian/reactingParcelFilmFoam/hotBoxes/Allrun.pre
index 784b007b2c1..ab63cbf9b3a 100755
--- a/tutorials/lagrangian/reactingParcelFilmFoam/hotBoxes/Allrun.pre
+++ b/tutorials/lagrangian/reactingParcelFilmFoam/hotBoxes/Allrun.pre
@@ -4,7 +4,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
-cp -rf 0.org 0
+restore0Dir
 
 # create the underlying block mesh
 runApplication blockMesh
diff --git a/tutorials/lagrangian/reactingParcelFilmFoam/rivuletPanel/Allrun.pre b/tutorials/lagrangian/reactingParcelFilmFoam/rivuletPanel/Allrun.pre
index d00e6b23ff0..c82f75cd2dd 100755
--- a/tutorials/lagrangian/reactingParcelFilmFoam/rivuletPanel/Allrun.pre
+++ b/tutorials/lagrangian/reactingParcelFilmFoam/rivuletPanel/Allrun.pre
@@ -1,7 +1,7 @@
 #!/bin/sh
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
-cp -rf 0.org 0
+restore0Dir
 
 runApplication blockMesh
 
diff --git a/tutorials/lagrangian/reactingParcelFilmFoam/splashPanel/Allrun.pre b/tutorials/lagrangian/reactingParcelFilmFoam/splashPanel/Allrun.pre
index 512715678f4..9292f83031b 100755
--- a/tutorials/lagrangian/reactingParcelFilmFoam/splashPanel/Allrun.pre
+++ b/tutorials/lagrangian/reactingParcelFilmFoam/splashPanel/Allrun.pre
@@ -1,7 +1,7 @@
 #!/bin/sh
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
-cp -rf 0.org 0
+restore0Dir
 
 runApplication blockMesh
 
diff --git a/tutorials/lagrangian/reactingParcelFoam/filter/Allclean b/tutorials/lagrangian/reactingParcelFoam/filter/Allclean
index a298a17347f..0949f3df045 100755
--- a/tutorials/lagrangian/reactingParcelFoam/filter/Allclean
+++ b/tutorials/lagrangian/reactingParcelFoam/filter/Allclean
@@ -6,13 +6,10 @@ cd ${0%/*} || exit 1    # Run from this directory
 
 cleanCase
 
-# remove 0 directory
-rm -rf 0
+# remove 0 directory and post-processing directories
+\rm -rf 0 postProcessing
 
-# remove post-processing directory
-rm -rf postProcessing
-
-# copy 0.org to 0
-cp -r 0.org 0
+# restore 0/ directory from 0.org/
+\cp -r 0.org 0
 
 #------------------------------------------------------------------------------
diff --git a/tutorials/lagrangian/reactingParcelFoam/verticalChannel/Allrun b/tutorials/lagrangian/reactingParcelFoam/verticalChannel/Allrun
index 35dc16c075d..a2fca0a8079 100755
--- a/tutorials/lagrangian/reactingParcelFoam/verticalChannel/Allrun
+++ b/tutorials/lagrangian/reactingParcelFoam/verticalChannel/Allrun
@@ -7,12 +7,12 @@ cd ${0%/*} || exit 1    # Run from this directory
 # create mesh
 runApplication blockMesh
 
-cp -r 0.org 0
+restore0Dir
 
 # initialise with potentialFoam solution
 runApplication potentialFoam
 
-rm -f 0/phi
+\rm -f 0/phi
 
 # run the solver
 runApplication `getApplication`
diff --git a/tutorials/lagrangian/reactingParcelFoam/verticalChannelLTS/Allrun b/tutorials/lagrangian/reactingParcelFoam/verticalChannelLTS/Allrun
index 35dc16c075d..a2fca0a8079 100755
--- a/tutorials/lagrangian/reactingParcelFoam/verticalChannelLTS/Allrun
+++ b/tutorials/lagrangian/reactingParcelFoam/verticalChannelLTS/Allrun
@@ -7,12 +7,12 @@ cd ${0%/*} || exit 1    # Run from this directory
 # create mesh
 runApplication blockMesh
 
-cp -r 0.org 0
+restore0Dir
 
 # initialise with potentialFoam solution
 runApplication potentialFoam
 
-rm -f 0/phi
+\rm -f 0/phi
 
 # run the solver
 runApplication `getApplication`
diff --git a/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/Allclean b/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/Allclean
index fa0d0929d96..dae58cf5bc5 100755
--- a/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/Allclean
+++ b/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/Allclean
@@ -5,10 +5,10 @@ cd ${0%/*} || exit 1    # Run from this directory
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 # remove old time and post-processing directories
-rm -rf 0 *[1-9]* processor* postProcessing
+\rm -rf 0 *[1-9]* processor* postProcessing
 
-# copy 0.org to 0
-cp -r 0.org 0
+# restore 0/ directory from 0.org/
+\cp -r 0.org 0
 
 cleanCase
 
diff --git a/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/Allrun b/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/Allrun
index 94c17f61f5b..a4698df1e26 100755
--- a/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/Allrun
+++ b/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/Allrun
@@ -4,15 +4,14 @@ cd ${0%/*} || exit 1    # Run from this directory
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
-rm -rf 0
-cp -rf 0.org 0
+restore0Dir
 
 runApplication blockMesh
 
 runApplication potentialFoam
 
 # remove incompatible (volumetric) flux field
-rm -f 0/phi
+\rm -f 0/phi 2>/dev/null
 
 runApplication $(getApplication)
 
diff --git a/tutorials/mesh/foamyHexMesh/mixerVessel/Allrun-simulation b/tutorials/mesh/foamyHexMesh/mixerVessel/Allrun-simulation
index 6d2f7197876..5041d32a558 100755
--- a/tutorials/mesh/foamyHexMesh/mixerVessel/Allrun-simulation
+++ b/tutorials/mesh/foamyHexMesh/mixerVessel/Allrun-simulation
@@ -18,7 +18,7 @@ runApplication mergeOrSplitBaffles -split -overwrite
 runApplication createPatch -overwrite
 
 # Copy fields after meshing to avoind the generation of unnecessary patch fields
-\cp -r 0.org 0
+restore0Dir
 
 # Initialize alpha
 runApplication setFields
diff --git a/tutorials/mesh/foamyQuadMesh/OpenCFD/Allrun-rhoCentralFoam b/tutorials/mesh/foamyQuadMesh/OpenCFD/Allrun-rhoCentralFoam
index 8ab7ec82512..266fee9c0b4 100755
--- a/tutorials/mesh/foamyQuadMesh/OpenCFD/Allrun-rhoCentralFoam
+++ b/tutorials/mesh/foamyQuadMesh/OpenCFD/Allrun-rhoCentralFoam
@@ -4,8 +4,8 @@ cd ${0%/*} || exit 1    # Run from this directory
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
-cp system/controlDict.rhoCentralFoam system/controlDict
-cp -r 0.org 0
+\cp system/controlDict.rhoCentralFoam system/controlDict
+restore0Dir
 
 runApplication decomposePar
 runParallel rhoCentralFoam
diff --git a/tutorials/mesh/parallel/filter/Allrun b/tutorials/mesh/parallel/filter/Allrun
index 9dabedb155f..e1c37c3dd1e 100755
--- a/tutorials/mesh/parallel/filter/Allrun
+++ b/tutorials/mesh/parallel/filter/Allrun
@@ -10,7 +10,7 @@ application=$(getApplication)
 runApplication blockMesh
 
 # Copy 0.org to 0
-cp -r 0.org 0
+restore0Dir
 
 # Create sets
 runApplication topoSet
diff --git a/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/Allrun b/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/Allrun
index deec9791eac..30113dd8334 100755
--- a/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/Allrun
+++ b/tutorials/multiphase/MPPICInterFoam/twoPhasePachuka/Allrun
@@ -13,7 +13,7 @@ m4 system/pachuka.m4 > system/blockMeshDict
 
 runApplication blockMesh
 
-cp 0/alpha.water.org 0/alpha.water
+\cp 0/alpha.water.org 0/alpha.water
 
 # create faceSet for burner inlet and faceZone for coupled wall
 runApplication topoSet
@@ -33,4 +33,4 @@ runParallel `getApplication`
 # Reconstruct case
 runApplication reconstructPar
 
-# ----------------------------------------------------------------- end-of-file
\ No newline at end of file
+# ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/multiphase/cavitatingFoam/les/throttle3D/Allrun b/tutorials/multiphase/cavitatingFoam/les/throttle3D/Allrun
index fb55f327c68..af67433fb29 100755
--- a/tutorials/multiphase/cavitatingFoam/les/throttle3D/Allrun
+++ b/tutorials/multiphase/cavitatingFoam/les/throttle3D/Allrun
@@ -25,7 +25,7 @@ refineMeshByCellSet()
    done
 }
 
-cp -r 0.org 0
+restore0Dir
 
 runApplication blockMesh
 refineMeshByCellSet 1 2 3
diff --git a/tutorials/multiphase/compressibleInterDyMFoam/ras/sloshingTank2D/Allrun b/tutorials/multiphase/compressibleInterDyMFoam/ras/sloshingTank2D/Allrun
index d527e2ed86f..188d7f9d74b 100755
--- a/tutorials/multiphase/compressibleInterDyMFoam/ras/sloshingTank2D/Allrun
+++ b/tutorials/multiphase/compressibleInterDyMFoam/ras/sloshingTank2D/Allrun
@@ -6,7 +6,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 
 m4 system/blockMeshDict.m4 > system/blockMeshDict
 runApplication blockMesh
-cp 0/alpha.water.org 0/alpha.water
+\cp 0/alpha.water.org 0/alpha.water
 runApplication setFields
 runApplication `getApplication`
 
diff --git a/tutorials/multiphase/compressibleInterFoam/laminar/depthCharge2D/Allrun b/tutorials/multiphase/compressibleInterFoam/laminar/depthCharge2D/Allrun
index 5040c29590b..fd07af1d46b 100755
--- a/tutorials/multiphase/compressibleInterFoam/laminar/depthCharge2D/Allrun
+++ b/tutorials/multiphase/compressibleInterFoam/laminar/depthCharge2D/Allrun
@@ -5,7 +5,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 runApplication blockMesh
-cp -r 0.org 0
+restore0Dir
 runApplication setFields
 runApplication $(getApplication)
 
diff --git a/tutorials/multiphase/compressibleInterFoam/laminar/depthCharge3D/Allrun b/tutorials/multiphase/compressibleInterFoam/laminar/depthCharge3D/Allrun
index 4e091494f62..6c6dafdea44 100755
--- a/tutorials/multiphase/compressibleInterFoam/laminar/depthCharge3D/Allrun
+++ b/tutorials/multiphase/compressibleInterFoam/laminar/depthCharge3D/Allrun
@@ -5,7 +5,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 runApplication blockMesh
-cp -r 0.org 0
+restore0Dir
 runApplication setFields
 runApplication decomposePar
 runParallel $(getApplication)
diff --git a/tutorials/multiphase/compressibleMultiphaseInterFoam/laminar/damBreak4phase/Allrun b/tutorials/multiphase/compressibleMultiphaseInterFoam/laminar/damBreak4phase/Allrun
index b275240a50d..c1e4f90ab10 100755
--- a/tutorials/multiphase/compressibleMultiphaseInterFoam/laminar/damBreak4phase/Allrun
+++ b/tutorials/multiphase/compressibleMultiphaseInterFoam/laminar/damBreak4phase/Allrun
@@ -7,8 +7,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 # Set application name
 application=`getApplication`
 
-\rm -rf 0
-cp -r 0.org 0
+restore0Dir
 
 runApplication blockMesh
 runApplication setFields
diff --git a/tutorials/multiphase/interDyMFoam/laminar/sloshingTank2D/Allrun b/tutorials/multiphase/interDyMFoam/laminar/sloshingTank2D/Allrun
index d527e2ed86f..188d7f9d74b 100755
--- a/tutorials/multiphase/interDyMFoam/laminar/sloshingTank2D/Allrun
+++ b/tutorials/multiphase/interDyMFoam/laminar/sloshingTank2D/Allrun
@@ -6,7 +6,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 
 m4 system/blockMeshDict.m4 > system/blockMeshDict
 runApplication blockMesh
-cp 0/alpha.water.org 0/alpha.water
+\cp 0/alpha.water.org 0/alpha.water
 runApplication setFields
 runApplication `getApplication`
 
diff --git a/tutorials/multiphase/interDyMFoam/laminar/sloshingTank2D3DoF/Allrun b/tutorials/multiphase/interDyMFoam/laminar/sloshingTank2D3DoF/Allrun
index d527e2ed86f..188d7f9d74b 100755
--- a/tutorials/multiphase/interDyMFoam/laminar/sloshingTank2D3DoF/Allrun
+++ b/tutorials/multiphase/interDyMFoam/laminar/sloshingTank2D3DoF/Allrun
@@ -6,7 +6,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 
 m4 system/blockMeshDict.m4 > system/blockMeshDict
 runApplication blockMesh
-cp 0/alpha.water.org 0/alpha.water
+\cp 0/alpha.water.org 0/alpha.water
 runApplication setFields
 runApplication `getApplication`
 
diff --git a/tutorials/multiphase/interDyMFoam/laminar/sloshingTank3D/Allrun b/tutorials/multiphase/interDyMFoam/laminar/sloshingTank3D/Allrun
index d527e2ed86f..188d7f9d74b 100755
--- a/tutorials/multiphase/interDyMFoam/laminar/sloshingTank3D/Allrun
+++ b/tutorials/multiphase/interDyMFoam/laminar/sloshingTank3D/Allrun
@@ -6,7 +6,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 
 m4 system/blockMeshDict.m4 > system/blockMeshDict
 runApplication blockMesh
-cp 0/alpha.water.org 0/alpha.water
+\cp 0/alpha.water.org 0/alpha.water
 runApplication setFields
 runApplication `getApplication`
 
diff --git a/tutorials/multiphase/interDyMFoam/laminar/sloshingTank3D3DoF/Allrun b/tutorials/multiphase/interDyMFoam/laminar/sloshingTank3D3DoF/Allrun
index d527e2ed86f..188d7f9d74b 100755
--- a/tutorials/multiphase/interDyMFoam/laminar/sloshingTank3D3DoF/Allrun
+++ b/tutorials/multiphase/interDyMFoam/laminar/sloshingTank3D3DoF/Allrun
@@ -6,7 +6,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 
 m4 system/blockMeshDict.m4 > system/blockMeshDict
 runApplication blockMesh
-cp 0/alpha.water.org 0/alpha.water
+\cp 0/alpha.water.org 0/alpha.water
 runApplication setFields
 runApplication `getApplication`
 
diff --git a/tutorials/multiphase/interDyMFoam/laminar/sloshingTank3D6DoF/Allrun b/tutorials/multiphase/interDyMFoam/laminar/sloshingTank3D6DoF/Allrun
index d527e2ed86f..188d7f9d74b 100755
--- a/tutorials/multiphase/interDyMFoam/laminar/sloshingTank3D6DoF/Allrun
+++ b/tutorials/multiphase/interDyMFoam/laminar/sloshingTank3D6DoF/Allrun
@@ -6,7 +6,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 
 m4 system/blockMeshDict.m4 > system/blockMeshDict
 runApplication blockMesh
-cp 0/alpha.water.org 0/alpha.water
+\cp 0/alpha.water.org 0/alpha.water
 runApplication setFields
 runApplication `getApplication`
 
diff --git a/tutorials/multiphase/interDyMFoam/laminar/testTubeMixer/Allrun b/tutorials/multiphase/interDyMFoam/laminar/testTubeMixer/Allrun
index f49fa8dbc48..44e088cf918 100755
--- a/tutorials/multiphase/interDyMFoam/laminar/testTubeMixer/Allrun
+++ b/tutorials/multiphase/interDyMFoam/laminar/testTubeMixer/Allrun
@@ -5,7 +5,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 runApplication blockMesh
-cp 0/alpha.water.org 0/alpha.water
+\cp 0/alpha.water.org 0/alpha.water
 runApplication setFields
 runApplication `getApplication`
 
diff --git a/tutorials/multiphase/interDyMFoam/ras/DTCHull/Allrun b/tutorials/multiphase/interDyMFoam/ras/DTCHull/Allrun
index 49e618ecd43..3eddb17d71b 100755
--- a/tutorials/multiphase/interDyMFoam/ras/DTCHull/Allrun
+++ b/tutorials/multiphase/interDyMFoam/ras/DTCHull/Allrun
@@ -5,10 +5,9 @@ cd ${0%/*} || exit 1    # Run from this directory
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # copy DTC hull surface from resources folder
-cp $FOAM_TUTORIALS/resources/geometry/DTC-scaled.stl.gz constant/triSurface/
+\cp $FOAM_TUTORIALS/resources/geometry/DTC-scaled.stl.gz constant/triSurface/
 
 runApplication surfaceFeatureExtract
-
 runApplication blockMesh
 
 for i in 1 2 3 4 5 6
@@ -21,18 +20,11 @@ do
 done
 
 runApplication snappyHexMesh -overwrite
-
-\rm -rf 0
-\cp -r 0.org 0
-
+restore0Dir
 runApplication setFields
-
 runApplication decomposePar
-
 runParallel renumberMesh -overwrite
-
 runParallel $(getApplication)
-
 runApplication reconstructPar
 
 #------------------------------------------------------------------------------
diff --git a/tutorials/multiphase/interDyMFoam/ras/damBreakWithObstacle/Allrun b/tutorials/multiphase/interDyMFoam/ras/damBreakWithObstacle/Allrun
index 0424df0e63d..e181b72ab57 100755
--- a/tutorials/multiphase/interDyMFoam/ras/damBreakWithObstacle/Allrun
+++ b/tutorials/multiphase/interDyMFoam/ras/damBreakWithObstacle/Allrun
@@ -4,7 +4,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
-cp -r 0.org 0 > /dev/null 2>&1
+restore0Dir
 runApplication blockMesh
 #runApplication setSet -batch createObstacle.setSet
 runApplication topoSet
diff --git a/tutorials/multiphase/interDyMFoam/ras/floatingObject/Allrun b/tutorials/multiphase/interDyMFoam/ras/floatingObject/Allrun
index 62915ff2cf5..64732439fc7 100755
--- a/tutorials/multiphase/interDyMFoam/ras/floatingObject/Allrun
+++ b/tutorials/multiphase/interDyMFoam/ras/floatingObject/Allrun
@@ -10,7 +10,7 @@ application=`getApplication`
 runApplication blockMesh
 runApplication topoSet
 runApplication subsetMesh -overwrite c0 -patch floatingObject
-cp -r 0.org 0 > /dev/null 2>&1
+restore0Dir
 runApplication setFields
 runApplication $application
 
diff --git a/tutorials/multiphase/interDyMFoam/ras/mixerVesselAMI/Allrun.pre b/tutorials/multiphase/interDyMFoam/ras/mixerVesselAMI/Allrun.pre
index a491c1ae2e7..6cc353f74f5 100755
--- a/tutorials/multiphase/interDyMFoam/ras/mixerVesselAMI/Allrun.pre
+++ b/tutorials/multiphase/interDyMFoam/ras/mixerVesselAMI/Allrun.pre
@@ -16,8 +16,8 @@ runApplication snappyHexMesh -overwrite
 runApplication createBaffles -overwrite
 runApplication mergeOrSplitBaffles -split -overwrite
 
-# Copy fields after meshing to avoind the generation of unnecessary patch fields
-\cp -r 0.org 0
+# Copy fields after meshing to avoid the generation of unnecessary patch fields
+restore0Dir
 
 # Initialize alpha
 runApplication setFields
diff --git a/tutorials/multiphase/interDyMFoam/ras/motorBike/Allrun.pre b/tutorials/multiphase/interDyMFoam/ras/motorBike/Allrun.pre
index 2a010de9b4a..5a68a5bd0c8 100755
--- a/tutorials/multiphase/interDyMFoam/ras/motorBike/Allrun.pre
+++ b/tutorials/multiphase/interDyMFoam/ras/motorBike/Allrun.pre
@@ -5,23 +5,27 @@ cd ${0%/*} || exit 1    # Run from this directory
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # copy motorbike surface from resources directory
-cp $FOAM_TUTORIALS/resources/geometry/motorBike.obj.gz constant/triSurface/
+\cp $FOAM_TUTORIALS/resources/geometry/motorBike.obj.gz constant/triSurface/
 
 runApplication surfaceFeatureExtract
 
 runApplication blockMesh
 
+# Serial
+# ------
 #runApplication snappyHexMesh -overwrite
 #\rm -f constant/polyMesh/refinementHistory*
 # - set the initial fields
-#cp -rf 0.org 0
+# restore0Dir
 #runApplication setFields
 
+# Parallel
+# --------
 runApplication decomposePar -force
 runParallel snappyHexMesh -overwrite
-ls -d processor* | xargs -I {} rm -f ./{}/constant/polyMesh/refinementHistory
+\ls -d processor* | xargs -I {} rm -f ./{}/constant/polyMesh/refinementHistory
 
 # - set the initial fields
-ls -d processor* | xargs -I {} rm -rf ./{}/0
-ls -d processor* | xargs -I {} cp -r 0.org ./{}/0
+\ls -d processor* | xargs -I {} \rm -rf ./{}/0
+\ls -d processor* | xargs -I {} \cp -r 0.org ./{}/0
 runParallel setFields
diff --git a/tutorials/multiphase/interFoam/laminar/capillaryRise/Allrun b/tutorials/multiphase/interFoam/laminar/capillaryRise/Allrun
index 9a17d2d5251..069d98ad5d5 100755
--- a/tutorials/multiphase/interFoam/laminar/capillaryRise/Allrun
+++ b/tutorials/multiphase/interFoam/laminar/capillaryRise/Allrun
@@ -7,7 +7,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 application=`getApplication`
 
 runApplication blockMesh
-cp 0/alpha.water.org 0/alpha.water
+\cp 0/alpha.water.org 0/alpha.water
 runApplication setFields
 runApplication $application
 
diff --git a/tutorials/multiphase/interFoam/laminar/damBreak/Allrun b/tutorials/multiphase/interFoam/laminar/damBreak/Allrun
index 125f1aa53b0..7bacb7fc1fa 100755
--- a/tutorials/multiphase/interFoam/laminar/damBreak/Allrun
+++ b/tutorials/multiphase/interFoam/laminar/damBreak/Allrun
@@ -34,7 +34,7 @@ cloneCase damBreak damBreakFine
 
     # Modify case
     setDamBreakFine
-    cp ../damBreak/0/alpha.water.org 0/alpha.water
+    \cp ../damBreak/0/alpha.water.org 0/alpha.water
     # And execute
     runApplication blockMesh
     runApplication setFields
diff --git a/tutorials/multiphase/interFoam/laminar/damBreak/damBreak/Allclean b/tutorials/multiphase/interFoam/laminar/damBreak/damBreak/Allclean
index 901c358b375..f1696e1017a 100755
--- a/tutorials/multiphase/interFoam/laminar/damBreak/damBreak/Allclean
+++ b/tutorials/multiphase/interFoam/laminar/damBreak/damBreak/Allclean
@@ -5,6 +5,6 @@ cd ${0%/*} || exit 1    # Run from this directory
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 cleanCase
-cp 0/alpha.water.org 0/alpha.water
+\cp 0/alpha.water.org 0/alpha.water
 
 #------------------------------------------------------------------------------
diff --git a/tutorials/multiphase/interFoam/laminar/mixerVessel2D/Allrun b/tutorials/multiphase/interFoam/laminar/mixerVessel2D/Allrun
index c0a3a7154e7..0017d885162 100755
--- a/tutorials/multiphase/interFoam/laminar/mixerVessel2D/Allrun
+++ b/tutorials/multiphase/interFoam/laminar/mixerVessel2D/Allrun
@@ -7,7 +7,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 application=`getApplication`
 
 runApplication ./makeMesh
-cp 0/alpha.water.org 0/alpha.water
+\cp 0/alpha.water.org 0/alpha.water
 runApplication setFields
 runApplication $application
 
diff --git a/tutorials/multiphase/interFoam/ras/DTCHull/Allrun b/tutorials/multiphase/interFoam/ras/DTCHull/Allrun
index 49e618ecd43..99249befa72 100755
--- a/tutorials/multiphase/interFoam/ras/DTCHull/Allrun
+++ b/tutorials/multiphase/interFoam/ras/DTCHull/Allrun
@@ -22,8 +22,7 @@ done
 
 runApplication snappyHexMesh -overwrite
 
-\rm -rf 0
-\cp -r 0.org 0
+restore0Dir
 
 runApplication setFields
 
diff --git a/tutorials/multiphase/interFoam/ras/damBreak/Allrun b/tutorials/multiphase/interFoam/ras/damBreak/Allrun
index 125f1aa53b0..7bacb7fc1fa 100755
--- a/tutorials/multiphase/interFoam/ras/damBreak/Allrun
+++ b/tutorials/multiphase/interFoam/ras/damBreak/Allrun
@@ -34,7 +34,7 @@ cloneCase damBreak damBreakFine
 
     # Modify case
     setDamBreakFine
-    cp ../damBreak/0/alpha.water.org 0/alpha.water
+    \cp ../damBreak/0/alpha.water.org 0/alpha.water
     # And execute
     runApplication blockMesh
     runApplication setFields
diff --git a/tutorials/multiphase/interFoam/ras/damBreak/damBreak/Allclean b/tutorials/multiphase/interFoam/ras/damBreak/damBreak/Allclean
index 901c358b375..f1696e1017a 100755
--- a/tutorials/multiphase/interFoam/ras/damBreak/damBreak/Allclean
+++ b/tutorials/multiphase/interFoam/ras/damBreak/damBreak/Allclean
@@ -5,6 +5,6 @@ cd ${0%/*} || exit 1    # Run from this directory
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 cleanCase
-cp 0/alpha.water.org 0/alpha.water
+\cp 0/alpha.water.org 0/alpha.water
 
 #------------------------------------------------------------------------------
diff --git a/tutorials/multiphase/interFoam/ras/damBreakPorousBaffle/Allclean b/tutorials/multiphase/interFoam/ras/damBreakPorousBaffle/Allclean
index 901c358b375..f1696e1017a 100755
--- a/tutorials/multiphase/interFoam/ras/damBreakPorousBaffle/Allclean
+++ b/tutorials/multiphase/interFoam/ras/damBreakPorousBaffle/Allclean
@@ -5,6 +5,6 @@ cd ${0%/*} || exit 1    # Run from this directory
 . $WM_PROJECT_DIR/bin/tools/CleanFunctions
 
 cleanCase
-cp 0/alpha.water.org 0/alpha.water
+\cp 0/alpha.water.org 0/alpha.water
 
 #------------------------------------------------------------------------------
diff --git a/tutorials/multiphase/interFoam/ras/weirOverflow/Allrun b/tutorials/multiphase/interFoam/ras/weirOverflow/Allrun
index 95936e3073e..1143e7ca735 100755
--- a/tutorials/multiphase/interFoam/ras/weirOverflow/Allrun
+++ b/tutorials/multiphase/interFoam/ras/weirOverflow/Allrun
@@ -3,11 +3,11 @@
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
-cp -r 0.org 0 > /dev/null 2>&1
+restore0Dir
 
 runApplication blockMesh
 
-cp 0/alpha.water.org 0/alpha.water
+\cp 0/alpha.water.org 0/alpha.water
 
 runApplication setFields
 
diff --git a/tutorials/multiphase/interPhaseChangeDyMFoam/propeller/Allrun.pre b/tutorials/multiphase/interPhaseChangeDyMFoam/propeller/Allrun.pre
index 40f5f5f1d4d..0fb9f454674 100755
--- a/tutorials/multiphase/interPhaseChangeDyMFoam/propeller/Allrun.pre
+++ b/tutorials/multiphase/interPhaseChangeDyMFoam/propeller/Allrun.pre
@@ -5,17 +5,14 @@ cd ${0%/*} || exit 1    # Run from this directory
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # copy propeller surface from resources directory
-cp $FOAM_TUTORIALS/resources/geometry/propellerTip.obj.gz constant/triSurface/
+\cp $FOAM_TUTORIALS/resources/geometry/propellerTip.obj.gz constant/triSurface/
 
 
 # - meshing
 
 runApplication blockMesh
-
 runApplication surfaceFeatureExtract
-
 runApplication snappyHexMesh -overwrite
-
 runApplication renumberMesh -overwrite
 
 # force removal of fields generated by snappy
@@ -27,7 +24,6 @@ runApplication renumberMesh -overwrite
 #runApplication setSet -batch createInletOutletSets.setSet
 runApplication topoSet -dict system/createInletOutletSets.topoSetDict
 
-
 # - create the inlet/outlet and AMI patches
 
 runApplication createPatch -overwrite
@@ -39,4 +35,4 @@ runApplication createPatch -overwrite
 
 # - apply the initial fields
 
-cp -rf 0.org 0
+restore0Dir
diff --git a/tutorials/multiphase/interPhaseChangeFoam/cavitatingBullet/Allrun b/tutorials/multiphase/interPhaseChangeFoam/cavitatingBullet/Allrun
index dc605176658..a47054a55e3 100755
--- a/tutorials/multiphase/interPhaseChangeFoam/cavitatingBullet/Allrun
+++ b/tutorials/multiphase/interPhaseChangeFoam/cavitatingBullet/Allrun
@@ -13,7 +13,7 @@ runApplication blockMesh
 # Generate the snappy mesh
 runApplication snappyHexMesh -overwrite
 
-cp -r 0.org 0
+restore0Dir
 
 # Initialise with potentialFoam solution
 runApplication potentialFoam -pName p_rgh
diff --git a/tutorials/multiphase/multiphaseEulerFoam/damBreak4phase/Allrun b/tutorials/multiphase/multiphaseEulerFoam/damBreak4phase/Allrun
index b275240a50d..c1e4f90ab10 100755
--- a/tutorials/multiphase/multiphaseEulerFoam/damBreak4phase/Allrun
+++ b/tutorials/multiphase/multiphaseEulerFoam/damBreak4phase/Allrun
@@ -7,8 +7,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 # Set application name
 application=`getApplication`
 
-\rm -rf 0
-cp -r 0.org 0
+restore0Dir
 
 runApplication blockMesh
 runApplication setFields
diff --git a/tutorials/multiphase/multiphaseEulerFoam/damBreak4phaseFine/Allrun b/tutorials/multiphase/multiphaseEulerFoam/damBreak4phaseFine/Allrun
index 6103dad6287..6557a49b3a6 100755
--- a/tutorials/multiphase/multiphaseEulerFoam/damBreak4phaseFine/Allrun
+++ b/tutorials/multiphase/multiphaseEulerFoam/damBreak4phaseFine/Allrun
@@ -7,8 +7,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 # Set application name
 application=`getApplication`
 
-\rm -rf 0
-cp -r 0.org 0
+restore0Dir
 
 runApplication blockMesh
 runApplication setFields
diff --git a/tutorials/multiphase/multiphaseInterDyMFoam/laminar/mixerVesselAMI2D/Allrun b/tutorials/multiphase/multiphaseInterDyMFoam/laminar/mixerVesselAMI2D/Allrun
index d7ecd3dbdce..e83b55a0354 100755
--- a/tutorials/multiphase/multiphaseInterDyMFoam/laminar/mixerVesselAMI2D/Allrun
+++ b/tutorials/multiphase/multiphaseInterDyMFoam/laminar/mixerVesselAMI2D/Allrun
@@ -8,8 +8,7 @@ application=`getApplication`
 
 ./makeMesh
 
-rm -rf 0
-cp -r 0.org 0
+restore0Dir
 runApplication setFields
 
 #runApplication $application
diff --git a/tutorials/multiphase/multiphaseInterFoam/laminar/damBreak4phase/Allrun b/tutorials/multiphase/multiphaseInterFoam/laminar/damBreak4phase/Allrun
index b275240a50d..c1e4f90ab10 100755
--- a/tutorials/multiphase/multiphaseInterFoam/laminar/damBreak4phase/Allrun
+++ b/tutorials/multiphase/multiphaseInterFoam/laminar/damBreak4phase/Allrun
@@ -7,8 +7,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 # Set application name
 application=`getApplication`
 
-\rm -rf 0
-cp -r 0.org 0
+restore0Dir
 
 runApplication blockMesh
 runApplication setFields
diff --git a/tutorials/multiphase/multiphaseInterFoam/laminar/damBreak4phaseFine/Allrun b/tutorials/multiphase/multiphaseInterFoam/laminar/damBreak4phaseFine/Allrun
index b92d6cc19a8..6557a49b3a6 100755
--- a/tutorials/multiphase/multiphaseInterFoam/laminar/damBreak4phaseFine/Allrun
+++ b/tutorials/multiphase/multiphaseInterFoam/laminar/damBreak4phaseFine/Allrun
@@ -7,7 +7,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 # Set application name
 application=`getApplication`
 
-cp -r 0.org 0
+restore0Dir
 
 runApplication blockMesh
 runApplication setFields
diff --git a/tutorials/multiphase/potentialFreeSurfaceDyMFoam/oscillatingBox/Allrun b/tutorials/multiphase/potentialFreeSurfaceDyMFoam/oscillatingBox/Allrun
index 4358c300592..558156dcd8c 100755
--- a/tutorials/multiphase/potentialFreeSurfaceDyMFoam/oscillatingBox/Allrun
+++ b/tutorials/multiphase/potentialFreeSurfaceDyMFoam/oscillatingBox/Allrun
@@ -18,7 +18,7 @@ runApplication -s selectBottom \
 
 runApplication createPatch -overwrite
 
-cp -r 0.org 0 > /dev/null 2>&1
+restore0Dir
 
 runApplication $application
 
diff --git a/tutorials/multiphase/potentialFreeSurfaceFoam/oscillatingBox/Allrun b/tutorials/multiphase/potentialFreeSurfaceFoam/oscillatingBox/Allrun
index 6514e8598bb..eb74ad45a9f 100755
--- a/tutorials/multiphase/potentialFreeSurfaceFoam/oscillatingBox/Allrun
+++ b/tutorials/multiphase/potentialFreeSurfaceFoam/oscillatingBox/Allrun
@@ -10,7 +10,8 @@ application=`getApplication`
 runApplication blockMesh
 runApplication topoSet
 runApplication subsetMesh -overwrite c0 -patch floatingObject
-cp -r 0.org 0 > /dev/null 2>&1
+
+restore0Dir
 
 runApplication $application
 
diff --git a/tutorials/multiphase/twoLiquidMixingFoam/lockExchange/Allrun b/tutorials/multiphase/twoLiquidMixingFoam/lockExchange/Allrun
index b275240a50d..c1e4f90ab10 100755
--- a/tutorials/multiphase/twoLiquidMixingFoam/lockExchange/Allrun
+++ b/tutorials/multiphase/twoLiquidMixingFoam/lockExchange/Allrun
@@ -7,8 +7,7 @@ cd ${0%/*} || exit 1    # Run from this directory
 # Set application name
 application=`getApplication`
 
-\rm -rf 0
-cp -r 0.org 0
+restore0Dir
 
 runApplication blockMesh
 runApplication setFields
-- 
GitLab