# Contact Element Example¶

This example demonstrates how to create contact elements for general contact.

Begin by launching MAPDL.

```from ansys.mapdl import core as pymapdl

mapdl = pymapdl.launch_mapdl()
```

Enter the pre-processor, create a block and mesh it with tetrahedral elements.

```mapdl.prep7()

vnum0 = mapdl.block(0, 1, 0, 1, 0, 0.5)

mapdl.et(1, 187)
mapdl.esize(0.1)

mapdl.vmesh(vnum0)
mapdl.eplot()
``` Out:

```[(2.173032607475616, 2.173032607475616, 1.923032607475616),
(0.5, 0.5, 0.25),
(0.0, 0.0, 1.0)]
```

Second a volume block above the existing block and mesh it with quadratic hexahedral elements. Ensure that these blocks do not touch by starting it slightly higher than the existing block.

Note how these two blocks do not touch and the mesh is non-conformal.

```mapdl.esize(0.09)
mapdl.et(2, 186)
mapdl.type(2)
vnum1 = mapdl.block(0, 1, 0, 1, 0.50001, 1)
mapdl.vmesh(vnum1)
mapdl.eplot()
``` Out:

```[(2.431851652578137, 2.431851652578137, 2.431851652578137),
(0.5, 0.5, 0.5),
(0.0, 0.0, 1.0)]
```

Select all the elements at the intersection between the two blocks and generate contact elements.

```mapdl.nsel('s', 'loc', 'z', 0.5, 0.50001)
mapdl.esln('s')
output = mapdl.gcgen('NEW', splitkey='SPLIT', selopt='SELECT')
print(output)
```

Out:

```GENERATE GENERAL CONTACT ELEMENTS
FEATURE ANGLE FOR SURFACE SPLITTING =   42.0 DEGREES
ASSIGN SECNUM BASED ON SPLIT SURFACES
USE EXTERIOR FACES OF SELECTED ELEMENTS ONLY

Number of general CONTA174 elements created =       366
on exterior faces of 3D solid base elements
New general contact elements have Section ID from     5 to     6
```

Plot the contact element pairs. Note from the command output above that the section IDs are 5 and 6.

Here, we plot the element mesh as a wire-frame to show that the contact pairs overlap.

```mapdl.esel('S', 'SEC', vmin=5, vmax=6)
mapdl.eplot(style='wireframe', line_width=3)
``` Out:

```[(2.07735026922906, 2.07735026922906, 2.07735526922906),
(0.5, 0.5, 0.500005),
(0.0, 0.0, 1.0)]
```

Total running time of the script: ( 0 minutes 1.882 seconds)

Gallery generated by Sphinx-Gallery