Skip to content

constr_user: fixed DOFs and user constraints were not applied - #318

Open
mageaustralia wants to merge 1 commit into
brookshsmith:masterfrom
mageaustralia:fix/constr-user-basis
Open

mageaustralia wants to merge 1 commit into
brookshsmith:masterfrom
mageaustralia:fix/constr-user-basis

Conversation

@mageaustralia

@mageaustralia mageaustralia commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

cfsm.constr_user should return the reduced basis R (one column per DOF left free after the node DOF flags and the master-slave constraints), as CUFSM's constr_user.m does. Three things in the current version stop that:

  1. r_user_matrix starts as np.eye(n_dof_m * len(m_a)) instead of zeros, so it keeps identity columns beyond the assigned blocks. They restore exactly the DOFs that were meant to be eliminated, and with several longitudinal terms they also couple the term blocks.
  2. The column-selection loop starts k at -1 and then slices [:, 0:k], which drops the last free DOF.
  3. The constraint node numbers are used as indices without int(). Constraint arrays are float (as load_cufsm_mat returns them), so any user constraint raises IndexError.

Because of (1), R comes back square and full rank. strip then takes null_space(r_user.T) as the constrained directions, finds none (nu0 = 0), and solves the model as if every DOF were free.

Effect on results

On CUFSM's tutorial lipped channel (10 nodes, S-S, unit compression), compared with CUFSM:

Case Before After
No fixed DOFs matches matches
Lip-end y and theta fixed up to 16% off (80.50 vs 96.29 at L = 30) matches to 3e-9
Master-slave constraint IndexError matches to 2e-8

(The reference values come from an independent port that is regression-tested against CUFSM
itself, run in Octave.)

Changes

  • solve/cfsm.py (constr_user):
    • start from zeros;
    • keep one column per free DOF (r_user_m_matrix[:, dof_reg == 1]);
    • assemble the blocks diagonally, sized (4n * M) x (k * M) as in constr_user.m;
    • cast the constraint node numbers to int.
  • tests/test_constr_user.py: the basis shape and which DOFs it can move (one term and two
    terms), block-diagonality, orthonormal columns, and a master-slave constraint.

Testing

  • The new tests fail on master (12x12 instead of 12x11; 24x24 instead of 24x20; IndexError)
    and pass with the fix.
  • The existing suite passes with both PRs applied (numpy 2.5.3). On its own this PR is checked
    by its unit tests, since end-to-end solves on master need PR 1 first.

A related observation, not changed here: load_cufsm_mat converts constraints to 0-based only
when a row has more than 5 columns. A 5-column constraints block from a .mat file would keep
1-based node numbers. Happy to open a separate issue if useful.

constr_user should return the reduced basis R, one column per DOF left free by
the node DOF flags and master-slave constraints, as CUFSM's constr_user.m does.

- r_user_matrix started as np.eye(n_dof_m * len(m_a)), so identity columns
  beyond the assigned blocks restored the eliminated DOFs (and coupled the
  term blocks when there are several terms). R came back square and full
  rank, null_space(r_user.T) was empty, nu0 was 0, and strip solved the
  model with every DOF free. It now starts from zeros and is assembled
  block-diagonally, (4n * M) x (k * M).
- The column selection started k at -1 and sliced [:, 0:k], dropping the
  last free DOF. It now keeps r_user_m_matrix[:, dof_reg == 1].
- Constraint node numbers were used as indices without int(); constraint
  arrays are float, so any user constraint raised IndexError.

tests/test_constr_user.py covers the basis shape and free DOFs for one and
two terms, block-diagonality, orthonormal columns, and a master-slave
constraint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant