Skip to content

Fix strip output assembly when mode count or DOF vary between lengths - #329

Open
NR-racond wants to merge 1 commit into
brookshsmith:masterfrom
NR-racond:fix/strip-variable-mode-count
Open

NR-racond wants to merge 1 commit into
brookshsmith:masterfrom
NR-racond:fix/strip-variable-mode-count

Conversation

@NR-racond

Copy link
Copy Markdown

Problem

pycufsm.fsm.strip fails when it is called with several lengths and the results do not all have the same size:

  1. The number of valid modes varies between lengths. Eigenvalues are filtered per length (imaginary, non-positive and > 1e6 load factors are dropped), so long half-wavelengths can keep fewer than n_eigs modes. The final padding loop copies every length into [:max_n_modes] and raises:
    ValueError: could not broadcast input array from shape (8,) into shape (10,)
    
  2. Several longitudinal terms (m_all with more than one term). Each mode then has 4 * n_nodes * total_m DOF, but uniform_shapes is sized with 4 * n_nodes:
    ValueError: could not broadcast input array from shape (10,444) into shape (10,148)
    

Reproduction

A lipped channel 200 x 75 x 20 x 2 (mm), uniform compression, S-S, n_eigs=10, 20 lengths from 10 to 20 000 mm: the number of modes per length is 10 up to ~3 000 mm and then 8, 7, 7, 6, so strip raises (1). The same section with B_C="C-C" and m_all=[[1, 2, 3]] * 3 raises (2). Each length on its own runs fine.

Fix

Pad every length to the largest mode count and the largest DOF count actually found, copying only the modes each length has. The zero padding (which the code already used) is now documented in the strip docstring. No change in results for lengths that already had max_n_modes modes.

Tests

New tests/test_strip.py (coarse plain channel, runs in ~0.2 s):

  • results are padded to the largest mode count, with zeros after the last valid mode
  • each row matches running that length on its own (signature, curve and shapes)
  • with m_all = [1, 2, 3] (C-C), shapes keep 4 * n_nodes * 3 DOF

All three fail on master and pass with this change.

Checks (pinned dev/test dependencies, numpy 2.2.6)

  • pylint ./pycufsm: 10.00/10
  • black --check .: passed
  • mypy: no issues
  • pytest --pspec tests/: 49 passed locally

Note: CI may show the same unrelated test_e2e.py::…rack_post_Mz::it_results_in_correct_signature_curve failure seen on #327 and #328 (see the comment on #328).

Independent of #328.

strip() filters eigenvalues per length, so the number of valid modes can
differ between lengths (e.g. fewer modes at long half-wavelengths). The
final padding loop copied every length into [:max_n_modes], raising
"could not broadcast input array from shape (8,) into shape (10,)".
It also sized the mode shapes as 4 * n_nodes DOF, which fails when m_all
has more than one longitudinal term (4 * n_nodes * total_m DOF).

Pad each length to the largest mode count and DOF actually found, and
document the zero padding in the docstring.

Add tests: results padded to the largest mode count, each row equal to a
single-length run, and all DOF kept with several longitudinal terms.
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