netsse.simul.ship_resp
======================

.. py:module:: netsse.simul.ship_resp

.. autoapi-nested-parse::

   Numerical simulation of **ship responses**.

   .. dropdown:: Copyright (C) 2023-2026 Technical University of Denmark, R.E.G. Mounet
       :color: primary
       :icon: law

       *This code is part of the NetSSE software.*

       NetSSE is free software: you can redistribute it and/or modify it under
       the terms of the GNU General Public License as published by the Free
       Software Foundation, either version 3 of the License, or (at your
       option) any later version.

       NetSSE is distributed in the hope that it will be useful, but WITHOUT
       ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       for more details.

       You should have received a copy of the GNU General Public License along
       with this program.  If not, see https://www.gnu.org/licenses/.

       To credit the author, users are encouraged to use below reference:

       .. code-block:: text

           Mounet, R. E. G., & Nielsen, U. D. NetSSE: An open-source Python package
           for network-based sea state estimation from ships, buoys, and other
           observation platforms (version 2.2). Technical University of Denmark,
           GitLab. February 2026. https://doi.org/10.11583/DTU.26379811.

   *Last updated on 20-02-2026 by R.E.G. Mounet*



Attributes
----------

.. autoapisummary::

   netsse.simul.ship_resp.fifo_queue


Classes
-------

.. autoapisummary::

   netsse.simul.ship_resp.MultiThread


Functions
---------

.. autoapisummary::

   netsse.simul.ship_resp.process_queue
   netsse.simul.ship_resp.simul_ship_resp
   netsse.simul.ship_resp.sum_components


Module Contents
---------------

.. py:class:: MultiThread(name)

   Bases: :py:obj:`threading.Thread`


   This constructor should always be called with keyword arguments. Arguments are:

   *group* should be None; reserved for future extension when a ThreadGroup
   class is implemented.

   *target* is the callable object to be invoked by the run()
   method. Defaults to None, meaning nothing is called.

   *name* is the thread name. By default, a unique name is constructed of
   the form "Thread-N" where N is a small decimal number.

   *args* is a list or tuple of arguments for the target invocation. Defaults to ().

   *kwargs* is a dictionary of keyword arguments for the target
   invocation. Defaults to {}.

   If a subclass overrides the constructor, it must make sure to invoke
   the base class constructor (Thread.__init__()) before doing anything
   else to the thread.



   .. py:method:: run()

      Method representing the thread's activity.

      You may override this method in a subclass. The standard run() method
      invokes the callable object passed to the object's constructor as the
      target argument, if any, with sequential and keyword arguments taken
      from the args and kwargs arguments, respectively.




   .. py:attribute:: name

      A string used for identification purposes only.

      It has no semantics. Multiple threads may be given the same name. The
      initial name is set by the constructor.


.. py:function:: process_queue()

   A function to process the FIFO queue.

   This basic function runs the function
   :func:`netsse.simul.ship_resp.sum_components` with the queued arguments,
   until the queue is empty, after which it signals that the task is completed.

   .. seealso:: :py:obj:`MultiThread`, :py:obj:`sum_components`


