# The mesh file

The APM Preprocessor supports mesh files in **.stl** format. The **.stl** file is a commonly used mesh file format which represents bodies with triangular elements. If a body is represented only with triangular elements its mesh is said to be unstructured. Conversely, if a body is represented only with quadrilateral elements its mesh is said to be structured. The images below show an unstructured mesh of a fixed-wing UAV, a structured mesh of a NACA0015 wing, and a hybrid (mixed) mesh of a fixed-wing UAV.

![Unstructured mesh of a fixed-wing UAV](https://81269019-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MV8htLPXN-_fWc_anY_%2F-MVXIQHMvGygHuzsNSXq%2F-MVXJEk3BcPa9XXm-j7b%2Fexample_mesh.png?alt=media\&token=1d4ed16b-0d4f-4a68-b038-93f7f6995718)

![Structured mesh of a NACA0015 wing](https://81269019-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MV8htLPXN-_fWc_anY_%2F-MVgETQYViE55tRZjCUV%2F-MVgEqNERMDyInDgYYtf%2Fexample_structured_mesh.png?alt=media\&token=207cd39b-f30f-4b83-aa1b-38c483681d3d)

<figure><img src="https://81269019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MV8htLPXN-_fWc_anY_%2Fuploads%2FVh3CRPKHoVOh6ZQw8MKh%2Fexample_mixed_mesh.png?alt=media&#x26;token=ae08c7be-8e31-410e-bf9c-9db9a02d4641" alt=""><figcaption></figcaption></figure>

## File formats

### .stl

The **.stl** mesh file format can only store unstructured meshes. However, the APM Preprocessor supports a non-standard **.stl** mesh file format which can store structured meshes. A typical structure of a **.stl** mesh file is shown below:

```
solid "name"
    facet normal nx ny nz      
        outer loop
            vertex x y z
            vertex x y z
            vertex x y z
        endloop
    endfacet                   
    facet normal nx ny nz      
        outer loop
            vertex x y z
            vertex x y z
            vertex x y z
        endloop
    endfacet       
    ...
    ...
    ...
endsolid
```

Each mesh element is defined by the `facet` keyword. The `normal` keyword and the `nx`, `ny`, `nz` variables specify the unit normal vector of the element. The `vertex` keyword and the `x`, `y`, `z` variables specify a vertex of the element. Since each element has 3 vertices the `vertex` keyword and the `x`, `y`, `z` variables are repeated three times.

For structured meshes, a fourth vertex is added to each element.

{% hint style="info" %}
A **.stl** file with four vertices per element is non-standard and is specific to the APM Preprocessor.
{% endhint %}

{% file src="<https://81269019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MV8htLPXN-_fWc_anY_%2Fuploads%2F6wEbp4oBestMKkNTTeAX%2Fnaca4412_wing.stl?alt=media&token=5cf438ea-8a65-40de-8628-93f1cd51e904>" %}

### .ucd

The **.ucd** mesh file format can only store unstructured and structured meshes. A typical structure of a **.ucd** mesh file is shown below:

```
# <comment 1>
.
.
.
# <comment n>
<num_nodes> <num_cells> <num_ndata> <num_cdata> <num_mdata>
<node_id 1> <x> <y> <z>
<node_id 2> <x> <y> <z>
<node_id num_nodes> <x> <y> <z>
<cell_id 1> <mat_id> <cell_type> <cell_vert 1> ... <cell_vert n>
<cell_id 2> <mat_id> <cell_type> <cell_vert 1> ... <cell_vert n>
<cell_id num_cells> <mat_id> <cell_type> <cell_vert 1> ...<cell_vert n>
```

{% file src="<https://81269019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MV8htLPXN-_fWc_anY_%2Fuploads%2FOZdm5jtb5vnsjAumHuWq%2Fnaca4412_wing.ucd?alt=media&token=450bc334-0cd0-477a-9e24-948af547cbcc>" %}

### .wrl

The **.wrl** mesh file format can only store unstructured and structured meshes. A typical structure of a **.wrl** mesh file is shown below:

```
Shape {
    geometry IndexedFaceSet {
        coord Coordinate {
            point [
                <x> <y> <z>
                <x> <y> <z>
                <x> <y> <z>
                ...
            ]
        }
        coordIndex [
            <cell_vert 1> ... <cell_vert n>
            <cell_vert 1> ... <cell_vert n>
            <cell_vert 1> ... <cell_vert n>
            ...
        ]
    }
}
```

{% file src="<https://81269019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MV8htLPXN-_fWc_anY_%2Fuploads%2F31NYWpLsqhtg8M37Q2I9%2Fnaca4412_wing.wrl?alt=media&token=aec84c05-be55-48cc-a836-c14dd72dddd8>" %}
