View Issue Details

IDProjectCategoryView StatusLast Update
0000961OpenFOAMBugpublic2013-11-27 14:24
Reporterrperry Assigned Touser4 
PriorityhighSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformSuse 10 
Summary0000961: transformPoints does not accept options when run with foamjob
DescriptionTake any decomposed mesh from snappy, and runing transform points using mpirun will transform them acceptably, and it will accept transformPoints options like

-scale '(0.001 0.001 0.001)'

However, using foamjob to execute the same option will raise the error "invalid number of inputs, expected 0 received 2"

It appears that with foamJob, no inputs are accepted, even though transformPoints requires at minimum one input in order to do anything. At first I thought it was just having issues accepting the vector input shown above, but indeed it does not accept any inputs.
TagsNo tags attached.

Activities

wyldckat

2013-08-14 21:21

updater   ~0002413

Last edited: 2013-08-14 21:22

This is related to the bug report #668: http://www.openfoam.org/mantisbt/view.php?id=668

Attached is a patch that fixes this. In essence, it's a matter of wrapping $@ in quotes, namely: "$@"

The only problem is that I could not find a way to echo properly the command that should be used, so it will appear to still be broken, but it will work as intended. Example:


$ foamJob transformPoints -translate '(1 0 0)'
Application : transformPoints
Executing: /home/user/OpenFOAM/OpenFOAM-2.2.x/platforms/linux64GccDPOpt/bin/transformPoints -translate (1 0 0) > log 2>&1 &

wyldckat

2013-08-14 21:21

updater  

foamJob.patch (994 bytes)   
diff --git a/bin/foamJob b/bin/foamJob
index 4eda404..87c4392 100755
--- a/bin/foamJob
+++ b/bin/foamJob
@@ -218,10 +218,10 @@ then
     if [ "$screenOpt" = true ]
     then
         echo "Executing: $mpirun $mpiopts $APPLICATION $@ -parallel | tee log"
-        $mpirun $mpiopts $APPLICATION $@ -parallel | tee log
+        $mpirun $mpiopts $APPLICATION "$@" -parallel | tee log
     else
         echo "Executing: $mpirun $mpiopts $APPLICATION $@ -parallel > log 2>&1"
-        $mpirun $mpiopts $APPLICATION $@ -parallel > log 2>&1 &
+        $mpirun $mpiopts $APPLICATION "$@" -parallel > log 2>&1 &
     fi
 
 else
@@ -231,11 +231,11 @@ else
     if [ "$screenOpt" = true ]
     then
         echo "Executing: $APPLICATION $@ | tee log &"
-        $APPLICATION $@ | tee log &
+        $APPLICATION "$@" | tee log &
         wait $!
     else
         echo "Executing: $APPLICATION $@ > log 2>&1 &"
-        $APPLICATION $@ > log 2>&1 &
+        $APPLICATION "$@" > log 2>&1 &
     fi
 fi
 
foamJob.patch (994 bytes)   

user258

2013-08-21 11:50

  ~0002433

What do you mean by "The only problem is that I could not find a way to echo properly the command that should be used". It is printing the application only, which the intended output. In other words, what is wrong with your example?

wyldckat

2013-08-21 14:05

updater   ~0002434

Ah, I see that your eyes are not yet fully trained in the ways of the shell ;)

If you try to run the command that foamJob tells us it's using, namely this:

  transformPoints -translate (1 0 0) > log 2>&1 &

the shell (sh or bash) will complain about the sub-shell that is started with the parenthesis, namely: (1 0 0)
where the complain is likely be because "1" is not a valid command.

Which is why we have to use the single quotes:

  transformPoints -translate '(1 0 0)' > log 2>&1 &

But since foamJob is using the "echo" command to show us what it's going to run, the single quotes are "taken out of the picture".

user258

2013-08-21 15:25

  ~0002435

Ha, if you make that mistake often you might spot it more easily indeed. Anyhow, challenge accepted, and this ugly code snippet might work :):

        echo -n "Executing: $APPLICATION"
        for v in "$@"; do
         if [[ "${v##* }" == "$v" ]]; then
          echo -n " $v"
         else
          echo -n " '$v'"
         fi
        done;
        echo " > log 2>&1 &"

wyldckat

2013-08-25 18:40

updater  

foamJob.v2.patch (1,860 bytes)   
diff --git a/bin/foamJob b/bin/foamJob
index 4eda404..24f7d48 100755
--- a/bin/foamJob
+++ b/bin/foamJob
@@ -50,6 +50,28 @@ USAGE
     exit 1
 }
 
