Tutorial 2.4: Deriving the EOM of a 4DOF floating wind turbine#

In this tutorial you will learn to derive the Equations of Motion of a floating offshore wind turbine. The tutorial is quite elaborate, but contains large portions of example code to fully understand so that it can be applied in other offshore application projects

We will schematize the floating wind turbine as follows:

  • A rigid body, assumed rectangular, for all floaters together

    • \(L\) = 50 m, \(B\) = 50m, \(H\) = 10 m, average density \(\rho\) = 500 kg/m3

    • With horizontal anchor stiffness of 10 MN/m, and no vertical/rotational anchor stiffness. The anchor is attatched at the centre of the floater.

    • With 3 DOF: surge, heave, roll

  • A turbine point mass connected via a rigid beam (assumed of negligible mass) and a rotational spring

    • \(L_{tower}\) = 200 m, \(m_{turbine}\) = 12.000 kg

    • A rotational spring of stiffness 15 GNm/rad

    • Located at 3/4 from the left of the substructure.

  • Loaded by

    • Wind

    • Waves

Assume seawater of \(\rho_{water}\) = 1025 kg/m3. The full system is without damping. We also assume small displacements. Additionally this means that the water forces are not dependent on the ship position in time.

Part 1: Kinematic equations#

We first start by defining the variables.

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
from sympy import *

var("t x_s z_s phi_s phi_t")      
# x_s substructure surge, z_s heave, phi_s roll, phi_t tower angle (to vertical)
x_s = Function("x_s")(t)
z_s = Function("z_s")(t)
phi_s = Function("phi_s")(t)
phi_t = Function("phi_t")(t)
# Define the kinematic relations here

# contants needed
var("x_st z_st L_t")
# dx_st hotizontal distance substructure centre to tower base
# dz_st vertica distance, L_t tower length

# positions of nacelle
x_t = x_s + x_st*cos(phi_s) - z_st*sin(phi_s) - L_t*sin(phi_t)
z_t = z_s + x_st*sin(phi_s) + z_st*cos(phi_s) + L_t*cos(phi_t)

# for energy relations later
phi_st = phi_s - phi_t

The velocities can then be obtained using:

# Compute/define the velocities here
x_s_dot = diff(x_s, t)
z_s_dot = diff(z_s, t)
phi_s_dot = diff(phi_s, t)
x_t_dot = diff(x_t, t)
z_t_dot = diff(z_t, t)
phi_t_dot = diff(phi_t, t) # will not be sued for point masses
phi_st_dot = diff(phi_st, t) # velocity will not be used

Part 2: Energy equations#

Kinetic energy:#

There are 2 masses in this system. The substructure also has some rotational inertia.

var("rho_s B_s H_s W_s m_t")
# substructure density, breadth, height, width; turbine mass

# Define the kinetic energy here (T)
m_s = rho_s*B_s*H_s*W_s
J_s = 1/12*m_s*(B_s**2 + H_s**2)
T_s = 1/2*m_s*(x_s_dot**2 + z_s_dot**2) + 1/2*J_s*(phi_s_dot**2)
T_t = 1/2*m_t*(x_t_dot**2 + z_t_dot**2) + 1/2*0*(phi_t_dot**2) # point mass so J_t = 0
T = T_s+T_t

Potential energy:#

var("rho_w g kr_st k_h")
# water density, rotational spring stiffness
# Define the potential energy here (V)

k_s = B_s*W_s*rho_w

draft_s = (B_s*W_s*H_s*rho_s)/(B_s*W_s*rho_w)
KB_s = draft_s/2 # COB, due to constant shape
nabla_s = B_s*W_s*draft_s # Submerged volume, taken in neutral position
J_sub = 1/12*W_s*B_s**3
BM_s = J_sub/nabla_s
KG_s = H_s/2 # COG, due to uniform weight
GM_s = KB_s + BM_s - KG_s
kr_s = rho_w*g*nabla_s*GM_s # Nm/rad

V_s = m_s*g*z_s + 1/2*k_h*x_s**2 + 1/2*k_s*z_s**2 + 1/2*kr_s*phi_s**2
V_t = m_t*g*z_t + 1/2*kr_st*phi_st**2 # need relative angle for this spring
V = V_s + V_t

Work by external force#

The work done by an external force working in the horizontal directio. The forces act on block 1 and 2 respectively

F_wave = Function("F_wave")(t)
M_wave = Function("M_wave")(t)
F_wind = Function("F_wind")(t)

# Define your external work here (W)
W = F_wave*z_s + M_wave*phi_s + F_wind*x_t

Step 3: Construct the Lagrangian#

# Define your Lagrangian here (L)
L = T - V - W

Step 4: Obtaining the EoM#

In order to obtain the EoMs we have to take derivatives w.r.t. \(x_1\) and its velocity, as well as \(x_2\).

# Compute the EOM here
EOM_x_s = diff( diff(L, x_s_dot), t) - diff(L, x_s)
EOM_z_s = diff( diff(L, z_s_dot), t) - diff(L, z_s)
EOM_phi_s = diff( diff(L, phi_s_dot), t) - diff(L, phi_s)
EOM_phi_t = diff( diff(L, phi_t_dot), t) - diff(L, phi_t)

The equations are nonlinear since they depend on the cosines and sindes of the angles. We want to obtain a linear function, so let’s linearize. We consider a perturbation around the point we want to linearize.

On a technical note: Using SymPy for function substitution can be tricky, hence we will use temporary symbols called tmp in order to do the substitution.

# dictionaries for substitution
var("x_s_0 x_s_epsilon")
tmp1_x_s = symbols("tmp1_x_s")
psi_x_s = Function("psi_x_s")(t) # perturbation function
tmp2_x_s = symbols("tmp2_x_s")

var("z_s_0 z_s_epsilon")
psi_z_s = Function("psi_z_s")(t) # perturbation function
tmp1_z_s = symbols("tmp1_z_s")
tmp2_z_s = symbols("tmp2_z_s")

var("phi_s_0 phi_s_epsilon")
psi_phi_s = Function("psi_phi_s")(t) # perturbation function
tmp1_phi_s = symbols("tmp1_phi_s")
tmp2_phi_s = symbols("tmp2_phi_s")

var("phi_t_0 phi_t_epsilon")
psi_phi_t = Function("psi_phi_t")(t) # perturbation function
tmp1_phi_t = symbols("tmp1_phi_t")
tmp2_phi_t = symbols("tmp2_phi_t")

subs1_dict = {x_s: tmp1_x_s, z_s: tmp1_z_s, phi_s: tmp1_phi_s, phi_t: tmp1_phi_t}
subs2_dict = {tmp1_x_s: x_s_0 + x_s_epsilon*psi_x_s,
              tmp1_z_s: z_s_0 + z_s_epsilon*psi_z_s,
              tmp1_phi_s: phi_s_0 + phi_s_epsilon*psi_phi_s,
              tmp1_phi_t: phi_t_0 + phi_t_epsilon*psi_phi_t}
