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

Running subfolder applications in Allrun

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 7, 2021, 14:59
Default Running subfolder applications in Allrun
  #1
New Member
 
Santi Parera
Join Date: Jul 2019
Location: BARCELONA
Posts: 26
Rep Power: 7
Kalabagh is on a distinguished road
Hey there,


I'm trying to make automatic my simulation by using the Allrun script. My simulation is so simmilar to the tutorial "propeller" so I'm changing just few things.


The fact is that my geometry has to be scaled because the 3D software outputs milimeters as meters... "surfaceConvert" is the command and has to be executed from case/constant/triSurface subfolder.


So my question is how we explain to Allrun from where it has to execute the commands as the rest of the commands have to be executed from the main case directory.



Thanks.
Kalabagh is offline   Reply With Quote

Old   March 7, 2021, 16:57
Default
  #2
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 736
Rep Power: 14
Tobermory will become famous soon enough
The Allrun script is just a shell script, and you can navigate around the directories just like you would from the command line. When you run the Allrun (shell) script, it is just the same as inputting the same command at the command prompt. So, for example, you could have:
Code:
cd subfolder1
<execute some commands in this subfolder>
cd ..
<execute some more commands in this subfolder>
etc.
Tobermory is offline   Reply With Quote

Old   March 8, 2021, 15:30
Default
  #3
New Member
 
Santi Parera
Join Date: Jul 2019
Location: BARCELONA
Posts: 26
Rep Power: 7
Kalabagh is on a distinguished road
Quote:
Originally Posted by Tobermory View Post
The Allrun script is just a shell script, and you can navigate around the directories just like you would from the command line. When you run the Allrun (shell) script, it is just the same as inputting the same command at the command prompt. So, for example, you could have:
Code:
cd subfolder1
<execute some commands in this subfolder>
cd ..
<execute some more commands in this subfolder>
etc.

Thank you, I realised quickly...






Now I have another problem. Commands do execute one after one, but this does not happen with logs... At first I tried without the "if" conditions and the same... It seems all the logs are requested to be writed at the same time so that the first that enters gets written, but not the others. I don't know so much the use of "runApplication" before each command. This is also happening with "blockMesh" and "rotateMesh" commands.


Thanks.
Attached Images
File Type: png Selección_032.png (30.6 KB, 13 views)
Kalabagh is offline   Reply With Quote

Old   March 8, 2021, 15:47
Default
  #4
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 736
Rep Power: 14
Tobermory will become famous soon enough
Bear in mind that the redirect ">" overwrites the contents of the file, if it is already existing. If you want to append to the log file, then use ">>" instead of ">" ... that might be your problem?
Tobermory is offline   Reply With Quote

Old   March 8, 2021, 15:57
Default
  #5
New Member
 
Santi Parera
Join Date: Jul 2019
Location: BARCELONA
Posts: 26
Rep Power: 7
Kalabagh is on a distinguished road
Quote:
Originally Posted by Tobermory View Post
Bear in mind that the redirect ">" overwrites the contents of the file, if it is already existing. If you want to append to the log file, then use ">>" instead of ">" ... that might be your problem?
I'll try.

But the problem is that from this script I expect 3 scaled geometry files and 3 logs or 1 log containing scaling processof the 3 geometry files. What I get is 3 scaled geometry files and just one log containing random information of one of 3 geometry files.
Kalabagh is offline   Reply With Quote

Old   March 8, 2021, 16:29
Default
  #6
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 736
Rep Power: 14
Tobermory will become famous soon enough
Maybe I am being stupid (I am tired), but I am struggling to see what your code is doing. First up, take this line:

Code:
if surfaceConvert rotor.stl rotor_scaled.stl -clean -scale 0.01 > /dev/null 2>&1 > log.surfaceConvert
you start by running the utility surfaceConvert, and then redirect the output into /dev/null, ie throw it away. Fine. You then redirect stderr to stdout, with 2>&1, which throws away any error messages as well. Okay. Then you are redirecting stdout again to the log file ... I don't think that you mean to redirect stdout twice - perhaps the following part
Code:
> /dev/null
can be deleted?

Also, as discussed, if you want to see the log file data from each time surfaceConvert is run, you want to change the line into something like the following:
Code:
if surfaceConvert rotor.stl rotor_scaled.stl -clean -scale 0.01 >> log.surfaceConvert  2>&1
The other bit that is puzzling me is the purpose of the if commands. As written, the argument of the if command in first bit of code above is true if surfaceConvert outputs any text, and false if no text is output. For example, the code:

Code:
if ls; then echo "true"; else echo "false"; fi
echoes "true". Is that what you want? Why do you need the if's?
Tobermory is offline   Reply With Quote

Old   March 9, 2021, 14:46
Default
  #7
New Member
 
Santi Parera
Join Date: Jul 2019
Location: BARCELONA
Posts: 26
Rep Power: 7
Kalabagh is on a distinguished road
Quote:
Originally Posted by Tobermory View Post
Maybe I am being stupid (I am tired), but I am struggling to see what your code is doing. First up, take this line:

