<jupyter_start><jupyter_text>Appendix extras<jupyter_code>%matplotlib inline
%load_ext autoreload
%autoreload 2

import warnings
warnings.filterwarnings('ignore')
# %load imports.py
"""
These is the standard setup for the notebooks.
"""

%matplotlib inline
%load_ext autoreload
%autoreload 2

import sys
sys.path.append("../../")

import pandas as pd
pd.options.display.max_rows = 999
pd.options.display.max_columns = 999
pd.set_option("display.max_columns", None)
import numpy as np
import os
import matplotlib.pyplot as plt
from collections import OrderedDict
import copy
from sklearn.pipeline import Pipeline
from rolldecayestimators.transformers import CutTransformer, LowpassFilterDerivatorTransformer, ScaleFactorTransformer, OffsetTransformer
from rolldecayestimators.direct_estimator_cubic import EstimatorQuadraticB, EstimatorCubic
from rolldecayestimators.ikeda_estimator import IkedaQuadraticEstimator
import src.equations as equations
import rolldecayestimators.lambdas as lambdas
from rolldecayestimators.substitute_dynamic_symbols import lambdify
import rolldecayestimators.symbols as symbols
import sympy as sp

from sympy.physics.vector.printing import vpprint, vlatex
from IPython.display import display, Math, Latex

from sklearn.metrics import r2_score
import shipflowmotionshelpers.shipflowmotionshelpers as helpers
import src.visualization.visualize as visualize
import scipy
from copy import deepcopy
import joblib
import warnings
warnings.filterwarnings('ignore')
if os.name == 'nt':
    plt.style.use('paper.mplstyle')  # Windows

from scipy.integrate import solve_ivp
from scipy.optimize import least_squares
from rolldecayestimators import fit_on_amplitudes
from reports import mdl_results
import rolldecayestimators.ikeda as ikeda_classes
from pyscores2.indata import Indata
from pyscores2.output import OutputFile
import joblib
import src.visualization.visualize as visualize
from rolldecayestimators import equations_ikeda_naked
from sympy import latex
from rolldecayestimators import logarithmic_decrement
from copy import deepcopy
import src.helpers
from src.notebook_to_latex import Equation, equation_dict

## Examples:
from reports import mdl_results
import reports.examples as examples
import reports.examples.ikeda_V_phi_a
import reports.examples.analytical_numerical
import reports.examples.eddy_sigma
import reports.examples.ikeda_section_table
import reports.examples.decision_tree
import reports.examples.KVLCC2_section_table
import reports.examples.logaritimic_decrement
import reports.examples.mdl
from reports.examples.mdl import plot_amplitudes
import reports.examples.ikeda
import reports.examples.hybrid_0
import reports.examples.hybrid_speed
import reports.examples.FNPF
import reports.examples.KVLCC2<jupyter_output>Duplicate key in file 'paper.mplstyle', line 462 ('figure.figsize   : 5, 3   ## figure size in inches')
Duplicate key in file 'paper.mplstyle', line 463 ('figure.dpi       : 100        ## figure dots per inch')<jupyter_text>Analytical solution A differential equation for a linearly decaying motion can be written as:<jupyter_code>Equation(equations.diff_eq, max_length=100, label='eq:linear')<jupyter_output><empty_output><jupyter_text>Which has an analytical solution :<jupyter_code>Equation(equations.analytical_solution, label='eq:analytical_solution', max_length=200)<jupyter_output><empty_output><jupyter_text>In the usual case of having no initial roll velocity ($\phi_0=0$) this equation can be simlified to:<jupyter_code>no_initial_speed = sp.simplify(equations.analytical_solution.subs(symbols.phi_0_dot,0))
Equation(no_initial_speed, label='eq:analytical_solution_no_initial_speed')<jupyter_output><empty_output><jupyter_text>And the damping coefficient $\zeta$ is very small for ships so that $\sqrt{1-\zeta}$ is almost 1 and the solution can be further simplified, into something that can easily be recognized as a decaying oscillation:<jupyter_code>no_initial_speed_zeta_small = no_initial_speed.subs(
    [(sp.sqrt(1-symbols.zeta**2),1),
     (symbols.zeta*sp.sin(symbols.omega0*symbols.t),0),
    ])
