View Issue Details

IDProjectCategoryView StatusLast Update
0001919OpenFOAM[All Projects] Bugpublic2015-11-20 09:31
ReporterTimm SeverinAssigned Tohenry 
PrioritylowSeverityfeatureReproducibilityalways
Status resolvedResolutionfixed 
PlatformGNU/LinuxOSUbuntuOS Version15.04
Product Version 
Fixed in Version 
Summary0001919: runApplication/runParallel allow to append or overwrite log
DescriptionIt would be nice if runApplication or runParallel could overwrite or append existing logs, which can be useful in cases where one continues the case (increase endTime in controlDict and startFrom latestTime).

This is similar to http://www.openfoam.org/mantisbt/view.php?id=1655, however I don't see foamJob used anywhere, at least not in the tutorials.
Additional InformationAttached a patch generated in 2.3.x for the RunFunctions file in $WM_PROJECT_DIR/bin/tools/.

Now it allows for example:
runApplication --append icoFoam
runParallel --append icoFoam 4
runApplication --overwrite icoFoam

Parameters which are added AFTER the executable will be passed on to it as before, e.g.
runApplication --overwrite blockMesh -dict system/myFancyBlockMeshDict
will call
blockMesh -dict system/myFancyBlockMeshDict > log.blockMesh

Note that I have tested the changes, but have not checked for compatibility with all terminals emulators.
TagsNo tags attached.

Activities

Timm Severin

2015-11-19 14:44

reporter  

RunFunctions.patch (3,159 bytes)
--- RunFunctions	2015-11-19 15:22:27.373679007 +0100
+++ RunFunctions.new	2015-11-19 15:21:25.177370592 +0100
@@ -40,31 +40,80 @@
 
 runApplication()
 {
-    APP_RUN=$1
-    APP_NAME=${1##*/}
+    ## parse options and executable
+    # set default variables
+    APP_RUN=
+    LOG_IGNORE=false
+    LOG_APPEND=false
+    # loop over all parameters until an executable has been passed,
+    #   all remaining parameters will be interpreted as arguments
+    #   for the executable
+    while [ $# -gt 0 ] && [ -z "$APP_RUN" ]; do
+        key="$1"
+        case "$key" in
+            --append)
+                LOG_IGNORE=true
+                LOG_APPEND=true
+                ;;
+            --overwrite)
+                LOG_IGNORE=true
+                ;;
+            *)
+                APP_RUN="$key"
+                APP_NAME="${key##*/}"
+                ;;
+        esac
     shift
+    done
 
-    if [ -f log.$APP_NAME ]
+    if [ -f log.$APP_NAME ] && [ "$LOG_IGNORE" = "false" ]
     then
         echo "$APP_NAME already run on $PWD: remove log file to re-run"
     else
         echo "Running $APP_RUN on $PWD"
-        $APP_RUN "$@" > log.$APP_NAME 2>&1
+        if [ "$LOG_APPEND" = "true" ]; then
+            $APP_RUN "$@" >> log.$APP_NAME 2>&1
+        else
+            $APP_RUN "$@" > log.$APP_NAME 2>&1
+        fi
     fi
 }
 
 runParallel()
 {
-    APP_RUN=$1
-    APP_NAME=${1##*/}
+    ## parse options and executable
+    # set default variables
+    APP_RUN=
+    LOG_IGNORE=false
+    LOG_APPEND=false
+    # loop over all parameters until an executable has been passed,
+    #   all remaining parameters will be interpreted as arguments
+    #   for the executable
+    while [ $# -gt 0 ] && [ -z "$APP_RUN" ]; do
+        key="$1"
+        case "$key" in
+            --append)
+                LOG_IGNORE=true
+                LOG_APPEND=true
+                ;;
+            --overwrite)
+                LOG_IGNORE=true
+                ;;
+            *)
+                APP_RUN="$key"
+                APP_NAME="${key##*/}"
+                # also read number of processors
+                nProcs="$2"
+                shift
+                ;;
+        esac
     shift
+    done
 
-    if [ -f log.$APP_NAME ]
+    if [ -f log.$APP_NAME ] && [ "$LOG_IGNORE" = "false" ]
     then
         echo "$APP_NAME already run on $PWD: remove log file to re-run"
     else
-        nProcs=$1
-        shift
         echo "Running $APP_RUN in parallel on $PWD using $nProcs processes"
 
         #if [ "$WM_SCHEDULER" ]
@@ -72,7 +121,11 @@
         #    echo "$PWD: $WM_SCHEDULER -np $nProcs" 1>&2
         #    $WM_SCHEDULER -np $nProcs "( mpirun -np $nProcs $APP_RUN -parallel "$@" < /dev/null > log.$APP_NAME 2>&1 )"
         #else
-            ( mpirun -np $nProcs $APP_RUN -parallel "$@" < /dev/null > log.$APP_NAME 2>&1 )
+            if [ "$LOG_APPEND" = "true" ]; then
+                ( mpirun -np $nProcs $APP_RUN -parallel "$@" < /dev/null >> log.$APP_NAME 2>&1 )
+            else
+                ( mpirun -np $nProcs $APP_RUN -parallel "$@" < /dev/null > log.$APP_NAME 2>&1 )
+            fi
         #fi
     fi
 }
RunFunctions.patch (3,159 bytes)

henry

2015-11-19 15:29

manager   ~0005631

foamJob is not used in other OpenFOAM scripts it is an end-user script.

I am OK with the changes your propose but I will change the options to -append and -overwrite to be consistent with the rest of OpenFOAM.

henry

2015-11-19 15:50

manager   ~0005632

Resolved in OpenFOAM-dev by commit 36fe080bc73e2e983d14728cb65d88d05c9a8331

Issue History

Date Modified Username Field Change
2015-11-19 14:44 Timm Severin New Issue
2015-11-19 14:44 Timm Severin File Added: RunFunctions.patch
2015-11-19 15:29 henry Note Added: 0005631
2015-11-19 15:50 henry Note Added: 0005632
2015-11-19 15:50 henry Status new => resolved
2015-11-19 15:50 henry Resolution open => fixed
2015-11-19 15:50 henry Assigned To => henry