Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
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
38911ef
adjust solver and testing tolerances such that tests pass, and add te…
ncdorn Apr 17, 2025
f166cbd
update solver tolerance, recompute reference solutions, relax test to…
ncdorn May 14, 2025
c7bd22a
tighten simulation tolerance for closedLoopHeart_singleVessel.json
ncdorn May 15, 2025
7748afe
tighten all test case absolute tolerances to 1e-9 and initialize clos…
ncdorn May 15, 2025
29e0618
loosen tolerance on coupledblock CLHSV, tighten tolerance on CLHSV
ncdorn May 15, 2025
990bdc2
reduce number of timesteps in coupledblock cases
ncdorn May 15, 2025
4ed1029
loosen abs tolerances on certain test cases
ncdorn May 15, 2025
e8cdb4b
reset solver tolerances
ncdorn May 15, 2025
037d227
reset num timesteps
ncdorn May 16, 2025
2d67efa
combine comments for closed loop blocks
ncdorn May 16, 2025
f2a0ea7
fix reference result i/o issue, fix result matching issue, create dif…
ncdorn May 16, 2025
43d37ca
improve difference error and clean up code
ncdorn May 16, 2025
476041b
print result and reference to debug other operating systems
ncdorn May 16, 2025
0498f0a
test dataframe prints reference and result values
ncdorn May 17, 2025
6a4ee19
add timesteps to test comparison dataframe
ncdorn May 19, 2025
a8fbcb0
reset coverage
ncdorn May 19, 2025
5477fbf
reduce timesteps in coupledblock tests
ncdorn May 19, 2025
f18bd7b
increase solver tolerance and reduce timesteps for coupledblock tests
ncdorn May 19, 2025
b54f7e2
tighten solver tolerance for copuledblock tests
ncdorn May 19, 2025
14d18a9
tighten solver tolerance for coupledblock tests
ncdorn May 19, 2025
70e0262
reduce number of timesteps for copuledblock tests
ncdorn May 19, 2025
aaf9c84
reduce number of timesteps for coupledblock test cases
ncdorn May 19, 2025
52df0e7
reset number of timesteps for coupledblock test cases
ncdorn May 19, 2025
8d2fee5
100 time steps
mrp089 May 19, 2025
c1ff81c
adapt reference solution
mrp089 May 19, 2025
354f550
100 timesteps for coupledblock test cases
ncdorn May 20, 2025
4d66191
reset solver tolerance for 100 timesteps
ncdorn May 20, 2025
3b51ae3
recompute reference solutions from ubuntu machine
ncdorn May 21, 2025
9632cea
fix timesteps in coupled block test cases to remove need for interpol…
ncdorn May 21, 2025
5cef229
clean up code
ncdorn May 21, 2025
5184a51
clean up time array to prevent rounding
ncdorn May 21, 2025
b0204ba
reduce number of cardiac cycles
ncdorn May 21, 2025
dbbaf25
convert coupledblocks to steady flow
ncdorn May 21, 2025
4825f0d
increase number of cardiac cycles
ncdorn May 21, 2025
9b99e39
Merge branch 'fix-solver-tests' of https://github.com/ncdorn/svZeroDS…
ncdorn May 21, 2025
b6391ef
clean up time array to prevent rounding
ncdorn May 21, 2025
58beabb
update reference solution
ncdorn May 21, 2025
ccd0e80
increase timesteps and adjust external coupling block array
ncdorn May 21, 2025
16dac29
increase cardiac cycles
ncdorn May 21, 2025
00de208
reset back to 100 timesteps
ncdorn May 21, 2025
7203dd1
increase test tolerance only for coupledbock withCoronaries case
ncdorn May 27, 2025
9f9783e
increase timesteps for withcoronaries case
ncdorn May 27, 2025
8575880
increase test tolerance for withcoronaries case
ncdorn May 27, 2025
398236b
remove default values from test function
ncdorn Jun 6, 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
6 changes: 3 additions & 3 deletions src/model/ClosedLoopHeartPulmonary.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ class ClosedLoopHeartPulmonary : public Block {
private:
// Below variables change every timestep and are then combined with
// expressions that are updated with solution
double AA; // Atrial activation function
double Elv; // LV elastance
double Erv; // RV elastance
double AA = 0.0; // Atrial activation function
double Elv = 0.0; // LV elastance
double Erv = 0.0; // RV elastance
double psi_ra, psi_la, psi_ra_derivative,
psi_la_derivative; // Expressions for atrial activation
double valves[16];
Expand Down
25 changes: 25 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Testing Guide

[Integration testing](https://en.wikipedia.org/wiki/Integration_testing) is an essential part of software development. It is performed when integrating code changes into the main development branch to verify that the code works as expected. The following sections describe how to run and add integration tests used to the svMultiPhysics program.


# Build svZeroDSolver

Running a test case requires you to [build svZeroDSolver](https://simvascular.github.io/documentation/rom_simulation.html#0d-solver-install) and install with pip in order to run test cases using `pytest`

# Running tests using pytest

to run the full set of svZeroDSolver test cases, navigate to the `tests/` directory and run `pytest` from the terminal

## Create a new solver test

In order to create a new test for the solver, complete the following steps:

1. Create a svZeroDSolver json file for the test (e.g. `pulsatileFlow_R_RCR.json`) in the `tests/cases` directory
2. Verify the results. If possible, verify against an analystical solution. If this is not feasible, find some way to verify that the test results are correct. For example, you might use reference solutions from other codes, manufactured solutions, convergence analysis, or something of that variety.
3. Compute a reference solution for the test by navigating to the `tests` directory and running `python compute_ref_sol.py <your_test_case_name..json>` from the terminal. This should create a resultant `result_your_test_case_name.json` file in the `tests/cases/results` directory. Verify the result is there.
4. Add your test case to the `pytest` parametrization in `test_solver.py`. simply add the name of your test `json` to the list of strings after the `@pytest.mark.parametrize` decorator.
5. Verify that the test runs properly by running `pytest` from the terminal while in the `tests` directory.



21 changes: 11 additions & 10 deletions tests/cases/chamber_elastance_inductor.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"description": {
"description of test case" : "pulsatile pressure -> valve -> chamber -> valve -> RC -> R",
"analytical results" : [
"Boundary conditions:",
"inlet:",
"pressure = sinusoid from 0 to 10 over 0.17s, then 0 for the rest of cycle",
"outlet:",
"Resistance: Rd = 1000, Pd = 64"
]
"description of test case": "pulsatile pressure -> valve -> chamber -> valve -> RC -> R",
"analytical results": [
"Boundary conditions:",
"inlet:",
"pressure = sinusoid from 0 to 10 over 0.17s, then 0 for the rest of cycle",
"outlet:",
"Resistance: Rd = 1000, Pd = 64"
]
},
"simulation_parameters": {
"number_of_cardiac_cycles": 30,
"number_of_time_pts_per_cardiac_cycle": 101,
"absolute_tolerance": 1e-09,
"output_all_cycles": false,
"output_variable_based":true
"output_variable_based": true
},
"boundary_conditions": [
{
Expand Down Expand Up @@ -295,4 +296,4 @@
"initial_condition": {
"Vc:ventricle": 96.07
}
}
}
33 changes: 11 additions & 22 deletions tests/cases/closedLoopHeart_singleVessel.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
{
"description": {
"description of test case" : "Closed-loop circulation with one vessel (aorta) connected on either side to the heart model."
"description of test case": "Closed-loop circulation with one vessel (aorta) connected on either side to the heart model."
},
"simulation_parameters": {
"number_of_cardiac_cycles": 1,
"number_of_time_pts_per_cardiac_cycle": 10000,
"number_of_cardiac_cycles": 10,
"number_of_time_pts_per_cardiac_cycle": 100,
"absolute_tolerance": 1e-8,
"steady_initial": false
},
"boundary_conditions": [
{
"bc_name": "RCR_aorta",
"bc_type": "ClosedLoopRCR",
"bc_values": {
"_comment_": "R_total = 1.570879*0.948914 = 1.490629075",
"_comment_": "Rp = 0.09*R_total",
"_comment_": "Rd = 0.91*R_total",
"_comment_": "C = 0.228215*1.044637, R_total = 1.570879*0.948914 = 1.490629075, Rp = 0.09*R_total, Rd = 0.91*R_total",
"Rp": 0.134156617,
"Rd": 1.356472458,
"_comment_": "C = 0.228215*1.044637",
"C": 0.238401833,
"closed_loop_outlet": true
}
Expand All @@ -34,9 +32,8 @@
"vessel_length": 10.0,
"zero_d_element_type": "BloodVessel",
"zero_d_element_values": {
"_comment_": "R = 4.464119/1333.34",
"_comment_": "L = 5.25/1333.34, R = 4.464119/1333.34",
"R_poiseuille": 0.003348073,
"_comment_": "L = 5.25/1333.34",
"L": 0.004
}
}
Expand All @@ -47,37 +44,29 @@
"branch0_seg0"
],
"closed_loop_type": "ClosedLoopHeartAndPulmonary",
"cardiac_cycle_period": 1.0169,
"cardiac_cycle_period": 1.0169,
"parameters": {
"Tsa": 0.407420,
"_comment_": "Lrv_a = 0.249155/pConv, Rrv_a = 0.993637 * this->Rrv_base /pConv, Lra_v = 0.289378/pConv, Rra_v = 10.516664/pConv, Lla_v = 0.469052/pConv, Rla_v = 7.081136/pConv, Rlv_ao = 0.972624 * this->Rlv_base /pConv, Llv_a = 0.147702/pConv, Rpd = 1.120725 * this->Rpd_base /pConv",
"Tsa": 0.40742,
"tpwave": 8.976868,
"Erv_s": 2.125279,
"Elv_s": 3.125202,
"iml": 0.509365,
"imr": 0.806369,
"_comment_": "Lrv_a = 0.249155/pConv",
"Lrv_a": 0.000186865,
"_comment_": "Rrv_a = 0.993637 * this->Rrv_base /pConv",
"Rrv_a": 0.035061704,
"_comment_": "Lra_v = 0.289378/pConv",
"Lra_v": 0.000217032,
"_comment_": "Rra_v = 10.516664/pConv",
"Rra_v": 0.007887459,
"_comment_": "Lla_v = 0.469052/pConv",
"Lla_v": 0.000351787,
"_comment_": "Rla_v = 7.081136/pConv",
"Rla_v": 0.005310825,
"_comment_": "Rlv_ao = 0.972624 * this->Rlv_base /pConv",
"Rlv_ao": 0.034320234,
"_comment_": "Llv_a = 0.147702/pConv",
"Llv_a": 0.000110776,
"Vrv_u": 9.424629,
"Vlv_u": 5.606007,
"_comment_": "Rpd = 1.120725 * this->Rpd_base /pConv",
"Rpd": 0.098865401,
"Cp": 1.090989,
"Cpa": 0.556854,
"Kxp_ra": 9.222440,
"Kxp_ra": 9.22244,
"Kxv_ra": 0.004837,
"Emax_ra": 0.208858,
"Vaso_ra": 4.848742,
Expand All @@ -95,4 +84,4 @@
"V_LV:CLH": 96.07,
"P_pul:CLH": 8.0
}
}
}
61 changes: 17 additions & 44 deletions tests/cases/closedLoopHeart_withCoronaries.json
Original file line number Diff line number Diff line change
@@ -1,57 +1,45 @@
{
"description": {
"description of test case" : "Closed-loop circulation with two RCR outlets and two coronary outlets"
"description of test case": "Closed-loop circulation with two RCR outlets and two coronary outlets"
},
"simulation_parameters": {
"number_of_cardiac_cycles": 1,
"number_of_time_pts_per_cardiac_cycle": 10000,
"number_of_cardiac_cycles": 10,
"number_of_time_pts_per_cardiac_cycle": 100,
"absolute_tolerance": 1e-09,
"steady_initial": false
},
"boundary_conditions": [
{
"bc_name": "LCA",
"bc_type": "ClosedLoopCoronaryLeft",
"bc_values": {
"_comment_": "Ra_total = 67.540250*0.361748 = 24.432550357",
"_comment_": "Ra = (0.32/0.84)*Ra_total",
"_comment_": "Ram = (0.52/0.84)*Ra_total",
"_comment_": "Ra_total = 67.540250*0.361748 = 24.432550357, Ra = (0.32/0.84)*Ra_total, Ram = (0.52/0.84)*Ra_total, Ca = 0.000110*5.022065, Rv = 12.864810*2.586199, Cim = 0.000890*4.198904",
"Ra": 9.307638231,
"Ram": 15.124912126,
"_comment_": "Rv = 12.864810*2.586199",
"Rv": 33.270958757,
"_comment_": "Cim = 0.000890*4.198904",
"Cim": 0.003737025,
"_comment_": "Ca = 0.000110*5.022065",
"Ca": 0.000552427
}
},
{
"bc_name": "RCA",
"bc_type": "ClosedLoopCoronaryRight",
"bc_values": {
"_comment_": "Ra_total = 41.778304*0.361748 = 15.113217915",
"_comment_": "Ra = (0.32/0.84)*Ra_total",
"_comment_": "Ram = (0.52/0.84)*Ra_total",
"_comment_": "Ra_total = 41.778304*0.361748 = 15.113217915, Ra = (0.32/0.84)*Ra_total, Ram = (0.52/0.84)*Ra_total, Ca = 0.000110*9.599613, Rv = 7.957772*2.586199, Cim = 0.000890*3.891162",
"Ra": 5.757416349,
"Ram": 9.355801566,
"_comment_": "Rv = 7.957772*2.586199",
"Rv": 20.580381989,
"_comment_": "Cim = 0.000890*3.891162",
"Cim": 0.003463134,
"_comment_": "Ca = 0.000110*9.599613",
"Ca": 0.001055957
}
},
{
"bc_name": "RCR_aorta",
"bc_type": "ClosedLoopRCR",
"bc_values": {
"_comment_": "R_total = 1.570879*0.948914 = 1.490629075",
"_comment_": "Rp = 0.09*R_total",
"_comment_": "Rd = 0.91*R_total",
"_comment_": "R_total = 1.570879*0.948914 = 1.490629075, Rp = 0.09*R_total, Rd = 0.91*R_total, C = 0.228215*1.044637",
"Rp": 0.134156617,
"Rd": 1.356472458,
"_comment_": "C = 0.228215*1.044637",
"C": 0.238401833,
"closed_loop_outlet": true
}
Expand All @@ -60,12 +48,9 @@
"bc_name": "RCR_aorta_br",
"bc_type": "ClosedLoopRCR",
"bc_values": {
"_comment_": "R_total = 6.922824*0.948914 = 6.569164613",
"_comment_": "Rp = 0.09*R_total",
"_comment_": "Rd = 0.91*R_total",
"_comment_": "R_total = 6.922824*0.948914 = 6.569164613, Rp = 0.09*R_total, Rd = 0.91*R_total, C = 0.051785*1.044637",
"Rp": 0.591224815,
"Rd": 5.977939798,
"_comment_": "C = 0.051785*1.044637",
"C": 0.054096527,
"closed_loop_outlet": true
}
Expand All @@ -82,9 +67,8 @@
"vessel_name": "branch0_seg0",
"zero_d_element_type": "BloodVessel",
"zero_d_element_values": {
"_comment_": "R = 4.464119/1333.34",
"_comment_": "R = 4.464119/1333.34, L = 5.25/1333.34",
"R_poiseuille": 0.003348073,
"_comment_": "L = 5.25/1333.34",
"L": 0.00393748
}
},
Expand All @@ -98,9 +82,8 @@
"vessel_name": "branch1_seg0",
"zero_d_element_type": "BloodVessel",
"zero_d_element_values": {
"_comment_": "R = 111.152028/1333.34",
"_comment_": "R = 111.152028/1333.34, L = 5.25/1333.34",
"R_poiseuille": 0.083363604,
"_comment_": "L = 5.25/1333.34",
"L": 0.00393748
}
},
Expand All @@ -114,9 +97,8 @@
"vessel_name": "branch2_seg0",
"zero_d_element_type": "BloodVessel",
"zero_d_element_values": {
"_comment_": "R = 5855.832840/1333.34",
"_comment_": "R = 5855.832840/1333.34, L = 10.0/1333.34",
"R_poiseuille": 4.391852671,
"_comment_": "L = 10.0/1333.34",
"L": 0.007499963
}
},
Expand All @@ -130,9 +112,8 @@
"vessel_name": "branch3_seg0",
"zero_d_element_type": "BloodVessel",
"zero_d_element_values": {
"_comment_": "R = 3013.987966/1333.34",
"_comment_": "R = 3013.987966/1333.34, L = 10.0/1333.34",
"R_poiseuille": 2.260479672,
"_comment_": "L = 10.0/1333.34",
"L": 0.007499963
}
}
Expand All @@ -146,37 +127,29 @@
"branch3_seg0"
],
"closed_loop_type": "ClosedLoopHeartAndPulmonary",
"cardiac_cycle_period": 1.0169,
"cardiac_cycle_period": 1.0169,
"parameters": {
"Tsa": 0.407420,
"_comment_": "Lrv_a = 0.249155/pConv, Rrv_a = 0.993637 * this->Rrv_base /pConv, Lra_v = 0.289378/pConv, Rra_v = 10.516664/pConv, Lla_v = 0.469052/pConv, Rla_v = 7.081136/pConv, Rlv_ao = 0.972624 * this->Rlv_base /pConv, Llv_a = 0.147702/pConv, Rpd = 1.120725 * this->Rpd_base /pConv",
"Tsa": 0.40742,
"tpwave": 8.976868,
"Erv_s": 2.125279,
"Elv_s": 3.125202,
"iml": 0.509365,
"imr": 0.806369,
"_comment_": "Lrv_a = 0.249155/pConv",
"Lrv_a": 0.000186865,
"_comment_": "Rrv_a = 0.993637 * this->Rrv_base /pConv",
"Rrv_a": 0.035061704,
"_comment_": "Lra_v = 0.289378/pConv",
"Lra_v": 0.000217032,
"_comment_": "Rra_v = 10.516664/pConv",
"Rra_v": 0.007887459,
"_comment_": "Lla_v = 0.469052/pConv",
"Lla_v": 0.000351787,
"_comment_": "Rla_v = 7.081136/pConv",
"Rla_v": 0.005310825,
"_comment_": "Rlv_ao = 0.972624 * this->Rlv_base /pConv",
"Rlv_ao": 0.034320234,
"_comment_": "Llv_a = 0.147702/pConv",
"Llv_a": 0.000110776,
"Vrv_u": 9.424629,
"Vlv_u": 5.606007,
"_comment_": "Rpd = 1.120725 * this->Rpd_base /pConv",
"Rpd": 0.098865401,
"Cp": 1.090989,
"Cpa": 0.556854,
"Kxp_ra": 9.222440,
"Kxp_ra": 9.22244,
"Kxv_ra": 0.004837,
"Emax_ra": 0.208858,
"Vaso_ra": 4.848742,
Expand All @@ -194,4 +167,4 @@
"V_LV:CLH": 96.07,
"P_pul:CLH": 8.0
}
}
}
Loading
Loading