# Wind turbine gearbox simulator
![Static Badge](https://img.shields.io/badge/Octave-11.1.0-orange)
![Static Badge](https://img.shields.io/badge/Arch%20Linux-6.19.12-blue)
![Static Badge](https://img.shields.io/badge/Gnuplot-6.0%20patchlevel%204-yellow)
![Static Badge](https://img.shields.io/badge/Gitlab-repo-red?logo=Gitlab)


Wind turbine gearbox simulator is a matlab/octave simulator for a lumped parameters mechanical model of wind turbine gearbox. It implements varying wind profile, defects, varying gear mesh, and compute numerically the dynamical behaviour of the system using a Newmark's scheme.

## Dependencies
**Development language:** Octave 11.1.0

**Compatibility:** Matlab v2026-a (delete all `graphics_toolkit("gnuplot")` mentions in the code)

**Plot engine:** Gnuplot 6.0 patchlevel 4

## Usage
```bash
$ git clone https://gitlab.com/afoucaultc/wind_turbine_gearbox
$ cd wind_turbine_gearbox
$ octave
$ octave:1> run main.m
$ # or run any standalone (starting by a "_")
$ octave:1> >>> run _[standalone].m
```

## File tree
```bash
: '
Main process takes the main parameters and compute the
whole process of calculations. It prints every figure
into .svg files, into folder print/run_print/. The
number of periods to calculate are asked as input when
the code is started.
"class_" are static functions used to calculate and plot
see in-code comments for more informations
'
## Main process
├── main.m
├── main_parameters.m
    ├── run_main.m
    │   └── _convergence.m
    ├── run_display.m
    │   └── class_display.m
    └── run_print.m
: '
Standalone files are files that do a single specific task
that cannot be done by the main process. These starts by
a "_" and can be ran using ">>> run _file.m"
- _init_speed.m calculates the optimal initial speed to 
    avoid the transitionnal regime.
- _rms-analysis.m gives a .csv (in /data) containing the 
    RMS, STD and Kurtosis for different defects conditions
- _animation.m is showing a visual animation of the diff-
    -erent shaft rotations and vibrations
- _gear-mesh-var.m plots the difference of mesh stiffness
    between different center distance error values
- _convergence.m plots the convergence between a high
    sample rate and other sample rates to determine which
    one to choose for minimal numerical error and comput-
    -ational
    time
'
## Standalone functions
├── _init_speed.m
├── _rms-analysis.m
├── _animation.m
├── _gear-mesh-var.m
└── _convergence.m
: '
Rendering folders stores the .csv datasheet and .svg plots
'
## Rendering folders
├── data
│   └── rms.csv
└── print
    ├── _convergence
    ├── _gear-mesh-var
    └── run_print

## Others
├── octave-workspace
└── README.md
```
## Model
![Model](images/kinematicscheme.png)

As showed on the image, the model is based on 2 shaft with 4DDL each ($x$, $y$, input and output $\theta$), as a lumped parameters model. The parameters are listed as a $q$ vector :
$$
\{q\} = \{x_1, y_1,\theta _{11},\theta_{12},x_2,y_2,\theta_{22},\theta_{21}\}
$$

### Equations of movement

The equations of movement are given by the Lagrange formulation, using the kinetic and potential energies.
$$
\left[\frac{\partial E_p}{\partial q_i}\right] 
        + \left[\frac{d}{dt}\left(\frac{\partial E_k}{\partial\dot{q}_i}\right)\right] 
        = \frac{\partial W}{\partial q_i}
        \label{eq:reformlagrange}
\\
        E_k = 	\frac{1}{2}
                \left(
                        m_1{\dot{x}_1}^2+
                        m_1{\dot{y}_1}^2+
                        I_{11}{\dot{\theta}_{11}}^2+
                        I_{12}{\dot{\theta}_{12}}^2+
                        m_2{\dot{x}_2}^2+
                        m_2{\dot{y}_2}^2+
                        I_{22}{\dot{\theta}_{22}}^2+
                        I_{21}{\dot{\theta}_{21}}^2
                \right)
\\
        E_p = \frac{1}{2}
                \left( 
                        k_{x_1}{x_{1}}^2+
                        k_{y_1}{y_{1}}^2+
                        k_{\theta_1}(\theta_{11}-\theta_{12})^2+
                        k_{x_2}{x_{2}}^2+
                        k_{y_2}{y_{2}}^2+
                        k_{\theta_2}(\theta_{21}-\theta_{22})^2+
                        K_e(t){\delta}^2
                \right)
$$

Where $I_{ij}$ inertias for shaft $i$ on its $j$ side; $K_e(t)$ the varying mesh stiffness (cf. *Mesh stiffness*); $\delta=(x_1-x_2)\sin(\alpha)+(y_1-y_2)\cos(\alpha)+r_{b_1}\theta_{12}+r_{b_2}\theta_{21}$ the tooth deflection.

The derivative of these equations is taken to directly get the movement, using:
$$
\frac{\partial E_p}{\partial q_i}+\frac{d}{dt}\left(\frac{\partial E_k}{\partial \dot{q}_i} \right) = F_i(t)
$$

The different terms ($k$ and $m$) are regrouped into matrices, to give the following system:
$$
\left[M\right]\{\ddot{q}\} + \left(\left[K_{mesh}\right](t)+\left[K_{cst}\right]\right) \{q\} = \left\{F(t)\right\}
$$
Where $K_{cst}$ represents the constant terms $k_{i_j}$ and $K_{mesh}$ the terms related to the gear mesh stiffness $K_e(t)$.

### Mesh stiffness

Mesh stiffness is calculated as a function of mesh period $T_{mesh}=60/(Z_1N_1)$, contact ratio $\varepsilon\approx c_{12}=\sum^2_{i=1}\frac{1+Z_i^{-1}}{0.5\sin(\alpha)+\sqrt{0.25\sin(\alpha)^2+(Z_i^{-2})+Z_i^{-1}}}$ and the one-tooth mesh stiffness $k_{mean}$. The one-tooth in contact is defined with a period of $T_{high} = T_{mesh}(\varepsilon -1)$ and stiffness $k_{max}=$; and the two-teeth period is defined by a period $T_{low} = T_{mesh}(2-\varepsilon)$ and stiffness 

### Forces

The forces vector is 

## Development machine specification

Hardware: Thinkpad E560, CPU Intel(R) Core(TM) i5-6200U(4)@2.8GHz, 3.70GiB RAM
OS: Arch Linux 6.19.12