subs3_dict = {diff(x_s, (t, 2)): tmp2_x_s, x_s: tmp1_x_s,
              diff(z_s, (t, 2)): tmp2_z_s, z_s: tmp1_z_s,
              diff(phi_s, (t, 2)): tmp2_phi_s, phi_s: tmp1_phi_s,
              diff(phi_t, (t, 2)): tmp2_phi_t, phi_t: tmp1_phi_t}
subs4_dict = {tmp2_x_s: diff(x_s_0 + x_s_epsilon*psi_x_s, (t, 2)), tmp1_x_s: x_s_0 + x_s_epsilon*psi_x_s,
              tmp2_z_s: diff(z_s_0 + z_s_epsilon*psi_z_s, (t, 2)), tmp1_z_s: z_s_0 + z_s_epsilon*psi_z_s,
              tmp2_phi_s: diff(phi_s_0 + phi_s_epsilon*psi_phi_s, (t, 2)), tmp1_phi_s: phi_s_0 + phi_s_epsilon*psi_phi_s,
              tmp2_phi_t: diff(phi_t_0 + phi_t_epsilon*psi_phi_t, (t, 2)), tmp1_phi_t: phi_t_0 + phi_t_epsilon*psi_phi_t}
epsilons_dict = {x_s_epsilon: 1, z_s_epsilon: 1, phi_s_epsilon: 1, phi_t_epsilon: 1}


startpos_dict = {x_s_0: 0, z_s_0: 0, phi_s_0: 0, phi_t_0: 0}
# x_s
EOM_psi_x_s = EOM_x_s.evalf(subs=subs1_dict)
EOM_psi_x_s = EOM_psi_x_s.evalf(subs=subs2_dict)
EOM_lin_x_s = series(EOM_psi_x_s, x_s_epsilon, n=2)

EOM_psi2_x_s = EOM_x_s.evalf(subs=subs3_dict)
EOM_psi2_x_s = EOM_psi2_x_s.evalf(subs=subs4_dict)
EOM_lin_x_s = series(EOM_psi2_x_s, x_s_epsilon, n=2)

EOM_lin_x_s = EOM_lin_x_s.removeO().evalf(subs=epsilons_dict)
EOM_lin_x_s_simplified = EOM_lin_x_s.evalf(subs=startpos_dict) # makes symbolic calcs easier
EOM_lin_x_s_iso = solve(EOM_lin_x_s_simplified, diff(psi_x_s, (t, 2)))

x_s_dotdot = EOM_lin_x_s_iso[0].evalf(subs=startpos_dict)
# z_s
EOM_psi_z_s = EOM_z_s.evalf(subs=subs1_dict)
EOM_psi_z_s = EOM_psi_z_s.evalf(subs=subs2_dict)
EOM_lin_z_s = series(EOM_psi_z_s, z_s_epsilon, n=2)

EOM_psi2_z_s = EOM_z_s.evalf(subs=subs3_dict)
EOM_psi2_z_s = EOM_psi2_z_s.evalf(subs=subs4_dict)
EOM_lin_z_s = series(EOM_psi2_z_s, z_s_epsilon, n=2)

EOM_lin_z_s = EOM_lin_z_s.removeO().evalf(subs=epsilons_dict)
EOM_lin_z_s_simplified = EOM_lin_z_s.evalf(subs=startpos_dict) # makes symbolic calcs easier
EOM_lin_z_s_iso = solve(EOM_lin_z_s_simplified, diff(psi_z_s, (t, 2)))

z_s_dotdot = EOM_lin_z_s_iso[0].evalf(subs=startpos_dict)
# phi_s

EOM_psi_phi_s = EOM_phi_s.evalf(subs=subs1_dict)
EOM_psi_phi_s = EOM_psi_phi_s.evalf(subs=subs2_dict)
EOM_lin_phi_s = series(EOM_psi_phi_s, phi_s_epsilon, n=2)

EOM_psi2_phi_s = EOM_phi_s.evalf(subs=subs3_dict)
EOM_psi2_phi_s = EOM_psi2_phi_s.evalf(subs=subs4_dict)
EOM_lin_phi_s = series(EOM_psi2_phi_s, phi_s_epsilon, n=2)

EOM_lin_phi_s = EOM_lin_phi_s.removeO().evalf(subs=epsilons_dict)
EOM_lin_phi_s_simplified = EOM_lin_phi_s.evalf(subs=startpos_dict) # makes symbolic calcs easier
EOM_lin_phi_s_iso = solve(EOM_lin_phi_s_simplified, diff(psi_phi_s, (t, 2)))

phi_s_dotdot = EOM_lin_phi_s_iso[0].evalf(subs=startpos_dict)
# phi_t

EOM_psi_phi_t = EOM_phi_t.evalf(subs=subs1_dict)
EOM_psi_phi_t = EOM_psi_phi_t.evalf(subs=subs2_dict)
EOM_lin_phi_t = series(EOM_psi_phi_t, phi_t_epsilon, n=2)

EOM_psi2_phi_t = EOM_phi_t.evalf(subs=subs3_dict)
EOM_psi2_phi_t = EOM_psi2_phi_t.evalf(subs=subs4_dict)
EOM_lin_phi_t = series(EOM_psi2_phi_t, phi_t_epsilon, n=2)

EOM_lin_phi_t = EOM_lin_phi_t.removeO().evalf(subs=epsilons_dict)
EOM_lin_phi_t_simplified = EOM_lin_phi_t.evalf(subs=startpos_dict) # makes symbolic calcs easier
EOM_lin_phi_t_iso = solve(EOM_lin_phi_t_simplified, diff(psi_phi_t, (t, 2)))

phi_t_dotdot = EOM_lin_phi_t_iso[0].evalf(subs=startpos_dict)

Now we isolate it for the acceleration. Then we convert the EOM to matrices for easier interpretation.

var("acc1 acc2 acc3 acc4 vel1 vel2 vel3 vel4")

dict_values = { Derivative(psi_x_s, (t,2)): acc1,
                Derivative(psi_z_s, (t,2)): acc2,
                Derivative(psi_phi_s, (t,2)): acc3,
                Derivative(psi_phi_t, (t,2)): acc4,
                Derivative(psi_x_s, t): vel1,
                Derivative(psi_z_s, t): vel2,
                Derivative(psi_phi_s, t): vel3,
                Derivative(psi_phi_t, t): vel4}

EOM_1 = EOM_lin_x_s_simplified.evalf(subs=dict_values)
EOM_2 = EOM_lin_z_s_simplified.evalf(subs=dict_values)
EOM_3 = EOM_lin_phi_s_simplified.evalf(subs=dict_values)
EOM_4 = EOM_lin_phi_t_simplified.evalf(subs=dict_values)

MTRX = linear_eq_to_matrix([EOM_1, EOM_2, EOM_3, EOM_4],
                           [acc1, acc2, acc3, acc4])
# Note: The results per line are the same af from for example EOM_lin_phi_t_iso

