Tip

For an interactive online version click here: Binder badge

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:\put\your\own\path\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.3.0 mt. Faber Release
Build-Date: $Date: 2025-11-18

------ Preparing model simulation --------

------------------------------------------
Computational mesh
------------------------------------------
Number of active z points      :     20687
Number of active u/v points    :     41018
Warning! Times in boundary conditions file do not cover entire simulation period !
Warning! Adjusting last time in boundary conditions time series !

------------------------------------------
Processes
------------------------------------------
Subgrid topography   : no
Quadtree refinement  : no
Advection            : yes
Viscosity            : yes
Coriolis             : no
Wind                 : no
Atmospheric pressure : no
Precipitation        : no
Infiltration         : no
SnapWave             : no
Wave paddles         : no
------------------------------------------


---------- Starting simulation -----------
---- Using 12 of 12 available threads ----

   0% complete,       - s remaining ...
   5% complete,    20.2 s remaining ...
  10% complete,    18.4 s remaining ...
  15% complete,    17.8 s remaining ...
  20% complete,    17.2 s remaining ...
  25% complete,    16.4 s remaining ...
  30% complete,    15.2 s remaining ...
  35% complete,    14.1 s remaining ...
  40% complete,    12.9 s remaining ...
  45% complete,    12.0 s remaining ...
  50% complete,    11.0 s remaining ...
  55% complete,    10.0 s remaining ...
  60% complete,     8.9 s remaining ...
  65% complete,     7.8 s remaining ...
  70% complete,     6.7 s remaining ...
  75% complete,     5.6 s remaining ...
  80% complete,     4.5 s remaining ...
  85% complete,     3.4 s remaining ...
  90% complete,     2.3 s remaining ...
  95% complete,     1.1 s remaining ...
 100% complete,     0.0 s remaining ...

---------- Simulation finished -----------

 Total time             :     22.580
 Total simulation time  :     22.562
 Time in input          :      0.018
 Time in boundaries     :      0.519 (  2.3%)
 Time in discharges     :      0.007 (  0.0%)
 Time in momentum       :     16.512 ( 73.2%)
 Time in continuity     :      5.312 ( 23.5%)
 Time in output         :      0.150 (  0.7%)

 Average time step (s)  :      3.445

---------- 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.3.0 mt. Faber Release
Build-Date: $Date: 2025-11-18

------ Preparing model simulation --------

------------------------------------------
Computational mesh
------------------------------------------
Number of active z points      :     20687
Number of active u/v points    :     41018
Warning! Times in boundary conditions file do not cover entire simulation period !
Warning! Adjusting last time in boundary conditions time series !

------------------------------------------
Processes
------------------------------------------
Subgrid topography   : no
Quadtree refinement  : no
Advection            : yes
Viscosity            : yes
Coriolis             : no
Wind                 : no
Atmospheric pressure : no
Precipitation        : no
Infiltration         : no
SnapWave             : no
Wave paddles         : no
------------------------------------------


---------- Starting simulation -----------
---- Using 12 of 12 available threads ----

   0% complete,       - s remaining ...
   5% complete,    20.2 s remaining ...
  10% complete,    18.4 s remaining ...
  15% complete,    17.8 s remaining ...
  20% complete,    17.2 s remaining ...
  25% complete,    16.4 s remaining ...
  30% complete,    15.2 s remaining ...
  35% complete,    14.1 s remaining ...
  40% complete,    12.9 s remaining ...
  45% complete,    12.0 s remaining ...
  50% complete,    11.0 s remaining ...
  55% complete,    10.0 s remaining ...
  60% complete,     8.9 s remaining ...
  65% complete,     7.8 s remaining ...
  70% complete,     6.7 s remaining ...
  75% complete,     5.6 s remaining ...
  80% complete,     4.5 s remaining ...
  85% complete,     3.4 s remaining ...
  90% complete,     2.3 s remaining ...
  95% complete,     1.1 s remaining ...
 100% complete,     0.0 s remaining ...

---------- Simulation finished -----------

 Total time             :     22.580
 Total simulation time  :     22.562
 Time in input          :      0.018
 Time in boundaries     :      0.519 (  2.3%)
 Time in discharges     :      0.007 (  0.0%)
 Time in momentum       :     16.512 ( 73.2%)
 Time in continuity     :      5.312 ( 23.5%)
 Time in output         :      0.150 (  0.7%)

 Average time step (s)  :      3.445

---------- 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.inp', 'sfincs.manning', 'sfincs.src', 'sfincs.msk', 'run.bat', 'sfincs.bzs', 'sfincs_log.txt', 'sfincs_map.nc', 'sfincs.dep', 'gis', 'sfincs.bnd', 'sfincs_his.nc', 'sfincs.ind', 'sfincs.obs']

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):