# How to create a new simulation?

The model requires several mesh files (the file format can be [.ply](https://en.wikipedia.org/wiki/PLY_(file_format)) or [.off](https://en.wikipedia.org/wiki/OFF_(file_format))):
* **mandible**:   
    * This is the closed surface mesh of the mandible. 
    * the boundary conditions will be applied in the global cartesian reference frame. Thus, this mesh should be aligned with its principal axes (see [MeshLab](https://www.meshlab.net/): Filters / Normals, Curvatures and Orientation / Transform: Align To Principal Axis)
    * A gmsh file (.msh) of the volume mesh can also be given
    * If this mesh is given as a surface mesh file, it will be meshed with gmsh. Try to mesh it manually in gmsh first because it sometimes fail.
* **teeth**:
    * A set of vertices selected on the top of the teeth where contact with the food occurs.
    * Using [MeshLab](https://www.meshlab.net/):
        * Select the vertices using vertex selector ("Select Vertices" button) and the mouse.
        * When the selection is finished, invert the selection (pressing "SHIFT-i").
        * Delete all the selected vertices using "Filters / Selection / "Delete selected vertices".
        * Check that your model only contains the desired number of vertices.
        * Save these vertices to a file (e.g. teeth.ply) 
* **LTMJ/RTMJ**:
    * Use the same procedure as for the teeth to save 1 vertex representing the left temporomandibular joint (LTMJ) and the right one (RTMJ) to 2 separate files (e.g. LTMJ.ply and RTMJ.ply)
* A series of **muscle attachement areas** (you can name them as you like)
    * for each muscle, using [MeshLab](https://www.meshlab.net/):
        * Select the faces on which the muscle is attached to the bone
        * When the selection is finished, invert the selection (pressing "SHIFT-i").
        * Delete all the selected faces and vertices using "Filters / Selection / "Delete selected faces and vertices".
        * Save this group of faces to a file (e.g. muscle.ply).
* Each muscle requires a **focal node** towards which the muscle force is directed.
    * If this focal point can be "picked" in [MeshLab](https://www.meshlab.net/) on another mesh, you can use the same procedure as for LTMJ/RTMJ.
    * If not you can write the coordinate of the point in a [.off](https://en.wikipedia.org/wiki/OFF_(file_format)) file (several examples ara available in this folder).

The mesh files are specified in the input file:

```
path = 'dolicorhynchops/10k'
p['mandible'] = f'{path}/mandible.ply'
p['teeth'] = f'{path}/teeth.off'
p['LTMJ'] = f'{path}/LTMJ.off'
p['RTMJ'] = f'{path}/RTMJ.off'
p['muscles'] = [
    {
        'file': f'{path}/Lmuscle.ply',
        'force': 100.,
        'focalpt': f'{path}/LmuscleF.off',
        'method': 'T'
    },
    {
        'file': f'{path}/Rmuscle.off',
        'force': 100.,
        'focalpt': f'{path}/RmuscleF.off',
        'method': 'T'
    }
]
```
For each muscle, the "method" can be 'U', 'T' or 'T+N' referring to (see [Grosse et al. 2007](https://doi.org/10.1002/ar.20568))
* **U**: Ad Hoc Uniform Traction Model: a traction exerted by the muscle on each face is directed towards the focal node and constant in amplitude whatever its orientientation is.
* **T**: Tangential-Traction Model: Same as 'U' but the traction on the faces which do not have a direct line of sight to the focal point are projected onto the face and become tangential.
* **T+N**: Tangential-Plus-Normal-Traction Model: Same as 'T' but a normal pressure component is added to the faces which do not have a direct line of sight to the focal point. This normal component depends on the local curvature and the distance to the muscle fiber origin.

# List of folders

* CLIpro: (V.Gaudichon) Clidastes propython FHSM17576
* contact: files used to create a meshed cylindrical surface so that we could model a bite onto a meshed surface (UNFINISHED). T
* cylinder: files used as a demontrator of boneload (see also view_cylinder_T.py and also view_cylinder_TN.py)
* Dolico_bon: (V.Gaudichon) Dolicorhyncops_bonneri_KUVP40001
* Dolico_osb: (V.Gaudichon)
* dolicorhynchops: first meshes sent by V.Gaudichon at the beginning of his master thesis
* PLTtymFrankencarpus: first meshes sent by V.Gaudichon at the beginning of his master thesis
* TYLber: (V.Gaudichon) Tylosaurus bernardi
* TYLnep: (V.Gaudichon) TYLnep_FHSM2209

# run simulations on warson

List the files you want to run in a file named `simus.txt`. For example:
```
ls *750k* > simus.txt
```
Edit `run_sim.py` and check Metafor executable path. Then, run the `run_sim.py` script through `at` (check `.forward` to get an e-mail notification at the end of the calculations):
```
echo ./run_sim.py | at now -m
```
Copy `zip_all_folders.sh` and `send_tbz2_to_dox.sh` to `workspace`.
```
cp *.sh workspace
cd workspace
./zip_all_folders.sh       # <= create a .tbz2 archive for each simulation
./send_tbz2_to_dox.sh      # <= send the tbz2 files to DoX
```