M = MTRX[0]
F = MTRX[1]
M
\[\begin{split}\displaystyle \left[\begin{matrix}1.0 B_{s} H_{s} W_{s} \rho_{s} + 1.0 m_{t} & 0 & - 1.0 m_{t} x_{st} \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} - 1.0 m_{t} z_{st} \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} & - 1.0 L_{t} m_{t} \cos{\left(\psi_{\phi t}{\left(t \right)} \right)}\\0 & 1.0 B_{s} H_{s} W_{s} \rho_{s} + 1.0 m_{t} & 1.0 m_{t} x_{st} \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} - 1.0 m_{t} z_{st} \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} & - 1.0 L_{t} m_{t} \sin{\left(\psi_{\phi t}{\left(t \right)} \right)}\\- 1.0 m_{t} x_{st} \psi_{\phi s}{\left(t \right)} - 1.0 m_{t} z_{st} & 1.0 m_{t} x_{st} - 1.0 m_{t} z_{st} \psi_{\phi s}{\left(t \right)} & 0.0833333333333333 B_{s}^{3} H_{s} W_{s} \rho_{s} + 0.0833333333333333 B_{s} H_{s}^{3} W_{s} \rho_{s} + 1.0 m_{t} x_{st}^{2} + 1.0 m_{t} z_{st}^{2} & 1.0 L_{t} m_{t} x_{st} \psi_{\phi s}{\left(t \right)} \cos{\left(\psi_{\phi t}{\left(t \right)} \right)} - 1.0 L_{t} m_{t} x_{st} \sin{\left(\psi_{\phi t}{\left(t \right)} \right)} + 1.0 L_{t} m_{t} z_{st} \psi_{\phi s}{\left(t \right)} \sin{\left(\psi_{\phi t}{\left(t \right)} \right)} + 1.0 L_{t} m_{t} z_{st} \cos{\left(\psi_{\phi t}{\left(t \right)} \right)}\\- 1.0 L_{t} m_{t} & - 1.0 L_{t} m_{t} \psi_{\phi t}{\left(t \right)} & - 1.0 L_{t} m_{t} x_{st} \psi_{\phi t}{\left(t \right)} \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} + 1.0 L_{t} m_{t} x_{st} \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} + 1.0 L_{t} m_{t} z_{st} \psi_{\phi t}{\left(t \right)} \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} + 1.0 L_{t} m_{t} z_{st} \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} & 1.0 L_{t}^{2} m_{t}\end{matrix}\right]\end{split}\]
F
\[\begin{split}\displaystyle \left[\begin{matrix}- 1.0 L_{t} m_{t} vel_{4}^{2} \sin{\left(\psi_{\phi t}{\left(t \right)} \right)} - 1.0 k_{h} \psi_{x s}{\left(t \right)} + 1.0 m_{t} vel_{3}^{2} x_{st} \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} - 1.0 m_{t} vel_{3}^{2} z_{st} \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} - F_{wind}{\left(t \right)}\\- B_{s} H_{s} W_{s} g \rho_{s} - 1.0 B_{s} W_{s} \rho_{w} \psi_{z s}{\left(t \right)} + 1.0 L_{t} m_{t} vel_{4}^{2} \cos{\left(\psi_{\phi t}{\left(t \right)} \right)} - g m_{t} + 1.0 m_{t} vel_{3}^{2} x_{st} \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} + 1.0 m_{t} vel_{3}^{2} z_{st} \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} - F_{wave}{\left(t \right)}\\- 0.0833333333333333 B_{s}^{3} W_{s} g \rho_{w} \psi_{\phi s}{\left(t \right)} - \frac{0.5 B_{s} H_{s}^{2} W_{s} g \rho_{s}^{2} \psi_{\phi s}{\left(t \right)}}{\rho_{w}} + 0.5 B_{s} H_{s}^{2} W_{s} g \rho_{s} \psi_{\phi s}{\left(t \right)} + 1.0 L_{t} m_{t} vel_{4}^{2} x_{st} \psi_{\phi s}{\left(t \right)} \sin{\left(\psi_{\phi t}{\left(t \right)} \right)} + 1.0 L_{t} m_{t} vel_{4}^{2} x_{st} \cos{\left(\psi_{\phi t}{\left(t \right)} \right)} - 1.0 L_{t} m_{t} vel_{4}^{2} z_{st} \psi_{\phi s}{\left(t \right)} \cos{\left(\psi_{\phi t}{\left(t \right)} \right)} + 1.0 L_{t} m_{t} vel_{4}^{2} z_{st} \sin{\left(\psi_{\phi t}{\left(t \right)} \right)} - g m_{t} x_{st} + g m_{t} z_{st} \psi_{\phi s}{\left(t \right)} - 1.0 kr_{st} \psi_{\phi s}{\left(t \right)} + 1.0 kr_{st} \psi_{\phi t}{\left(t \right)} + x_{st} F_{wind}{\left(t \right)} \psi_{\phi s}{\left(t \right)} + z_{st} F_{wind}{\left(t \right)} - M_{wave}{\left(t \right)}\\L_{t} g m_{t} \psi_{\phi t}{\left(t \right)} - 1.0 L_{t} m_{t} vel_{3}^{2} x_{st} \psi_{\phi t}{\left(t \right)} \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} - 1.0 L_{t} m_{t} vel_{3}^{2} x_{st} \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} - 1.0 L_{t} m_{t} vel_{3}^{2} z_{st} \psi_{\phi t}{\left(t \right)} \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} + 1.0 L_{t} m_{t} vel_{3}^{2} z_{st} \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} + L_{t} F_{wind}{\left(t \right)} + 1.0 kr_{st} \psi_{\phi s}{\left(t \right)} - 1.0 kr_{st} \psi_{\phi t}{\left(t \right)}\end{matrix}\right]\end{split}\]

As one can see, this system is already linearized. We can therefore immediately start solving the system. In case of a non-linear example, the linearization must be performed for each EOM separately.

Step 4: Solve the equation#

For students looking for a challenge

The student is invited to try and plot a 100s trace of the horizontal and vertical nacelle movement. All relevant info can be find in the previous tutorial on how to use solve_ivp for multiple DOF, and on how to plot the relevant output. The floater is subjected to the following force (in MN):

\[ F_h(t) = 1.25 \cos(0.1 t) + 0.5 \cos(0.5 t - 0.75) + 0.1 \cos(1.3 t + 2.28) \]

Hint: Think about how the nacelle moves. Which DOF contribute to its movement?
Hint: Looking at the force in 1 direction (for the horizontal DOF), which movements do you excpect? Are the DOF coupled? How could one see that in the DOF-matrices?

In practice an irregular wave consits of waves generated from a spectrum, each with their respective amplitude, frequency and/or phase difference. More information is given here. Ask yourself then:

  • Which forces act on the structure?

  • Assuming small deformations, how does a water wave result in a force and moment in time on the structure Think about wave potentials, their pressures, and integration over the area on which the water acts

# Filling in values

L = 50
B = 50
H = 10
rho_ship = 400
L_tower = 200
m_turbine = 12e3
k_r = 15e9
x_r = L/4 # Distance from centre of floater
z_r = H/2
rho_water = 1025
g_val = 9.81
k_anchor = 10e6

def F_h(t):
    return (1.25 * cos(0.1*t) + 0.5*cos(0.5*t - 0.75) + 0.1*cos(1.3*t + 2.28))*10e3

dict_fillin = {B_s: L, H_s:H, W_s:B, m_t: m_turbine, z_st: z_r, x_st: x_r,
               L_t: L_tower, rho_s: rho_ship, g: g_val, rho_w: rho_water,
               F_wind: 0, kr_st: k_r, M_wave: 0, k_h: k_anchor}
