# Mesh¶

This section presents functions dedicated to creation or manipulation of meshes to produce avatars (rigid or deformable). The `mesh` class allows to define a mesh object in the lightest way: nodes, connectivity and possibly the groups elements belongs to. In 3D only a volumic mesh can become a deformable or rigid avatar whereas a surfacic mesh can only be used to generate a rigid avatar. In 2D a mesh may define a deformable or a rigid avatar.

Again it is possible to define a mesh by hand using the class constructor and the basic methods as explained in Avatar definition section. But this solution is not usable to generate big meshes.

Basic example

```m = mesh(dimension=2)
```

Available geometrical elements are:

• 1D : Point, S2xxx, S3xxx,
• 2D : Point, S2xxx, S3xxx, T3xxx, Q4xxx, T6xxx, Q8xxx, Q9xxx,
• 3D : Point, S2xxx, S3xxx, T3xxx, Q4xxx, T6xxx, Q8xxx, Q9xxx, H8xxx, H20xx, TE4xx, TE10x, PRI6x, PRI15

Remember that rigid2d() and rigid3d() allow to define rigid element. It is equivalent to

```element( type='Point', connectivity=, physicalEntity='1')
```

## Built-in Generation¶

For the specific case of 2D rectangular mesh, the `buildMesh2D()` function can be used and for the case of 3D paralleloid mesh `buildMeshH8()` also.

Example:

Generating a simple rectangular mesh:

```my_mesh = buildMesh2D('Q4', x0=0.025, y0=0.05, lx=0.10, ly=0.05, nb_elem_x=10, nb_elem_y=5)
```

## Importing a mesh¶

The most efficient way to generate a mesh is to use a meshing software like gmsh . To this end the `lecture()` function allow to read a file with gmsh format. In this way any kind of mesh may be put in a mesh object.

Example:

```dim=2
mesh = lecture('block.msh',dim)
```

## Mesh to avatar¶

Creating an avatar from a mesh is possible using:

• deformable 2D/3D

`buildMeshedAvatar()`

Example:

```mesh_cube   = lecture('gmsh/cube_t4.msh', dim)
cube=buildMeshedAvatar(mesh=mesh_cube, model=m3Dl, material=stone)
cube.imposeDrivenDof(group='105' , component=[1, 2, 3], dofty='vlocy')
```

Remarks:

It exists various strategies for contactors:

• 2D

```# candidates at nodes
# candidates on edges
# antagonist
```
• 3D

```# candidates at nodes
# antagoniste
```
• rigid 2D

`rigidFromMesh2D()`

• rigid 3D

Example:

```body_donut = volumicMeshToRigid3D(volumic_mesh=mesh_donut, model=mod, material=tdur, color='BLEUx')
```

For the rigid avatar, the mesh is used to define the boundary of the corresponding polygons/polyhedra.

The deformable avatars inherit the group of the original mesh, allowing to define the desired boundary conditions and to add the contactors on them.

Sometimes, it is wanted to explode the continuous mesh in a collection of avatars (if one wants to use cohezive zone model for example). The function allowing to obtain a container of avatars are:

## Extracting a mesh from meshes¶

Eventually a mesh loaded from a file may contain several parts which correspond to different avatars. Using `mesh.separateMeshes()` it is possible to separate the meshes.

Example:

```dim=3
complete_mesh = lecture(name='gmsh/3_briques.msh', dim=dim)
entity2mesh=complete_mesh.separateMeshes(dim=dim, entity_type="geometricalEntity", keep_all_elements=False)
for volumic_mesh in entity2mesh.values():
body = volumicMeshToRigid3D(volumic_mesh=volumic_mesh, model=mod, material=pdur, color='BLEUx')
```

The output when separting meshes is a dictionary.

By the way it is possible to directly separate a surfacic mesh in avatars using `surfacicMeshesToRigid3D()`

## Managing groups¶

Groups are necessary to define model, material, contactors, boundary condition, etc.

When defining material and models with `buildMeshedAvatar()` one implicitely assumes that all the elements have the same group and usually uses default group all. However it is possible to define several material and model:

```my_mesh = lecture('Mesh.msh', dim)
my_mesh.rankRenumbering()
body = avatar(number=1, dimension=dim)
body.defineGroups()
body.defineModel(model=modPorous, group = '11')
body.defineMaterial(material=matBiot, group = '11')
body.defineModel(model=modFluid, group = '12')
body.defineMaterial(material=matStokes, group = '12')
```

## Applying boundary condition without group¶

predicates and so on

```def p(x):
return abs(x - 0.0016) < 5.e-4

other use of `avatar.addContactors()`
```outil.addContactors(group='11',shape='ALpxx',color='BLUEx',reverse='yes')