Skip to content

Allow 0D solver to be coupled to equations other than the first - #605

Open
michelebucelli wants to merge 10 commits into
SimVascular:mainfrom
michelebucelli:fix/sv0d-equation-order
Open

Allow 0D solver to be coupled to equations other than the first#605
michelebucelli wants to merge 10 commits into
SimVascular:mainfrom
michelebucelli:fix/sv0d-equation-order

Conversation

@michelebucelli

Copy link
Copy Markdown
Collaborator

Fixes #592

Current situation

The interface to svZeroDSolver assumes that the equation it is being coupled to is the first. If it isn't, any indication of coupling to svZeroDSolver in the XML file is silently disregarded.

Release Notes

  1. svZeroDSolver can be coupled to an arbitrary equation. The coupled equation index is tracked in cplBCType::equation_index. Coupling to multiple equations was and still is unsupported.
  2. Several integral computation functions have been modified to select the right variable to integrate based on the equation index. These include CoupledBoundaryCondition::compute_flowrates, CoupledBoundaryCondition::compute_pressures, gnnbandinteg`.
  3. The interface to gnnb and integ has been simplified to remove redundant arguments (e.g. separately passing an Array and its size).
  4. Perturbation magnitudes used to evaluate the derivative of the 0D solver by finite differences were hardcoded. Now they can be specified through the XML file in the section <svZeroDSolver_interface> (especially important for the absolute tolerance, since it is dimensional).
  5. svZeroDSolver output files (svZeroD_data, P_svZeroD and Q_svZeroD) are written to the same output directory as the 3D simulation results, instead of the current directory.
  6. svZeroD_data is reset by every simulation, instead of appended to (i.e, the file is cleared before writing the header).
  7. Classes under ActiveStress and IonicModel, and their files, have been renamed to more consistently use upper camel case.

Documentation

Modified or added data members and functions have been given Doxygen documentation.

Testing

I have verified that the automatic tests still pass.

The coupling of the 0D solver to an equation other than the first was tested in a ventricular electromechanics simulation. This simulation should eventually become an automatic test. However, the choice of various model parameters is still very much work in progress, and I would postpone making it an automatic test until it gives plausible results, so that the test can be a reasonable starting point for electromechanics setups.

Code of Conduct & Contributing Guidelines

@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 removes the implicit assumption that svZeroDSolver-coupled boundary conditions must belong to equation 0 by tracking the coupled equation via ComMod::cplBCType::equationIndex, and updates integration/normal-computation utilities accordingly. It also improves svZeroD interface configurability and aligns several electromechanics-related classes/files with consistent UpperCamelCase naming.

Changes:

  • Track which equation owns coupled BCs (cplBCType::equationIndex) and use it to drive svZeroD coupling/integration logic.
  • Refactor all_fun::integ() and nn::gnnb() interfaces and update call sites to select the correct solution-row offsets.
  • Add XML-configurable finite-difference perturbations for the 0D tangent and write svZeroD outputs to the simulation output directory; rename ActiveStress/IonicModel classes/files for consistency.

Reviewed changes

Copilot reviewed 42 out of 44 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Code/Source/solver/txt.cpp Updates integ() calls to new overloads.
Code/Source/solver/svZeroD_interface.h Extends init_svZeroD() interface and documents output directory behavior.
Code/Source/solver/svZeroD_interface.cpp Writes svZeroD outputs to appPath and resets svZeroD_data header per simulation.
Code/Source/solver/set_bc.cpp Uses equationIndex and offset-aware integration for coupled BCs and surface normals.
Code/Source/solver/ris.cpp Updates integ() calls to new overloads.
Code/Source/solver/read_files.cpp Reads new svZeroD finite-difference perturbation parameters; updates includes.
Code/Source/solver/Parameters.h Adds svZeroD finite-difference perturbation parameters (XML).
Code/Source/solver/Parameters.cpp Registers defaults for svZeroD perturbation parameters.
Code/Source/solver/nn.h Refactors gnnb() API and adds detailed Doxygen.
Code/Source/solver/nn.cpp Implements new gnnb() overloads returning normals and supporting displaced configurations.
Code/Source/solver/IonicModelTTP.h Updates include to renamed ionic model base header.
Code/Source/solver/IonicModelTTP.cpp Updates include to renamed TTP header.
Code/Source/solver/IonicModelFitzHughNagumo.h Updates include to renamed ionic model base header.
Code/Source/solver/IonicModelFitzHughNagumo.cpp Updates include to renamed FitzHugh-Nagumo header.
Code/Source/solver/IonicModelBuenoOrovio.h Updates include to renamed ionic model base header.
Code/Source/solver/IonicModelBuenoOrovio.cpp Updates include to renamed Bueno-Orovio header.
Code/Source/solver/IonicModelAlievPanfilov.h Updates include to renamed ionic model base header.
Code/Source/solver/IonicModelAlievPanfilov.cpp Updates include to renamed Aliev-Panfilov header.
Code/Source/solver/IonicModel.h New UpperCamelCase ionic model base header with expanded documentation.
Code/Source/solver/IonicModel.cpp Updates include to renamed ionic model base header.
Code/Source/solver/Integrator.cpp Applies coupled BCs when stepping the coupled equation, not only equation 0.
Code/Source/solver/initialize.cpp Detects coupled BCs across equations; enforces single-equation ownership; sets equationIndex.
Code/Source/solver/eq_assem.cpp Updates gnnb() usage to new return-by-value API.
Code/Source/solver/distribute.cpp Broadcasts new svZeroD finite-difference perturbation parameters; updates includes.
Code/Source/solver/CoupledBoundaryCondition.cpp Computes Q/P using equationIndex offsets; updates cap gather logic accordingly.
Code/Source/solver/ComMod.h Adds equationIndex and svZeroD finite-difference perturbation fields to cplBCType.
Code/Source/solver/cmm.cpp Updates gnnb() usage to new return-by-value API.
Code/Source/solver/CMakeLists.txt Switches build inputs to renamed ActiveStress/IonicModel source files.
Code/Source/solver/CepMod.h Updates include to renamed ionic model base header.
Code/Source/solver/baf_ini.cpp Uses equationIndex for coupled BC equation; passes appPath into init_svZeroD().
Code/Source/solver/all_fun.h Refactors and documents integ() overloads; adds displacement-index variants.
Code/Source/solver/all_fun.cpp Implements refactored integ() overloads using new gnnb() API.
Code/Source/solver/ActiveStressUniformUnsteady.h Renames class/header and updates includes for ActiveStress refactor.
Code/Source/solver/ActiveStressUniformUnsteady.cpp Renames implementation + factory registration to new class name.
Code/Source/solver/ActiveStressUniformSteady.h Renames class/header and updates includes for ActiveStress refactor.
Code/Source/solver/ActiveStressUniformSteady.cpp Renames implementation + factory registration to new class name.
Code/Source/solver/ActiveStressRegazzoni.h Renames class/header and improves formatting of documentation.
Code/Source/solver/ActiveStressRegazzoni.cpp Renames implementation + factory registration to new class name.
Code/Source/solver/ActiveStressODE.h Updates include to renamed ActiveStress base header.
Code/Source/solver/ActiveStressODE.cpp Updates include to renamed ActiveStressODE header.
Code/Source/solver/ActiveStressNashPanfilov.h Renames class/header and updates includes for ActiveStress refactor.
Code/Source/solver/ActiveStressNashPanfilov.cpp Renames implementation + factory registration to new class name.
Code/Source/solver/ActiveStress.h New UpperCamelCase active stress base header with expanded documentation.
Code/Source/solver/ActiveStress.cpp Updates include to renamed ActiveStress base header.
Suppressed comments (1)

Code/Source/solver/set_bc.cpp:173

  • Same indexing issue as for Po: Pn should integrate the pressure dof at eq.s + nsd so coupling works when the coupled equation is not the first equation.

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

Comment on lines +168 to +170
cplBC.fa[ptr].Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd,
solutions, std::nullopt, false) /
area;
Comment on lines +650 to +654
double Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, solutions,
nsd - 1, false);
double Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, solutions,
std::nullopt, false) /
area;
Comment thread Code/Source/solver/nn.cpp
Comment on lines +1000 to +1003
// Notice that this assumes that the mesh displacement is stored
// starting at the nsd+1 index of the solution array. This is enforced
// in read_files, by throwing an exception if the equations are not
// ordered correctly.
@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.52582% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.72%. Comparing base (a3413e0) to head (30fbe05).

Files with missing lines Patch % Lines
Code/Source/solver/set_bc.cpp 47.45% 31 Missing ⚠️
Code/Source/solver/CoupledBoundaryCondition.cpp 76.00% 6 Missing ⚠️
Code/Source/solver/ris.cpp 50.00% 5 Missing ⚠️
Code/Source/solver/all_fun.cpp 81.81% 4 Missing ⚠️
Code/Source/solver/ActiveStressUniformSteady.cpp 0.00% 2 Missing ⚠️
Code/Source/solver/txt.cpp 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #605      +/-   ##
==========================================
- Coverage   72.73%   72.72%   -0.01%     
==========================================
  Files         255      255              
  Lines       39290    39356      +66     
  Branches     6726     6727       +1     
==========================================
+ Hits        28576    28622      +46     
- Misses      10472    10492      +20     
  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.

Coupling to 0D solver only supported for first equation

2 participants