M_filled = M.evalf(subs=dict_fillin)
M_filled
\[\begin{split}\displaystyle \left[\begin{matrix}10012000.0 & 0 & - 150000.0 \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} - 60000.0 \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} & - 2400000.0 \cos{\left(\psi_{\phi t}{\left(t \right)} \right)}\\0 & 10012000.0 & - 60000.0 \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} + 150000.0 \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} & - 2400000.0 \sin{\left(\psi_{\phi t}{\left(t \right)} \right)}\\- 150000.0 \psi_{\phi s}{\left(t \right)} - 60000.0 & 150000.0 - 60000.0 \psi_{\phi s}{\left(t \right)} & 2168841666.66667 & 12000000.0 \psi_{\phi s}{\left(t \right)} \sin{\left(\psi_{\phi t}{\left(t \right)} \right)} + 30000000.0 \psi_{\phi s}{\left(t \right)} \cos{\left(\psi_{\phi t}{\left(t \right)} \right)} - 30000000.0 \sin{\left(\psi_{\phi t}{\left(t \right)} \right)} + 12000000.0 \cos{\left(\psi_{\phi t}{\left(t \right)} \right)}\\-2400000.0 & - 2400000.0 \psi_{\phi t}{\left(t \right)} & 12000000.0 \psi_{\phi t}{\left(t \right)} \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} - 30000000.0 \psi_{\phi t}{\left(t \right)} \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} + 30000000.0 \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} + 12000000.0 \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} & 480000000.0\end{matrix}\right]\end{split}\]
F_filled = F.evalf(subs=dict_fillin)
F_filled
\[\begin{split}\displaystyle \left[\begin{matrix}- 60000.0 vel_{3}^{2} \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} + 150000.0 vel_{3}^{2} \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} - 2400000.0 vel_{4}^{2} \sin{\left(\psi_{\phi t}{\left(t \right)} \right)} - 10000000.0 \psi_{x s}{\left(t \right)}\\150000.0 vel_{3}^{2} \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} + 60000.0 vel_{3}^{2} \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} + 2400000.0 vel_{4}^{2} \cos{\left(\psi_{\phi t}{\left(t \right)} \right)} - F_{wave}{\left(t \right)} - 2562500.0 \psi_{z s}{\left(t \right)} - 98217720.0\\30000000.0 vel_{4}^{2} \psi_{\phi s}{\left(t \right)} \sin{\left(\psi_{\phi t}{\left(t \right)} \right)} - 12000000.0 vel_{4}^{2} \psi_{\phi s}{\left(t \right)} \cos{\left(\psi_{\phi t}{\left(t \right)} \right)} + 12000000.0 vel_{4}^{2} \sin{\left(\psi_{\phi t}{\left(t \right)} \right)} + 30000000.0 vel_{4}^{2} \cos{\left(\psi_{\phi t}{\left(t \right)} \right)} - 19937435409.1463 \psi_{\phi s}{\left(t \right)} + 15000000000.0 \psi_{\phi t}{\left(t \right)} - 1471500.0\\- 30000000.0 vel_{3}^{2} \psi_{\phi t}{\left(t \right)} \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} - 12000000.0 vel_{3}^{2} \psi_{\phi t}{\left(t \right)} \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} + 12000000.0 vel_{3}^{2} \sin{\left(\psi_{\phi s}{\left(t \right)} \right)} - 30000000.0 vel_{3}^{2} \cos{\left(\psi_{\phi s}{\left(t \right)} \right)} + 15000000000.0 \psi_{\phi s}{\left(t \right)} - 14976456000.0 \psi_{\phi t}{\left(t \right)}\end{matrix}\right]\end{split}\]
# Initial conditions and solve_ivp
q0 = np.zeros(8)

def qdot(t,q):

    print(t)
    
    vt = q[int(len(q)/2):]

    F_x_s = F_h(t)

    dict_values = { psi_x_s: q[0], psi_z_s: q[1],psi_phi_s: q[2], psi_phi_t: q[3], 
                    vel1: q[4], vel2: q[4], vel3: q[6], vel4: q[7],
                    F_wave: F_x_s}  
    Mass_matr =  M_filled.evalf(subs=dict_values)
    Force_vect = F_filled.evalf(subs=dict_values)
    at = Mass_matr.inv()*Force_vect

    return list(vt) + list(np.transpose(at)[0])