.. py:function:: simul_ship_resp(S2D, freq_wave, betas_wave, U=0, RespStr='Waves', max_threads=0, freq_TRF=[0], betas_TRF=0, TRF_amps=0, TRF_phases=0, NoTs=10, fs=10, T=30 * 60, Nomega=500, AddNoise=False, snr=20)

   Generates several time histories of the waves encountered by a ship and,
   optionally, the wave-induced vessel motion responses (heave, roll, pitch).

   A 2D wave spectrum must be given as input. If ship response is to be simulated
   too, then the wave-to-motion transfer functions of the vessel must also be
   provided.

   :param S2D: 2-D wave spectrum characterizing the sea state [m^2.s.s/rad].
   :type S2D: array_like of shape (Nf_wave,Nmu)
   :param freq_wave: Vector of wave frequencies [Hz] in which the wave spectrum is expressed.
   :type freq_wave: array_like of shape (Nf_wave,)
   :param betas_wave: Vector of the `relative` wave headings [deg] for the wave spectrum.

                      .. note::
                          The relative wave headings are defined as:
                          0 deg: following sea; 90 deg: beam waves from port side;
                          180 deg: head sea; 270 deg: beam waves from starboard side.
   :type betas_wave: array_like of shape (Nmu,)
   :param U: Vessel speed [m/s].
   :type U: float, default 0
   :param RespStr: Use ``'Motions'`` if vessel motions in waves are also to be simulated
                   (in addition to the waves). Otherwise, use ``'Waves'`` and only the wave
                   surface elevation will be simulated. The default is ``'Waves'``.
   :type RespStr: {'Waves','Motions'}, optional
   :param max_threads: Indicates to maximum number of threads to be used to parallelize the
                       execution.

                       .. attention::
                           A large value for ``max_threads`` should only be used if the program
                           is run on a high-performance computer. The code execution risks
                           crashing otherwise.
   :type max_threads: int, default 0
   :param freq_TRF: Vector of wave frequencies [Hz] in which the transfer functions are
                    expressed.
   :type freq_TRF: array_like of shape (Nf_TRF,), default [0,]
   :param betas_TRF: Vector of the relative wave headings [deg] indicating the direction of
                     propagation of the energy (relative to vessel heading) for the transfer
                     functions.
   :type betas_TRF: array_like of shape (Nbeta,), default 0
   :param TRF_amps: The amplitude of the transfer functions for heave, roll, and pitch,
                    respectively. The default is 0.
   :type TRF_amps: array_like of shape (Nf_TRF, Nbeta, 3), optional
   :param TRF_phases: The phase of the transfer functions for heave, roll, and pitch,
                      respectively. The default is 0.
   :type TRF_phases: array_like of shape (Nf_TRF, Nbeta), optional
   :param NoTs: Number of time series to be generated.
   :type NoTs: int, default 10
   :param fs: Sampling frequency [Hz] for the generated time histories.
   :type fs: float, default 10
   :param T: Duration [s] of the time histories. The default is 30*60 = 1800 s.
   :type T: float, optional
   :param Nomega: Number of wave components used for each direction to generate the time
                  histories.
   :type Nomega: int, default 500

   :returns: * **time** (*array_like of shape (T*fs,).*) -- Vector of time [s].
             * **wavet** (*array_like of shape (NoTs,T*fs).*) -- Wave elevation [m] time series.
             * **heavet, rollt, pitcht** (*array_like of shape (NoTs,T*fs).*) -- Heave, roll and pitch time series.

               .. note::
                   ``heavet``, ``rollt``, ``pitcht`` are returned if and only if
                   RespStr = ``'Motions'``

   :param AddNoise: A boolean that indicates whether random noise (Gaussian white noise)
                    is added to be added the motion time histories.
   :type AddNoise: bool, default False
   :param snr: The signal-to-noise ratio to be used for addition of noise.
   :type snr: float, default 20

   .. seealso::

      :py:obj:`sum_components`
          Performs the summation of the sine components to simulate in the time domain the encountered wave elevation or the wave-induced responses on a ship.

   .. rubric:: Example

   >>> # Wave simulations
   >>> time, wavet =
   ...     simul_ship_resp(S2D,freq_wave,betas_wave,U,'Waves',0,NoTs=10,fs=10,T=30*60,
   ...                     Nomega=500,AddNoise=True,snr=20)
   >>> # Motion simulations
   >>> time, wavet, heavet, rollt, pitcht =
   ...     simul_ship_resp(S2D,freq_wave,betas_wave,U,'Motions',0,freq_TRF,betas_TRF,
   ...                     TRF_amps,TRF_phases,NoTs,fs,T,Nomega,AddNoise=True,snr=20)


.. py:function:: sum_components(aw, V_seed, W_seed, epsilon_seed, om_enc, time, seed, result, TRF_amps=0, TRF_phases=0, RespStr='Waves', AddNoise=False, snr=20)

   Performs the summation of the sine components to simulate in the time domain
   the encountered wave elevation or the wave-induced responses on a ship.

   :param aw: Amplitude of the wave components.
   :type aw: array_like of shape (Nfreq,Nbeta,1)
   :param V_seed: Standard normal distributed variables with mean 0 and std. 1.
   :type V_seed: array_like of shape (Nfreq,Nbeta,1)
   :param W_seed: Standard normal distributed variables with mean 0 and std. 1.
   :type W_seed: array_like of shape (Nfreq,Nbeta,1)
   :param epsilon_seed: Random phases [rad] of the wave components. Those are uniformly distributed
                        variables between 0 and :math:`2\pi`.
   :type epsilon_seed: array_like of shape (Nfreq,Nbeta,1)
   :param om_enc: Vector of encounter wave frequencies [rad/s].
   :type om_enc: array_like of shape (Nfreq,1,1)
   :param time: Vector of time [s].
   :type time: array_like of shape (1,1,Nt)
   :param seed: Index of the seed number.
   :type seed: int
   :param result: Anterior value of the vector of wave/response sequence.

                  .. note::
                      Consult the documentation of the :func:`netsse.simul.ship_resp.simul_ship_resp`
                      function for information on the other parameters.
   :type result: array_like of shape (Nseed,Nt)

   :returns: **result** -- Updated value of the vector of wave/response sequence.
   :rtype: array_like of shape (Nseed,Nt)

   .. seealso:: :py:obj:`simul_ship_resp`, :py:obj:`process_queue`


.. py:data:: fifo_queue

