Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dat/Daring/righting_moment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Heel": [0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0],
"GZ": [0.000, 0.120, 0.230, 0.310, 0.350, 0.330, 0.260]
}
5 changes: 5 additions & 0 deletions dat/orc/asym_cl_kite.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# asymmetric spinnaker centerline tack lift and drag coefficients (ORC VPP). first row is awa
0.02639,,,,,,,,,,,
0.0000,28.000,41.000,50.000,60.000,67.000,75.000,100.000,115.000,130.000,150.000,180.000
0.0000,0.19100,0.28000,0.36600,0.52300,0.44800,0.55600,0.75700,0.79000,0.77600,0.62000,0.40000
0.0000,0.02600,1.01800,1.27700,1.47100,1.51300,1.44400,1.13700,0.82900,0.56000,0.25000,-0.12000
5 changes: 5 additions & 0 deletions dat/orc/asym_pole_kite.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# asymmetric spinnaker pole tack lift and drag coefficients (ORC VPP). first row is awa
0.02639,,,,,,,,,,,
0.0000,28.000,41.000,50.000,60.000,67.000,75.000,100.000,115.000,130.000,150.000,180.000
0.0000,0.17000,0.23800,0.30600,0.45900,0.39200,0.49300,0.79100,0.89400,0.93600,0.93600,0.93600
0.0000,0.08500,1.11400,1.36000,1.51300,1.54800,1.47900,1.20700,0.95600,0.70600,0.42500,0.00000
5 changes: 5 additions & 0 deletions dat/orc/jib.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# jib lift drag and lift coefficient (high). first row is awa
0.016,,,,,,,,,
0.00000,7.0000,15.0000,20.0000,27.0000,50.0000,60.0000,100.0000,150.0000,180.0000
0.003,0.05000,0.03200,0.03100,0.03700,0.25000,0.35000,0.73000,0.95000,0.90000
0.00000,0.00000,1.10000,1.47500,1.50000,1.45000,1.25000,0.40000,0.00000,-0.10000
5 changes: 5 additions & 0 deletions dat/orc/jib_low.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# jib lift drag and lift coefficient (low performance rig). first row is awa
0.016,,,,,,,,,
0.00000,7.0000,15.0000,20.0000,27.0000,50.0000,60.0000,100.0000,150.0000,180.0000
0.003,0.05000,0.03200,0.03100,0.03700,0.25000,0.35000,0.73000,0.95000,0.90000
0.00000,0.00000,1.00000,1.37500,1.45000,1.43000,1.25000,0.40000,0.00000,-0.10000
5 changes: 5 additions & 0 deletions dat/orc/kite.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# kite lift drag and lift coefficient (high). first row is awa
0.02639,,,,,,,,,,,,
0.0000,28.000,41.000,50.000,60.000,67.000,75.000,100.000,115.000,130.000,150.000,170.000,180.000
0.0000,0.19152,0.28152,0.35496,0.43920,0.48960,0.53280,0.61920,0.65880,0.67320,0.67320,0.67320,0.67320
0.0000,-0.02484,0.69437,0.90677,1.04400,1.08000,1.08000,0.95760,0.81360,0.61200,0.32400,0.10800,0.00000
5 changes: 5 additions & 0 deletions dat/orc/main.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# mainsail lift drag and lift coefficient (high). first row is awa
0.01379,,,,,,,,,
0.00000,7.0000,9.0000,12.0000,28.0000,60.0000,90.0000,120.0000,150.0000,180.000
0.03448,0.01724,0.01466,0.01466,0.02586,0.11302,0.38250,0.96888,1.31578,1.34483
0.00000,0.94828,1.13793,1.25000,1.42681,1.38319,1.26724,0.93103,0.38793,-0.11207
5 changes: 5 additions & 0 deletions dat/orc/main_low.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# mainsail lift drag and lift coefficient (low performance rig). first row is awa
0.01379,,,,,,,,,
0.00000,7.0000,9.0000,12.0000,28.0000,60.0000,90.0000,120.0000,150.0000,180.000
0.04300,0.02600,0.02300,0.02300,0.03300,0.11302,0.38250,0.96888,1.31578,1.34483
0.00000,0.86200,1.05200,1.16400,1.34700,1.23900,1.12500,0.83800,0.29600,-0.11207
5 changes: 5 additions & 0 deletions dat/orc/sym_kite.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# symmetric spinnaker lift and drag coefficients (ORC VPP). first row is awa
0.02639,,,,,,,,,,,
0.0000,28.000,41.000,50.000,60.000,67.000,75.000,100.000,115.000,130.000,150.000,180.000
0.0000,0.21300,0.32100,0.42500,0.58700,0.59800,0.61900,0.85000,0.91100,0.93500,0.93500,0.93500
0.0000,0.00000,0.97800,1.24100,1.45400,1.45600,1.43700,1.19000,0.95100,0.70600,0.42500,0.00000
261 changes: 209 additions & 52 deletions src/SailMod.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,118 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np
__author__ = "Marin Lauber"
__copyright__ = "Copyright 2020, Marin Lauber"
__license__ = "GPL"
__version__ = "1.0.1"
__email__ = "M.Lauber@soton.ac.uk"