sol = solve_ivp(fun=qdot,t_span=[0,100],y0=q0) # Takes around 6 minutes to run 100 seconds of simulation
0.0
1e-06
1.9999999999999998e-05
2.9999999999999997e-05
7.999999999999999e-05
8.888888888888888e-05
9.999999999999999e-05
9.999999999999999e-05
0.00030000000000000003
0.00039999999999999996
0.0009
0.0009888888888888888
0.0011
0.0011
0.0031000000000000003
0.0041
0.0091
0.00998888888888889
0.0111
0.0111
0.031100000000000003
0.0411
0.09110000000000001
0.09998888888888889
0.1111
0.1111
0.271793766300492
0.352140649450738
0.753875065201968
0.8252945168910755
0.9145688315024599
0.9145688315024599
1.072664136876536
1.1517117895635738
1.5469500529987636
1.6172146331650197
1.7050453583728395
1.7050453583728395
1.02285817335736
1.07700284428481
1.3477261989220604
1.3958547953020162
1.4560155407769606
1.4560155407769606
1.5643048826318608
1.6184495535593109
1.8891729081965614
1.9373015045765167
1.9974622500514614
1.9974622500514614
2.1058234275283247
2.1600040162667566
2.430906959958915
2.4790674832819652
2.539268137435778
2.539268137435778
2.0784767992070643
2.118984073784866
2.3215204466738735
2.3575269129652523
2.4025349958294764
2.4025349958294764
2.4835495449850793
2.524056819562881
2.7265931924518885
2.7625996587432673
2.8076077416074914
2.8076077416074914
2.8824048990159237
2.91980347772014
3.1067963712412205
3.140039552311635
3.181593528649653
3.181593528649653
3.2500888302205486
3.2843364810059965
3.4555747349332355
3.486017091186967
3.5240700365041313
3.5240700365041313
3.592783821142421
3.627140713461566
3.7989251750572905
3.82946463489653
3.8676389596955802
3.8676389596955802
3.964310880731274
4.012646841249121
4.254326643838356
4.297291942076441
4.3509985648740495
4.3509985648740495
3.93272719801245
3.965271317170885
4.12799191296306
4.156920018881668
4.193080151279929
4.193080151279929
4.258168389596799
4.290712508755234
4.4534331045474085
4.482361210466017
4.518521342864278
4.518521342864278
4.584440748214873
4.61740045089017
4.782198964266656
4.811496477755809
4.848118369617251
4.848118369617251
4.944457820777153
4.992627546357103
5.233476174256857
5.276293708105703
5.329815625416759
5.329815625416759
4.91024619257417
4.941310104052629
5.0966296614449265
5.124242027203557
5.158757484401845
5.158757484401845
5.220885307358764
5.251949218837224
5.407268776229521
5.434881141988152
5.46939659918644
5.46939659918644
5.5341784649324754
5.566569397805493
5.728524062170582
5.7573160025021535
5.7933059279166175
5.7933059279166175
5.874202309218608
5.9146504998696035
6.1168914531245795
6.152845400369909
6.19778783442657
6.19778783442657
5.854376915879278
5.8849124098606085
6.03758987976726
6.064732541083998
6.0986608677299206
6.0986608677299206
6.1597318556925815
6.190267349673912
6.342944819580563
6.370087480897301
6.404015807543224
6.404015807543224
6.473634240775971
6.508443457392345
6.682489540474215
6.713431066355436
6.752107973706963
6.752107973706963
6.81899212603397
6.852434202197473
7.019644583014989
7.049370872938103
7.086528735341996
7.086528735341996
7.146784211243605
7.17691194919441
7.327550638948434
7.3543308504602605
7.387806114850044
7.387806114850044
7.4575784125584175
7.492464561412604
7.666895305683539
7.697905215776149
7.736667603391913
7.736667603391913
7.8006476011986665
7.832637600102044
7.992587594618928
8.021023149199706
8.056567592425681
8.056567592425681
8.11556143600056
8.145058357788
8.292542966725199
8.318762452758477
8.351536810300077
8.351536810300077
8.42546599975627
8.462430594484367
8.647253568124848
8.680110985660933
8.72118275758104
8.72118275758104
8.41193545740932
8.442134780963944
8.593131398737054
8.619975241896718
8.653530045846297
8.653530045846297
8.713928692955541
8.744128016510164
8.895124634283274
8.921968477442938
8.955523281392518
8.955523281392518
9.017080905716087
9.047859717877873
9.201753778686799
9.229112722830607
9.263311403010368
9.263311403010368
9.33701759883865
9.373870696752789
9.558136186323493
9.590894495580507
9.631842382151774
9.631842382151774
9.322306210037075
9.35180361355043
9.4992906311172
9.525510545351292
9.558285438143907
9.558285438143907
9.617280245170614
9.646777648683969
9.794264666250738
9.82048458048483
9.853259473277445
9.853259473277445
9.92606715796806
9.962471000313368
10.144490212039907
10.176849183013513
10.217297896730521
10.217297896730521
9.913392412915202
9.943458882734083
10.093791231828478
10.120516982778591
10.153924171466235
10.153924171466235
10.214057111103992
10.244123580922873
10.394455930017267
10.421181680967381
10.454588869655025
10.454588869655025
10.516810591400748
10.547921452273611
10.703475756637923
10.731129855191577
10.765697478383647
10.765697478383647
10.837187914414494
10.872933132429917
11.051659222507034
11.083432749631855
11.123149658537882
11.123149658537882
10.822777330801431
10.851317257010324
10.994016888054785
11.019385711351578
11.05109674047257
11.05109674047257
11.108176592890354
11.136716519099247
11.279416150143708
11.304784973440501
11.336496002561493
11.336496002561493
11.408304515120227
11.444208771399595
11.623730052796429
11.655644947266977
11.695538565355163
11.695538565355163
11.39460381820015
11.423657726019476
11.568927265116116
11.59475296095552
11.627035080754773
11.627035080754773
11.68514289639343
11.714196804212756
11.859466343309396
11.8852920391488
11.917574158948053
11.917574158948053
11.978324455095503
12.00869960316923
12.160575343537857
12.187575475158946
12.221325639685308
12.221325639685308
12.284481003675658
12.316058685670832
12.473947095646707
12.502016146309085
12.537102459637058
12.537102459637058
12.277147379143871
12.305058248873154
12.444612597519564
12.469422259501147
12.500434336978127
12.500434336978127
12.556256076436691
12.584166946165974
12.723721294812384
12.748530956793967
12.779543034270947
12.779543034270947
12.860515922674871
12.901002366876833
13.103434587886644
13.139422538288388
13.184407476290568
13.184407476290568
12.835433015553525
12.863378006194814
13.003102959401257
13.027942951082403
13.058992940683835
13.058992940683835
13.114882921966412
13.1428279126077
13.282552865814145
13.30739285749529
13.338442847096722
13.338442847096722
13.407005508069044
13.441286838555206
13.61269349098601
13.643165784751487
13.681256151958332
13.681256151958332
13.395276293985958
13.423693017430574
13.565776634653663
13.591035944382213
13.622610081542899
13.622610081542899
13.679443528432135
13.70786025187675
13.849943869099839
13.87520317882839
13.906777315989075
13.906777315989075
13.968278245905262
13.999028710863355
14.152781035653822
14.180114782283239
14.21428196557001
14.21428196557001
14.276370707446139
14.307415078384205
14.46263693307453
14.49023192946392
14.524725674950659
14.524725674950659
14.269673745436634
14.297369635369945
14.435849085036505
14.460467653866116
14.49124086490313
14.49124086490313
14.546632644769755
14.574328534703065
14.712807984369626
14.737426553199237
14.76819976423625
14.76819976423625
14.847588080798392
14.887282239079463
15.085753030484815
15.121036726734657
15.165141347046957
15.165141347046957
14.823329567931891
14.850894469779712
14.988718979018815
15.013221113994655
15.043848782714456
15.043848782714456
15.098978586410096
15.126543488257918
15.26436799749702
15.28887013247286
15.31949780119266
15.31949780119266
15.391011126152375
15.42676778863223
15.605551101031512
15.637334801013608
15.677064425991226
15.677064425991226
15.374586269566182
15.402130503752943
15.539851674686744
15.564335438408309
15.594940143060265
15.594940143060265
15.650028611433786
15.677572845620546
15.815294016554349
15.839777780275913
15.87038248492787
15.87038248492787
15.933794107847547
15.965499919307385
16.124028976606578
16.152211920126433
16.187440599526255
16.187440599526255
16.245706397140477
16.274839295947586
16.42050378998314
16.446399700033908
16.478769587597363
16.478769587597363
16.534656065808882
16.562599304914645
16.702315500443447
16.72715393520412
16.758201978654967
16.758201978654967
16.83331774106212
16.870875622265697
17.058665028283578
17.09204981157565
17.133780790690732
17.133780790690732
16.81330015512416
16.840849243358754
16.978594684531735
17.00308276296249
17.03369286100093
17.03369286100093
17.088791037470124
17.116340125704717
17.2540855668777
17.27857364530845
17.309183743346892
17.309183743346892
17.385133586692696
17.4231085083656
17.612983116730113
17.646738602661582
17.688932960075917
17.688932960075917
17.36312902596323
17.390101667271395
17.52496487381223
17.548940554975047
17.578910156428567
17.578910156428567
17.632855439044903
17.65982808035307
17.794691286893904
17.81866696805672
17.84863656951024
17.84863656951024
17.913478185275988
17.94589899315886
18.108003032573222
18.13682152846911
18.17284464833897
18.17284464833897
17.90456713647376
17.932532419955518
18.072358837364312
18.097216867125876
18.12828940432783
18.12828940432783
18.18421997129135
18.212185254773107
18.352011672181902
18.376869701943466
18.40794223914542
18.40794223914542
18.466156116463335
18.495263055122294
18.64079774841708
18.666670582780597
18.699011625734993
18.699011625734993
18.757652294057618
18.786972628218933
18.933574299025498
18.959636818279996
18.992214967348122
18.992214967348122
19.04626632114089
19.073291998037273
19.208420382519193
19.232443206427092
19.262471736311962
19.262471736311962
19.340743854400113
19.37987991344419
19.575560208664566
19.610347816703744
19.653832326752717
19.653832326752717
19.31595263834016
19.342693089354263
19.476395344424763
19.50016463421507
19.52987624645296
19.52987624645296
19.58335714848116
19.610097599495262
19.74379985456576
19.76756914435607
19.79728075659396
19.79728075659396
19.87438713568573
19.912940325231617
20.105706272961044
20.139975774779607
20.182812652052814
20.182812652052814
19.850372153688106
19.87691785223518
20.009646344970548
20.033242521456835
20.062737742064694
20.062737742064694
20.11582913915884
20.142374837705916
20.275103330441283
20.29869950692757
20.32819472753543
20.32819472753543
20.396120380338044
20.43008320673935
20.59989733874589
20.630086517769275
20.667822991548505
20.667822991548505
20.382716665025974
20.409977633771245
20.546282477497606
20.570514449715628
20.60080441498815
20.60080441498815
20.655326352478696
20.682587321223966
20.818892164950327
20.84312413716835
20.873414102440872
20.873414102440872
20.93486387252667
20.96558875756957
21.119213182784062
21.146524191711084
21.18066295286986
21.18066295286986
20.928568683267365
20.95614597368061
21.094032425746835
21.11854557278083
21.149187006573328
21.149187006573328
21.20434158739982
21.231918877813065
21.36980532987929
21.394318476913288
21.424959910705784
21.424959910705784
21.482528548733544
21.511312867747424
21.65523446281682
21.680820524162492
21.71280310084458
21.71280310084458
21.772791289920356
21.802785384458243
21.952755857147682
21.97941727451469
22.012744046223457
22.012744046223457
21.765603506310697
21.792003709043758
21.92400472270905
21.947471569582877
21.976805128175165
21.976805128175165
22.029525508460807
22.055885698603632
22.18768664931774
22.21111792944469
22.240407029603382
22.240407029603382
22.30891237297415
22.343165044659532
22.514428403086452
22.544875222362347
22.58293374645722
22.58293374645722
22.29339251341244
22.31988525531697
22.45234896483961
22.47589806875475
22.505334448648668
22.505334448648668
22.558319932457724
22.584812674362254
22.717276383884897
22.740825487800034
22.770261867693954
22.770261867693954
22.845231812929487
22.882716785547252
23.070141648636085
23.103461624296322
23.14511159387162
23.14511159387162
22.821726765456493
22.84745921433776
22.976121458744107
22.99899474663857
23.027586356506646
23.027586356506646
23.079016872321436
23.104732130228832
23.233308419765812
23.256166426794607
23.284738935580602
23.284738935580602
23.3591353037843
23.396333487886146
23.582324408395387
23.615389460930363
23.656720776599084
23.656720776599084
23.33711434102027
23.363302043740106
23.494240557339282
23.517518515312467
23.54661596277895
23.54661596277895
23.59899136821862
23.625179070938454
23.75611758453763
23.779395542510816
23.8084929899773
23.8084929899773
23.87828904855791
23.913187077848214
24.087677224299735
24.118697694780007
24.157473282880346
24.157473282880346
23.859826289433745
23.885492939161967
24.013826187803076
24.036640987561498
24.06515948725952
24.06515948725952
24.116492786715966
24.14215943644419
24.270492685085298
24.29330748484372
24.321825984541743
24.321825984541743
24.387475973850307
24.420300968504588
24.584425941775994
24.61360371480202
24.650075931084558
24.650075931084558
24.374484075839778
24.400813121488795
24.53245834973388
24.55586194586634
24.585116441031914
24.585116441031914
24.63777453232995
24.664103577978967
24.79574880622405
24.81915240235651
24.848406897522086
24.848406897522086
24.910614318042988
24.94171802830344
25.0972365796057
25.124884322059433
25.1594440001266
25.1594440001266
24.90038497034717
24.926374006759712
25.05631918882242
25.079420554522457
25.108297261647504
25.108297261647504
25.160275334472587
25.18626437088513
25.31620955294784
25.339310918647875
25.368187625772922
25.368187625772922
25.426981219809193
25.456378016827326
25.603362001918
25.629492488156345
25.66215559595427
25.66215559595427
25.715287596485524
25.741853596751152
25.87468359807929
25.898297820537625
25.927815598610543
25.927815598610543
25.983499566887343
26.01134155102574
26.150551471717733
26.175299902062978
26.206235439994533
26.206235439994533
26.264311208957345
26.29334909343875
26.438538515845778
26.46434996871814
26.49661428480859
26.49661428480859
26.54902536250917
26.575230901359458
26.7062585956109
26.72955240792227
26.75866967331148
26.75866967331148
26.827815470547332
26.86238836916526
27.035252862254893
27.065984327693048
27.104398659490744
27.104398659490744
26.8111302960124
26.83736060736286
26.968512164115158
26.99182799642668
27.020972786816078
27.020972786816078
27.073433409516998
27.099663720867458
27.230815277619755
27.254131109931276
27.283275900320675
27.283275900320675
27.358063105468233
27.395456708042012
27.58242472091091
27.61566347875427
27.65721192605847
27.65721192605847
27.334129594741203
27.359556441951465
27.48669067800278
27.50929231996746
27.53754437242331
27.53754437242331
27.588398066843837
27.6138249140541
27.740959150105414
27.763560792070095
27.791812844525943
27.791812844525943
27.86566620003107
27.902592877783636
28.087226266546455
28.12004998010429
28.161079622051584
28.161079622051584
27.84354396105112
27.869409519313713
27.99873731062666
28.02172891797118
28.050468427151838
28.050468427151838
28.102199543677017
28.128065101939605
28.257392893252554
28.280384500597076
28.309124009777733
28.309124009777733
28.38090566970449
28.416796499667868
28.59625064948476
28.628153609452205
28.668032309411515
28.668032309411515
28.359053016255977
28.3840175194951
28.508840035690707
28.531030705236592
28.55876904216895
28.55876904216895
28.608698048647195
28.633662551886317
28.758485068081924
28.78067573762781
28.80841407456017
28.80841407456017
28.876896060400924
28.9111370533213
29.082342017923192
29.11277845607464
29.150824003763947
29.150824003763947
28.85949513875369
28.88503567085045
29.012738331334255
29.035441026531377
29.063819395527776
29.063819395527776
29.114900459721298
29.14044099181806
29.268143652301863
29.290846347498984
29.319224716495384
29.319224716495384
29.387219726264146
29.42121723114853
29.591204755570438
29.62142475991211
29.6591997653392
29.6591997653392
29.369006473866367
29.39389735255186
29.518351745979317
29.54047697147753
29.5681335033503
29.5681335033503
29.617915260721283
29.642806139406773
29.767260532834232
29.789385758332447
29.817042290205215
29.817042290205215
29.883606690885035
29.916888891224943
30.083299892924487
30.11288407100441
30.149864293604306
30.149864293604306
29.867800242829194
29.893179219141185
30.020074100701134
30.042633190756234
30.070832053325113
30.070832053325113
30.12159000594909
30.146968982261082
30.27386386382103
30.29642295387613
30.32462181644501
30.32462181644501
30.391267680248472
30.424590612150205
30.591205271658858
30.620825655571508
30.65785113546232
30.65785113546232
30.37436711904096
30.39923977033894
30.523603026828823
30.545712050204802
30.573348329424775
30.573348329424775
30.623093632020726
30.647966283318706
30.772329539808588
30.794438563184567
30.82207484240454
30.82207484240454
30.88813097388317
30.92115903962249
31.086299368319075
31.115657648976246
31.152355499797707
31.152355499797707
30.87266190261236
30.897955432716273
31.024423083235824
31.046906221105967
31.075010143443645
31.075010143443645
31.125597203651466
31.150890733755375
31.27735838427493
31.299841522145073
31.32794544448275
31.32794544448275
31.394145625121958
31.42724571544156
31.592746167039575
31.62216846954589
31.658946347678782
31.658946347678782
31.377724878326354
31.40261459524816
31.527063179857173
31.549187372676553
31.576842613700776
31.576842613700776
31.62662204754438
31.651511764466186
31.7759603490752
31.79808454189458
31.825739782918802
31.825739782918802
31.89112364089405
31.92381556988168
32.087275214819805
32.116334707253245
32.15265907279505
32.15265907279505
31.87570529574259
31.900688052154486
32.02560183421396
32.04780872880231
32.07556734703775
32.07556734703775
32.125532859861536
32.15051561627343
32.2754293983329
32.297636292921254
32.32539491115669
32.32539491115669
32.39240109699268
32.425904189910675
32.59341965450064
32.623200181538856
32.66042584033663
32.66042584033663
32.37587650700439
32.40111730492825
32.527321294547505
32.5497575593687
32.577802890395205
32.577802890395205
32.628284486242904
32.65352528416676
32.77972927378602
32.80216553860721
32.83021086963372
32.83021086963372
32.89731512682575
32.930867255421774
33.09862789840186
33.12845201270943
33.16573215559389
33.16573215559389
32.88008161913398
32.90501699388411
33.02969386763477
33.05185864519044
33.079564617135034
33.079564617135034
33.12940845603358
33.15433037548285
33.278939972729205
33.30109279001745
33.32878381162775
33.32878381162775
33.396204981745065
33.42991556680372
33.59846849209701
33.6284334565936
33.665889662214326
33.665889662214326
33.38001403303256
33.405629143734956
33.53370469724697
33.556473684538
33.584934918651776
33.584934918651776
33.63616514005658
33.66178025075898
33.78985580427099
33.81262479156202
33.8410860256758
33.8410860256758
33.907698098385424
33.94100413474024
34.1075343165143
34.13713968216302
34.17414638922392
34.17414638922392
33.891120397033156
33.91613758271183
34.041223511105215
34.06346100948626
34.09125788246257
34.09125788246257
34.14129225381993
34.166309439498605
34.29139536789199
34.31363286627303
34.34142973924934
34.34142973924934
34.406411635559195
34.438902583714125
34.60135732448877
34.63023816729314
34.66633922079862
34.66633922079862
34.39270671358409
34.41834520075146
34.546537636588326
34.569327402959324
34.59781461092307
34.59781461092307
34.64909158525782
34.67473007242519
34.80292250826206
34.825712274633055
34.854199482596805
34.854199482596805
34.91766417882602
34.949396526940625
35.10805826751366
35.136264799171094
35.17152296374288
35.17152296374288
34.90338743754653
34.92798141502139
35.0509513023957
35.07281261570669
35.100139257345425
35.100139257345425
35.14932721229515
35.17392118977001
35.29689107714432
35.31875239045531
35.346079032094046
35.346079032094046
35.40826843451686
35.43936313572827
35.594836641785314
35.62247637619546
35.65702604420813
35.65702604420813
35.3965425118311
35.42177425169963
35.54793295104226
35.570361164258735
35.59839643077932
35.59839643077932
35.64885991051637
35.674091650384895
35.800250349727534
35.822678562944006
35.85071382946459
35.85071382946459
35.91293431107913
35.94404455188639
36.09959575592273
36.12724930330697
36.161816237537266
36.161816237537266
35.899985115425046
35.924620758405275
36.04779897330641
36.069697322622176
36.09707025926687
36.09707025926687
36.14634154522733
36.17097718820756
36.2941554031087
36.31605375242446
36.343426689069155
36.343426689069155
36.405583478665804
36.436661873464125
36.592053847455745
36.61967908727648
36.654210637052394
36.654210637052394
36.39295475981306
36.41771879518501
36.541538972044776
36.563551447930955
36.59106704278868
36.59106704278868
36.640595113532584
36.665359148904535
36.7891793257643
36.81119180165048
36.838707396508205
36.838707396508205
36.902183607674374
36.93392171325746
37.09261224117288
37.12082389058006
37.15608845233905
37.15608845233905
36.88793301362874
36.912545822189
37.035609864990334
37.05748791704391
37.08483548211087
37.08483548211087
37.1340610992314
37.158673907791666
37.281737950593
37.30361600264657
37.33096356771353
37.33096356771353
37.39578853226846
37.428201014545934
37.590263425933266
37.61907452129101
37.655088390488196
37.655088390488196
37.3799951119476
37.40451088406463
37.52708974464979
37.54888154208716
37.57612128888386
37.57612128888386
37.62515283311793
37.64966860523496
37.77224746582012
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/core/evalf.py:1481, in evalf(x, prec, options)
   1480 try:
