Run a SFINCS model#
This notebook demonstrates how to run and inspect a SFINCS model. The notebook does not contain the SFINCS code or executables to run the model with. Below there is explained where and how to get the SFINCS executable
All lines in this notebook which start with !
are executed from the command line. Within jupyter (except for jupyter lab) the logging messages are shown after completion.
Inspecting the batch-file to run SFINCS#
On Windows, you can run SFINCS by executing a batch-file. We have already prepared this for an example model called ‘sfincs_compound’. Let’s now inspect this batch-file.
[1]:
fn = "./sfincs_compound/run.bat"
with open(fn, "r") as f:
txt = f.read()
print(txt)
call "c:\change_path_of_folder\sfincs.exe">sfincs_log.txt
Explanation of what is in the batch file:
‘call’ means here that an executable has to be run.
..:nbsphinx-math:sfincs_exe is the folder where the executable ‘sfincs.exe’ is located
The ‘>sfincs_log.txt’ means that the output should be written to a log-file called ‘sfincs_log.txt’
If you don’t have SFINCS yet, download SFINCS from here: https://download.deltares.nl/en/download/sfincs/
Then open the file ‘run.bat’ in any text editor, and add the folder of where you have saved the SFINCS executable ‘sfincs.exe’.
e.g. to *”c:\SFINCS_download:nbsphinx-math:sfincs.exe”*
Open log file#
Let’s see whether this log-file with information of SFINCS output information is already available
[2]:
fn = "./sfincs_compound/sfincs_log.txt"
with open(fn, "r") as f:
txt = f.read()
print(txt)
----------- Welcome to SFINCS -----------
@@@@@ @@@@@@@ @@ @@ @@ @@@@ @@@@@
@@@ @@@ @@@@@@@ @@ @@@ @@ @@@@@@@ @@@ @@@
@@@ @@ @@ @@@ @@ @@ @@ @@@
@@@@@ @@@@@@ @@ @@@@@@ @@ @@@@@
@@@ @@ @@ @@ @@@ @@ @@ @@@
@@@ @@@ @@ @@ @@ @@ @@@@@@ @@@ @@@
@@@@@ @@ @@ @@ @ @@@@ @@@@@
..............
......:@@@@@@@@:......
..::::..@@........@@.:::::..
..:::::..@@..::..::..@@.::::::..
.::::::..@@............@@.:::::::.
.::::::..@@..............@@.:::::::.
.::::::::..@@............@@..::::::::.
.:::::::::...@@.@..@@..@.@@..::::::::::.
.:::::::::...:@@@..@@..@@@:..:::::::::..
............@@.@@..@@..@@.@@............
^^^~~^^~~^^@@..............@@^^^~^^^~~^^
.::::::::::@@..............@@.:::::::::.
.......:.@@.....@.....@....@@.:.......
.::....@@......@.@@@.@....@@.....::.
.:::~@@.:...:.@@...@@.:.:.@@~::::.
.::~@@@@@@@@@@.....@@@@@@@@@~::.
..:~~~~~~~:.......:~~~~~~~:..
......................
..............
-----------------------------------------
Build-Revision: $Rev: v2.0.2-Blockhaus
Build-Date: $Date: 2023-06-09
Reading input file ...
Info : Running SFINCS in regular mode ...
Turning on process: Viscosity, with nuvisc= 0.5000000
Reading meteo data ...
Info : Preparing SFINCS grid on regular mesh ...
Reading sfincs.ind ...
Reading sfincs.msk ...
Number of active z points : 20359
Number of active u/v points : 40364
Reading sfincs.dep
Reading water level boundaries ...
Reading observation points ...
Reading discharges ...
Initializing output ...
---------- Starting simulation ----------
0% complete, - s remaining ...
5% complete, 7.8 s remaining ...
10% complete, 7.7 s remaining ...
15% complete, 7.3 s remaining ...
20% complete, 6.6 s remaining ...
25% complete, 6.0 s remaining ...
30% complete, 5.5 s remaining ...
35% complete, 5.1 s remaining ...
40% complete, 4.7 s remaining ...
45% complete, 4.3 s remaining ...
50% complete, 4.0 s remaining ...
55% complete, 3.7 s remaining ...
60% complete, 3.3 s remaining ...
65% complete, 2.9 s remaining ...
70% complete, 2.4 s remaining ...
75% complete, 2.0 s remaining ...
80% complete, 1.6 s remaining ...
85% complete, 1.2 s remaining ...
90% complete, 0.8 s remaining ...
95% complete, 0.4 s remaining ...
100% complete, 0.0 s remaining ...
Info : Write maximum values of final timestep since t=dtmaxout was not reached
yet...
---------- Simulation finished ----------
Total time : 8.654
Total simulation time : 8.090
Time in input : 0.564
Time in boundaries : 0.506 ( 6.3%)
Time in discharges : 0.014 ( 0.2%)
Time in momentum : 6.060 ( 74.9%)
Time in continuity : 1.418 ( 17.5%)
Time in output : 0.137 ( 1.7%)
Average time step (s) : 3.216
---------- Closing off SFINCS -----------
In case you get an error message, this means that the log-file is not available, and SFINCS has not run yet.
Let’s now do this…
Now let’s try to run this batch-file#
[3]:
import os
run_path = "./sfincs_compound"
cur_dir = os.getcwd()
# uncomment to run sfincs
# os.chdir(run_path)
# os.system("run.bat")
# os.chdir(cur_dir)
It should now take less than a minute or so for the SFINCS simulation to finish (not available on Binder)
We can now have a look at the log-file
Created log-file#
[4]:
fn = "./sfincs_compound/sfincs_log.txt"
with open(fn, "r") as f:
txt = f.read()
print(txt)
----------- Welcome to SFINCS -----------
@@@@@ @@@@@@@ @@ @@ @@ @@@@ @@@@@
@@@ @@@ @@@@@@@ @@ @@@ @@ @@@@@@@ @@@ @@@
@@@ @@ @@ @@@ @@ @@ @@ @@@
@@@@@ @@@@@@ @@ @@@@@@ @@ @@@@@
@@@ @@ @@ @@ @@@ @@ @@ @@@
@@@ @@@ @@ @@ @@ @@ @@@@@@ @@@ @@@
@@@@@ @@ @@ @@ @ @@@@ @@@@@
..............
......:@@@@@@@@:......
..::::..@@........@@.:::::..
..:::::..@@..::..::..@@.::::::..
.::::::..@@............@@.:::::::.
.::::::..@@..............@@.:::::::.
.::::::::..@@............@@..::::::::.
.:::::::::...@@.@..@@..@.@@..::::::::::.
.:::::::::...:@@@..@@..@@@:..:::::::::..
............@@.@@..@@..@@.@@............
^^^~~^^~~^^@@..............@@^^^~^^^~~^^
.::::::::::@@..............@@.:::::::::.
.......:.@@.....@.....@....@@.:.......
.::....@@......@.@@@.@....@@.....::.
.:::~@@.:...:.@@...@@.:.:.@@~::::.
.::~@@@@@@@@@@.....@@@@@@@@@~::.
..:~~~~~~~:.......:~~~~~~~:..
......................
..............
-----------------------------------------
Build-Revision: $Rev: v2.0.2-Blockhaus
Build-Date: $Date: 2023-06-09
Reading input file ...
Info : Running SFINCS in regular mode ...
Turning on process: Viscosity, with nuvisc= 0.5000000
Reading meteo data ...
Info : Preparing SFINCS grid on regular mesh ...
Reading sfincs.ind ...
Reading sfincs.msk ...
Number of active z points : 20359
Number of active u/v points : 40364
Reading sfincs.dep
Reading water level boundaries ...
Reading observation points ...
Reading discharges ...
Initializing output ...
---------- Starting simulation ----------
0% complete, - s remaining ...
5% complete, 7.8 s remaining ...
10% complete, 7.7 s remaining ...
15% complete, 7.3 s remaining ...
20% complete, 6.6 s remaining ...
25% complete, 6.0 s remaining ...
30% complete, 5.5 s remaining ...
35% complete, 5.1 s remaining ...
40% complete, 4.7 s remaining ...
45% complete, 4.3 s remaining ...
50% complete, 4.0 s remaining ...
55% complete, 3.7 s remaining ...
60% complete, 3.3 s remaining ...
65% complete, 2.9 s remaining ...
70% complete, 2.4 s remaining ...
75% complete, 2.0 s remaining ...
80% complete, 1.6 s remaining ...
85% complete, 1.2 s remaining ...
90% complete, 0.8 s remaining ...
95% complete, 0.4 s remaining ...
100% complete, 0.0 s remaining ...
Info : Write maximum values of final timestep since t=dtmaxout was not reached
yet...
---------- Simulation finished ----------
Total time : 8.654
Total simulation time : 8.090
Time in input : 0.564
Time in boundaries : 0.506 ( 6.3%)
Time in discharges : 0.014 ( 0.2%)
Time in momentum : 6.060 ( 74.9%)
Time in continuity : 1.418 ( 17.5%)
Time in output : 0.137 ( 1.7%)
Average time step (s) : 3.216
---------- Closing off SFINCS -----------
Now we actually should have output!
You have run your first SFINCS model.
Created netcdf output files#
Let’s now inspect what files there are situated in the folder of the model setup:
[5]:
path = "./sfincs_compound"
dir_list = os.listdir(path)
# prints all files
print(dir_list)
['sfincs.dis', 'sfincs.dep', 'sfincs.inp', 'sfincs_map.nc', 'sfincs_log.txt', 'sfincs.ind', 'sfincs.bnd', 'sfincs.msk', 'sfincs_his.nc', 'run.bat', 'sfincs.bzs', 'figs', 'sfincs.obs', 'gis', 'sfincs.src']
We see here the earlier inspected log-file ‘sfincs_log.txt’
Do you additionally see the files ‘sfincs_map.nc’ and ‘sfincs_his.nc’ ?
These are output files of SFINCS, containing the model results in the common NetCDF format.
Continue to postprocessing and visualization#
You can now continue to the notebook(s):