mafredo package

Submodules

mafredo.helpers module

class mafredo.helpers.MotionMode(value)[source]

Bases: enum.Enum

An enumeration.

HEAVE = 2
PITCH = 4
ROLL = 3
SURGE = 0
SWAY = 1
YAW = 5
mafredo.helpers.MotionModeToStr(mode: mafredo.helpers.MotionMode) str[source]

These are used in the netcdf databases

class mafredo.helpers.Symmetry(value)[source]

Bases: enum.Enum

An enumeration.

Circular = 4
No = 0
XZ = 1
XZ_and_YZ = 3
YZ = 2
mafredo.helpers.dof_names_to_numbers(ds)[source]

Converts the names of the DOFS to numbers. This is unfortunately required to make sure that the order of the dofs makes sense when retrieving added mass or damping matrices.

mafredo.helpers.expand_direction_to_full_range(dataset)[source]

Adds entries at value+360 or values-360 if the wave_direction in the dataset do not span the 0…360 interval

Returns

expanded dataset

mafredo.helpers.expand_omega_dim_const(dataset, new_omega)[source]

Expands the omega axis of dataset to cover the range of new_omega. Extrapolation is done by repeating the nearest values (ie: keep constant)

Returns

expanded dataset

mafredo.helpers.f10(number, tol=1e-12)[source]

Make a length-10 string representing the given number

We use {:10g} for numbers (general format) which converts the numbers in the best way:

‘{:10g}’.format(1325123551512511.0) –> ‘1.32512e+15’ (11 chars) ‘{:10g}’.format(2.0) –> ‘ 2’ ‘{:10g}’.format(2) –> ‘ 2’ ‘{:10g}’.format(-432.0) –> ‘ -432’ ‘{:10g}’.format(-1.1641532182693481e-10) –> ‘-1.16415e-10’ (12 chars)

Numbers with an absolute value below tol are exported as 0

mafredo.helpers.wavelength(omega, waterdepth=0)[source]

Returns the wave-length for this frequency [rad/s] and waterdepth.

In deep water the wave-length is 2*pi*g / omega^2

In shallow water the following equations need to be solved numerically:

  1. k = 2*pi / wavelength

  2. c = sqrt((g/k) * tanh(k*waterdepth))

  3. wavelength = T * c = (2*pi/omega) * c

Parameters
  • omega – wave-frequency in rad/s

  • waterdepth – waterdepth in [m], use 0 for infinite waterdepth

mafredo.hyddb1 module

class mafredo.hyddb1.Hyddb1[source]

Bases: object

This class contains all information for first order floating bodies. That is:

  • Added mass

  • Damping

  • Wave-forces

Typically all of the above are obtained from BEM package such as capytaine, wamit, diffrac, orcawave, etc.

Getting data in

The following methods exist for loading data from supported formats:

Load from mafredo’s own format (netcdf)

create_from()[source]

Load from capytaine

create_from_capytaine()[source]

Load from MARIN .hyd file

create_from_hyd()[source]

Load from Orcaflex .yml file

create_from_orcaflex_yml()[source]

From data

create_from_data(everything)[source]
set_data(everything)[source]
set_amass(omega, m6x6)[source]
set_damping(omega, m6x6)[source]

Modifications

expand360_using_symmetry()[source]
add_frequency()[source]
add_add_direction()
regrid_omega()[source]
regrid_direction()[source]

Plotting

plot()[source]

Getting data out

It is possible to obtain the data directly from the _mass , _damping and _force xarrays. But my be easier to use one of the following instead:

force()[source]
damping()[source]
amass()[source]

Saving to file

To .hyd format, hydrostatics to be supplied optionally

to_hyd_file()[source]

To .dhyd format

save_as()[source]
add(other)[source]

Merges the contents of ‘other’ into the current database. This is done using ‘merge’ of xarray using its default arguments.

add_direction(wave_direction)[source]
add_frequencies(omegas)[source]

Adds more frequencies to the database by linear interpolation

add_frequency(omega)[source]

Adds a frequency to the database by linear interpolation

amass(omega)[source]

Returns the added mass xarray for given frequency or frequencies. Linear interpolated is applied if needed

assert_allclose_to(other, atol=1, rtol=0.001, atol_phase=0.0001)[source]

Asserts that the two databases are equal

static create_from(filename)[source]

Loads hydrodynamic data from a netcdf4 file, for example one as saved using save_as.

See also

save_as

static create_from_capytaine(filename)[source]

Loads hydrodynamic data from a dataset produced with capytaine.

  • Wave forces,

  • radiation_damping and

  • added_mass are read.

See also

Rao.wave_force_from_capytaine

static create_from_data(self, omega, added_mass, damping, directions, force_amps, force_phase_rad)[source]

Creates a new database using the provided data.

