# 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)
![Static Badge](https://img.shields.io/badge/Last%20update-21%2F04%2F2026-green)

"uncertainties4windturbinegearbox" is a program designed to simulate the uncertainties of a wind turbine gearbox model. 

Its main purpose is the comparison between :
- Monte Carlo method 
- Generalized Polynomial Chaos method (GPC)

With this model, proofs that GPC is a valid method are given, with convergence criteria. The wind turbine gearbox model is a 8-DOF gearbox integrated in time with Newmark's scheme. Uncertain parameters are mapped into uniform distributions in the interval $[-1,1]$.

## Dependencies
**Development language:** [Octave 11.1.0](https://octave.org/) ("some packages" installed, follow first start requirements, follow the error messages) (add `graphic_toolkit("gnuplot")` in `main`)

**Compatibility:** [Matlab v2026-a](https://fr.mathworks.com/products/matlab.html) (delete all `graphics_toolkit("gnuplot")` occurrences in the code)
> Optional: Parallel Computing Toolbox (for `parfor` functions)

**Plot engine:** [Gnuplot](http://gnuplot.info/) 6.0 patchlevel 4

**Recommended:** [Inkscape](https://inkscape.org/) can be used for graphs that are printed into `.svg` to be converted into `.pdf`

**Perspectives:** the code will probably be transferred into Python, as it is free and open source, and coherence with Python machine learning models

## Usage
### Run the code
```bash
$ git clone https://gitlab.com/afoucaultc/wind_turbine_gearbox
$ cd wind_turbine_gearbox/uncertainties4windturbinegearbox
$ mkdir save
$ mkdir print
$ octave
$ octave:1> run main.m
$ # or run any standalone (starting by a "_")
$ octave:1> run _[standalone].m
```
### Parameters
Stored in **`parameters.m`**.

| Variable | Default | Description |
|---|---|---|
| `N` | `10000` | Number of Monte Carlo draws |
| `pmax` | `5` | Maximum polynomial order for CPG |
| `theta` | `0.01` | Convergence threshold on residual rate |
| `r_uncertainty` | `20` | ±% variation around nominal values |
| `newparams` | see file | Cell array of uncertain variable names and nominal values |

Adding or removing uncertain variables : edit `newparams` array
```matlab
newparams = {
    'Z2'  , 18  ;   % number of teeth (gear 2)
    'b'   , 0.1 ;   % gear width [m]
    'la1' , 2   ;   % shaft 1 length [m]
    % 'kx', 1e8 ;   % uncomment to include bearing stiffness
};
```

### OUTPUTS :
#### Figures (exported to `print/`)

| File | Content |
|---|---|
| `mean_cpg_r=*_p=*_uncertainty=*.pdf` | Mean displacement — CPG vs MC (with 95% CI) |
| `var_cpg_r=*_p=*_uncertainty=*.pdf` | Standard deviation — CPG vs MC (with 95% CI) |
| `modes_cpg_r=*_p=*_uncertainty=*.pdf` | Modal energy contribution by polynomial order |
| `CPG_MC_time.pdf` | Evaluation time — CPG vs MC as a function of sample size |
| `CPG_polytime.pdf` | Training time of CPG as a function of polynomial order |
| `MC_convergence.pdf` | Convergence of MC mean estimate vs. number of draws |

#### Raw values (saved to `save/`)

| File | Content |
|---|---|
| `mc_r=*_N=*.mat` | Full MC workspace |
| `cpg_r=*_p=*.mat` | Full CPG workspace at converged order |

### File tree
```bash
## Main process

├── main.m                  # Main, runs MC then CPG, produces figures
│   ├── monte_carlo             # Monte Carlo
│   │   ├── method_XiToX.m          # Mapping from normalized ξ ∈ [-1,1]^r to physical X
│   │   └── method_lambda.m         # Batch model evaluation over a parameter grid
│   │       └── model_main.m            # Model used (wind turbine gearbox)
│   │           ├── model_func.m (class)    # Function class for model
│   │           └── model_parameters.m      # Parameters for model
│   └── cpg                     # GPC
│       ├── cpg_polyLegendre.m      # Legendre polynomials up to order pmax
│       ├── cpg_polyChaos.m         # Multi dimensional chao basis (multi index α)
│       ├── cpg_gaussColloc.m       # Tensor of Gauss collocation grid
│       ├── method_XiToX.m          # Mapping from normalized ξ ∈ [-1,1]^r to physical X
│       ├── method_lambda.m         # Batch model evaluation over a parameter grid
│       │   └── model_main.m            # Model used (wind turbine gearbox)
│       │       ├── model_func.m (class)    # Function class for model
│       │       └── model_parameters.m      # Parameters for model
│       ├── cpg_modes.m             # Stochastic mode computation (Φ \ λ)
│       ├── cpg_evaluate.m          # CPG evaluation on random ξ samples from MC
│       └── cpg_errors.m            # Convergence metrics and stopping criterion
└── plot_guerine.m          # Plots : mean, std and modal energy

## Standalone functions

└── _timeaccuracy.m         # Compute and plot : time for MC, GPC, convergence MC

## Rendering folders
├── print 
│   ├── mean_cpg_r=?_p=?_uncertainty=?.pdf (main)
│   ├── var_cpg_r=?_p=?_uncertainty=?.pdf (main)
│   ├── modes_cpg_r=?_p=?_uncertainty=?.pdf (main)
│   ├── CPG_MC_polytime.pdf (_timeaccuracy)
│   ├── MC_convergence.pdf (_timeaccuracy)
│   └── CPG_MC_time.pdf (_timeaccuracy)
└── save
    ├── cpg_r=?_p=?.mat
    └── mc_r=?_N=?.mat

## Others
├── octave-workspace
└── README.md
```

## Calculation machine specification

Hardware: 32Go RAM, Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz, NVIDIA GeForce RTX 4060
OS: Windows 10, version 22H2 (last update 16/05/2023)

