Skip to content

perf: cheaper nodal-twist kernels (Hessians, frame-only transfer) - #187

Merged
SMI-Lab-Inha merged 4 commits into
devfrom
perf/twist-kernels
Nov 20, 2026
Merged

SMI-Lab-Inha merged 4 commits into
devfrom
perf/twist-kernels

Conversation

@SMI-Lab-Inha

@SMI-Lab-Inha SMI-Lab-Inha commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

A finite-EI cable with the nodal twist (torsion with polar inertia Irn) evaluates, for every element, a reference twist and an element holonomy. On a tangent assembly it also forms their 12 x 12 Hessians. In a coupled OpenFAST run of a lazy-wave power cable these kernels were the largest single part of the cable step.

This PR makes them cheaper in two commits, each measured separately, plus two review fixes to the second. Both are bit-identical: every output, .CD.out row and restart is unchanged to the bit.

1. Cheaper reference and holonomy Hessians (CableDyn_HermiteTorsion)

  • Library calls removed. skew, outer, outer9 and identity3 used RESHAPE and SPREAD, which gfortran compiles into calls into its run-time library (_gfortran_spread, _gfortran_reshape_r8) on every Gauss point and solid angle. They now set their entries one at a time, with the same products.
  • Only the solid-angle blocks that are read. The solid angle of a reference triangle formed its full 9 x 9 Hessian. CD_HermiteTwist_Reference reads only the blocks between the triangle's free vertices: the node tangents, not the committed tangents or end directors. A new optional argument free makes solid_angle form those blocks alone, each entry with the same expression.
  • Holonomy work trimmed. element_holonomy evaluated the shape derivatives twice per Gauss point (once directly, once inside element_ab). It also formed two blocks of its 9 x 9 intermediate Hessian that nothing reads.
  • Fewer check calls. The finiteness checks of the reference vertices and of the Hessian are now one rank-3 test and one rank-2 test, instead of 6 and 12 calls per element.

2. A frame-only twist transfer re-bases only the elements that moved (tw_advance_reference)

CD_HermiteCable_Dyn_Set_Torsion_Frames moves the committed torsion end frames without a step. The OpenFAST output probe calls it on every CalcOutput, and the checkpoint rebuild and linearization call it too. It re-based the reference of every element. The host, however, writes only the end nodes.

