*EQUATION that names the same DOF in two terms is mis-assembled: wrong stiffness and mass, no message

Summary

An *EQUATION in which one DOF appears in two independent terms is accepted without a message. The constraint holds, but the stiffness (and mass) of the eliminated dependent DOF is assembled wrongly. Suppose the dependent DOF has diagonal stiffness k and one independent DOF appears in two terms whose coefficients, divided by the dependent coefficient, are a and b. That independent DOF then receives k(a² + ab + b²) instead of k(a + b)²: the cross term is counted once instead of twice. The manual does not forbid a DOF from appearing twice in one equation.

This also happens without anyone writing a DOF twice. ccx reads equation terms on a node with a *TRANSFORM in local axes and expands each local term into global DOFs. Two local terms of the same node therefore share global DOFs. A second deck below shows this case.

Version

ccx 2.23 (conda-forge build pl5321h484372f_2, macOS arm64). Master (9ba5d76, 2026-10-16) has the same code in mafillsm.f, equations.f and cascade.c; I have not run master.

Minimal input

eqrep.inp:

** spring k=100 on DOF 1 of node 1; node 2 tied to it by u1(1) = u1(2),
** written with the term of node 2 split in two halves; unit force on node 2
*NODE, NSET=NALL
1, 0., 0., 0.
2, 1., 0., 0.
*ELEMENT, TYPE=SPRING1, ELSET=EK
1, 1
*SPRING, ELSET=EK
1
100.
*BOUNDARY
NALL, 2, 3
*EQUATION
3
1, 1, 1., 2, 1, -0.5, 2, 1, -0.5
*STEP
*STATIC
*CLOAD
2, 1, 1.
*NODE PRINT, NSET=NALL
U
*END STEP

eqref.inp is the same deck with the equation written with one term per DOF:

*EQUATION
2
1, 1, 1., 2, 1, -1.
The same bug through a *TRANSFORM (eqtransform.inp)
** spring k=100 on DOF 1 of node 1; node 2 has a *TRANSFORM (45 deg about z), so the
** tie u_x(1) = u_x(2) is written in its local DOFs: u_x(2) = c*u'1(2) - s*u'2(2)
** (ccx expands both local terms into global DOFs 1 and 2 of node 2: each appears twice)
** spring k=300 on global DOF 2 of node 2; unit force on node 1 in x
*NODE, NSET=NALL
1, 0., 0., 0.
2, 1., 0., 0.
*NSET, NSET=N2
2
*TRANSFORM, NSET=N2, TYPE=R
0.70710678, 0.70710678, 0., -0.70710678, 0.70710678, 0.
*ELEMENT, TYPE=SPRING1, ELSET=EK1
1, 1
*ELEMENT, TYPE=SPRING1, ELSET=EK2
2, 2
*SPRING, ELSET=EK1
1
100.
*SPRING, ELSET=EK2
2
300.
*BOUNDARY
1, 2, 3
2, 3, 3
*EQUATION
3
1, 1, 1., 2, 1, -0.70710678, 2, 2, 0.70710678
*STEP
*STATIC
*CLOAD
1, 1, 1.
*NODE PRINT, NSET=NALL, GLOBAL=YES
U
*END STEP

How to run

ccx eqref
ccx eqrep
ccx eqtransform

Then compare the displacements in the .dat files.

Expected

Only the spring resists the unit force, so u1(1) = u1(2) = F/k = 1/100 = 1.0E-02. eqref gives exactly that. eqtransform should also give u_x(1) = u_x(2) = 1.0E-02; the same model without the *TRANSFORM, with the tie in global DOFs, does.

Actual

eqrep finishes with no warning or error:

 displacements (vx,vy,vz) for set NALL and time  0.1000000E+01

         1  1.333333E-02  0.000000E+00  0.000000E+00
         2  1.333333E-02  0.000000E+00  0.000000E+00

