-
Notifications
You must be signed in to change notification settings - Fork 17
Add RCR-Windkessel model #935
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
LasNikas
merged 43 commits into
trixi-framework:main
from
LasNikas:add-rcr-windkessel-model
Nov 17, 2025
Merged
Changes from 28 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
051533c
initial prototype - not tested yet
06c5155
add check
93bb63d
make full velocity optional
df62d79
1st try to make it GPU compatible
c3b455e
add comment
6b4efaa
make it work on GPU
0c37246
add comment
e642dd3
revise show
44951f9
add initial pressure
f9104f4
fix flow rate
093800d
fix stupid bug
63cc35a
add test
1f35aed
adapt for other boundary model
d752bfb
add docs
7eb545e
add literature
5845b9b
fix
bfbf3b6
rm cached
1412448
rm weird keyword
01091ef
fix flow rate calculation
f6532cf
fix again flow rate calculation
2a5b82c
Merge branch 'main' into add-rcr-windkessel-model
e309ec2
Merge branch 'main' into add-rcr-windkessel-model
d4b7345
fix tests
57e112d
Merge branch 'main' into add-rcr-windkessel-model
6f34301
fix
82949fe
Merge branch 'main' into add-rcr-windkessel-model
fafcfdf
Merge branch 'main' into add-rcr-windkessel-model
57ebeb4
Merge branch 'main' into add-rcr-windkessel-model
440eb9c
implement suggestions
d8d75a0
Merge branch 'main' into add-rcr-windkessel-model
d2daa67
add functor
648e840
fix gpu
f0232c8
add foreach_enumerate
def2288
implement suggestions
78c45fa
fix refs
2cc5e8c
implement suggestions
9a19e78
Merge branch 'main' into add-rcr-windkessel-model
c7e3345
fix doc strings
2d1d080
minor doc changes
5b98ef3
fix test
0c2d4d3
fix
7809f01
Merge branch 'main' into add-rcr-windkessel-model
9d714e9
Merge branch 'main' into add-rcr-windkessel-model
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
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
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,138 @@ | ||
| """ | ||
| RCRWindkesselModel(; characteristic_resistance, peripheral_resistance, compliance) | ||
|
|
||
| The `RCRWindkessel` model is a biomechanical lumped-parameter representation | ||
LasNikas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| that captures the relationship between pressure and flow in pulsatile systems, e.g., vascular systems. | ||
| It is derived from an electrical circuit analogy and consists of three elements: | ||
|
|
||
| - characteristic resistance (``R_1``): Represents the proximal resistance at the vessel entrance. | ||
| It models the immediate pressure drop that arises at the entrance of a vessel segment, | ||
| due either to a geometric narrowing or to a mismatch in characteristic impedance between adjacent segments. | ||
LasNikas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| A larger ``R_1`` produces a sharper initial pressure rise at the onset of flow. | ||
| - peripheral resistance (``R_2``): Represents the distal resistance, | ||
| which controls the sustained outflow into the peripheral circulation and thereby determines the level of the mean pressure. | ||
| A high ``R_2`` maintains a higher pressure (reduced outflow), whereas a low ``R_2`` allows a faster pressure decay. | ||
| - compliance (``C``): Connected in parallel with ``R_2`` and represents the capacity of elastic walls | ||
| to store and release volume; in other words, it models the "stretchiness" of walls. | ||
LasNikas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Analogous to a capacitor in an electrical circuit, it absorbs blood when pressure rises and releases it during diastole. | ||
| The presence of ``C`` smooths pulsatile flow and produces a more uniform outflow profile. | ||
|
|
||
| Lumped-parameter models for the vascular system are well described in the literature (e.g. [Westerhof2008](@cite)). | ||
LasNikas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| A practical step-by-step procedure for identifying the corresponding model parameters is provided by [Gasser2021](@cite). | ||
|
|
||
| # Keywords | ||
| - `characteristic_resistance`: characteristic resistance (``R_1``) | ||
| - `peripheral_resistance`: peripheral resistance (``R_2``) | ||
| - `compliance`: compliance (``C``) | ||
| """ | ||
| struct RCRWindkesselModel{ELTYPE <: Real} | ||
| characteristic_resistance :: ELTYPE | ||
| peripheral_resistance :: ELTYPE | ||
| compliance :: ELTYPE | ||
| is_prescribed :: Bool | ||
LasNikas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| function RCRWindkesselModel(; characteristic_resistance, peripheral_resistance, compliance) | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return RCRWindkesselModel(characteristic_resistance, peripheral_resistance, compliance, | ||
| true) | ||
| end | ||
|
|
||
| function Base.show(io::IO, ::MIME"text/plain", pressure_model::RCRWindkesselModel) | ||
| @nospecialize pressure_model # reduce precompilation time | ||
|
|
||
| if get(io, :compact, false) | ||
| show(io, pressure_model) | ||
| else | ||
| summary_header(io, "RCRWindkesselModel") | ||
| summary_line(io, "characteristic_resistance", | ||
| pressure_model.characteristic_resistance) | ||
| summary_line(io, "peripheral_resistance", | ||
| pressure_model.peripheral_resistance) | ||
| summary_line(io, "compliance", pressure_model.compliance) | ||
| summary_footer(io) | ||
| end | ||
| end | ||
|
|
||
| function update_pressure_model!(system::OpenBoundarySystem, v, u, semi, dt) | ||
| isnothing(system.pressure_model_values) && return system | ||
|
|
||
| calculate_flow_rate_and_pressure!(system, v, u, dt) | ||
|
|
||
| return system | ||
| end | ||
|
|
||
| function calculate_flow_rate_and_pressure!(system, v, u, dt) | ||
| for (zone_id, boundary_zone) in enumerate(system.boundary_zones) | ||
| if boundary_zone.pressure_model.is_prescribed | ||
| calculate_flow_rate_and_pressure!(boundary_zone.pressure_model, system, | ||
| boundary_zone, zone_id, v, u, dt) | ||
| end | ||
| end | ||
|
|
||
| return system | ||
| end | ||
|
|
||
| function calculate_flow_rate_and_pressure!(pressure_model, system, boundary_zone, | ||
| zone_id, v, u, dt) | ||
| dt < sqrt(eps()) && return pressure_model | ||
LasNikas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (; particle_spacing) = system.initial_condition | ||
| (; characteristic_resistance, peripheral_resistance, compliance) = pressure_model | ||
| (; flow_rate, pressure) = system.pressure_model_values[zone_id] | ||
| (; face_normal, zone_origin) = boundary_zone | ||
|
|
||
| # Use a thin slice for the flow rate calculation | ||
LasNikas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| slice = particle_spacing * 125 / 100 | ||
|
|
||
| # Find particles within a thin slice near the boundary face for flow rate computation | ||
| candidates = findall(x -> dot(x - zone_origin, -face_normal) <= slice, | ||
| reinterpret(reshape, SVector{ndims(system), eltype(u)}, u)) | ||
|
|
||
| particles_in_zone = findall(particle -> boundary_zone == | ||
| current_boundary_zone(system, particle), | ||
| each_integrated_particle(system)) | ||
|
|
||
| intersect!(candidates, particles_in_zone) | ||
|
|
||
| cross_sectional_area = length(candidates) * particle_spacing^(ndims(system) - 1) | ||
|
|
||
| # Division inside the `sum` closure to maintain GPU compatibility | ||
| velocity_avg = sum(candidates) do particle | ||
| return dot(current_velocity(v, system, particle), -face_normal) / length(candidates) | ||
| end | ||
|
|
||
| # Compute volumetric flow rate: Q = v * A | ||
| current_flow_rate = velocity_avg * cross_sectional_area | ||
|
|
||
| previous_pressure = pressure[] | ||
| previous_flow_rate = flow_rate[] | ||
| flow_rate[] = current_flow_rate | ||
|
|
||
| # Calculate new pressure according to eq. 22 in Zhang et al. (2025) | ||
efaulhaber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| R1 = characteristic_resistance | ||
| R2 = peripheral_resistance | ||
| C = compliance | ||
|
|
||
| term_1 = (1 + R1 / R2) * flow_rate[] | ||
| term_2 = C * R1 * (flow_rate[] - previous_flow_rate) / dt | ||
| term_3 = C * previous_pressure / dt | ||
| divisor = C / dt + 1 / R2 | ||
|
|
||
| pressure_new = (term_1 + term_2 + term_3) / divisor | ||
|
|
||
| pressure[] = pressure_new | ||
|
|
||
| return system | ||
| end | ||
|
|
||
| function imposed_pressure(system, pressure_model_values, boundary_zone, | ||
| pressure, particle) | ||
| boundary_zone.pressure_model.is_prescribed || return pressure | ||
|
|
||
| zone_id = system.boundary_zone_indices[particle] | ||
| return pressure_model_values[zone_id].pressure[] | ||
| end | ||
|
|
||
| function imposed_pressure(system, pressure_model_values::Nothing, boundary_zone, | ||
| pressure, particle) | ||
| return pressure | ||
| end | ||
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.
Uh oh!
There was an error while loading. Please reload this page.