CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

Batch scripts

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 30, 2019, 19:36
Default
  #21
Senior Member
 
Brett
Join Date: May 2013
Posts: 212
Rep Power: 13
Bdew8556 is on a distinguished road
yep. The script is called "batch.sh" still. this is the command line:

AUBD501827@L19AU-32823 /cygdrive/c/OpenFOAM/18.10/AUBD501827-dev/run
$ chmod +x batch.sh

AUBD501827@L19AU-32823 /cygdrive/c/OpenFOAM/18.10/AUBD501827-dev/run
$ ./batch.sh
./batch.sh: line 4: syntax error near unexpected token `$'\r''
'/batch.sh: line 4: `

AUBD501827@L19AU-32823 /cygdrive/c/OpenFOAM/18.10/AUBD501827-dev/run
$


line 4 of the script is just blank.
Bdew8556 is offline   Reply With Quote

Old   April 30, 2019, 19:43
Default
  #22
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
Short of suggesting that that you do exactly what I suggested, I am not sure what more to add. It works fine for me. Someone else may have a better idea of what is causing the output you see. A final thought -- did you include the

Code:
#!/bin/bash
as the first line? There are various "Allrun" scripts included in the tutorials that may help you troubleshoot.

Caelan
clapointe is offline   Reply With Quote

Old   April 30, 2019, 19:51
Default
  #23
Senior Member
 
Brett
Join Date: May 2013
Posts: 212
Rep Power: 13
Bdew8556 is on a distinguished road
Yep I've got that in.
It seems to just "stall" at the line "do". almost as if it's looking for something extra?
Bdew8556 is offline   Reply With Quote

Old   April 30, 2019, 19:57
Default
  #24
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
Thought about the error and the path does not look familiar. How did you install openfoam?

Caelan
clapointe is offline   Reply With Quote

Old   April 30, 2019, 20:07
Default
  #25
Senior Member
 
Brett
Join Date: May 2013
Posts: 212
Rep Power: 13
Bdew8556 is on a distinguished road
just installed it on my machine? wasnt aware there were different ways to install it??
Bdew8556 is offline   Reply With Quote

Old   April 30, 2019, 20:10
Default
  #26
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
Right. What type of machine is it?

Caelan
clapointe is offline   Reply With Quote

Old   April 30, 2019, 20:14
Default
  #27
Senior Member
 
Brett
Join Date: May 2013
Posts: 212
Rep Power: 13
Bdew8556 is on a distinguished road
desktop PC. Running windows.
Bdew8556 is offline   Reply With Quote

Old   April 30, 2019, 20:20
Default
  #28
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
Well there you have it -- the script is for linux. You will need help from someone familiar with using OF for windows. Or, I bet that you could do some debugging yourself and google for windows-specific answers.

Caelan
clapointe is offline   Reply With Quote

Old   April 30, 2019, 20:43
Default
  #29
Senior Member
 
Brett
Join Date: May 2013
Posts: 212
Rep Power: 13
Bdew8556 is on a distinguished road
ok. I've done some digging and I can't even seem to get a basic script running. I thought I'd made the changes for windows, for example....

#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
for value in {10..0..2}
do
echo $value
done
echo All done

wont even run.
Bdew8556 is offline   Reply With Quote

Old   April 30, 2019, 20:55
Default Trying to run a bash (or is it batch?) script in openfoam installed on a windows PC
  #30
Senior Member
 
Brett
Join Date: May 2013
Posts: 212
Rep Power: 13
Bdew8556 is on a distinguished road
Hi foamers.

I'm trying to run a bash (or is it batch?) script in openfoam installed on a windows PC.
Basically it's running different mass flow rates.
I had some great help from someone but he assumed I was using linux.
So the question is how do I modify it to run on windows?

Code:
#!/bin/bash

