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.
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.1-beta$
Build-Date: $Date: 2023-03-10$
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, 5.4 s remaining ...
10% complete, 4.6 s remaining ...
15% complete, 4.1 s remaining ...
20% complete, 3.8 s remaining ...
25% complete, 3.7 s remaining ...
30% complete, 3.5 s remaining ...
35% complete, 3.4 s remaining ...
40% complete, 3.3 s remaining ...
45% complete, 3.1 s remaining ...
50% complete, 2.8 s remaining ...
55% complete, 2.5 s remaining ...
60% complete, 2.3 s remaining ...
65% complete, 2.0 s remaining ...
70% complete, 1.7 s remaining ...
75% complete, 1.4 s remaining ...
80% complete, 1.1 s remaining ...
85% complete, 0.8 s remaining ...
90% complete, 0.6 s remaining ...
95% complete, 0.3 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 : 5.639
Total simulation time : 5.614
Time in input : 0.025
Time in boundaries : 0.345 ( 6.1%)
Time in discharges : 0.008 ( 0.1%)
Time in momentum : 4.176 ( 74.4%)
Time in continuity : 1.024 ( 18.2%)
Time in output : 0.039 ( 0.7%)
Average time step (s) : 3.134
---------- 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()
os.chdir(run_path)
os.system("run.bat")
os.chdir(cur_dir)
sh: 1: run.bat: not found
It should now take less than a minute or so for the SFINCS simulation to finish (might take longer in Binder than when running locally using Jupyter Notebook)
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.1-beta$
Build-Date: $Date: 2023-03-10$
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, 5.4 s remaining ...
10% complete, 4.6 s remaining ...
15% complete, 4.1 s remaining ...
20% complete, 3.8 s remaining ...
25% complete, 3.7 s remaining ...
30% complete, 3.5 s remaining ...
35% complete, 3.4 s remaining ...
40% complete, 3.3 s remaining ...
45% complete, 3.1 s remaining ...
50% complete, 2.8 s remaining ...
55% complete, 2.5 s remaining ...
60% complete, 2.3 s remaining ...
65% complete, 2.0 s remaining ...
70% complete, 1.7 s remaining ...
75% complete, 1.4 s remaining ...
80% complete, 1.1 s remaining ...
85% complete, 0.8 s remaining ...
90% complete, 0.6 s remaining ...
95% complete, 0.3 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 : 5.639
Total simulation time : 5.614
Time in input : 0.025
Time in boundaries : 0.345 ( 6.1%)
Time in discharges : 0.008 ( 0.1%)
Time in momentum : 4.176 ( 74.4%)
Time in continuity : 1.024 ( 18.2%)
Time in output : 0.039 ( 0.7%)
Average time step (s) : 3.134
---------- 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)
['hydromt_data.yml', 'sfincs.dis', 'gis', 'sfincs.bnd', 'sfincs_map.nc', 'sfincs.dep', 'sfincs_his.nc', 'sfincs_log.txt', 'sfincs.inp', 'sfincs.obs', 'sfincs.ind', 'sfincs.src', 'figs', 'run.bat', 'sfincs.msk', 'sfincs.bzs']
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):