Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
5f20ef9
BloodVessel_duplicate
EmmaJVE Feb 18, 2025
e171823
revert csv_writer.cpp
EmmaJVE Feb 20, 2025
74af9bf
edited csv_writer.cpp to include BloodVesselNew
EmmaJVE Feb 24, 2025
3a43dae
added test case for BloodVesselNew block
EmmaJVE Feb 24, 2025
dce4e3a
updated test_solver.py to include new BVN testcase
EmmaJVE Feb 24, 2025
75422ee
compare dataframes more efficiently, recompute some reference solutions
ncdorn Apr 2, 2025
b5b5d59
update refefrence solution
ncdorn Apr 2, 2025
bfdc35d
update reference solutions for Open Loop Coronary cases
ncdorn Apr 2, 2025
df63bd9
Clean up code and update ref vs res plotting
ncdorn Apr 2, 2025
5d12245
Remove unused plotting functions from utils.py
ncdorn Apr 2, 2025
669be6a
some values close to zero still have relative difference above tolerance
ncdorn Apr 2, 2025
23bebd7
Refine relative difference calculation and tolerance check in run_wit…
ncdorn Apr 3, 2025
a78a67b
Fix relative difference calculation to handle absolute values and rem…
ncdorn Apr 3, 2025
b1cc0e7
Replace coverage import with pytest coverage for improved testing int…
ncdorn Apr 3, 2025
dc4b1a4
Simplify error message for tolerance assertion in run_with_reference …
ncdorn Apr 3, 2025
58e2c9b
update solver flow tolerance to see if tests pass on Ubuntu
ncdorn Apr 3, 2025
4fdc3e1
Fix pressure column name and enhance failure message with relative di…
ncdorn Apr 3, 2025
d9ab50a
Update solver + test tolerance values and enhance reference solution …
ncdorn Apr 3, 2025
095f359
Added eqns from Caruel 2014 to BloodVesselNew block & its test
EmmaJVE Apr 10, 2025
38e24bc
cleanup
EmmaJVE Apr 14, 2025
467166e
Merge branch 'master' into add_eqns_to_block
EmmaJVE Apr 14, 2025
38911ef
adjust solver and testing tolerances such that tests pass, and add te…
ncdorn Apr 17, 2025
d2dc326
updated units to cgs
EmmaJVE Apr 23, 2025
e08d669
updated active function
EmmaJVE Apr 23, 2025
ca41140
updated_active_stress_eqns
EmmaJVE Apr 28, 2025
0dba7fe
added_post.py
EmmaJVE Apr 28, 2025
a585693
chamber with outlet vessel
EmmaJVE Apr 29, 2025
b3bcf48
troubleshooting post.py output
EmmaJVE Apr 29, 2025
58eb09e
simplified and messed up
mrp089 May 2, 2025
a10bab0
rename
mrp089 May 2, 2025
d9bf77c
final test case and matlab script
EmmaJVE May 3, 2025
f166cbd
update solver tolerance, recompute reference solutions, relax test to…
ncdorn May 14, 2025
deb65c8
Merge branch 'fix_C_eqns' of github.com:EmmaJVE/svZeroDSolver into fi…
mrp089 May 14, 2025
bc6be6f
first python jacobian script
mrp089 May 14, 2025
e8f18b8
put definition in yaml file
mrp089 May 14, 2025
ed9a20e
also print constants and variables
mrp089 May 14, 2025
c699bff
reset equations
mrp089 May 14, 2025
6724fbc
rename variables
mrp089 May 14, 2025
5c32d66
Merge remote-tracking branch 'nick/fix-solver-tests' into fix_C_eqns
mrp089 May 14, 2025
3c7737b
add more examples and readme
mrp089 May 14, 2025
08bd1fb
cleanup
mrp089 May 14, 2025
f51041a
tidy up equations
mrp089 May 14, 2025
88a27e1
remove unintended edits
mrp089 May 14, 2025
35e9d9e
more cleanup
mrp089 May 14, 2025
27c9d95
remove unused test
mrp089 May 16, 2025
823505e
clang-format
mrp089 May 16, 2025
c9f0a63
add dirgraph
mrp089 May 16, 2025
094c973
fix doxygen
mrp089 May 16, 2025
febb03d
move readme
mrp089 May 16, 2025
8b0b39c
check code format on macos-latest
mrp089 May 16, 2025
165295e
Merge remote-tracking branch 'origin/master' into fix_C_eqns
mrp089 May 19, 2025
1cd78f8
Merge branch 'master' into spherical_ventricle_144
mrp089 Jun 25, 2025
2ec493a
remove unintended files and modifications
mrp089 Jun 25, 2025
55e32e3
clang format
mrp089 Jun 25, 2025
d17eb58
new license format
mrp089 Jun 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/codechecks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ name: Codechecks
on: [push, pull_request]
jobs:
clang-format:
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get install clang-format-19
brew install clang-format
- name: Run clang-format
run: |
mkdir Release
Expand Down
6 changes: 4 additions & 2 deletions docs/pages/add_block.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[TOC]

