# Sway hull equation


```python
%load_ext autoreload
%autoreload 2
%matplotlib inline
```


```python
import sympy as sp
from sympy.plotting import plot as plot
from sympy.plotting import plot3d as plot3d
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
sp.init_printing()
from IPython.core.display import HTML
```


```python
import seaman.helpers
import seaman_symbol as ss
import sway_hull_equations as equations
import sway_hull_lambda_functions as lambda_functions
from bis_system import BisSystem
```

## Coordinate system


## Symbols


```python
from seaman_symbols import *
```


```python
HTML(ss.create_html_table(symbols=equations.total_sway_hull_equation_SI.free_symbols))
```

## Sway equation


```python
equations.sway_hull_equation
```

### Force due to drift


```python
equations.sway_drift_equation
```

Same equation in SI units


```python
equations.sway_drift_equation_SI
```

### Force due to yaw rate


```python
equations.sway_yaw_rate_equation
```


```python
equations.sway_yaw_rate_equation_SI
```

### Nonlinear force
The nonlinear force is calculated as the sectional cross flow drag.




```python
equations.sway_none_linear_equation
```

Simple assumption for section draught:


```python
equations.section_draught_equation
```


```python
equations.simplified_sway_none_linear_equation
```

Nonlinear force equation expressed as bis force:


```python
equations.simplified_sway_none_linear_equation_bis
```


```python
equations.sway_hull_equation_SI
```


```python
equations.sway_hull_equation_SI
```


```python
equations.total_sway_hull_equation_SI
```

### Plotting the total sway hull force equation


```python
df = pd.DataFrame()
df['v_w'] = np.linspace(-0.3,3,10)
df['u_w'] = 5.0
df['r_w'] = 0.0
df['rho'] = 1025
df['t_a'] = 1.0
df['t_f'] = 1.0
df['L'] = 1.0
df['Y_uv'] = 1.0
df['Y_uuv'] = 1.0
df['Y_ur'] = 1.0
df['Y_uur'] = 1.0
df['C_d'] = 0.5
df['g'] = 9.81
df['disp'] = 23

result = df.copy()
result['fy'] = lambda_functions.Y_h_function(**df)

result.plot(x = 'v_w',y = 'fy');
```

### Plotting with coefficients from a real seaman ship model


```python
import generate_input
shipdict = seaman.ShipDict.load('../../tests/test_ship.ship')
```


```python
df = pd.DataFrame()
df['v_w'] = np.linspace(-3,3,20)
df['rho'] = 1025.0
df['g'] = 9.81
df['u_w'] = 5.0
df['r_w'] = 0.0

df_input = generate_input.add_shipdict_inputs(lambda_function=lambda_functions.Y_h_function,
                                              shipdict = shipdict,
                                              df = df)
df_input
```


```python
result = df_input.copy()
result['fy'] = lambda_functions.Y_h_function(**df_input)
```


```python
result.plot(x = 'v_w',y = 'fy');
```

## Real seaman++
Run real seaman in C++ to verify that the documented model is correct. 


```python
import run_real_seaman
```


```python
df = pd.DataFrame()
df['v_w'] = np.linspace(-3,3,20)
df['rho'] = 1025.0
df['g'] = 9.81
df['u_w'] = 5.0
df['r_w'] = 0.0

result_comparison = run_real_seaman.compare_with_seaman(lambda_function=lambda_functions.Y_h_function,
                                                        shipdict = shipdict,
                                                        df = df)

fig,ax = plt.subplots()
result_comparison.plot(x = 'v_w',y = ['fy','fy_seaman'],ax = ax)
ax.set_title('Drift angle variation');
```


```python
df = pd.DataFrame()
df['r_w'] = np.linspace(-0.1,0.1,20)
df['rho'] = 1025.0
df['g'] = 9.81
df['u_w'] = 5.0
df['v_w'] = 0.0


df_input = generate_input.add_shipdict_inputs(lambda_function=lambda_functions.Y_h_function,
                                              shipdict = shipdict,
                                              df = df)

result_comparison = run_real_seaman.compare_with_seaman(lambda_function=lambda_functions.Y_h_function,
                                                        shipdict = shipdict,
                                                        df = df,)
fig,ax = plt.subplots()
result_comparison.plot(x = 'r_w',y = ['fy','fy_seaman'],ax = ax)
ax.set_title('Yaw rate variation');
```


```python
df_input
```


```python

```

0f16e8c62fcdacd3e7d897489e25521ca43ea09f
ipynb
Jupyter Notebook
docs/seaman/02.1_seaman_sway_hull_equation.ipynb
martinlarsalbert/wPCC
16e0d4cc850d503247916c9f5bd9f0ddb07f8930
MIT
docs/seaman/02.1_seaman_sway_hull_equation.ipynb
martinlarsalbert/wPCC
16e0d4cc850d503247916c9f5bd9f0ddb07f8930
MIT
docs/seaman/02.1_seaman_sway_hull_equation.ipynb
martinlarsalbert/wPCC
16e0d4cc850d503247916c9f5bd9f0ddb07f8930
MIT
Qwen/Qwen-72B
1. YES
2. YES