tw_advance_reference now forms the unit node tangents first. An interior element (not at a rigid end) keeps its reference twist without the evaluation when its 12 DOFs are those of the last committed step (tw_rq, recorded by the step's tw_commit_reference) and its unit node tangents are those of the present reference, bit for bit. Its transport solid angles are then exactly the reference terms they are differenced against, so twist_reference would return tw_beta(e) + tw_wrap(0) + 0, and that sum is formed directly. The element also passed every check of twist_reference at that very shape.

Matching the tangents alone is not enough for the checks (commit 3, from review): a host that translates an elastically restrained end past its neighbour without turning its tangent folds the end element while both tangents are unchanged. Commit 4, also from review, refines this:

  • tw_rq is recorded only by the commit of a step. A frame-only transfer moves no element DOF but the end nodes', so it keeps tw_rq.
  • A mirror reload keeps tw_rq as well: it is a configuration this model evaluated, and the tangent condition admits a reloaded reference only where it matches. In the first version, a reload dropped it, so the shortcut was off for the next output probe.
  • A change of the unstretched lengths (rebuild_length_caches, active line control) drops tw_rq, because the element shape depends on the reference length. The same happens before the first step and at tw_init.

A frame-only transfer therefore evaluates only the elements at a rigid end, or at a node whose tangent the host turned. The commit of a step still evaluates every element whose tangents moved. A zero tangent handle keeps a zero tangent in the scratch, so its elements are still evaluated and report it.

Tests

  • OpenFAST coupled runs: IEA-15 MW VolturnUS-S with three chains and a lazy-wave power cable (nodal twist, clamped hang-off), 300 s, one thread. The .out and .CD.out of each build are compared with the build without this PR:

    Deck Commit 1 Commits 1 + 2
    241 elements, DT 0.02 s .out and .CD.out byte-identical byte-identical
    291 elements, DT 0.025 s byte-identical byte-identical
  • tests/test_nodal_twist_dynamic.f90 (new gate F) covers the review case. A bending-pinned line, elastic in torsion, is marched. Its coupled end is then written 0.8 m back along the line, past its neighbour, with the tangent unchanged. The write is refused before anything is written, both after the march and after a frame-only transfer of the committed pose. The gate also checks that a step records the configuration, that a length change drops it, and that the next step records it again.

  • Checkpoint restart (checkpoint at 50 s of a 100 s run, compared with the continuous run): the .CD.out (2000 rows) and .out (1000 rows) after 50 s are identical to the continuous run, which is itself byte-identical to the build without this PR.

  • Full ctest (including the slow tier) on the default OpenBLAS kernel and with OPENBLAS_CORETYPE=Prescott: 433 of 433 passed on each.

Cost

This is the simulation CPU time of the 300 s runs, scaled to one simulated hour:

Deck dev Commit 1 (Hessians) Commits 1 + 2 (frame-only transfer) Total change
241 elements, DT 0.02 s 36.52 min/h 33.32 min/h (-3.20) 32.48 min/h (-0.84) -4.04 min/h (-11.1 %)
291 elements, DT 0.025 s 35.03 min/h 31.56 min/h (-3.47) 30.60 min/h (-0.96) -4.43 min/h (-12.6 %)

Final head (ed43f45) against dev (5d97bde), measured interleaved (dev, branch, dev, branch) on a busier machine, so the absolute values sit about 10 % above the table:

Deck dev, runs 1 / 2 ed43f45, runs 1 / 2 Change of the means
241 elements, DT 0.02 s 40.11 / 40.22 min/h 36.57 / 36.12 min/h -9.5 %
291 elements, DT 0.025 s 39.00 / 38.59 min/h 33.74 / 33.69 min/h -13.1 %

The .out and .CD.out files of these runs are byte-identical to dev.

@SMI-Lab-Inha

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T07:10:10.260071Z ed43f45 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@read-the-docs-community

read-the-docs-community Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 CableDyn | 🛠️ Build #36034631 | 📁 Comparing ed43f45 against latest (789cb6d)

  🔍 Preview build  

16 files changed · ± 16 modified

± Modified

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9da84fa58b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/CableDyn_HermiteCableDynamic.f90 Resolved
The nodal twist evaluates every element's reference twist and holonomy,
with their 12 x 12 Hessians on each tangent assembly. On a power cable
with the nodal twist in a coupled OpenFAST run, these kernels are a
large share of the cable step. A good part of that time went on
run-time library calls and on Hessian entries nobody reads:

- skew, outer, outer9 and identity3 used RESHAPE and SPREAD, which
  gfortran turns into calls into its run-time library (spread,
  reshape_r8) on every Gauss point and solid angle. They now set their
  entries one by one, with the same products.
- The solid angle of a reference triangle formed its full 9 x 9 Hessian,
  while CD_HermiteTwist_Reference reads only the blocks between the
  triangle's free vertices (the node tangents; the committed tangents
  and end directors are fixed). With the new optional argument free,
  solid_angle forms those blocks alone, each entry with the same
  expression as before.