import matplotlib.pyplot as plt
from scipy.interpolate import Akima1DInterpolator
import numpy as np
from scipy import interpolate


SAIL_TYPES = {
"main": "main",
"main_low": "main_low",
"jib": "jib",
"jib_low": "jib_low",
"kite": "kite",
"sym_kite": "sym_kite",
"asym_cl_kite": "asym_cl_kite",
"asym_pole_kite": "asym_pole_kite",
}


class Sail(object):
def __init__(self, name, type, area, vce, up=True):
def __init__(self, name, type, area, vce, up=True, data_source="orc",
cl_data=None, cd_data=None, sail_type=None):
"""
Base sail class.

Parameters
----------
name : str
Sail identifier (e.g. "J1", "A2").
type : str
Sail type, used to load coefficient data from ``dat/<type>.dat``.
One of ``"main"``, ``"jib"``, or ``"kite"``.
area : float
Sail area (m^2).
vce : float
Vertical centre of effort above deck (m).
up : bool, optional
Whether this is an upwind sail. Default is True.
data_source : str, optional
Coefficient data source directory under ``dat/``. Default "orc".
cl_data : dict, optional
User-provided CL data: ``{"awa": [...], "values": [...]}``.
cd_data : dict, optional
User-provided CD data: ``{"awa": [...], "values": [...]}``.
sail_type : str, optional
Override for the coefficient data file name. E.g. ``"main_low"``,
``"sym_kite"``, ``"asym_cl_kite"``, ``"asym_pole_kite"``.
If None, uses *type*.
"""
self.name = name
self.type = type
self.area = area
self.vce = vce
# Determine which data file to load
coeff_file = sail_type if sail_type is not None else self.type
# get sails coefficients
self._build_interp_func(self.type)
if cl_data is not None and cd_data is not None:
self._build_interp_func(coeff_file, data_source=data_source)
self._build_interp_from_arrays(cl_data, cd_data)
else:
self._build_interp_func(coeff_file, data_source=data_source)
self.bk = 1.0 # always valid for main, only AWA<135 for jib
self.up = up # is that an upwind sail?


def _build_interp_func(self, fname):
"""
build interpolation function and returns it in a list
def _build_interp_func(self, fname, data_source="orc"):
"""Build cubic B-spline interpolation functions for CL and CD.

