-
Notifications
You must be signed in to change notification settings - Fork 36
Spherical ventricle block #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
5f20ef9
BloodVessel_duplicate
EmmaJVE e171823
revert csv_writer.cpp
EmmaJVE 74af9bf
edited csv_writer.cpp to include BloodVesselNew
EmmaJVE 3a43dae
added test case for BloodVesselNew block
EmmaJVE dce4e3a
updated test_solver.py to include new BVN testcase
EmmaJVE 75422ee
compare dataframes more efficiently, recompute some reference solutions
ncdorn b5b5d59
update refefrence solution
ncdorn bfdc35d
update reference solutions for Open Loop Coronary cases
ncdorn df63bd9
Clean up code and update ref vs res plotting
ncdorn 5d12245
Remove unused plotting functions from utils.py
ncdorn 669be6a
some values close to zero still have relative difference above tolerance
ncdorn 23bebd7
Refine relative difference calculation and tolerance check in run_wit…
ncdorn a78a67b
Fix relative difference calculation to handle absolute values and rem…
ncdorn b1cc0e7
Replace coverage import with pytest coverage for improved testing int…
ncdorn dc4b1a4
Simplify error message for tolerance assertion in run_with_reference …
ncdorn 58e2c9b
update solver flow tolerance to see if tests pass on Ubuntu
ncdorn 4fdc3e1
Fix pressure column name and enhance failure message with relative di…
ncdorn d9ab50a
Update solver + test tolerance values and enhance reference solution …
ncdorn 095f359
Added eqns from Caruel 2014 to BloodVesselNew block & its test
EmmaJVE 38e24bc
cleanup
EmmaJVE 467166e
Merge branch 'master' into add_eqns_to_block
EmmaJVE 38911ef
adjust solver and testing tolerances such that tests pass, and add te…
ncdorn d2dc326
updated units to cgs
EmmaJVE e08d669
updated active function
EmmaJVE ca41140
updated_active_stress_eqns
EmmaJVE 0dba7fe
added_post.py
EmmaJVE a585693
chamber with outlet vessel
EmmaJVE b3bcf48
troubleshooting post.py output
EmmaJVE 58eb09e
simplified and messed up
mrp089 a10bab0
rename
mrp089 d9bf77c
final test case and matlab script
EmmaJVE f166cbd
update solver tolerance, recompute reference solutions, relax test to…
ncdorn deb65c8
Merge branch 'fix_C_eqns' of github.com:EmmaJVE/svZeroDSolver into fi…
mrp089 bc6be6f
first python jacobian script
mrp089 e8f18b8
put definition in yaml file
mrp089 ed9a20e
also print constants and variables
mrp089 c699bff
reset equations
mrp089 6724fbc
rename variables
mrp089 5c32d66
Merge remote-tracking branch 'nick/fix-solver-tests' into fix_C_eqns
mrp089 3c7737b
add more examples and readme
mrp089 08bd1fb
cleanup
mrp089 f51041a
tidy up equations
mrp089 88a27e1
remove unintended edits
mrp089 35e9d9e
more cleanup
mrp089 27c9d95
remove unused test
mrp089 823505e
clang-format
mrp089 c9f0a63
add dirgraph
mrp089 094c973
fix doxygen
mrp089 febb03d
move readme
mrp089 8b0b39c
check code format on macos-latest
mrp089 165295e
Merge remote-tracking branch 'origin/master' into fix_C_eqns
mrp089 1cd78f8
Merge branch 'master' into spherical_ventricle_144
mrp089 2ec493a
remove unintended files and modifications
mrp089 55e32e3
clang format
mrp089 d17eb58
new license format
mrp089 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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