Parameters
  • omega – common omega vector [rad/s]

  • added_mass – added mass components : [iOmega, iRadating_dof, iInfluenced_dof]

  • damping – damping components : [iOmega, iRadating_dof, iInfluenced_dof]

  • directions – wave directions for wave-forces [degrees, coming from]

  • force_amps – wave forces [iMode (0..5) , iDirection, iOmega]

  • force_phase_rad – wave force phase in rad [iMode (0..5) , iDirection, iOmega]

static create_from_hyd(filename)[source]

Load from the MARIN .hyd format

.Hyd files are databases containing both hydrodynamics and hydrostatics. Both are expressed about the same origin. We only read the hydrodynamcis.

Definition: https://mods.marin.nl/download/attachments/13139976/HYDFILE_Description_Nov_2012.pdf?version=1&modificationDate=1453716460000&api=v2

Assumptions:

Headings are repeated in same order for each omega

Parameters

filename – file to read

Returns

A freshly created hydrodynamic database

static create_from_orcaflex_yml(filename, vessel_type_name='Vessel type1', iDraught=0)[source]

Creates a database from the hydrodynamic data of a vessel-type in an orcaflex model.

Parameters
  • filename – Orcaflex .yml file to read

  • vessel_type_name – Name of the vessel-type to read

  • iDraught – Index of the draught. Note that the first draught is number 0

Returns

A freshly created hydrodynamic database

damping(omega)[source]

Returns the damping xarray for given frequency or frequencies. Linear interpolated is applied if needed

expand360_using_symmetry()[source]

Expands the database to cover the full 360 degrees spectrum using the current symmetry setting. Sets the symmetry to ‘No’ afterwards

force(omega, wave_direction)[source]

Returns the force vector for given omega/wave-direction

force_rao(mode: mafredo.helpers.MotionMode)[source]

Return a reference to the internal force rao object

Parameters

mode – 0…5 for surge…yaw

property frequencies
property n_frequencies

Returns the number of frequencies of the mass, damping and force. Raises a ValueError if mass, force or damping have unequal number of frequencies.

property n_wave_directions

Returns the number of wave directions in the first of the RAOs

plot(adm=True, damp=True, amp=True, phase=True, do_show=True)[source]

Produces a plot of the contents of the database

Parameters
  • adm – plot added mass

  • damp – plot damping

  • amp – plot force amplitudes

  • phase – plot force phases

  • do_show – do plt.show()

Returns

figure handles

regrid_direction(new_headings)[source]
regrid_omega(new_omega)[source]
save_as(filename)[source]

Saves the contents of the database using the netcdf format.

See also

load_from

set_amass(omega, m6x6)[source]

Sets the added-mass matrix for a given omega

set_damping(omega, m6x6)[source]

Sets the damping-mass matrix for a given omega

set_data(omega, added_mass, damping, directions, force_amps, force_phase_rad)[source]

Sets all internal data for added mass, damping and wave-forces.

Parameters
  • omega – common omega vector [rad/s]

  • added_mass – added mass components : [iOmega, iRadating_dof, iInfluenced_dof]

  • damping – damping components : [iOmega, iRadating_dof, iInfluenced_dof]

  • directions – wave directions for wave-forces [degrees, coming from]

  • force_amps – wave forces [iMode (0..5) , iDirection, iOmega]

  • force_phase_rad – wave force phase in rad [iMode (0..5) , iDirection, iOmega]

See Also: create_from_data

property symmetry
to_hyd_file(filename, hydrostatics=None)[source]

Export the database to a .hyd file.

The exported file will be a single-body, first order .hyd database.

.Hyd files are databases containing both hydrodynamics and hydrostatics. Both are expressed about the same origin.

Definition: https://mods.marin.nl/download/attachments/13139976/HYDFILE_Description_Nov_2012.pdf?version=1&modificationDate=1453716460000&api=v2

A .hyd file contains hydrostatic information as well. This hydrostatic information needs to be provided in the “hydrostatic” argument.

  • water_depth : waterdepth (not hydrostatics)

  • body_draft : draft of body (m)

  • waterline : Z-coordinate of waterline wrt hydrodynamic origin of body (m)

  • disp_m3 : displacement of body (m3)

  • Awl_m2 : waterline plane area (m2)

  • COFX_m : X-coordinate of centre of flotation (m)

  • COBX_m : X-coordinate of centre of buoyancy (m)

  • KMT_m : transverse metacentric height KMT measured from keel (m)

  • KML_m : longitudinal metacentric height KML measured from keel (m)

Parameters
  • filename – file to write to

  • hydrostatics – A dictionary containing the hydrostatic properties. Optionally define None for all values 0.

Returns

None

property wave_directions

mafredo.rao module

class mafredo.rao.Rao[source]

Bases: object

