Skip to content

Commit

Permalink
Example to show how to use the lumped mass approach
Browse files Browse the repository at this point in the history
This example is a modified/simplified version of one of the tests we made. As this example is meant to show how to use this new functionality only, I didn't check the results of the example case thoroughly.
  • Loading branch information
lucas-carmo committed Aug 2, 2024
1 parent 75e6d39 commit 27d8659
Show file tree
Hide file tree
Showing 3 changed files with 322 additions and 0 deletions.
Binary file added examples/RAO_fl.pkl
Binary file not shown.
74 changes: 74 additions & 0 deletions examples/lumped_mass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import moorpy as mp
import os
import numpy as np
from moorpy.helpers import lines2subsystem, lines2ss
try:
import pickle5 as pickle
except:
import pickle
import matplotlib.pyplot as plt

def JONSWAP(ws, Hs, Tp, Gamma=None):
'''JONSWAP function copied from RAFT
'''
# If peak shape parameter gamma is not specified, use the recommendation
# from IEC 61400-3 as a function of Hs and Tp. For PM spectrum, use 1.
if not Gamma:
TpOvrSqrtHs = Tp/np.sqrt(Hs)
if TpOvrSqrtHs <= 3.6:
Gamma = 5.0
elif TpOvrSqrtHs >= 5.0:
Gamma = 1.0
else:
Gamma = np.exp( 5.75 - 1.15*TpOvrSqrtHs )

# handle both scalar and array inputs
if isinstance(ws, (list, tuple, np.ndarray)):
ws = np.array(ws)
else:
ws = np.array([ws])

# initialize output array
S = np.zeros(len(ws))


# the calculations
f = 0.5/np.pi * ws # wave frequencies in Hz
fpOvrf4 = pow((Tp*f), -4.0) # a common term, (fp/f)^4 = (Tp*f)^(-4)
C = 1.0 - ( 0.287*np.log(Gamma) ) # normalizing factor
Sigma = 0.07*(f <= 1.0/Tp) + 0.09*(f > 1.0/Tp) # scaling factor

Alpha = np.exp( -0.5*((f*Tp - 1.0)/Sigma)**2 )

return 0.5/np.pi *C* 0.3125*Hs*Hs*fpOvrf4/f *np.exp( -1.25*fpOvrf4 )* Gamma**Alpha



current_dir = os.path.dirname(os.path.abspath(__file__))
ms = mp.System(os.path.join(current_dir, 'volturn_chain.dat'))
ms.initialize()
ms.solveEquilibrium()
# ms = lines2ss(ms) # For cases with multisegment lines, need to convert each of them to a subsystem

# Updates the dynamic matrices of all the lines in the system.
# This function can only properly update the inertia, added mass, and stiffness matrices of each line.
# Though it updates the damping matrix, this is done considering unitary amplitude motions of the nodes and
# no fluid kinematics, so it is not correct.
ms.updateSystemDynamicMatrices()
M, A, B, K_dyn = ms.getCoupledDynamicMatrices() # Get the dynamic matrices of the system
K_qsA = ms.getCoupledStiffnessA(lines_only=True) # We can also compute the stiffness matrix without the lumped mass model. K_dyn should be similar to K_qsa


# Get the dynamic tension along the line
line = ms.lineList[0] # Get the line object
RAO_data = pickle.load(open(os.path.join(current_dir, 'RAO_fl.pkl'), 'rb')) # Read the nFreq x 3 RAO matrix (nFreq x 4 complex numpy array, first column are the frequencies in rad/s)
RAO_fl = RAO_data[:, 1:] # Motion RAOs of the fairlead
w = RAO_data[:, 0] # Frequencies of the RAO data
Sw = JONSWAP(ws = w, Hs = 6, Tp = 8) # Arbitrary wave spectrum
T_nodes_amp, T_nodes_psd,T_nodes_std,s,r_static,r_dynamic,r_total,X = line.dynamicSolve(w, Sw, RAO_A=0,RAO_B=RAO_fl, depth=np.abs(line.rA[2]))