-> 1481     rf = evalf_table[type(x)]
   1482     r = rf(x, prec, options)

KeyError: psi_phi_t

During handling of the above exception, another exception occurred:

KeyboardInterrupt                         Traceback (most recent call last)
Cell In[20], line 21
     17     at = Mass_matr.inv()*Force_vect
     19     return list(vt) + list(np.transpose(at)[0])
---> 21 sol = solve_ivp(fun=qdot,t_span=[0,100],y0=q0) # Takes around 6 minutes to run 100 seconds of simulation

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/scipy/integrate/_ivp/ivp.py:591, in solve_ivp(fun, t_span, y0, method, t_eval, dense_output, events, vectorized, args, **options)
    589 status = None
    590 while status is None:
--> 591     message = solver.step()
    593     if solver.status == 'finished':
    594         status = 0

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/scipy/integrate/_ivp/base.py:181, in OdeSolver.step(self)
    179 else:
    180     t = self.t
--> 181     success, message = self._step_impl()
    183     if not success:
    184         self.status = 'failed'

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/scipy/integrate/_ivp/rk.py:144, in RungeKutta._step_impl(self)
    141 h = t_new - t
    142 h_abs = np.abs(h)
--> 144 y_new, f_new = rk_step(self.fun, t, y, self.f, h, self.A,
    145                        self.B, self.C, self.K)
    146 scale = atol + np.maximum(np.abs(y), np.abs(y_new)) * rtol
    147 error_norm = self._estimate_error_norm(self.K, h, scale)

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/scipy/integrate/_ivp/rk.py:64, in rk_step(fun, t, y, f, h, A, B, C, K)
     62 for s, (a, c) in enumerate(zip(A[1:], C[1:]), start=1):
     63     dy = np.dot(K[:s].T, a[:s]) * h