+#for being able to echo strings that have single quotes
+echoArgs() {
+    addSpace=""
+
+    for stringItem in "$@"; do
+
+        echo -n "${addSpace}"
+
+        if [ "${stringItem##* }" = "$stringItem" ]
+        then
+            echo -n "$stringItem"
+            addSpace=" "
+        else
+            echo -n "'$stringItem'"
+            addSpace=" "
+        fi
+
+    done
+
+    unset stringItem addSpace
+}
+
 unset version
 
 # replacement for possibly buggy 'which'
@@ -217,11 +239,11 @@ then
     #
     if [ "$screenOpt" = true ]
     then
-        echo "Executing: $mpirun $mpiopts $APPLICATION $@ -parallel | tee log"
-        $mpirun $mpiopts $APPLICATION $@ -parallel | tee log
+        echo "Executing: $mpirun $mpiopts $APPLICATION $(echoArgs "$@") -parallel | tee log"
+        $mpirun $mpiopts $APPLICATION "$@" -parallel | tee log
     else
-        echo "Executing: $mpirun $mpiopts $APPLICATION $@ -parallel > log 2>&1"
-        $mpirun $mpiopts $APPLICATION $@ -parallel > log 2>&1 &
+        echo "Executing: $mpirun $mpiopts $APPLICATION $(echoArgs "$@") -parallel > log 2>&1"
+        $mpirun $mpiopts $APPLICATION "$@" -parallel > log 2>&1 &
     fi
 
 else
@@ -230,12 +252,12 @@ else
     #
     if [ "$screenOpt" = true ]
     then
-        echo "Executing: $APPLICATION $@ | tee log &"
-        $APPLICATION $@ | tee log &
+        echo "Executing: $APPLICATION $(echoArgs "$@") | tee log &"
+        $APPLICATION "$@" | tee log &
         wait $!
     else
-        echo "Executing: $APPLICATION $@ > log 2>&1 &"
-        $APPLICATION $@ > log 2>&1 &
+        echo "Executing: $APPLICATION $(echoArgs "$@") > log 2>&1 &"
+        $APPLICATION "$@" > log 2>&1 &
     fi
 fi
 
foamJob.v2.patch (1,860 bytes)   

wyldckat

2013-08-25 18:44

updater   ~0002438

@bernhardr: Nice hack!

The attached patch file "foamJob.v2.patch" includes bernhardr's adapted code snippet.
The adaptation uses "sh" if-statements instead of "bash" if-statements and uses a function named "echoArgs" for using echo in a dedicated manner for the "$@".

The modified code was tested on Ubuntu 12.04, using for "sh" the "dash" shell.

rperry

2013-11-27 10:04

reporter   ~0002661

I have found the same issue exists with the orientFaceZone utility - you cannot give orientFaceZone the coordinate point input it requires using foamJob.

Is there any way both of these issues can be resolved in the core openFOAM repository?

wyldckat

2013-11-27 10:20

updater   ~0002662

@rperry: Have you tested whether any of the provided patches in attachment work for you?

rperry

2013-11-27 10:48

reporter   ~0002663

Hi wyldckat, your first patch worked for all the utilities I was having problems with. I just realized the reason I had this problem again today was that I was on a system that had recently had OpenFOAM installed, and thus didn't have the patch applied :-P

Will this fix be included at some point in the standard release of OpenFOAM?

user4

2013-11-27 14:24

  ~0002664

c7b2d61927b00fc26a6e0f53e41b7ea48a184c04

Thanks for fix.

Issue History

Date Modified Username Field Change
2013-08-14 12:25 rperry New Issue
2013-08-14 21:21 wyldckat Note Added: 0002413
2013-08-14 21:21 wyldckat File Added: foamJob.patch
2013-08-14 21:22 wyldckat Note Edited: 0002413
2013-08-21 11:50 user258 Note Added: 0002433
2013-08-21 14:05 wyldckat Note Added: 0002434
2013-08-21 15:25 user258 Note Added: 0002435
2013-08-25 18:40 wyldckat File Added: foamJob.v2.patch
2013-08-25 18:44 wyldckat Note Added: 0002438
2013-11-27 10:04 rperry Note Added: 0002661
2013-11-27 10:20 wyldckat Note Added: 0002662
2013-11-27 10:48 rperry Note Added: 0002663
2013-11-27 14:24 user4 Note Added: 0002664
2013-11-27 14:24 user4 Status new => resolved
2013-11-27 14:24 user4 Fixed in Version => 2.2.x
2013-11-27 14:24 user4 Resolution open => fixed
2013-11-27 14:24 user4 Assigned To => user4