Falls back to linear (k=1) if fewer than 4 data points are available.
Tries ``dat/{data_source}/{fname}.dat`` first, then ``dat/{fname}.dat``.
"""
a = np.genfromtxt("dat/" + fname + ".dat", delimiter=",", skip_header=1)
import os
path = os.path.join("dat", data_source, fname + ".dat")
if not os.path.exists(path):
path = os.path.join("dat", fname + ".dat")
a = np.genfromtxt(path, delimiter=",", skip_header=1)
self.kp = a[0, 0]
# linear for now, this is not good, might need to polish data outside
self.interp_cd = Akima1DInterpolator(a[1, :], a[2, :])
self.interp_cl = Akima1DInterpolator(a[1, :], a[3, :])
# Filter NaN values (trailing commas in CSV create NaNs)
mask = ~(np.isnan(a[1, :]) | np.isnan(a[2, :]) | np.isnan(a[3, :]))
x = a[1, mask]
cd = a[2, mask]
cl = a[3, mask]
k = 3 if len(x) >= 4 else 1
self.interp_cd = interpolate.make_interp_spline(x, cd, k=k)
self.interp_cd.extrapolate = True
self.interp_cl = interpolate.make_interp_spline(x, cl, k=k)
self.interp_cl.extrapolate = True

def _build_interp_from_arrays(self, cl_data, cd_data):
"""Build interpolation from user-provided coefficient arrays.

Parameters
----------
cl_data : dict
{"awa": [...], "values": [...]} for lift coefficients.
cd_data : dict
{"awa": [...], "values": [...]} for drag coefficients.
"""
cl_awa = np.array(cl_data["awa"])
cl_vals = np.array(cl_data["values"])
cd_awa = np.array(cd_data["awa"])
cd_vals = np.array(cd_data["values"])
k_cl = 3 if len(cl_awa) >= 4 else 1
k_cd = 3 if len(cd_awa) >= 4 else 1
self.interp_cl = interpolate.make_interp_spline(cl_awa, cl_vals, k=k_cl)
self.interp_cl.extrapolate = True
self.interp_cd = interpolate.make_interp_spline(cd_awa, cd_vals, k=k_cd)
self.interp_cd.extrapolate = True

def cl(self, awa):
awa = max(0, min(awa, 180))
Expand All @@ -36,6 +122,9 @@ def cd(self, awa):
awa = max(0, min(awa, 180))
return self.interp_cd(awa)

def measure(self, rfm, ftj):
"""Update sail dimensions for current reef/furl state."""

def debbug_coeffs(self, N=256):
awa = np.linspace(0, 180, N)
coeffs = np.empty((N, 2))
Expand All @@ -49,46 +138,31 @@ def debbug_coeffs(self, N=256):


class Main(Sail):
def __init__(self, name, P, E, Roach, BAD):
def __init__(self, name, P, E, Roach, BAD, data_source="orc",
cl_data=None, cd_data=None, sail_type=None):
"""
Initialize mainsail

This function initializes an object of class Main which inherits the class Sail.
It calculates the area, the Vertical Center of Effort (vce),
sets CE = 1 and calls the super class constructor.
Initialize mainsail.

Parameters
----------
name : string
Of the sail

P : Float
Height of the Mainsail in meters

E: Float
Length (Foot) of the Mainsail in meters

Roach: Float
Percentage by which the triangular area is increased in order to obtain the mainsail area.
This is area behind the line from clew to head.
To get this number you have to calculate Mainsail_area / (P*E/2) -1

BAD: Float
Boom Above Deck: Distance between boom and Deck in meters

Returns
-------
Main
Object of type Main( Sail )

See Also
--------
Jib( Sail )

Examples
--------
>>> Main("MN1", P=16.60, E=5.60, Roach=0.1, BAD=1.0)
<src.SailMod.Main object at 0xFFFFFFFFF>
name : str
Sail identifier.
P : float
Height of the Mainsail in meters.
E : float
Length (Foot) of the Mainsail in meters.
Roach : float
Roach factor (Mainsail_area / (P*E/2) - 1).
BAD : float
Boom Above Deck in meters.
data_source : str, optional
Coefficient data source. Default "orc".
cl_data : dict, optional
User-provided CL data.
cd_data : dict, optional
User-provided CD data.
sail_type : str, optional
Coefficient variant: ``"main"`` (default) or ``"main_low"``.
"""
self.name = name
self.type = "main"
Expand All @@ -98,18 +172,56 @@ def __init__(self, name, P, E, Roach, BAD):
self.BAD = BAD
self.area0 = 0.5 * P * E * (1 + self.roach)
self.vce = P / 3.0 * (1 + self.roach) + self.BAD
super().__init__(self.name, self.type, self.area0, self.vce)
super().__init__(self.name, self.type, self.area0, self.vce,
data_source=data_source, cl_data=cl_data, cd_data=cd_data,
sail_type=sail_type)
self.measure()

def measure(self, rfm=1, ftj=1):
"""
Update mainsail dimensions for reef state.

