Run TUFLOW From a Batch-file: Difference between revisions
Content deleted Content added
Ellis Symons (talk | contribs) No edit summary |
|||
| (24 intermediate revisions by 5 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_2.5m_001.tcf > M01_2.5m_001.txt</pre>
== TUFLOW switches in a batch file==
Line 88 ⟶ 92:
An example is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -nq "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
===Set End Time for a Simulation===▼
The use of the -et<time_in_hours> (end time) switch allows the user to specify the end time for a simulation. Any end time specified via this run option argument is given the highest priority and overrides the "End Time ==" settings in the .tcf, event files (.tef) and override files. <br>▼
An example is:<br>▼
▲<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -et3 "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
===Copy a TUFLOW model===
Line 109 ⟶ 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 152 ⟶ 148:
: The addition of the “L” flag (e.g. -pmL) list the files to be copied into an output file, but don’t copy.<br>
;* “ini” (file.ini)<br>
: The addition of the “ini” flag (e.g. -pmini) provides a .ini file with user defined options. A .ini file can be used to overwrite the default base and destination folders, and specify events/scenarios for models with events/scenarios in filenames.
Combinations of the above are also valid, with the order of the optional switches not being important (-pmAllL would be treated the same as -pmLAll).<br>
Line 171 ⟶ 167:
An example of package model that copies all files with specified .ini file (-pmAllini) is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -pmAllini package.ini "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
An example of .ini file to overwrite the default base and destination folders, and specify events/scenarios for models with events/scenarios in filenames:<br>▼
====INI files with Events and Scenarios====
▲An example of .ini file to overwrite the default base and destination folders, and specify events/scenarios for models with events/scenarios in filenames
The model scenario and event options are required only if there are files that use the event or scenario variables in file names. This option does not limit the files that TUFLOW will package by scenario or event.
E.g. you may have the following command to read in either a base or development TIF grid:
<pre>
Read GRID Zpts == ..\model\grid\DEM_<<~s1~>>.tif
</pre>
In this example, we can assume that the <tt><<~s1~>></tt> variable could be replaced with either <tt>"Base"</tt> or <tt>"Dev"</tt>. The example ini file below shows how to ensure that TUFLOW will package both the "Base" and "Dev" files correctly. The same concept applies for event variables, noting that events defined in the event file (TEF) and their associated boundary files are not required to use this. It is only required if the event variable is used i.e. <tt><<~e1~>></tt>.
<pre>
Base Folder ==
Copy Destination ==
Model Scenario ~
Model Event ~
</pre>
Line 208 ⟶ 212:
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===
The use of the -st<time_in_hours> (start time) switch allows the user to specify the start time for a simulation. Any start time specified via this run option argument is given the highest priority and overrides the "Start Time ==" settings in the .tcf, event files (.tef) and override files. <br>
▲An example is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -st0 "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
▲===Set End Time for a Simulation===
▲The use of the -et<time_in_hours> (end time) switch allows the user to specify the end time for a simulation. Any end time specified via this run option argument is given the highest priority and overrides the "End Time ==" settings in the .tcf, event files (.tef) and override files. <br>
An example is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -et3 "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
===Suppress Message Box Prompts===
The use of the -nmb (no message boxes) switch suppresses the use of Windows message boxes to prompt the user. All prompts will be via the console window. <br>
An example is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -nmb "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
===Search for a Network License===
The use of the -nwk (network) switch forces TUFLOW to search for a network licence. I.e. Skip the search for a local license. <br>
An example is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -nwk "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
===Search for a WIBU License===
The use of the -wibu (WIBU license) switch forces TUFLOW to search only for a WIBU Codemeter license.<br>
An example is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -wibu "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
===Specify the Output Drive===
The -od<drive> (output drive) switch allows the user to specify the Output Drive for a simulation. <br>
For example, the following will redirect all outputs to the C:\ drive:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -odC "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
===Specify Map Output===
The -oz<name> (output zone) switch specifies that the map output includes the input zone. <br>
For example, the following would include output for 'Zone A':<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -ozZoneA "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
===Query the Creation of a Folder===
The -qcf (query the creation of a folder) switch is useful if you would prefer to have the create folder query dialog appear (rather than TUFLOW automatically creating folders - see <u>[[Run_TUFLOW_From_a_Batch-file#Automatically_Create_Folders_in_a_TUFLOW_model | -acf]]</u>). <br>
An example is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -qcf "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
===Execute a Simulation (the Default)===
The -x (execute) switch executes the simulation. This switch is used by default and does not need to be included on the TUFLOW command line.
===Copy or Test Model License Free===
For Build 2018-03-AA or later, it is possible to use the <u>[[Run_TUFLOW_From_a_Batch-file#Copy_a_TUFLOW_model | copy model]]</u> (-c option) or <u>[[Run_TUFLOW_From_a_Batch-file#Testing_a_simulation | test model]]</u> (-t option) without using a license. To utilise this licence free copy/test, the -nlc (no license check) input argument must be specified. If running without a TUFLOW licence, no diagnostic output is generated (e.g. messages layer). If these are required, the -nlc option must be removed.
===Simulation Log Path (Legacy)===
The -slp (simulation log path) switch is a legacy option for Solftlock (blue) dongles to set the path to a folder on the intranet to log all simulation initiated from the lock. Refer to the <u>[https://www.tuflow.com/downloads/ TUFLOW Manual]</u> (2018 or earlier) for details.<br>
==Advanced Batch Files==
Line 240 ⟶ 290:
Batch files can be easily setup so that they are more generic and easily customised when moving from one project to another. For example, in the below a variable, TUFLOWEXE, is used to define the path to the TUFLOW exe to be used, and a variable RUN is used to incorporate options such as the /wait so that the simulations run in series (one after the other).
<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===
If you have a large number of events to run using the event files a for loop can be used in a batch file. In this example we have 5 event magnitudes (-e1 input) and 5 event durations (-e2 input). The following batch file can be used to run all 25 simulations one after the other:
Line 261 ⟶ 312:
FOR %%a in (%A%) do (
FOR %%b in (%B%) DO (
start "TUFLOW" /wait "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -b -e1 %%a -e2 %%b filename.tcf
)
)
Line 267 ⟶ 318:
</pre>
In order to test the syntax, you can test the batch file by replacing the following line:<br>
<tt>start "TUFLOW" /wait "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -b -e1 %%a -e2 %%b filename.tcf</tt><br>
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 280 ⟶ 331:
set B=10min 30min 60min 120min 270min
FOR %%a in (%A%) do FOR %%b in (%B%) do start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -b -e1 %%a -e2 %%b filename_~e1~_~e2~.tcf
pause
</pre>
Line 294 ⟶ 345:
FOR %%b in (%B%) do (
FOR %%c in (%C%) do (
start "TUFLOW" /wait "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -b -e1 %%a -e2 %%b -s1 %%c filename_~e1~_~e2~_~s1~.tcf
)
)
Line 368 ⟶ 419:
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 413 ⟶ 464:
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 423 ⟶ 499:
:: 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"
| |||