Skip to content

Conversation

@JordanBlenn
Copy link
Contributor

@JordanBlenn JordanBlenn commented Jul 8, 2025

Capillary Resistance Bug Fixes (and Ubuntu Actions Update)

This PR focuses on fixing the small bugs in Reprosim's capillary_resistance() function, found by Jordan when investigating this function and attempting to port it to the ReprosimV2 python library.

Bugs were all in the constructions of the flow constraints for the venous side of the intermediate villous tree.

Bug 1:
curgen = ceiling((dble(p_unknowns) - dble(i2))/dble(numconvolutes))
was calculating the generation wrong on edge cases (i.e. the one right before going up a generation)
Fix:
curgen = ceiling((dble(p_unknowns) - dble(i2) + 1)/dble(numconvolutes))

Bug 2:

 if(j.eq.(p_unknowns - i2))then
     SparseCol(nnz) = p_unknowns+j
     SparseVal(nnz) = R_seg
     nnz = nnz+1
else

This should always still be R_seg/divisor, otherwise it could run into more edge cases like above where divisor is 2 and the flow isn't splitting accordingly.
Fix:
remove this whole if block and always do the else block instead.

Bug 3:
As we loop over ng = 1,numgens, we calculate the segment resistance top down generation wise:
int_radius_gen = int_rad_vin + (int_rad_vout-int_rad_vin)/dble(numgens)*(dble(ng)-1.0_dp)
However, the constraints are set via looping through:
i2 =p_unknowns/2 + (ng-1)*numconvolutes + nc,
where i2 orders the venule from the bottom node to the top node (i.e. the final node is the starting node).
Thus, the wrong R_seg is being used for each calculation.
Fix:
int_radius_gen = int_rad_vin + (int_rad_vout-int_rad_vin)/dble(numgens)*(dble(numgens + 1.0_dp - ng)-1.0_dp)
(update numgens -> numgens + 1.0_dp - ng .
This value is used in other parts of the venous construction code to get the current generation as well, i.e: numgens - ng + 1 !current generation

Actions Update:

  • swap out the now-deprecated ubuntu-20.4 for ubuntu-latest for PR checks

@alysclark alysclark merged commit 4702c7f into VirtualPregnancy:develop Sep 2, 2025
2 checks passed
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.

2 participants