MATLAB Tutorial 1

From TUFLOW FV Wiki
Jump to navigation Jump to search
USEFUL LINKS
Wiki Links Help Downloads
TUFLOW FV Wiki Main Page Products Support/Contact TUFLOW FV Downloads
TUFLOW FV Tutorials Requesting a Licence Tutorial Module Data
TUFLOW Classic/HPC Wiki TUFLOW FV Glossary Manuals

Using FVG Sheet

This example demonstrates a way to quickly visualise results at a single timestep in a 2D ‘sheet’ form. The goal is to plot two representations of the model mesh next to one another and then colour it to correspond to different variables, in this case water level, and current velocity. We would then like to be able to scroll through timesteps with both plots updating automatically.

Basic Setup

An fvgraphics object must first be created.

fobj = fvgraphics;

fvgraphics object

This creates a matlab figure window with a slider bar to control the timestep.

In order to plot the 2D sheet objects neatly we need to specify 2 axes. This can be done any normal way in MATLAB, but a convenient method is using subplot

ax(1) = subplot(2,1,1);
ax(2) = subplot(2,1,2);

Axes added

Now it's time to plot the fvg_sheet object. The input arguments are the handle to the fvgraphics object, and the full file path to the model results, and the axis to plot it in.

modfil = 'C:\users\COM\TUFLOWFV\results\example_model_output.nc';

sheetObj1 = fvg_sheet(fobj,modfil,'peerObj',ax(1));
sheetObj2 = fvg_sheet(fobj,modfil,'peerObj',ax(2));

fvg sheets

The Default variable that fvg_sheet will plot is the cell-centered bathymetry at the first timestep as can be seen above.

Setting Parameters

Now we need to set the variables that we want, the top one to water level H and the bottom one to the current velocity V, we can also add a title to each plot showing the time that we are looking at. Then we can add a MATLAB colorbar, and set the limits to sensible numbers: the water level between 2 and 5m, and the current velocity between 0 and 0.5m/s. Lastly, we can turn the axes off to remove the x and y bars, and make each axis equal to stop the figure from being stretched.

set(sheetObj1,'Variables','H');
set(sheetObj2,'Variables','V');

set(sheetObj1,'TitleTime','on');
set(sheetObj2,'TitleTime','on');

colorbar('peer',ax(1));
colorbar('peer',ax(2));

set(ax(1),'CLim',[ 2 5 ]);
set(ax(2),'CLim',[ 0 0.5 ]);

axis(ax,'equal')
axis(ax,'off')

fvgraphics object

Other Parameters

There are other parameters that can be set to further customize the desired output. For a list of these examine the help documentation for fvg_sheet

help fvg_sheet

Many of these can be specified directly upon calling the fvg_sheet object. Here is the previous example called directly

fobj = fvgraphics;

ax(1) = subplot(2,1,1);
ax(2) = subplot(2,1,2);

sheetObj1 = fvg_sheet(fobj,modfil,'peerObj',ax(1),'Variables','H');
sheetObj2 = fvg_sheet(fobj,modfil,'peerObj',ax(2),'Variables','V');

colorbar('peer',ax(1));
colorbar('peer',ax(2));

set(ax(1),'CLim',[ 2 5]);
set(ax(2),'CLim',[ 0 0.5]);

axis(ax,'equal')
axis(ax,'off')

Potential Applications

With all the available parameters it is possible to create highly customized graphics of your TUFLOWFV model results. The image below shows a 3D rendering of the bathymetry, with semi-transparent fvg_sheet objects to show plumes and cones to show current vectors. If you have any questions about this tutorial, or any novel ideas for impressive graphics using these tools, please email support@tuflow.com.

fvgraphics object