---> 64     K[s] = fun(t + c * h, y + dy)
     66 y_new = y + h * np.dot(K[:-1].T, B)
     67 f_new = fun(t + h, y_new)

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/scipy/integrate/_ivp/base.py:138, in OdeSolver.__init__.<locals>.fun(t, y)
    136 def fun(t, y):
    137     self.nfev += 1
--> 138     return self.fun_single(t, y)

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/scipy/integrate/_ivp/base.py:20, in check_arguments.<locals>.fun_wrapped(t, y)
     19 def fun_wrapped(t, y):
---> 20     return np.asarray(fun(t, y), dtype=dtype)

Cell In[20], line 16, in qdot(t, q)
     12 dict_values = { psi_x_s: q[0], psi_z_s: q[1],psi_phi_s: q[2], psi_phi_t: q[3], 
     13                 vel1: q[4], vel2: q[4], vel3: q[6], vel4: q[7],
     14                 F_wave: F_x_s}  
     15 Mass_matr =  M_filled.evalf(subs=dict_values)
---> 16 Force_vect = F_filled.evalf(subs=dict_values)
     17 at = Mass_matr.inv()*Force_vect
     19 return list(vt) + list(np.transpose(at)[0])

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/matrices/common.py:2031, in MatrixOperations.evalf(self, n, subs, maxn, chop, strict, quad, verbose)
   2028 """Apply evalf() to each element of self."""
   2029 options = {'subs':subs, 'maxn':maxn, 'chop':chop, 'strict':strict,
   2030         'quad':quad, 'verbose':verbose}