Code:
if surfaceConvert rotor.stl rotor_scaled.stl -clean -scale 0.01 > /dev/null 2>&1 > log.surfaceConvert
you start by running the utility surfaceConvert, and then redirect the output into /dev/null, ie throw it away. Fine. You then redirect stderr to stdout, with 2>&1, which throws away any error messages as well. Okay. Then you are redirecting stdout again to the log file ... I don't think that you mean to redirect stdout twice - perhaps the following part
Code:
> /dev/null
can be deleted?

Also, as discussed, if you want to see the log file data from each time surfaceConvert is run, you want to change the line into something like the following:
Code:
if surfaceConvert rotor.stl rotor_scaled.stl -clean -scale 0.01 >> log.surfaceConvert  2>&1
The other bit that is puzzling me is the purpose of the if commands. As written, the argument of the if command in first bit of code above is true if surfaceConvert outputs any text, and false if no text is output. For example, the code:

Code:
if ls; then echo "true"; else echo "false"; fi
echoes "true". Is that what you want? Why do you need the if's?

Thank you so much, now it works well.


One thing I do not understand is that if I navigate to the installation directory of OpenFOAM I can see that "surfaceConvert", "blockMesh" and "rotateMesh" are applications. Now why I have to execute blockMesh with "runApplication" and not with surfaceConvert??


This is the code I have now:
Code:
#!/bin/sh
cd ${0%/*} || exit 1    # Run from this directory

# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions

# - scaling

cd constant/triSurface/
surfaceConvert ROTOR.stl ROTOR_SCALED.stl -clean -scale 0.01 >> log.surfaceConvert 2>&1
surfaceConvert TURBINA.stl TURBINA_SCALED.stl -clean -scale 0.01 >> log.surfaceConvert 2>&1
surfaceConvert REACTOR.stl REACTOR_SCALED.stl -clean -scale 0.01 >> log.surfaceConvert 2>&1

# - meshing

cd ../..
cd system/
m4 blockMeshDict.m4 > blockMeshDict
cd ..
runApplication blockMesh >> log.blockMesh 2>&1
runApplication rotateMesh  '(0 0 1)' '(0 1 0)' >> log.rotateMesh 2>&1
What happens is that everything goes well till blockMesh. The mesh is not done as the log informs that "blockMesh already run on ...directory, remove log file to re-run".


This also happens with "rotateMesh"
Kalabagh is offline   Reply With Quote

Old   March 9, 2021, 16:18
Default
  #8
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 736
Rep Power: 14
Tobermory will become famous soon enough
Quote:
Thank you so much, now it works well.
Excellent!

Quote:
One thing I do not understand is that if I navigate to the installation directory of OpenFOAM I can see that "surfaceConvert", "blockMesh" and "rotateMesh" are applications. Now why I have to execute blockMesh with "runApplication" and not with surfaceConvert??
You can certainly ignore runApplication, and just run directly as per your script. I tend to use runApplication because it automatically generates me a log file for that application, and I find it is quite compact coding and easy to read ... no other advantage though. You can find the coding for runApplication in $WM_PROJECT_DIR/bin/tools/RunFunctions, if you want to see the detail.

Quote:
This is the code I have now:
Looks good. As a fine-tuning tweak, you could change
Code:
surfaceConvert ROTOR.stl ROTOR_SCALED.stl -clean -scale 0.01 >> log.surfaceConvert 2>&1
to
Code:
surfaceConvert ROTOR.stl ROTOR_SCALED.stl -clean -scale 0.01 > log.surfaceConvert 2>&1
so that the first time you run surfaceConvert you overwrite the previous version of the logfile, but for the 2nd and 3rd times you will append.

Quote:
What happens is that everything goes well till blockMesh. The mesh is not done as the log informs that "blockMesh already run on ...directory, remove log file to re-run". This also happens with "rotateMesh"
Try add a -overwrite flag to the runApplication or delete the log.blockMesh file - it is complaining that you have already got a set of results from the application (eg blockMesh) there already, so you need to tell it that you want to overwrite it ... it's a safety feature I guess. Also, runApplication already dumps the output into a logfile that is called log.{applicationName}, so you can just write:
Code:
runApplication -overwrite blockMesh
and same for rotateMesh.

Good luck my friend!
Tobermory is offline   Reply With Quote

Reply

Tags
allrun, directory, surfaceconvert


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
Hypersonic Sim (running at Mach 7): floating point exception has occurred bungusbeefcake STAR-CCM+ 10 March 31, 2015 07:59
CFX11 + Fortran compiler ? Mohan CFX 20 March 30, 2011 19:56
Suse10 FoamX problem frank178 OpenFOAM Installation 6 January 14, 2010 05:18
Statically Compiling OpenFOAM Issues herzfeldd OpenFOAM Installation 21 January 6, 2009 10:38
Kubuntu uses dash breaks All scripts in tutorials platopus OpenFOAM Bugs 8 April 15, 2008 08:52


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