for value in {10..5..20}
do
    #print case $value
    echo "Starting simulation $value"

    #copy a base case to the current case $value
    cp -rf att_test att_test_$value

    #set line number for sed to use
    lineNo1=32

    #replace lineNo1 (line 49) in 0/U with value uniform (0 $value 0)
    sed -i "${lineNo1}s/.*/volumetricFlowRate      $value;/" att_test_$value/0/U

    #enter current case directory
    cd att_test_$value

    #run solver of choice (e.g. buoyantPimpleFoam)
    simpleFoam > log.simpleFOAM 2>&1 &

    #find line starting with "Patch Pressure :" in solver log file and save value of 4th set of characters (pretty sure)
    press=`grep -r "Patch Pressure : " log.simpleFoam | awk '{print $4}'`

    #pipe saved value to data log file
    echo press >> log.dat

    cd ..

done

echo All done

Last edited by wyldckat; May 5, 2019 at 14:52. Reason: Added [CODE][/CODE] markers
Bdew8556 is offline   Reply With Quote

Old   May 5, 2019, 14:53
Default
  #31
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quick questions:
  1. Which version and/or variant of OpenFOAM did you install?
  2. Which installation instructions did you follow?
__________________
wyldckat is offline   Reply With Quote

Old   May 5, 2019, 19:16
Default
  #32
Senior Member
 
Brett
Join Date: May 2013
Posts: 212
Rep Power: 13
Bdew8556 is on a distinguished road
OpenFoam for windows 18.1

No idea what instructions?
Bdew8556 is offline   Reply With Quote

Old   May 6, 2019, 19:07
Default
  #33
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quick note: I moved the last 3 posts from a separate thread to this common thread.

Quick answers:
Quote:
Originally Posted by Bdew8556 View Post
I'm trying to run a bash (or is it batch?) script in openfoam installed on a windows PC.
The script you provided can be considered a "bash script" or "shell script". It can also be referred to as a batch script, in case you are using it to run a batch of commands.

That said, within the Windows Operating System context, a "batch file" usually refers to a file with the file extension ".bat", which uses a different scripting language from what Bash and Shell scripting usually mean on Linux/POSIX systems.


Quote:
Originally Posted by Bdew8556 View Post
OpenFoam for windows 18.1
Uh... looking for it online did not give any valid results, mostly because "18.1" is an unknown version.

Quote:
Originally Posted by Bdew8556 View Post
No idea what instructions?
I was referring to the instructions you had followed to install OpenFOAM in your machine...


OK, so after looking for your previous posts, I finally managed to make heads and tails out of this... Technically, you can run that script that you provided on your Cygwin installation, but you have to correct the line ending of the file. There is massive Wikipedia article on this topic, where you might notice the "\r" being listed here: https://en.wikipedia.org/wiki/Newline#Escape_sequences

So, what you need to do to fix the problem with running the bash/shell scripts on Cygwin is to correct the line ending, which you can do by either:
  1. Using a text editor that can change the line ending to LF, namely Linux/POSIX mode. For example:
    1. Notepad++ for Windows supports this.
    2. Or use a text editor inside Cygwin, for example, gedit.
  2. Or use a command that converts the file from Windows to Linux/POSIX/Unix format. For example, you can run the following command to convert the file name "example.sh" to said Unix format:
    Code:
    dos2unix example.sh
wyldckat is offline   Reply With Quote

Old   May 8, 2019, 01:07
Default
  #34
Senior Member
 
Brett
Join Date: May 2013
Posts: 212
Rep Power: 13
Bdew8556 is on a distinguished road
Wow this is all so far over my head.

What does the /r do?

I'm writing this in sublime text, saving it and then trying to run it on the OpenFoam command window with "test_script.sh"

I can't even get that to work!

#!/bin/bash
for /l %%a in (1;1;3) do (

echo "Starting simulation $%%x"

)
Bdew8556 is offline   Reply With Quote

Old   May 11, 2019, 08:51
Default
  #35
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
But that script is now in the Windows Batch script format, not in the Bash shell script format...

And if it's in the Windows Batch script format, you no longer need to worry about the line ending and can use the default text editing options on Windows.

Oh, and you do not need the first line:
Code:
#!/bin/bash
As for documentation on how to write Windows Batch scripts, this guide looks like it provides a ton of information on what you are looking for: http://steve-jansen.github.io/guides...g-started.html
wyldckat is offline   Reply With Quote

Old   September 21, 2020, 03:27
Default
  #36
Senior Member
 