RAO is a data-object for dealing with RAO-type data being:

  • amplitude [any] and

  • phase [radians]

as function of:

  • heading [degrees]

  • omega [rad/s]

This class is created to provide methods for the correct interpolation of this type of data which means:

  • the amplitude and phase are interpolated separately (interpolation of complex numbers result in incorrect amplitude)

  • continuity in heading is considered (eg: interpolation of heading 355 from heading 345 and 0)

An attribute “mode” is added which determine which mode is represented (surge/sway/../yaw) and is needed to determine how symmetry should be applied (if any). Why? Well, for heave it does not matter whether a wave comes from sb or ps, but for roll it does.

The amplitude and phase can physically be anything. But typically would be one of the following:

  • A motion RAO (result of frequency domain response calculation)

  • A force or moment RAO (result of diffraction analysis)

  • A response spectrum with relative phase angles (result of a motion RAO combined with a wave-spectrum)

It is suggested to define the wave_direction as the direction of wave propagation relative to the X-axis. So heading 90 is propagation along the y-axis.

Create:

create_from_data()[source]
create_from_capytaine_wave_force()[source]
create_from_xarray_nocomplex()[source]

Modify:

regrid_omega()[source]
regrid_direction()[source]
add_direction()[source]
add_frequency()[source]
apply_symmetry_xz()

Properties:

  • n_frequencies

  • omega

  • n_wave_directions

  • wave_directions

Get data:

get_value()[source]
get_heading()[source]

['amplitude'] to get amplitude as xarray ['phase'] to get phase as xarray ['complex'] to get complex rao ['complex_unit'] to get normalized complex rao

Plotting:

For plotting just use xarray:

>>> my_rao['ampltiude'].plot()

others:

for netcdf:

to_xarray_nocomplex()[source]
  • anything from xarray. For example myrao[‘amplitude’].plot() or myrao[‘amplitude’].sel(wave_direction=180).values

Note For ease of interpolation the phase is stored internally as “complex_unit” which equals exp(1j*phase). This is a complex number with angle (phase) and amplitude 1. The relation bewteen these two is:

>>> phase = np.angle(cu)
>>> cu = np.exp(phase *1j)
add(other)[source]

Merges the contents of ‘other’ into the current RAO. This is done using ‘merge’ of xarray using its default arguments.

add_direction(wave_direction)[source]

Adds the given direction to the RAO by interpolation [deg]

add_frequency(omega)[source]

Adds the given frequency to the RAO by interpolation [rad/s]

static create_from_capytaine_wave_force(filename, mode: mafredo.helpers.MotionMode)[source]

Reads hydrodynamic data from a netCFD file created with capytaine and copies the data for the requested mode into the object.

Parameters
  • filename – .nc file to read from

  • mode – Name of the mode to read MotionMode

Returns

None

Examples

test = Rao() test.wave_force_from_capytaine(r”capytaine.nc”, MotionMode.HEAVE)

static create_from_data(directions, omegas, amplitude, phase, mode=None)[source]

Creates a new Rao object with the given data

Parameters
  • directions – wave directions

  • omegas – wave frequencies [rad/s]

  • amplitude – wave fores [iDirection, iOmega]

  • phase – wave phases [iDirection, iOmega] in radians

  • mode – (None) MotionMode - optional, only mandatory when applying symmetry

static create_from_xarray_nocomplex(a, mode: mafredo.helpers.MotionMode)[source]

From xarray with complex numbers separated (netCDF compatibility)

expand_symmetry_xz()[source]

Appends equivalent headings considering xz symmetry to the dataset.

That is: The RAO for heading = a is identical to the RAO for heading = -a

except that for sway, roll and yaw a sign change will be applied (phase shift of pi)

expand_symmetry_yz()[source]

Appends equivalent headings considering yz symmetry to the dataset.

That is: The RAO for heading = a is identical to the RAO for heading = 180 -a

except that for surge, pitch and yaw a sign change will be applied (phase shift of pi)

get_heading(wave_direction)[source]

Returns the complex at the requested wave direction If the data-point is not yet available in the database, then the corresponding wave-direction is added to the grid by linear interpolation.

get_value(omega, wave_direction)[source]

Returns the value at the requested position. If the data-point is not yet available in the database, then the corresponding frequency and wave-direction are added to the grid by linear interpolation.

property n_frequencies

The number of frequencies in the database

property n_wave_directions

The number of headings or wave-directions

property omega
regrid_direction(new_headings)[source]

Regrids the direction axis to new_headings [degrees].

regrid_omega(new_omega)[source]

Regrids the omega axis to new_omega [rad/s]

scale(factor)[source]

Scales the amplitude by the given scale factor (positive numbers only as amplitude can not be negative)

to_xarray_nocomplex()[source]

To xarray with complex numbers separated (netCDF compatibility)

property wave_directions

Module contents