Allow 0D solver to be coupled to equations other than the first - #605
Allow 0D solver to be coupled to equations other than the first#605michelebucelli wants to merge 10 commits into
Conversation
…te deformed configurations without assuming equation order
…tion without passing meaningless arguments
…be specified in the XML file
There was a problem hiding this comment.
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()andnn::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:Pnshould integrate the pressure dof ateq.s + nsdso 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.
| cplBC.fa[ptr].Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, | ||
| solutions, std::nullopt, false) / | ||
| area; |
| 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; |
| // 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 Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
Fixes #592
Current situation
The interface to
svZeroDSolverassumes that the equation it is being coupled to is the first. If it isn't, any indication of coupling tosvZeroDSolverin the XML file is silently disregarded.Release Notes
svZeroDSolvercan be coupled to an arbitrary equation. The coupled equation index is tracked incplBCType::equation_index. Coupling to multiple equations was and still is unsupported.CoupledBoundaryCondition::compute_flowrates, CoupledBoundaryCondition::compute_pressures,gnnbandinteg`.gnnbandinteghas been simplified to remove redundant arguments (e.g. separately passing anArrayand its size).<svZeroDSolver_interface>(especially important for the absolute tolerance, since it is dimensional).svZeroDSolveroutput files (svZeroD_data,P_svZeroDandQ_svZeroD) are written to the same output directory as the 3D simulation results, instead of the current directory.svZeroD_datais reset by every simulation, instead of appended to (i.e, the file is cleared before writing the header).ActiveStressandIonicModel, 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