Franco
Join Date: Nov 2019
Location: Compiègne, France
Posts: 129
Rep Power: 6
otaolafr is on a distinguished road
Quote:
Originally Posted by Bdew8556 View Post
Hi foamers.

I'm trying to run a bash (or is it batch?) script in openfoam installed on a windows PC.
Basically it's running different mass flow rates.
I had some great help from someone but he assumed I was using linux.
So the question is how do I modify it to run on windows?

Code:
#!/bin/bash

for value in {10..5..20}
do
    #print case $value
    echo "Starting simulation $value"

    #copy a base case to the current case $value
    cp -rf att_test att_test_$value

    #set line number for sed to use
    lineNo1=32

    #replace lineNo1 (line 49) in 0/U with value uniform (0 $value 0)
    sed -i "${lineNo1}s/.*/volumetricFlowRate      $value;/" att_test_$value/0/U

    #enter current case directory
    cd att_test_$value

    #run solver of choice (e.g. buoyantPimpleFoam)
    simpleFoam > log.simpleFOAM 2>&1 &

    #find line starting with "Patch Pressure :" in solver log file and save value of 4th set of characters (pretty sure)
    press=`grep -r "Patch Pressure : " log.simpleFoam | awk '{print $4}'`

    #pipe saved value to data log file
    echo press >> log.dat

    cd ..

done

echo All done
hello,
i am windows user too.
can i asume that you are using WSL no? with a ubuntu subsystem?
if that the case what you are trying to do it is easy to accomplish.
first you have your casefile folder with constant, system... etc.
you rename the folder baseCase.
normally i would say to create an allRun file (inside the baseCase folder) for this you create a text file without extension and edit it in a text editor (recomend notePad ++)
inside you copy depending on the vr of your OF (you can look in a tutorial E.G.tutorials\incompressible\pimpleFoam\RAS\elipse kkLOmega the first two lines of the allRun file.
after the two lines you add the commands of the bash that you are going to use like blockMesh sanppyHex etc etc...
after in the WLS you go to the folder baseCase and then from there you do “chmod 755 ./AllRun”
this will make it able to be excecuted.
so to recapitulate until here you have created your base case, and you can run it from your WSL command line by going inside of the baseCase folder and doing ./AllRun
the modification of the U file.
you go up a folder and create a file "run.sh" file by creating a text file.
then you can base yourself in the example that they gave you in the third commend or you can use the run.sh file from the benchmark from here https://openfoamwiki.net/index.php/Benchmarks
and modify it to change the velocity in the 0/U file (it is with the sed command)
after this in the WLS you go to that folder (if you are inside baseCase folder "cd ..")
and then another time “chmod 755 ./run.sh”
and then you have converted run.sh in executable that it copies the baseCase folder, renames it changes the U vector file inside the new copied folder and then run the AllRun script running your case. and then creating a new copie puting the second U vector and doing the same. this should work correctly.
I recommend to be attentive of the space of your disk as each time it would create a copy, so for example if you are running an steady state simulation write only the endTime. for function object I recommend you to create another topic as it is better to be easy to read that the topic stays in on subject (at least one at a time...)

speaking about the subject of using the sed function, if i may, @clapointe have you already used arrays in bash for this type of template? (and calling an element of the array in the sed function). I was looking in to it as i wanted to do the same modification but with different list of values, like doing a for loop with 0 1 2 values and then call each element array inside the loop. I have not tried and want it to have any feed back about this and see if it is possible.... (as i can not try it myself right now....)

best regards, franco
otaolafr is offline   Reply With Quote

Reply

Tags
batch job, programming


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Batch file in combination with the workbench D0nT0m CFX 3 February 6, 2017 05:28
Fluent batch command for unsteady taekyu8 FLUENT 0 January 7, 2013 15:18
Regarding about Fluent batch scripts solefire FLUENT 3 July 5, 2009 09:39
regarding about Fluent batch scripts solefire FLUENT 3 July 5, 2009 04:05
Running Job in Batch mode (EFD) Nick Sessions FloEFD, FloWorks & FloTHERM 0 April 16, 2008 16:44


All times are GMT -4. The time now is 23:36.