Run TUFLOW From a Batch-file: Difference between revisions
Content deleted Content added
Chris Huxley (talk | contribs)  | 
				|||
| (15 intermediate revisions by 3 users not shown) | |||
Line 23: 
===Pause=== 
A second line with the text "pause" can be added, this will prompt the user to press a key at the end of the batch file.  This is useful if the  
<pre>"C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" "M01_5m_001.tcf" 
pause</pre> 
Line 62: 
==No Console Option== 
Using the -nc switch will run a simulation without opening a 
<pre>Start "TUFLOW" /wait /min "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -nc M01_5m_001.tcf 
Start "TUFLOW" /wait /min "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -nc M01_2.5m_001.tcf</pre> 
It is possible to get a text output of the console using: 
<pre>Start "TUFLOW" /wait /min "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -nc M01_5m_001.tcf > M01_5m_001.txt 
Start "TUFLOW" /wait /min "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -nc M01_2.5m_001.tcf > M01_2.5m_001.txt</pre> 
== TUFLOW switches in a batch file== 
Line 101 ⟶ 105: 
;* “p” (path); and<br> 
: The addition of the “p” flag (e.g. -cp) allows the user to specify an alternate path in which to copy the model. Without this flag, the location defaults to the .tcf’s location. For example, specifying the following, will place a copy of the model into a folder C:\put_model_here:<br> 
;* “ncf” (no check files)<br> 
: The addition of the “ncf” flag (e.g. -cncf) copies the essential input files and excludes all check files.<br> 
Line 200 ⟶ 204: 
The following command could be used to run a model with CPU hardware on 8 threads:  
<pre>"C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -b -hwcpu -nt8 FS_Hardware_01.tcf </pre> 
The following command could be used to run a model on GPU hardware using 2 devices (GPU 0 and GPU1): 
<pre>"C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -b -hwgpu -pu0 -pu1 FS_Hardware_01.tcf </pre> 
===Set Start Time for a Simulation=== 
Line 279 ⟶ 283: 
<pre>set TUFLOWEXE="C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" 
set RUN=start "TUFLOW" /wait  
%RUN% MR_H99_C25_Q100.tcf 
%RUN% MR_H99_C25_Q050.tcf 
%RUN% MR_H99_C25_Q020.tcf</pre> 
The advantage of using variables is if the path to the TUFLOW exe changes, or to run a different version of TUFLOW, it is just a simple change in the .bat file.  In the above, note the use of quotes 
===Looping in a batch file=== 
Line 309 ⟶ 313: 
With the following line:<br> 
<tt><u>echo</u> start "TUFLOW" /wait "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -b -e1 %%a -e2 %%b filename.tcf</tt><br> 
By using the echo in the command line, rather than starting the simulations the command line will be displayed in the  
[[File:DOS nested batch output.png|frame|none]] 
Line 407 ⟶ 411: 
REM ______________SET RUN VARIABLES_____________ 
set TUFLOWEXE="C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" 
set RUN=start "TUFLOW" /low  
set /a CPU_Cores=5 
Line 452 ⟶ 456: 
endlocal 
</pre> 
===Copy model, checks and results in a looped batch file=== 
This batch file uses the copy model function to copy the model (inputs and check files), of both scenarios 5m and 2.5m, to a specified folder location. After copying, <u>[https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy robocopy]</u> is used to copy the results, based off the tcf filename and specified scenarios, to the destination result folder.  
<pre> 
@echo off 
set TUFLOWEXE_iSP="C:\Releases\2023-03-AF\TUFLOW_iSP_w64.exe" 
set RUN_iSP=start "TUFLOW" /wait %TUFLOWEXE_iSP% -cp  "D:\tuflow_models\copy" 
set A=5m 2.5m 
set source_results=..\results 
set destination_results=C:\tuflow_models\copy\results 
FOR %%a in (%A%) do ( 
    :: Copy model 
    %RUN_iSP% -s1 %%a M01_~s1~_001.tcf 
    :: Copy results folder to copy model location 
    robocopy "%source_results%" "%destination_results%" "M01_%%a_001*" /S 
) 
pause 
</pre> 
===Coordinating Asynchronous Simulations=== 
This batch file will set off asynchronous runs on separate threads, and then wait for all runs to finish before moving to the next process. This example kicks off 8 tuflow.exe processes and then waits before collating (in fortran) and processing the results (in python). Both “combine_therad_outputs.exe” and “Post_process.py” are dummy programs only (with dummy arguments), and are included just to demonstrate how any sort of post processing might be called after the synchronisation of all TUFLOW simulations. 
Line 462 ⟶ 491: 
:: User defined variables – will need to be changed 
set "for_infile=inputs_fortran.inp" 
set "run_exe= 
set "file_prefix=C:\temp\test" 
set "sum_exe=combine_thread_outputs.exe" 
 | |||