fig, ax = plt.subplots(1, 1)
ax.plot(w, T_nodes_psd[:,-1], '-k')
ax.set_xlabel('Frequency (rad/s)')
ax.set_ylabel('PSD fairlead tension (N^2.s/rad)')
plt.show()
248 changes: 248 additions & 0 deletions examples/volturn_chain.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
--------------------- MoorDyn Input File ------------------------------------
MoorDyn input file
----------------------- LINE TYPES ------------------------------------------
TypeName Diam Mass/m EA BA/-zeta EI Cd Ca CdAx CaAx
(name) (m) (kg/m) (N) (N-s/-) (N-m^2) (-) (-) (-) (-)
chain 3.33000e-01 6.85000e+02 3.27000e+09 -1.00000e+00 0 1.11000e+00 8.20000e-01 2.00000e-01 2.70000e-01
---------------------- POINT PROPERTIES --------------------------------
ID Type X Y Z Mass Volume CdA Ca
(#) (-) (m) (m) (m) (kg) (m^3) (m^2) (-)
1 Vessel -5.80000e+01 0.00000e+00 -1.40000e+01 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
2 Fixed -8.37600e+02 0.00000e+00 -2.00000e+02 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00
---------------------- LINES ----------------------------------------
ID LineType AttachA AttachB UnstrLen NumSegs LineOutputs
(#) (name) (#) (#) (m) (-) (-)
1 chain 2 1 8.50000e+02 50 -
---------------------- OPTIONS -----------------------------------------
2 writeLog Write a log file
0.001 dtM time step to use in mooring integration (s)
3.0e6 kBot bottom stiffness (Pa/m)
3.0e5 cBot bottom damping (Pa-s/m)
1025.0 WtrDnsty water density (kg/m^3)
200.0 WtrDpth water depth (m)
1.0 dtIC time interval for analyzing convergence during IC gen (s)
60.0 TmaxIC max time for ic gen (s)
4.0 CdScaleIC factor by which to scale drag coefficients during dynamic relaxation (-)
0.001 threshIC threshold for IC convergence (-)
------------------------ OUTPUTS --------------------------------------------
FAIRTEN1
POINT1PX
POINT1PY
POINT1PZ
POINT1FX
POINT1FY
POINT1FZ
POINT1T
POINT2PX
POINT2PY
POINT2PZ
POINT2FX
POINT2FY
POINT2FZ
POINT2T
LINE1N0PX
LINE1N0PY
LINE1N0PZ
LINE1N0T
LINE1N1PX
LINE1N1PY
LINE1N1PZ
LINE1N1T
LINE1N2PX
LINE1N2PY
LINE1N2PZ
LINE1N2T
LINE1N3PX
LINE1N3PY
LINE1N3PZ
LINE1N3T
LINE1N4PX
LINE1N4PY
LINE1N4PZ
LINE1N4T
LINE1N5PX
LINE1N5PY
LINE1N5PZ
LINE1N5T
LINE1N6PX
LINE1N6PY
LINE1N6PZ
LINE1N6T
LINE1N7PX
LINE1N7PY
LINE1N7PZ
LINE1N7T
LINE1N8PX
LINE1N8PY
LINE1N8PZ
LINE1N8T
LINE1N9PX
LINE1N9PY
LINE1N9PZ
LINE1N9T
LINE1N10PX
LINE1N10PY
LINE1N10PZ
LINE1N10T
LINE1N11PX
LINE1N11PY
LINE1N11PZ
LINE1N11T
LINE1N12PX
LINE1N12PY
LINE1N12PZ
LINE1N12T
LINE1N13PX
LINE1N13PY
LINE1N13PZ
LINE1N13T
LINE1N14PX
LINE1N14PY
LINE1N14PZ
LINE1N14T
LINE1N15PX
LINE1N15PY
LINE1N15PZ
LINE1N15T
LINE1N16PX
LINE1N16PY
LINE1N16PZ
LINE1N16T
LINE1N17PX
LINE1N17PY
LINE1N17PZ
LINE1N17T
LINE1N18PX
LINE1N18PY
LINE1N18PZ
LINE1N18T
LINE1N19PX
LINE1N19PY
LINE1N19PZ
LINE1N19T
LINE1N20PX
LINE1N20PY
LINE1N20PZ
LINE1N20T
LINE1N21PX
LINE1N21PY
LINE1N21PZ
LINE1N21T
LINE1N22PX
LINE1N22PY
LINE1N22PZ
LINE1N22T
LINE1N23PX
LINE1N23PY
LINE1N23PZ
LINE1N23T
LINE1N24PX
LINE1N24PY
LINE1N24PZ
LINE1N24T
LINE1N25PX
LINE1N25PY
LINE1N25PZ
LINE1N25T
LINE1N26PX
LINE1N26PY
LINE1N26PZ
LINE1N26T
LINE1N27PX
LINE1N27PY
LINE1N27PZ
LINE1N27T
LINE1N28PX
LINE1N28PY
LINE1N28PZ
LINE1N28T
LINE1N29PX
LINE1N29PY
LINE1N29PZ
LINE1N29T
LINE1N30PX
LINE1N30PY
LINE1N30PZ
LINE1N30T
LINE1N31PX
LINE1N31PY
LINE1N31PZ
LINE1N31T
LINE1N32PX
LINE1N32PY
LINE1N32PZ
LINE1N32T
LINE1N33PX
LINE1N33PY
LINE1N33PZ
LINE1N33T
LINE1N34PX
LINE1N34PY
LINE1N34PZ
LINE1N34T
LINE1N35PX
LINE1N35PY
LINE1N35PZ
LINE1N35T
LINE1N36PX
LINE1N36PY
LINE1N36PZ
LINE1N36T
LINE1N37PX
LINE1N37PY
LINE1N37PZ
LINE1N37T
LINE1N38PX
LINE1N38PY
LINE1N38PZ
LINE1N38T
LINE1N39PX
LINE1N39PY
LINE1N39PZ
LINE1N39T
LINE1N40PX
LINE1N40PY
LINE1N40PZ
LINE1N40T
LINE1N41PX
LINE1N41PY
LINE1N41PZ
LINE1N41T
LINE1N42PX
LINE1N42PY
LINE1N42PZ
LINE1N42T
LINE1N43PX
LINE1N43PY
LINE1N43PZ
LINE1N43T
LINE1N44PX
LINE1N44PY
LINE1N44PZ
LINE1N44T
LINE1N45PX
LINE1N45PY
LINE1N45PZ
LINE1N45T
LINE1N46PX
LINE1N46PY
LINE1N46PZ
LINE1N46T
LINE1N47PX
LINE1N47PY
LINE1N47PZ
LINE1N47T
LINE1N48PX
LINE1N48PY
LINE1N48PZ
LINE1N48T
LINE1N49PX
LINE1N49PY
LINE1N49PZ
LINE1N49T
LINE1N50PX
LINE1N50PY
LINE1N50PZ
LINE1N50T
END
------------------------- need this line --------------------------------------

0 comments on commit 27d8659

Please sign in to comment.