Skip to content

Skip fiber stretch/rate computation when active stress model doesn't need it - #610

Open
dseyler wants to merge 5 commits into
SimVascular:mainfrom
dseyler:perf/skip-unused-fiber-stretch
Open

Skip fiber stretch/rate computation when active stress model doesn't need it#610
dseyler wants to merge 5 commits into
SimVascular:mainfrom
dseyler:perf/skip-unused-fiber-stretch

Conversation

@dseyler

@dseyler dseyler commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Current situation

As discussed in issue #604, this PR adds flags stating whether each active stress model needs to use fiber stretch or stretch rate. Computing these quantities at each time step was quite expensive (~5% of total runtime for 500k element simulation), so it makes sense to skip when the active stress model does not need them.

In active_stress.h:

  /// Whether this model uses fiber stretch.
  const bool needs_fiber_stretch;

  /// Whether this model uses fiber stretch rate.
  const bool needs_fiber_stretch_rate;

In each active stress model:

NashPanfilov() : ActiveStressODE(/* n_state_variables = */ 1,
                                  /* needs_fiber_stretch = */ false,
                                  /* needs_fiber_stretch_rate = */ false) {}

Then Integrator::predictor() determines when stretch and stretch rate should be computed:

    for (const auto &dmn : eq.dmn) {
        if (dmn.active_stress != nullptr) {
          need_fiber_stretch = true;
          need_fiber_stretch_rate = true;
          have_active_stress = true;
          need_fiber_stretch |= dmn.active_stress->needs_fiber_stretch;
          need_fiber_stretch_rate |=
              dmn.active_stress->needs_fiber_stretch_rate;
.
.
.

    if (need_fiber_stretch && fiber_stretch_eq_index >= 0) {
      for (const auto &mesh : com_mod.msh) {
        Vector<double> tmp(mesh.nNo);

        post::fib_stretch(com_mod, fiber_stretch_eq_index, mesh, Dn, tmp);
        for (int a = 0; a < mesh.nNo; ++a)
          fiber_stretch[mesh.gN[a]] = tmp[a];

Release Notes

  • Added needs_fiber_stretch and needs_fiber_stretch_rate for each active stress model
  • Integrator::predictor() only computes stretch/rate when needed

Testing

Please ensure that the PR meets the testing requirements set by GitHub Actions.

In addition, please ensure all modified and new code is covered by tests.

Code of Conduct & Contributing Guidelines

@dseyler
dseyler requested review from kko27 and michelebucelli and a lite review from Copilot August 20, 2026 18:01

@claude claude 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds per–active stress model flags indicating whether fiber stretch and/or fiber stretch rate are required, and updates Integrator::predictor() to compute those quantities only when needed (reducing per-step overhead for models that don’t use them).

Changes:

  • Add needs_fiber_stretch / needs_fiber_stretch_rate flags to the ActiveStress base class and plumb them through ActiveStressODE.
  • Update active stress model constructors to declare their stretch / stretch-rate requirements.
  • Update Integrator::predictor() to allocate stretch vectors when active stress is present, but only compute stretch/rate when required by at least one model.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Code/Source/solver/Integrator.cpp Computes fiber stretch/rate conditionally based on active stress model needs while preserving required allocations.
Code/Source/solver/active_stress.h Adds required flags to the ActiveStress API via constructor + public const members.
Code/Source/solver/active_stress_ode.h Extends ActiveStressODE constructor to forward stretch/rate requirement flags.
Code/Source/solver/active_stress_uniform_unsteady.h Declares uniform-unsteady model does not require stretch or stretch rate.
Code/Source/solver/active_stress_uniform_steady.h Declares uniform-steady model does not require stretch or stretch rate.
Code/Source/solver/active_stress_regazzoni.h Declares Regazzoni model requires stretch and stretch rate.
Code/Source/solver/active_stress_nash_panfilov.h Declares Nash–Panfilov model does not require stretch or stretch rate.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 466 to +468
// Determine if we need to compute fiber stretch and stretch rate, by going
// through all domains of all equations until we find one for which active
// stress is enabled.
// stress is enabled and the active stres model needs the stretch or stretch rate.
Comment on lines +520 to 524
if (have_active_stress) {
fiber_stretch_rate.resize(com_mod.tnNo);

if (fiber_stretch_eq_index >= 0) {
if (need_fiber_stretch_rate && fiber_stretch_eq_index >= 0) {
for (const auto &mesh : com_mod.msh) {
Comment on lines +126 to +128
RegazzoniActiveStress() : ActiveStress(/* n_state_variables = */ n_state_variables,
/* needs_fiber_stretch = */ true,
/* needs_fiber_stretch_rate = */ true) {}
Comment thread Code/Source/solver/active_stress_uniform_steady.h Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.73%. Comparing base (a3413e0) to head (0e51c7f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #610   +/-   ##
=======================================
  Coverage   72.73%   72.73%           
=======================================
  Files         255      255           
  Lines       39290    39300   +10     
  Branches     6726     6726           
=======================================
+ Hits        28576    28586   +10     
  Misses      10472    10472           
  Partials      242      242           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants