# Surge 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 surge_hull_equations as equations
import surge_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.surge_hull_equation_SI.free_symbols))
```

## Surge equation


```python
sp.latex(equations.surge_hull_equation)
```


```python
equations.surge_hull_equation_SI
```

### Plotting the total surge hull equation


```python
df = pd.DataFrame()
df['v_w'] = np.linspace(-0.3,0.3,20)
df['r_w'] = 0.0
df['rho'] = 1025
df['L'] = 1.0
df['g'] = 9.81
df['X_vv'] = -1.0
df['X_vr'] = 1.0
df['X_rr'] = 1.0
df['X_res'] = 0.0
df['disp'] = 23


result = df.copy()
result['fx'] = lambda_functions.X_h_function(**df)

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

### 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(-0.3,0.3,20)
df['r_w'] = 0.0
df['rho'] = 1025
df['g'] = 9.81
df['X_res'] = 0.0

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


```python
result = df_input.copy()
result['fx'] = lambda_functions.X_h_function(**df_input)
```


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

## 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(-0.3,0.3,20)
df['r_w'] = 0.0
df['rho'] = 1025
df['g'] = 9.81
df['X_res'] = 0.0

result_comparison = run_real_seaman.compare_with_seaman(lambda_function=lambda_functions.X_h_function,
                                                        shipdict = shipdict,
                                                        df = df,label='fx',
                                                        seaman_function=run_real_seaman.calculate_resistance)

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


```python
df = pd.DataFrame()
df['r_w'] = np.linspace(-0.3,0.3,20)
df['v_w'] = 0.0
df['rho'] = 1025
df['g'] = 9.81
df['X_res'] = 0.0

shipdict2 = shipdict.copy()
shipdict2.resistance_data['xrr'] = -0.01

result_comparison = run_real_seaman.compare_with_seaman(lambda_function=lambda_functions.X_h_function,
                                                        shipdict = shipdict2,
                                                        df = df,label='fx',
                                                        seaman_function=run_real_seaman.calculate_resistance)

fig,ax = plt.subplots()
result_comparison.plot(x = 'r_w',y = ['fx','fx_seaman'],ax = ax)
ax.set_title('Yaw rate variation');
```


```python
df = pd.DataFrame()
df['v_w'] = np.linspace(-0.3,0.3,20)
df['r_w'] = 0.01
df['rho'] = 1025
df['g'] = 9.81
df['X_res'] = 0.0

result_comparison = run_real_seaman.compare_with_seaman(lambda_function=lambda_functions.X_h_function,
                                                        shipdict = shipdict,
                                                        df = df,label='fx',
                                                        seaman_function=run_real_seaman.calculate_resistance)

fig,ax = plt.subplots()
result_comparison.plot(x = 'v_w',y = ['fx','fx_seaman'],ax = ax)
ax.set_title('Drift angle variation, yaw rate = 0.01 rad/s');
```


```python
df = pd.DataFrame()
df['r_w'] = np.linspace(-0.3,0.3,20)
df['v_w'] = 0.01
df['rho'] = 1025
df['g'] = 9.81
df['X_res'] = 0.0

result_comparison = run_real_seaman.compare_with_seaman(lambda_function=lambda_functions.X_h_function,
                                                        shipdict = shipdict,
                                                        df = df,label='fx',
                                                        seaman_function=run_real_seaman.calculate_resistance)

fig,ax = plt.subplots()
result_comparison.plot(x = 'r_w',y = ['fx','fx_seaman'],ax = ax)
ax.set_title('Yaw rate variation');
```


```python
import save_lambda_functions

function_name = 'X_h_function'
lambda_function = lambda_functions.X_h_function

save_lambda_functions.save_lambda_to_python_file(lambda_function = lambda_function,
                                                 function_name = function_name)

save_lambda_functions.save_lambda_to_matlab_file(lambda_function = lambda_function,
                                                 function_name = function_name)
```

445b7c8619e72fbb29b9ff3d1d1779bdd61d2cb5
ipynb
Jupyter Notebook
docs/seaman/05.1_seaman_surge_hull_equation.ipynb
martinlarsalbert/wPCC
16e0d4cc850d503247916c9f5bd9f0ddb07f8930
MIT
docs/seaman/05.1_seaman_surge_hull_equation.ipynb
martinlarsalbert/wPCC
16e0d4cc850d503247916c9f5bd9f0ddb07f8930
MIT
docs/seaman/05.1_seaman_surge_hull_equation.ipynb
martinlarsalbert/wPCC
16e0d4cc850d503247916c9f5bd9f0ddb07f8930
MIT
Qwen/Qwen-72B
1. YES
2. YES