- element_holonomy evaluated the shape derivatives twice per Gauss
  point (once directly, once inside element_ab). It also formed the two
  blocks of its 9 x 9 intermediate Hessian that are never read (rows of
  the unit tangent against the r' and r'' columns).
- The finiteness checks of the reference vertices and of the Hessian
  are one rank-3 and one rank-2 test instead of 6 and 12 calls per
  element.

Every entry is formed by the same floating-point operations in the same
order, so the results are bit-identical.

Signed-off-by: Jae Hoon Seo <jaehoon.seo@inha.ac.kr>
CD_HermiteCable_Dyn_Set_Torsion_Frames moves the committed torsion end
frames without a step. The OpenFAST output probe calls it on every
CalcOutput, and the checkpoint rebuild and the linearization call it as
well. It re-based the twist reference of every element
(tw_advance_reference), one twist_reference evaluation per element
including the element holonomy. Yet the host writes only the end nodes,
so the reference twist of every other element stays as it was.

tw_advance_reference now forms the unit node tangents first. An
interior element (not at a rigid end) whose two tangents equal the
reference tangents, bit for bit, keeps its reference twist without the
evaluation. Its transport solid angles are then exactly the reference
terms they are differenced against, so twist_reference returns
tw_beta(e) + tw_wrap(0) + 0; that sum is formed directly. The
directors are carried as before. A frame-only transfer therefore
evaluates only the elements at a rigid end, or at a node whose tangent
the host turned. The commit of a step evaluates every element whose
tangents moved.

A zero tangent handle keeps a zero tangent in the scratch, so its
elements are still evaluated and report it. The results are
bit-identical.

Signed-off-by: Jae Hoon Seo <jaehoon.seo@inha.ac.kr>
The frame-only shortcut of tw_advance_reference kept an element's
reference twist when its two unit node tangents were the reference's.
That was enough for the value: the reference twist depends on the
element only through those tangents. It was not enough for the checks,
though. twist_reference also checks the element's shape (the holonomy's
fold and handle checks). Suppose a host translates an elastically
restrained end past its neighbouring node without turning the end
tangent. The end element then folds while both of its tangents are
unchanged, and the q_check pass of CD_HermiteCable_Dyn_Set_Torsion_Frames
accepted it. So CD_HFMF_SetCoupledKinematics wrote the boundary before
the following assembly found the fold, which broke its all-or-nothing
update.

The committed reference now records the configuration it was formed at
(tw_rq, set by tw_commit_reference from the configuration
tw_advance_reference re-based at). An element keeps its reference twist
only when its 12 DOFs are those, bit for bit, as well as its tangents.
It then passed every check of twist_reference at that very shape. A
reference that comes from a mirror, a snapshot or tw_init carries no
configuration (tw_rq_ok = .FALSE.), so every element is evaluated until
the next commit. The results stay bit-identical.

Signed-off-by: Jae Hoon Seo <jaehoon.seo@inha.ac.kr>
@SMI-Lab-Inha

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0742970893

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/CableDyn_HermiteCableDynamic.f90 Resolved
…nd drops it with the lengths

The reference-twist shortcut of tw_advance_reference keeps an element's
reference twist only at the configuration tw_rq, at which every element
passed every check. Two problems with how tw_rq was kept:

- It was re-recorded at every reference commit, a frame-only transfer's
  included, and dropped by every mirror reload (tw_unpack). In the
  OpenFAST shell the output probe moves the coupled end, commits the
  reference at that pose and is then reloaded from the mirror. So the
  shortcut was off for the probe of the following call, which cost the
  speed-up this change is for. tw_rq is now recorded only by the commit
  of a step (tw_commit_reference without frames_only). A frame-only
  transfer moves no element DOF but the end nodes', and keeps it. A
  reload keeps it as well: tw_rq is a configuration this model evaluated,
  and the shortcut still requires the element's unit node tangents to be
  those of the present reference, so a reloaded reference is used only
  where it matches.
- A change of the unstretched lengths (active line control,
  rebuild_length_caches) did not drop it. The element shape depends on
  its reference length: a 0.5 m element with unit tangent handles folds
  at 2 m with the same DOFs, so its checks no longer hold. tw_rq_ok is
  now cleared there.

Gate F of test_nodal_twist_dynamic gains the length case: a step records
the configuration, a length change drops it, and the next step records
it again. Results stay bit-identical.

Signed-off-by: Jae Hoon Seo <jaehoon.seo@inha.ac.kr>
@SMI-Lab-Inha

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: ed43f45d09

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@SMI-Lab-Inha
SMI-Lab-Inha merged commit 93010d4 into dev Nov 20, 2026
16 checks passed
@SMI-Lab-Inha
SMI-Lab-Inha deleted the perf/twist-kernels branch November 20, 2026 08:03
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