7.1. Wave generators

There are no restrictions on programming styles applied in wave generators as long as it can produce a sound SWD-file.

Wave generators are typical limited to provide wave fields described by a small set of spectral formulations. Often only one or two formulations. Consequently, only a small subset of the SWD-specification needs to be considered when including support for writing SWD files.

7.1.1. Case Studies

Before considering any programming, you first need to establish the relationship between the mathematical formulation you apply in your wave generator, and the relevant SWD shape formulation.

To assist you in this process we provide two case studies from real world wave generators.

  • Case 1 explains how the formulation applied in HOS-Ocean, for long-crested finite depth waves, relates to the SWD formulation shape 2.

  • Case 2 relates a variable depth flow formulation by Gouin et al. to the SWD formulation shape 3.

7.1.2. Programming

7.1.2.1. Fortran

Fortran programmers may apply the following section for how to write a sound SWD file from a wave generator. The handling of making a C binary stream is demonstrated.

For each spectral formulation this repository provides source code demonstrating how to create proper SWD-files with minimal effort. Implementation or adaption of this source code to the actual wave generator is expected to be a very small job.

Spectral model

Example source files for wave generators

shape 1 or 2

swd_write_shape_1_or_2.f90

shape 3

swd_write_shape_3.f90

shape 4 or 5

swd_write_shape_4_or_5.f90

shape 6

swd_write_shape_6.f90

Note

If your wave generator applies a different numerical precision than double precision you need to adjust the kind parameter wp defined in the beginning of the source code.

Assuming your wave generator will support the spectral shape_X formulation where X is one of the shape models as defined in the theory section, you may write something like this in your wave generator.

program my_wave_generator
...
use swd_write_shape_X_def, only: swd_write_shape_X   ! Replace X with the index of the actual model
...
type(swd_write_shape_X) :: swd_X
...
swd_X % init('my_wave.swd', nx, dk, ...)  ! All time independent swd-format parameters for shape X
...
do (temporal integration loop)
    ...
    swd_X % update(h, ht, c, ct)   ! Relevant spectral amplitudes for this time step for shape X
end do
swd_X % close()
...
program my_wave_generator

If your wave generator also supports another spectral formulation shp=y, just add a similar swd_y variable of type(swd_write_shape_y) and provide the relevant parameters for that model too.

Following this approach, Fortran source code dealing with the low level binary C-stream output for the various spectral formulations are listed in this table

7.1.2.2. C / C++ / Python

Writing C-streams using these programming languages are straight forward. The logical ordering is the same as for the fortran examples given above. An example from open source is the raschii Python package for making non-linear regular waves.

Note

Any 2-dimensional arrays should be written using the Fortran element ordering described in the SWD format description.