That is F/(0.75 k), 33 % too large. Other splits follow k(a² + ab + b²) exactly:

split of the node-2 term ccx gives correct
-0.25 and -0.75 1.230769E-02 (= F/0.8125k) 1.0E-02
-2 and +1 3.333333E-03 (= F/3k) 1.0E-02

eqtransform gives the same wrong value, with no message:

         1  1.333333E-02  0.000000E+00  0.000000E+00
         2  1.333333E-02  0.000000E+00  0.000000E+00

The mass matrix is affected the same way. Consider a *FREQUENCY step with a point mass of 1 on node 1, the spring on node 2, the half split, and a few stiff, separate spring–mass pairs added so that ARPACK has enough DOFs. ccx gives 1.837763 Hz instead of 1.591549 Hz (ω² = 100/0.75 instead of 100).

The constraint itself is satisfied. With NLGEOM the static result is nearly right (9.986283E-03), because the residual is correct and only the tangent matrix is wrong.

Where it goes wrong

mafillsm.f, branch MPC id1 / MPC id1 (lines 447 ff. and 795 ff. on master). This branch handles an element entry whose row and column are the same dependent DOF. It visits each pair of terms (index1, index2 ≥ index1) once. That is right for symmetric storage as long as the terms name different DOFs. When two terms name the same DOF, the pair lands on the diagonal, and add_sm_st (called with i0,i0) adds it once, although it stands for both (a,b) and (b,a):

!     MPC id1 / MPC id1
                    ...
                      index2=index1
                      do
                        idof2=nactdof(nodempc(2,index2),
     &                       nodempc(1,index2))
                        value=coefmpc(index1)*coefmpc(index2)*
     &                       s(jj,ll)/coefmpc(ist)/coefmpc(ist)
                        if((idof1.gt.0).and.(idof2.gt.0)) then
                          if(stiffonly(1).eq.1) then
                            call add_sm_st(au,ad,jq,irow,
     &                           idof1,idof2,value,i0,i0)

The neighbouring branches regular DOF / MPC and MPC id1 / MPC id2 contain if(idof1.eq.idof2) value=2.d0*value (and the same for valu2). This branch has no such line.

equations.f stores the terms as read. cascade.c merges repeated terms (“collecting terms corresponding to the same DOF”) only in an equation into which another MPC is substituted. Accordingly, when node 2’s DOF is itself the dependent term of a second equation, u1(2) = u1(3), with the load moved to node 3, ccx gives the correct 1.0E-02.

There are two possible fixes. One is to merge repeated (node, DOF) terms of every equation once, for instance by running cascade.c’s term collection on all MPCs. The other is to double value and valu2 in this branch when index1.ne.index2 and idof1.eq.idof2.

Workaround

Write each DOF once per equation, adding up its coefficients. When the repeats come from a *TRANSFORM, add an untransformed twin node at the same place. Tie it to the node with one equation per local direction, u’_j(node) − e_j · u(twin) = 0, and use the twin’s global DOFs in the equation. In eqtransform, this gives the correct 1.0E-02.

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

eqref.dat:

 displacements (vx,vy,vz) for set NALL and time  0.1000000E+01

         1  1.000000E-02  0.000000E+00  0.000000E+00
         2  1.000000E-02  0.000000E+00  0.000000E+00

eqrep.dat:

 displacements (vx,vy,vz) for set NALL and time  0.1000000E+01

         1  1.333333E-02  0.000000E+00  0.000000E+00
         2  1.333333E-02  0.000000E+00  0.000000E+00

eqtransform.dat:

 displacements (vx,vy,vz) for set NALL and time  0.1000000E+01

         1  1.333333E-02  0.000000E+00  0.000000E+00
         2  1.333333E-02  0.000000E+00  0.000000E+00

Posted: *EQUATION that names the same DOF in two terms is mis-assembled: wrong stiffness and mass, no message · Issue #212 · Dhondtguido/CalculiX · GitHub

1 Like