Equation(no_initial_speed_zeta_small,label='eq:analytical_solution_no_initial_speed_zeta_small')<jupyter_output><empty_output><jupyter_text>Time and frequency domain\label{se:time_and_frequency}Ikeda's method is defined in the frequency domain, where the damping is expressed as a function of roll angle amplitude $\phi_a$ and roll angle frequency $\omega$. The equivalent linear damping $B_e$ (not to confuse with eddy damping $B_E$) is a way to convert the frequency domain damping into time domain damping , so that time domain roll simulations can be conducted with results from Ikeda's method. The most general way to determine $B_e$ is to assume that the energy loss due to damping during a half cycle of roll is the same when nonlinear and linear dampings are used . The $B_e$ can then be calculated as a Fourier series expansion of the damping model, which in the case of a cubic model yields as:<jupyter_code>Equation(equations.B_e_equation, label='eq:B_e_equation')<jupyter_output><empty_output><jupyter_text>The expression above gives a relation between the frequency domain quantities $\phi_a$, $\omega$ and the time domain quantities $B_1$ and $B_2$ which can be used to obtain the latter ones from the Ikeda's method. This can be done by calculating the damping with Ikeda's method for a variation of frequencies and amplitudes and then fit the above expression to this damping and obtain $B_1$, $B_2$:$$B^{Ikeda}(\phi_a, \omega) = B_e(\phi_a, \omega)$$In the case of a roll decay test $\phi_a$ is the only parameter being varied. In order to verify this approach, an alternative method using the logaritmic decrement  to obtaining the frequency domain quantities from time series result is also used.  This method is investigated on simulation results with a quadratic model: $B_1 = 0.05$, $B_2 = 0.9$, $A_{44} = 1.0$, $C_1 = 5.0$. The peak values, being the only known amplitudes from this signal, is shown in the figure below.<jupyter_code>examples.logaritimic_decrement.show_figure_1()<jupyter_output>findfont: Font family ['"serif"'] not found. Falling back to DejaVu Sans.<jupyter_text>The decrement is calculated as the ratio between every other peak, so that negative and positive roll peaks are separated. This decrement can be calulated for each peak:$$ \Delta_n = \frac{\phi_{a,n}}{\phi_{a,n+2}}$$ The nondimensional $\zeta$ damping coefficient for each peak can be calculated from the logaritimic decrement: $$\zeta_n = \frac{\delta_n}{2\pi}=\frac{ln(\Delta_n)}{2\pi}$$ The dimensional damping $B_n$ (Nm*s) can be then be obtained:<jupyter_code>Equation(equations.B_1_zeta_eq.subs(symbols.B_1, symbols.B), label='eq:B_1_zeta_eq')<jupyter_output><empty_output><jupyter_text>So the damping can be obtained for each oscillation this way but it is not obvious which of the roll amplitudes these dampings correspond to. Four different choices were tried, associating damping $B_n$ with the following amplitudes:* A : $\phi_n$* B : $\phi_{n+1}$* C : $\phi_{n+2}$* D : $(\phi_n + \phi_{n+1} + \phi_{n+2})/3$<jupyter_code>examples.logaritimic_decrement.show_figure_2();<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0779491454772822, 'fraction_numerical': 0.010143115186883423, 'mean_word_length': 6.5928270042194095, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '569168', 'license': 'MIT', 'n_tokens_mistral': 2304, 'n_tokens_neox': 2161, 'n_words': 717, 'path': 'reports/ISOPE_outline/02.1.appendix_extras.ipynb', 'repo_name': 'rddaz2013/Prediction-of-roll-motion-using-fully-nonlinear-potential-flow-and-Ikedas-method', 'size': '7197'}