Below are details on the steps required to implement a new block in svZeroDSolver.
Below are details on the steps required to implement a new block in svZeroDSolver. To help with defining the block matrices, you can use the [Jacobian Generator](@ref jacobian).

*Note: The best way to implement a new block is to look at examples of existing block classes. See the `ValveTanh` class for an example.*

Expand Down Expand Up @@ -68,6 +68,8 @@ Below are details on the steps required to implement a new block in svZeroDSolve

## 3. Set up the governing equations for the block.

Use the [Jacobian Generator](@ref jacobian) to calculate matrix contributions symbolically.

### State vector

* The local state vector for each block is always arranged as `y = [P_in, Q_in, P_out, Q_out, InternalVariable_1, ..., InternalVariable_N]`.
Expand Down Expand Up @@ -111,7 +113,7 @@ Below are details on the steps required to implement a new block in svZeroDSolve

## 4. Implement the matrix equations for the block.

* Implement the `update_constant`, `update_time` and `update_solution` functions.
* Implement the `update_constant`, `update_time` and `update_solution` functions (which can be output by the [Jacobian Generator](@ref jacobian)).
* All matrix elements that are constant must be specified in `update_constant`.
* Matrix elements that depend only on time (not the state variables) must be specified in `update_time`.
* Matrix elements that change with the solution (i.e. depend on the state variables themselves) must be specified in `update_solution`.
Expand Down
84 changes: 84 additions & 0 deletions docs/pages/jacobian.md
Copy link
Contributor

Choose a reason for hiding this comment

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

this is super useful, thanks Martin

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
@page jacobian Jacobian Generator for svZeroDSolver

This tool generates C++ code for block implementations in the svZeroDSolver framework using symbolic mathematics.

## Overview

The script `script/jacobian.py` reads block definitions from YAML files and generates C++ code for implementing the mathematical models in the solver. It uses symbolic differentiation (via SymPy) to automatically derive the necessary Jacobian matrices and system contributions.

## Usage

```bash
python jacobian.py <yaml_file>
```

## YAML File Format

The YAML files define the mathematical model of a block with the following structure:

### Required Sections

- `variables`: List of variable names in the model
- `derivatives`: List of derivative names (must match variables with `_dt` suffix)
- `constants`: List of parameter names
- `residuals`: List of residual equations that define the system

### Optional Sections

- `time_dependent`: List of parameters that depend on time (e.g., activation functions)
- `helper_functions`: Python code defining helper functions used in the residuals

### Example

```yaml
variables:
- Pin
- Qin
- Pout
- Qout

derivatives:
- dPin_dt
- dQin_dt
- dPout_dt
- dQout_dt

constants:
- R
- C
- L
- S

residuals:
- Pin - Pout - (R + S * abs(Qin)) * Qin - L * dQout_dt
- Qin - Qout - C * dPin_dt + C * (R + 2 * S * abs(Qin)) * dQin_dt
```

## Output

The script generates three C++ function implementations:

1. `update_constant` - Sets up constant matrix coefficients for the system
2. `update_time` - Updates time-dependent parameters
3. `update_solution` - Computes solution-dependent terms and Jacobians

## Workflow

1. Create a YAML file defining your block's mathematical model
2. Run `jacobian.py` on this file to generate C++ code
3. Copy the generated code to your block implementation file
4. Complete the implementation with necessary boilerplate code

