Simulating tidal stream turbines for an operational: real-world case of Pentland Firth, Scotland
Prerequisite: Thetis and Firedrake must be installed on your system:
curl -O https://raw.githubusercontent.com/firedrakeproject/firedrake/master/scripts/firedrake-install
python3 firedrake-install --install thetis (or otherwise consult Firedrake's Github)
PF0_assess.msh: Computational mesh for the domain, Case PF0, for resource assessment
bathy.txt: Bathymetry data, interpolated on the meshlat.txt: Lowest Astronomical Tide, used for adjusting bathymetryextra_detectors.npyandextra_detectors_names.npy: List of detector coordinates and namesn_max_125.npy: Distribution of Manning friction
useful_gauges.csv: Location and tidal constituent information for various gauges around the UK and from the Meygen site.simulation_parameters.py: Simulation parameters configuration, see below.
Most model data is available on request (or can be obtained online from various sources). This should include:
- Bed class file:
bed_class_pentland_rev.nc - Bathymetry files:
digimap_pentland.nc: low resolution data covering all Scottish coasts,orkney_digimap.nc: medium-resolution data covering the north-east of Scotland and the Orkneys and ShetlandPentland_firth_Gebco.nc: very low resolution data covering North UK and Scandinavia
Forcing files: gridES2008.nc and hfES2008.nc.
- Mesh: mesh to interpolate data to and calculate on.
- Bathymetry: bathymetry files, in order from least to highest resolution. See
bathymetry.pyintools. - Forcing: tidal signal forcing data.
- Detectors: detector locations.
- Bed morphology: bed morphology data file.
- Friction: friction file.
- Output folders: choice of output folder location and name for the ramp and run.
- UTM zone and band: 30V
- Simulation start time: year, month, day, hour, minute
- Detector:
- Eikonal:
- Boundary values: boundary tags on the mesh that represent the open boundaries (i.e. the North Sea) and the land boundaries.
- Bathymetry: Minimum depth and name of the bathymetry parameter from the NetCDF file e.g.
'z','elevation'etc. - Time: Ramp duration, timestep for the simulation, wetting and drying, Manning parameter, Coriolis parameter, export times and run simulation.
- Physical parameters: gravitational acceleration and seawater density.
A series of files to aid the preprocessing and model runs.
utm.py: Converts from lat/lon to UTM and vice versa.bathymetry.py: Interpolation of the bathymetry.detectors.py: Takes the expected tidal amplitude across the domain and outputs it for a transformation between datums.thetis_support_scripts.py: Functions for use in pre-processing and running of the model e.g. Coriolis term inclusion, re-initialisation of flow/parameter fields and exporting states.tidal_amplitude.py: Transforms data (e.g. bathymetry) to lowest astronical tide (/chart datum) data.tidal_forcing.py: Sets the tidal field.tidal_forcing_ramp.py: Sets the tidal field for the ramp.power.py: Calculates the power output of the turbine, override Thetis' default module.
This method offers maximum autonomous control during operational use.
Information about the command is given by typing into the command prompt (terminal):
$ sim.py -h
usage: sim.py [-h] [-c CASE] [-s START] [-d DURATION] [-r RAMP_DURATION] [-p NUM_PROC]
Time information for tidal dynamic simulation
options:
-h, --help Show this help message and exit
-s CASE, --case CASE
Name of the simulation case, used for output folder name
-s START, --start START
Start date time (YYYY-MM-DDTHH:MM) of simulation
-d DURATION, --duration DURATION
Duration length of simulation, number and units e.g. "30d", "120h", "14c" (here "c" is semi-diurnal cycle)
-r RAMP_DURATION, --ramp-duration RAMP_DURATION
Duration length of ramp-up, number and units e.g. "2d", "24", "4c" (here "c" is semi-diurnal cycle)
-p NUM_PROC, --num-proc NUM_PROC
Number of processes used in parallel simulation
An example where running a "base" case with a one-day long simulation, starting at 00:00 20 Oct 2002, preceded by a ramping-up time period of three hours, using 8 CPU cores:
$ python sim.py -c BASE -s 2002-10-20T00:00 -r 3h -d 1d -p 8
You may want to install the Python package utm beforehand:
$ pip install utm
Output produced in two forms collected in the folder out_DT:
- time-series of elevation at a selected station (Wick, 58.44°N, 3.09°W or X = 497120 m, Y = 6477545 m in UTM 30V) (tab-separated text file
Tser.tsv) - field elevation of a small region between Stroma and Scotland mainland (longitude range 3.145°W to 3.135°W, latitude range 58.655°N to 58.660°N) (
field.nc)
Live plot is produced during the run with tools/simple_plot.py which generates tools/plot.html and this can be viewed using Firefox browser if available.
Due to the size of the model and the nature of the problem, this model lends itself to parallel processing. This is typically achieved with the Open MPI commands. If running in parallel, it is important that all the scripts are run on the same number of cores.
NOTE: It is recommended to use the script
sim.pyto run the script. Even if you were to adjust, arrange the processing steps, it is easier to do in a batch file likesim.pyinstead of typing the commands into the terminal.
CAUTION: Performing MPI parallel run at this stage is not recommended because while creating checkpoint (hdf5) files, parallel runs easily consume all system memory!
Before ramping up the model, we must process the model data from its initial form (e.g. a NetCDF (.nc) file) to a .h5 file which Thetis uses. The bathymetry is interpolated to the mesh, viscosity ``sponges'' are added near the boundaries for model stability and the Manning friction fields are interpolated to the mesh.
Interpolates bathymetry to an hdf5 file that can be imported later
- Adds viscosity sponges in boundary conditions
- Can be used to edit bathymetry/ friction and other fields that then feed into the simulations
Generates:
inputs/bathymetry2D.h5: bathymetry data for running the modelinputs/manning2D.h5: friction data for running the modelinputs/viscosity.h5: viscosity data for running the modeloutputs_CASE/outputs/bath.pvd& corresponding.pvtuand.vtufiles: bathymetry data to be viewed with ParaViewoutputs_CASE/outputs/dist.pvd& corresponding.pvtuand.vtufiles:outputs_CASE/outputs/lat.pvd& corresponding.pvtuand.vtufiles:outputs_CASE/outputs/manning.pvd& corresponding.pvtuand.vtufiles: friction data to be viewed with ParaViewoutputs_CASE/outputs/viscosity.pvd& corresponding.pvtuand.vtufiles: viscosity data to be viewed with ParaView
Before running the model, we need to ramp up the elevation and velocity fields up to the desired start point. Once running for a simulated day or two, the data files are saved for the main run.
When run, the simulation parameters should be output followed by the remaining time in the simulation.
Generates:
outputs_CASE/outputs_ramp/Elevation2d: elevation outputsoutputs_CASE/outputs_ramp/init_bathymetry_2d: bathymetry data to be viewed with ParaViewoutputs_CASE/outputs_ramp/Velocity2d: velocity outputsoutputs_CASE/outputs_ramp/bath.pvd& corresponding.pvtuand.vtufiles: bathymetry data to be viewed with ParaViewoutputs_CASE/outputs_ramp/diagnostic_volume2d.hdf5outputs_CASE/outputs_ramp/manning.pvd& corresponding.pvtuand.vtufiles: friction data to be viewed with ParaViewoutputs_CASE/outputs_ramp/viscosity.pvd& corresponding.pvtuand.vtufiles: viscosity data to be viewed with ParaViewoutputs_CASE/elevationout.pvd& corresponding.pvtuand.vtufiles: final elevation data to be viewed with ParaViewoutputs_CASE/velocityout.pvd& corresponding.pvtuand.vtufiles: final velocity data to be viewed with ParaView
The main model can now be run. Unless altered, velocities and elevation fields will be outputted at the desired export times. For optimisation use, some .h5 files will also be output at certain time periods.
Generates:
outputs_CASE/outputs_run/Elevation2d: elevation outputsoutputs_CASE/outputs_run/hdf5: hdf5 files for manipulation lateroutputs_CASE/outputs_run/init_bathymetry_2d: bathymetry data to be viewed with ParaViewoutputs_CASE/outputs_run/Velocity2d: velocity outputsoutputs_CASE/outputs_run/bath.pvd& corresponding.pvtuand.vtufiles: bathymetry data to be viewed with ParaViewoutputs_CASE/outputs_run/diagnostic_detectors-adcp.hdf5outputs_CASE/outputs_run/diagnostic_turbine.hdf5outputs_CASE/outputs_run/diagnostic_volume2d.hdf5outputs_CASE/outputs_run/elevation_imported.pvd& corresponding.pvtuand.vtufiles: imported elevation data to be viewed with ParaViewoutputs_CASE/outputs_run/manning.pvd& corresponding.pvtuand.vtufiles: friction data to be viewed with ParaViewoutputs_CASE/outputs_run/velocity_imported.pvd& corresponding.pvtuand.vtufiles: imported velocity data to be viewed with ParaViewoutputs_CASE/outputs_run/viscosity.pvd & corresponding.pvtuand.vtufiles: viscosity data to be viewed with ParaView.
Assuming that we finish simulation, and the results are stored in different folders according to various scenarios:
- Base case, named e.g.
outputs_BASECASE - Coarse-grid case, e.g.
outputs_COARSEGRID - Fine-grid case, e.g.
outputs_FINEGRID - No-turbine case, e.g.
outputs_NOTRB - Full-array case, e.g.
outputs_ARRAY
Then rename the corresponding folders in the code file.
Running this script can be done in two steps:
- Step 1: to produce the intermediate flux files
raw_flux_output/sthuv_base_ext.npyandraw_flux_output/Q_all_ext.npy - Step 2: indicate the corresponding files in the code file and run to produce the plots similar to that presented in the present paper.
The script is for plotting the difference in flow field and energy flux between the base (e.g. ambient) case and the modified (altered) case. The plots will be shown as filled contours.
As with the above script, be careful first to get the correct names for output (simulated) folders, and filled in the code statements:
compare_and_plot: for plotting the difference in velocity.compare_and_plot_flux: for plotting the difference in energy flux.
The parameters for these functions/statements are:
levels: for example(-80, 80, 17)will show difference ranging from -80% to +80% with 17 levels of contour lines.folder: name of folder to save the image files in.fformat: file format for such image files, e.g.pngorpdf(for simple plots).quantityandscenario: to generate appropriate file names.subfig: annotates on the plots. Specifically when preparing paper manuscripts, to indicate the order within a figure.
The validation scripts can be used to compare tracked velocities and elevations in the model to measured data. This includes plotting water level and velocity-time series, peak velocities and turbine powers. A number of predefined metrics to quantify the goodness-of-fit between the model and the data is established, including root-mean-square error (RMSE), mean absolute error (MAE), bias, and coefficient of determination (R^2^).
gof.py: Performing godness-of-fit between a time series of water level (or generally, a scalar quantity) against observed data.gof_vel.py: Performing godness-of-fit between a time series of velocity (or generally, a vector quantity) against observed data. Also separates flood and ebb phases, analyses velocity peaks and histograms.
The scripts can be invoked after simulation stopped, e.g. after step 2 mentioned above.