-> 2031 return self.applyfunc(lambda i: i.evalf(n, **options))

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/matrices/common.py:1989, in MatrixOperations.applyfunc(self, f)
   1986 if not callable(f):
   1987     raise TypeError("`f` must be callable.")
-> 1989 return self._eval_applyfunc(f)

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/matrices/common.py:1931, in MatrixOperations._eval_applyfunc(self, f)
   1930 def _eval_applyfunc(self, f):
-> 1931     out = self._new(self.rows, self.cols, [f(x) for x in self])
   1932     return out

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/matrices/common.py:1931, in <listcomp>(.0)
   1930 def _eval_applyfunc(self, f):
-> 1931     out = self._new(self.rows, self.cols, [f(x) for x in self])
   1932     return out

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/matrices/common.py:2031, in MatrixOperations.evalf.<locals>.<lambda>(i)
   2028 """Apply evalf() to each element of self."""
   2029 options = {'subs':subs, 'maxn':maxn, 'chop':chop, 'strict':strict,
   2030         'quad':quad, 'verbose':verbose}
-> 2031 return self.applyfunc(lambda i: i.evalf(n, **options))

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/core/evalf.py:1647, in EvalfMixin.evalf(self, n, subs, maxn, chop, strict, quad, verbose)
   1645     options['quad'] = quad
   1646 try:
-> 1647     result = evalf(self, prec + 4, options)
   1648 except NotImplementedError:
   1649     # Fall back to the ordinary evalf
   1650     if hasattr(self, 'subs') and subs is not None:  # issue 20291

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/core/evalf.py:1482, in evalf(x, prec, options)
   1480 try:
   1481     rf = evalf_table[type(x)]
-> 1482     r = rf(x, prec, options)
   1483 except KeyError:
   1484     # Fall back to ordinary evalf if possible
   1485     if 'subs' in options:

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/core/evalf.py:600, in evalf_add(v, prec, options)
    597 while 1:
    598     options['maxprec'] = min(oldmaxprec, 2*prec)
--> 600     terms = [evalf(arg, prec + 10, options) for arg in v.args]
    601     n = terms.count(S.ComplexInfinity)
    602     if n >= 2:

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/core/evalf.py:600, in <listcomp>(.0)
    597 while 1:
    598     options['maxprec'] = min(oldmaxprec, 2*prec)
--> 600     terms = [evalf(arg, prec + 10, options) for arg in v.args]
    601     n = terms.count(S.ComplexInfinity)
    602     if n >= 2:

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/core/evalf.py:1482, in evalf(x, prec, options)
   1480 try:
   1481     rf = evalf_table[type(x)]
-> 1482     r = rf(x, prec, options)
   1483 except KeyError:
   1484     # Fall back to ordinary evalf if possible
   1485     if 'subs' in options:

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/core/evalf.py:648, in evalf_mul(v, prec, options)
    646 from .numbers import Float
    647 for arg in args:
--> 648     result = evalf(arg, prec, options)
    649     if result is S.ComplexInfinity:
    650         special.append(result)

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/core/evalf.py:1486, in evalf(x, prec, options)
   1483 except KeyError:
   1484     # Fall back to ordinary evalf if possible
   1485     if 'subs' in options:
-> 1486         x = x.subs(evalf_subs(prec, options['subs']))
   1487     xe = x._eval_evalf(prec)
   1488     if xe is None:

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/core/evalf.py:1023, in evalf_subs(prec, subs)
   1021 newsubs = {}
   1022 for a, b in subs.items():
-> 1023     b = S(b)
   1024     if b.is_Float:
   1025         b = b._eval_evalf(prec)

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/core/sympify.py:383, in sympify(a, locals, convert_xor, strict, rational, evaluate)
    381         conv = _sympy_converter.get(superclass)
    382     if conv is not None:
--> 383         return conv(a)
    385 if cls is type(None):
    386     if strict:

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/core/numbers.py:1069, in Float.__new__(cls, num, dps, precision)
   1067 elif num is S.NaN:
   1068     return num
-> 1069 elif _is_numpy_instance(num):  # support for numpy datatypes
   1070     num = _convert_numpy_types(num)
   1071 elif isinstance(num, mpmath.mpf):

File ~/.virtualenvs/.venv/lib/python3.9/site-packages/sympy/core/sympify.py:73, in _is_numpy_instance(a)
     68 """
     69 Checks if an object is an instance of a type from the numpy module.
     70 """
     71 # This check avoids unnecessarily importing NumPy.  We check the whole
     72 # __mro__ in case any base type is a numpy type.
---> 73 return any(type_.__module__ == 'numpy'
     74            for type_ in type(a).__mro__)

KeyboardInterrupt: 
# Plot
# From earlier: x_t = x_s + x_st*cos(phi_s) - z_st*sin(phi_s) - L_t*sin(phi_t)
# To see changes: do -x_r
x_s = sol.y[0]
phi_s = sol.y[2]
phi_t = sol.y[3]
move_nacelle = x_s + x_r*np.cos(phi_s) - z_r*np.sin(phi_s) - L_tower*np.sin(phi_t) - x_r

plt.plot(sol.t,move_nacelle, label="Nacelle movement at 3 frequencies")
plt.xlabel("Time [s]")
plt.ylabel("Excursion from initial position [m]")
plt.title("Nacelle from Lagrangian equations")
plt.legend();