## Tips

- Ensure the number of variables equals the number of derivatives
- The number of residuals should be equal to the number of variables minus 2
- Use helper functions for complex expressions to improve readability
- Define time-dependent constants separately

## Examples

See the provided YAML examples:
- `ChamberSphere.yaml` - Spherical heart chamber model
- `BloodVessel.yaml` - Blood vessel model with optional stenosis
- `ClosedLoopCoronaryBC.yaml` - Coronary boundary condition model
14 changes: 14 additions & 0 deletions docs/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,17 @@ @article{kerckhoffs2007coupling
year={2007},
publisher={Springer}
}

@article{caruel13,
author = {M. Caruel and R. Chabiniok and P. Moireau and Y. Lecarpentier and D. Chapelle},
doi = {10.1007/s10237-013-0544-6},
journal = {Biomechanics and Modeling in Mechanobiology},
month = {dec},
number = {4},
pages = {897--914},
publisher = {Springer Science and Business Media {LLC}},
timestamp = {2022-02-28},
title = {Dimensional reductions of a cardiac model for effective validation and calibration},
volume = {13},
year = {2013}
}
21 changes: 21 additions & 0 deletions scripts/BloodVessel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
variables:
- Pin
- Qin
- Pout
- Qout

derivatives:
- dPin_dt
- dQin_dt
- dPout_dt
- dQout_dt

constants:
- R
- C
- L
- S

residuals:
- Pin - Pout - (R + S * abs(Qin)) * Qin - L * dQout_dt
- Qin - Qout - C * dPin_dt + C * (R + 2 * S * abs(Qin)) * dQin_dt
52 changes: 52 additions & 0 deletions scripts/ChamberSphere.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
variables:
- Pin
- Qin
- Pout
- Qout
- radius
- velo
- stress
- tau
- volume

derivatives:
- dPin_dt
- dQin_dt
- dPout_dt
- dQout_dt
- dradius_dt
- dvelo_dt
- dstress_dt
- dtau_dt
- dvolume_dt

constants:
- rho
- thick0
- radius0
- W1
- W2
- eta
- act
- act_plus
- sigma_max

time_dependent:
- act
- act_plus

helper_functions: |
def CG(radius):
return (1 + (radius / radius0)) ** 2

def dCG(radius, dradius_dt):
return 2 * (1 + (radius / radius0)) * (1 / radius0) * dradius_dt

residuals:
- rho * thick0 * dvelo_dt + (thick0 / radius0) * (1 + (radius / radius0)) * stress - Pout * CG(radius)
- -stress + tau + 4 * (1 - CG(radius) ** -3) * (W1 + CG(radius) * W2) + 2 * eta * dCG(radius, dradius_dt) * (1 - 2 * CG(radius) ** -6)
- 4 * pi * radius0 ** 2 * CG(radius) * velo - dvolume_dt
- dtau_dt + act * tau - sigma_max * act_plus
- dradius_dt - velo
- Qin - Qout - dvolume_dt
- Pin - Pout
32 changes: 32 additions & 0 deletions scripts/ClosedLoopCoronaryBC.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
variables:
- Pin
- Qin
- Pout
- Qout
- Vim
- Pa

derivatives:
- dPin_dt
- dQin_dt
- dPout_dt
- dQout_dt
- dVim_dt
- dPa_dt

constants:
- Ra
- Ram
- Rv
- Ca
- Cim
- Pim

time_dependent:
- Pim

residuals:
- Pout - Pin + (Ram + Ra) * Qin + Rv * Qout + Ram * Ca * dPa_dt - Ram * Ca * dPin_dt + Ram * Ra * Ca * dQin_dt
- Qin - Qout + Ca * dPa_dt - Ca * dPin_dt + Ca * Ra * dQin_dt - dVim_dt
- Cim * Pout + Cim * Rv * Qout - Cim * Pim - Vim
- Pa - Pin - Ra * Qin
3 changes: 3 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# svZeroDSolver scripts

The [Jacobian Generator](../docs/pages/jacobian.md) tool generates C++ code for new block implementations using symbolic math.
Loading
Loading