# README

## Overview

This MATLAB script performs a parametric structural study of a twin-carcass wheel with a cylindrical external architecture using MSC Patran and MSC Nastran.

The script automatically generates the geometry, assigns materials and shell properties, builds the finite element model, runs a linear static analysis, reads the results from the generated HDF5 file, and stores the outputs in a MATLAB table.

The objective is to evaluate the structural behavior of the twin-carcass configuration under different parameter combinations.

---

## Main Features

- Parametric generation of a twin-carcass wheel architecture
- Automatic creation of Patran session files
- Automatic execution of MSC Patran and MSC Nastran
- Extraction of:
  - vertical deflection
  - maximum von Mises stress
  - wheel mass
  - wheel stiffness
  - durability index
- Automatic storage of results in a `.mat` table

---

## Software Requirements

To run this script, the following software is required:

- MATLAB
- MSC Patran
- MSC Nastran

The script assumes that:

- Patran is installed at  
  `C:\Program Files\MSC.Software\NaPa_SE\20241\Patran\bin\patran.exe`
- Nastran is installed at  
  `C:\Program Files\MSC.Software\NaPa_SE\20241\Nastran\bin\nastran.exe`

---

## Input Parameters

The script defines several parameter groups.

### Geometric parameters
- `R_ext_vec`: external cylindrical radius
- `R_int_vec`: internal radius
- `B_vec`: wheel width
- `t_ext_vec`: external ring thickness
- `t_int_vec`: internal shell thickness
- `t_rinf_vec`: reinforcement thickness

### Vehicle and loading parameters
- `N_vec`: number of wheels
- `M_vec`: vehicle mass
- `g`: gravitational acceleration

### Architectural parameters
- `R_ext_cil_vec`: cylindrical outer radius
- `N_elem_vec`: number of repeated elements
- `N_elem_tot`: auxiliary total angular subdivision parameter

### Material parameters
The material structure includes:
- name
- Young’s modulus
- Poisson’s ratio
- density
- yield stress

### Mesh parameter
- `mesh_vec`: finite element mesh size

---

## Analysis Workflow

For each parameter combination, the script performs the following steps:

1. Defines the current wheel geometry and loading
2. Creates a Patran session file
3. Builds the base hub geometry
4. Creates carcass and reinforcement surfaces
5. Generates the outer cylindrical geometry
6. Replicates reinforcement surfaces around the wheel
7. Assigns materials and shell properties
8. Applies boundary conditions and central load
9. Generates the finite element mesh
10. Creates an RBE3 connection between the load point and the wheel structure
11. Writes the Nastran analysis deck
12. Runs Patran and Nastran
13. Reads displacement, stress, and mass results from the `.h5` file
14. Stores the results in a MATLAB matrix and table

---

## Output Variables

The output table contains the following columns:

- `R ext [m]`
- `R int [m]`
- `Width [m]`
- `t ext [m]`
- `t int [m]`
- `t rinf [m]`
- `Vehicle weight [N]`
- `Load [N]`
- `N° rinf`
- `Material ext & int`
- `Material rinf`
- `Vertical deflection [m]`
- `Maximum stress [Pa]`
- `Wheel mass [kg]`
- `Wheel stiffness [kg/s^2]`
- `Durability index`

---

## Durability Index

The durability index is computed as:

`DI = 1 - S_Mises_max / sigma_y`

where:

- `S_Mises_max` is the maximum von Mises stress
- `sigma_y` is the material yield stress

A higher durability index indicates a larger margin with respect to yielding.

---

## Saved Results

The script saves the aggregated table in:

`TAB_tol_twin.mat`

If the file already exists:
- the new results are appended
- identical duplicate rows are removed
- the table is sorted
- the file is overwritten with the updated table

---

## Notes

- The script is configured for a linear static analysis.
- The session and solver files are overwritten during each iteration.
- The current material assignment is set using `selected_mat`.
- The model includes repeated carcass and reinforcement surfaces distributed around the wheel.
- The code reads displacement, stress, and mass directly from the Nastran HDF5 result file.

---

## Typical Generated Files

During execution, the script may generate files such as:

- `architecture_twin_carcasses_cilinder.ses`
- `architecture_twin_carcasses_cilinder.db`
- `architecture_twin_carcasses_cilinder.bdf`
- `architecture_twin_carcasses_cilinder.h5`
- `patran.ses.01`
- `architecture_twin_carcasses_cilinder.db.jou`
- `patran.conf.ini`

---

## Purpose

This script is intended for automated tolerance, robustness, and parametric studies of twin-carcass wheel structural configurations.