Parameters
----------
rfm : float
Reef factor for mainsail (0 to 1). 1 = fully unreefed.
ftj : float
Furl factor for jib (unused for mainsail, present for interface
compatibility).
"""
self.P_r = self.P*rfm
self.vce = self.P_r / 3.0 * (1 + self.roach) + self.BAD
self.area = self.area0*rfm**2
self.CE = 1.


class Jib(Sail):
def __init__(self, name, I, J, LPG, HBI):
def __init__(self, name, I, J, LPG, HBI, data_source="orc",
cl_data=None, cd_data=None, sail_type=None):
"""
Headsail (jib/genoa).

Parameters
----------
name : str
Sail identifier (e.g. "J1").
I : float
Forestay height (m).
J : float
Base of the foretriangle (m).
LPG : float
Luff perpendicular (m).
HBI : float
Height of the jib tack above deck (m).
data_source : str, optional
Coefficient data source. Default "orc".
cl_data : dict, optional
User-provided CL data.
cd_data : dict, optional
User-provided CD data.
sail_type : str, optional
Coefficient variant: ``"jib"`` (default) or ``"jib_low"``.
"""
self.name = name
self.type = "jib"
self.I = I
Expand All @@ -119,27 +231,72 @@ def __init__(self, name, I, J, LPG, HBI):
self.HBI = HBI
self.area = 0.5 * I * max(J, LPG)
self.vce = I / 3.0 + HBI
super().__init__(self.name, self.type, self.area, self.vce)
super().__init__(self.name, self.type, self.area, self.vce,
data_source=data_source, cl_data=cl_data, cd_data=cd_data,
sail_type=sail_type)
self.measure()

def measure(self, rfm=1, ftj=1):
"""
Update jib dimensions for furl state.

Parameters
----------
rfm : float
Reef factor for mainsail (unused for jib, present for interface
compatibility).
ftj : float
Furl factor for jib (0 to 1). 0 = fully unfurled.
"""
self.LPG_r = self.LPG*ftj
self.IG_r = self.IG*ftj
self.area = 0.5 * self.I * max(self.J, self.LPG_r)


class Kite(Sail):
def __init__(self, name, area, vce):
def __init__(self, name, area, vce, data_source="orc",
cl_data=None, cd_data=None, sail_type=None):
"""
Spinnaker or asymmetric downwind sail.

Parameters
----------
name : str
Sail identifier (e.g. "A2", "A5").
area : float
Sail area (m^2).
vce : float
Vertical centre of effort above deck (m).
data_source : str, optional
Coefficient data source. Default "orc".
cl_data : dict, optional
User-provided CL data.
cd_data : dict, optional
User-provided CD data.
sail_type : str, optional
Coefficient variant: ``"kite"`` (default), ``"sym_kite"``,
``"asym_cl_kite"``, or ``"asym_pole_kite"``.
"""
self.name = name
self.type = "kite"
self.area = area
self.min_area = self.area
self.vce = vce
super().__init__(self.name, self.type, self.area, self.vce, up=False)
super().__init__(self.name, self.type, self.area, self.vce, up=False,
data_source=data_source, cl_data=cl_data, cd_data=cd_data,
sail_type=sail_type)
self.measure()

def measure(self, rfm=1, ftj=1):
pass

# class Kite(Sail):
# def __init__(self, SLU, SLE, SFL, SHW, ISP, J, SPL):
# self.type = 'kite'
# area_d = 1.14*np.sqrt(ISP**2+J**2)*max(SPL,J) # only for symm kite
# self.area = max(area_d, 0.5*(SLU+SLE)*(SFL+4*SHW)/6.)
# self.vce = 0.565*ISP # above base of I
# super().__init__(self.type, self.area, self.vce, up=False)

if __name__=="__main__":
pass
Loading