# Node-to-surface contact: a slave surface with many faces (e.g. a whole body) overflows the slave-face arrays in inicont.c: wrong forces, hangs or crashes

**URL:** <https://calculix.discourse.group/t/node-to-surface-contact-a-slave-surface-with-many-faces-e-g-a-whole-body-overflows-the-slave-face-arrays-in-inicont-c-wrong-forces-hangs-or-crashes/4297>\
**Category:** Analysis issues\
**Created:** [November 3, 2026, 9:17pm UTC](https://calculix.discourse.group/t/node-to-surface-contact-a-slave-surface-with-many-faces-e-g-a-whole-body-overflows-the-slave-face-arrays-in-inicont-c-wrong-forces-hangs-or-crashes/4297 "2026-11-03T21:17:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandervdb](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@Sandervdb](https://calculix.discourse.group/u/Sandervdb)\
**Post date:** [November 3, 2026, 9:17pm UTC](https://calculix.discourse.group/t/node-to-surface-contact-a-slave-surface-with-many-faces-e-g-a-whole-body-overflows-the-slave-face-arrays-in-inicont-c-wrong-forces-hangs-or-crashes/4297/1 "2026-11-03T21:17:46Z")

</div>

## Summary

For node-to-surface contact, `tiefaccont.f` stores, for each contact pair, one entry per slave face in `islavsurf` and one entry per (slave node, slave face) incidence in `inoels` and `xnoels`. `inicont.c` allocates these arrays before the call with room for `6*ne` faces (`islavsurf`) and `nkon` incidences (`inoels`, `xnoels`), i.e. for the size of the whole mesh. When the slave surfaces of all pairs together have more face-node incidences than the mesh has element-node incidences, `tiefaccont.f` writes past the end of the arrays.

That happens in small models whose slave surface is a whole body, and when one body is the slave of two pairs. Depending on what gets overwritten, ccx

- returns a wrong contact force with exit 0 and no message (two cubes: 1.04 instead of 5.00, plus lateral forces of 0.52 although nothing is loaded sideways);
- hangs;
- crashes with SIGSEGV or SIGBUS.

With the three arrays allocated ten times larger, every deck below runs and gives the right force.

## Version

ccx 2.23 (macOS arm64) and current master (537aa81, 2 Nov 2026): the same numbers and outcomes.

## Already reported or fixed?

Not reported: I found no GitHub issue or pull request in Dhondtguido/CalculiX about `inicont`, `tiefaccont`, `inoels` or wrong forces with whole-body slave surfaces, and no matching calculix.discourse.group topic title (searched 3 Nov 2026). Not fixed: `inicont.c` lines 91 and 95-96 are unchanged on master.

## Minimal input

`n2f_all.inp`: one pair. The slave surface is the whole upper cube (6 faces, 24 face-node incidences); the mesh has 2 elements, so `nkon` = 16.

```auto
** Two unit cubes stacked at z = 1 (E = 1000, nu = 0), the upper one pushed
** 0.01 into the lower one; node-to-surface contact, K = 1.E6.
** Expected reaction: 0.01/(1/1000 + 1/1000 + 1/1.E6) = 4.9975.
** The slave surface is the whole upper cube (all six faces).
*NODE, NSET=NALL
1, 0., 0., 0.
2, 1., 0., 0.
3, 1., 1., 0.
4, 0., 1., 0.
5, 0., 0., 1.
6, 1., 0., 1.
7, 1., 1., 1.
8, 0., 1., 1.
9, 0., 0., 1.
10, 1., 0., 1.
11, 1., 1., 1.
12, 0., 1., 1.
13, 0., 0., 2.
14, 1., 0., 2.
15, 1., 1., 2.
16, 0., 1., 2.
*ELEMENT, TYPE=C3D8, ELSET=LOW
1, 1, 2, 3, 4, 5, 6, 7, 8
*ELEMENT, TYPE=C3D8, ELSET=UP
2, 9, 10, 11, 12, 13, 14, 15, 16
*NSET, NSET=BOT
1, 2, 3, 4
*NSET, NSET=TOP
13, 14, 15, 16
*MATERIAL, NAME=M
*ELASTIC
1000., 0.
*SOLID SECTION, ELSET=LOW, MATERIAL=M
*SOLID SECTION, ELSET=UP, MATERIAL=M
*SURFACE, NAME=LTOP
LOW, S2
*SURFACE, NAME=USL
UP, S1
UP, S2
UP, S3
UP, S4
UP, S5
UP, S6
*SURFACE INTERACTION, NAME=SI
*SURFACE BEHAVIOR, PRESSURE-OVERCLOSURE=LINEAR
1.E6
*CONTACT PAIR, INTERACTION=SI, TYPE=NODE TO SURFACE
USL, LTOP
*BOUNDARY
BOT, 1, 3
NALL, 1, 2
*STEP
*STATIC
1., 1.
*BOUNDARY
TOP, 3, 3, -0.01
*NODE PRINT, NSET=TOP, TOTALS=ONLY
RF
*END STEP

```

> **stack3x.inp: three blocks; the middle block's whole exterior surface is the slave of the block above and of the block below (two pairs, 60 slave faces, 240 incidences; nkon = 136)**
>
> ```auto
> ** Three blocks stacked in z: C (2 x 2 C3D8, held at z = 0), B (3 x 3 C3D8),
> ** A (2 x 2 C3D8, pushed down 0.01 at z = 1.5). Node-to-surface contact:
> ** B (its whole exterior surface, BALL) is the slave of A's bottom
> ** and of C's top.
> *NODE, NSET=NALL
> 1, 0, 0, 0
> 2, 0.6, 0, 0
> 3, 1.2, 0, 0
> 4, 0, 0.6, 0
> 5, 0.6, 0.6, 0
> 6, 1.2, 0.6, 0
> 7, 0, 1.2, 0
> 8, 0.6, 1.2, 0
> 9, 1.2, 1.2, 0
> 10, 0, 0, 0.5
> 11, 0.6, 0, 0.5
> 12, 1.2, 0, 0.5
> 13, 0, 0.6, 0.5
> 14, 0.6, 0.6, 0.5
> 15, 1.2, 0.6, 0.5
> 16, 0, 1.2, 0.5
> 17, 0.6, 1.2, 0.5
> 18, 1.2, 1.2, 0.5
> 19, 0, 0, 0.5
> 20, 0.4, 0, 0.5
> 21, 0.8, 0, 0.5
> 22, 1.2, 0, 0.5
> 23, 0, 0.4, 0.5
> 24, 0.4, 0.4, 0.5
> 25, 0.8, 0.4, 0.5
> 26, 1.2, 0.4, 0.5
> 27, 0, 0.8, 0.5
> 28, 0.4, 0.8, 0.5
> 29, 0.8, 0.8, 0.5
> 30, 1.2, 0.8, 0.5
> 31, 0, 1.2, 0.5
> 32, 0.4, 1.2, 0.5
> 33, 0.8, 1.2, 0.5
> 34, 1.2, 1.2, 0.5
> 35, 0, 0, 1
> 36, 0.4, 0, 1
> 37, 0.8, 0, 1
> 38, 1.2, 0, 1
> 39, 0, 0.4, 1
> 40, 0.4, 0.4, 1
> 41, 0.8, 0.4, 1
> 42, 1.2, 0.4, 1
> 43, 0, 0.8, 1
> 44, 0.4, 0.8, 1
> 45, 0.8, 0.8, 1
> 46, 1.2, 0.8, 1
> 47, 0, 1.2, 1
> 48, 0.4, 1.2, 1
> 49, 0.8, 1.2, 1
> 50, 1.2, 1.2, 1
> 51, 0, 0, 1
> 52, 0.6, 0, 1
> 53, 1.2, 0, 1
> 54, 0, 0.6, 1
> 55, 0.6, 0.6, 1
> 56, 1.2, 0.6, 1
> 57, 0, 1.2, 1
> 58, 0.6, 1.2, 1
> 59, 1.2, 1.2, 1
> 60, 0, 0, 1.5
> 61, 0.6, 0, 1.5
> 62, 1.2, 0, 1.5
> 63, 0, 0.6, 1.5
> 64, 0.6, 0.6, 1.5
> 65, 1.2, 0.6, 1.5
> 66, 0, 1.2, 1.5
> 67, 0.6, 1.2, 1.5
> 68, 1.2, 1.2, 1.5
> *ELEMENT, TYPE=C3D8, ELSET=EALL
> 1, 1, 2, 5, 4, 10, 11, 14, 13
> 2, 2, 3, 6, 5, 11, 12, 15, 14
> 3, 4, 5, 8, 7, 13, 14, 17, 16
> 4, 5, 6, 9, 8, 14, 15, 18, 17
> 5, 19, 20, 24, 23, 35, 36, 40, 39
> 6, 20, 21, 25, 24, 36, 37, 41, 40
> 7, 21, 22, 26, 25, 37, 38, 42, 41
> 8, 23, 24, 28, 27, 39, 40, 44, 43
> 9, 24, 25, 29, 28, 40, 41, 45, 44
> 10, 25, 26, 30, 29, 41, 42, 46, 45
> 11, 27, 28, 32, 31, 43, 44, 48, 47
> 12, 28, 29, 33, 32, 44, 45, 49, 48
> 13, 29, 30, 34, 33, 45, 46, 50, 49
> 14, 51, 52, 55, 54, 60, 61, 64, 63
> 15, 52, 53, 56, 55, 61, 62, 65, 64
> 16, 54, 55, 58, 57, 63, 64, 67, 66
> 17, 55, 56, 59, 58, 64, 65, 68, 67
> *MATERIAL, NAME=M
> *ELASTIC
> 1000., 0.
> *SOLID SECTION, ELSET=EALL, MATERIAL=M
> *ELSET, ELSET=EC
> 1, 2, 3, 4
> *ELSET, ELSET=EB
> 5, 6, 7, 8, 9, 10, 11, 12, 13
> *ELSET, ELSET=EA
> 14, 15, 16, 17
> *SURFACE, NAME=ABOT
> EA, S1
> *SURFACE, NAME=CTOP
> EC, S2
> *SURFACE, NAME=BALL
> EB, S1
> EB, S2
> 5, S3
> 6, S3
> 7, S3
> 7, S4
> 10, S4
> 13, S4
> 11, S5
> 12, S5
> 13, S5
> 5, S6
> 8, S6
> 11, S6
> *SURFACE INTERACTION, NAME=SI
> *SURFACE BEHAVIOR, PRESSURE-OVERCLOSURE=LINEAR
> 1.E6
> *CONTACT PAIR, INTERACTION=SI, TYPE=NODE TO SURFACE
> BALL, ABOT
> BALL, CTOP
> *NSET, NSET=BASE
> 1, 2, 3, 4, 5, 6, 7, 8, 9
> *NSET, NSET=TOP
> 60, 61, 62, 63, 64, 65, 66, 67, 68
> *BOUNDARY
> BASE, 1, 3
> NALL, 1, 2
> *STEP
> *STATIC
> 1., 1.
> *BOUNDARY
> TOP, 3, 3, -0.01
> *NODE PRINT, NSET=TOP, TOTALS=ONLY
> RF
> *END STEP
> 
> ```

## How to run

```auto
ccx n2f_all
ccx stack3x

```

## Expected

`n2f_all`: total force on TOP about (0, 0, -4.9975), as with the bottom face alone as slave surface.

`stack3x`: about (0, 0, -9.47), as with B’s top face as slave of A and B’s bottom face as slave of C.

## Actual

ccx 2.23 and master give the same results. “Job finished”, exit 0, unless noted otherwise:

| deck | total force on TOP (fx, fy, fz) | with the three arrays 10x larger |
| --- | --- | --- |
| `n2f_all.inp` (6 faces, 24 incidences \> nkon 16) | **5.207239E-01 -5.207239E-01 -1.041448E+00** | -1.342649E-14 1.346715E-14 -4.999157E+00 |
| slave `UP, S1` only (4 incidences) | -7.083906E-15 6.799303E-15 -4.997494E+00 | same |
| slave `UP, S1` … `UP, S4` (16 incidences = nkon) | 2.078501E-04 -2.078501E-04 -4.998533E+00 | same |
| `n2f_all.inp` with `TYPE=SURFACE TO SURFACE` | -1.044493E-14 -8.850207E-14 -4.997501E+00 | same |
| `n2f_all.inp` with the line `USL, LTOP` written twice | **hangs** (killed after 60 s) | -4.999575E+00 |
| … written three times | **SIGBUS** | runs |
| … written four times | **SIGSEGV** (master: hangs in 2 of 4 runs) | runs |
| `stack3x.inp` (240 incidences \> nkon 136) | **-2.828206E-01 -1.897738E-01 -6.176028E+00** | -5.252743E-15 9.436896E-15 -9.474692E+00 |
| `stack3x.inp`, BALL = top and bottom faces only (`BTOP, ABOT` and `BBOT, CTOP`) | 5.481726E-15 7.466250E-15 -9.471298E+00 | same |
| `stack3x.inp`, BALL = every face of B’s elements (`EB, S1` … `EB, S6`; 108 faces \> 6·ne = 102) | **SIGSEGV** or SIGBUS (2.23), **SIGBUS** or SIGABRT (master) | -9.480282E+00 |

No message in any of these runs. The outcome is not fully repeatable, as expected from an out-of-bounds write: one of eight master runs of `n2f_all.inp` aborted with SIGABRT instead of printing the force (another eight runs all printed it), and the crashing rows change between SIGSEGV, SIGBUS, SIGABRT and a hang from run to run (four runs each); the three-times row gave SIGBUS in all eight runs. (The slightly different values with the larger arrays come from the side faces’ share in the slave-node areas.)

Section 6.7.8 of the 2.23 manual (face-to-face mortar contact) advises: “One must not use the same contact surface in more than one contact definition”. `n2f_all.inp` has a single pair, so that advice does not cover it. Where a surface is reused (the repeated lines, `stack3x.inp`), the runs with larger arrays show that node-to-surface contact handles it correctly once the arrays are big enough; if reuse is not meant to be allowed, a message would be the way to say so.

I counted the entries in a build with a print at the end of `tiefaccont.f`: `n2f_all.inp` stores `ifreenoels` = 24 incidences against room for 16, `stack3x.inp` 240 against 136, and the every-face variant 108 faces against room for 102 and 432 incidences.

## Where it goes wrong

`src/inicont.c` (master):

```c
  RENEW(islavsurf,ITG,2*6**ne);DMEMSET(islavsurf,0,12**ne,0); /* line 91 */
  ...
  NNEW(inoels,ITG,2**nkon); /* line 95 */
  NNEW(xnoels,double,*nkon); /* line 96 */
  ...
  FORTRAN(tiefaccont,(...,itiefac,islavsurf,islavnode,...,ifacecount,
       iponoels,inoels,&ifreenoels,...,xnoels));
  RENEW(islavsurf,ITG,2**ifacecount+2); /* line 110 */
  RENEW(islavnode,ITG,*nslavs);
  RENEW(inoels,ITG,2*ifreenoels);
  RENEW(xnoels,double,ifreenoels);

```

`src/tiefaccont.f` appends to these arrays pair by pair: `ifacecount` counts the slave faces of all pairs, and `ifreenoels` one entry per slave node and slave face of each pair (for element-face slave surfaces line 402: `ifacecount=ifacecount+1`, `islavsurf(1,ifacecount)=...`, and line 470: `ifreenoels=ifreenoels+1`, then `inoels(1,ifreenoels)=...`, `xnoels(ifreenoels)=...`; the nodal-slave-surface branch does the same at line 239). Neither count is bounded by the size of the mesh. A quadrilateral slave face adds 4 incidences and an element brings 8 to `nkon`, so a C3D8 model overflows `inoels` as soon as its slave faces outnumber twice its elements. A body that is the slave of two pairs counts twice.

`allocont` already returns the number of slave faces of all pairs (`ncone`) before these allocations, and `islavnode` is sized from it (`8*ncone`, line 92).

## Fix

Size the three arrays from the slave surfaces instead of the mesh. For element-face slave surfaces, `ncone` faces and `8*ncone` incidences (8 = the largest number of nodes per face) are upper bounds, as `islavnode` already uses. For a nodal slave surface (`*SURFACE, TYPE=NODE`), where `ncone` counts nodes, the bound has to come from the faces around those nodes; alternatively `tiefaccont.f` could count first and fill in a second pass. The `RENEW` calls after `tiefaccont` already trim the arrays to the size used.

---

<div class="post-metadata">

**Author:** ![Calc\_em](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@Calc\_em](https://calculix.discourse.group/u/Calc_em)\
**Post date:** [November 3, 2026, 10:58pm UTC](https://calculix.discourse.group/t/node-to-surface-contact-a-slave-surface-with-many-faces-e-g-a-whole-body-overflows-the-slave-face-arrays-in-inicont-c-wrong-forces-hangs-or-crashes/4297/2 "2026-11-03T22:58:25Z")

</div>

Confirmed using official ccx 2.23 build on Windows, needs a GitHub ticket.

> [@Sandervdb](#):
>
> The outcome is not fully repeatable, as expected from an out-of-bounds write: one of eight master runs of `n2f_all.inp` aborted with SIGABRT instead of printing the force (another eight runs all printed it)

For me, it also keeps crashing. And it happens all the time.

---

<div class="post-metadata">

**Author:** ![Sandervdb](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@Sandervdb](https://calculix.discourse.group/u/Sandervdb)\
**Post date:** [November 4, 2026, 6:37am UTC](https://calculix.discourse.group/t/node-to-surface-contact-a-slave-surface-with-many-faces-e-g-a-whole-body-overflows-the-slave-face-arrays-in-inicont-c-wrong-forces-hangs-or-crashes/4297/3 "2026-11-04T06:37:39Z")

</div>

Posted: [Node-to-surface contact: a slave surface with many faces (e.g. a whole body) overflows the slave-face arrays in inicont.c: wrong forces, hangs or crashes · Issue #317 · Dhondtguido/CalculiX · GitHub](https://github.com/Dhondtguido/CalculiX/issues/317)
