-
Notifications
You must be signed in to change notification settings - Fork 15
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
Open
LasNikas
wants to merge
34
commits into
trixi-framework:main
Choose a base branch
from
LasNikas:add-rcr-windkessel-model
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+370
−10
Open
Changes from all commits
Commits
Show all changes
34 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| abstract type AbstractPressureModel end | ||
|
|
||
| """ | ||
| RCRWindkesselModel(; characteristic_resistance, peripheral_resistance, compliance) | ||
|
|
||
| The `RCRWindkessel` model is a biomechanical lumped-parameter representation | ||
| that captures the relationship between pressure and flow in pulsatile systems, e.g., vascular systems | ||
| and is used to compute the pressure in a [`BoundaryZone`](@ref). | ||
| 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. | ||
| 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. | ||
| 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)). | ||
| 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, P, FR} <: AbstractPressureModel | ||
| characteristic_resistance :: ELTYPE | ||
| peripheral_resistance :: ELTYPE | ||
| compliance :: ELTYPE | ||
| pressure :: P | ||
| flow_rate :: FR | ||
| end | ||
|
|
||
| # The default constructor needs to be accessible for Adapt.jl to work with this struct. | ||
| # See the comments in general/gpu.jl for more details. | ||
| function RCRWindkesselModel(; characteristic_resistance, peripheral_resistance, compliance) | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pressure = Ref(zero(compliance)) | ||
| flow_rate = Ref(zero(compliance)) | ||
| return RCRWindkesselModel(characteristic_resistance, peripheral_resistance, compliance, | ||
| pressure, flow_rate) | ||
| 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, v, u, semi, dt) | ||
| # Skip update for the first time step | ||
| dt < sqrt(eps()) && return system | ||
LasNikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if any(pm -> isa(pm, AbstractPressureModel), system.cache.pressure_reference_values) | ||
| @trixi_timeit timer() "update pressure model" begin | ||
| calculate_flow_rate_and_pressure!(system, v, u, dt) | ||
| end | ||
| end | ||
|
|
||
| return system | ||
| end | ||
|
|
||
| function calculate_flow_rate_and_pressure!(system, v, u, dt) | ||
| (; pressure_reference_values) = system.cache | ||
| foreach_enumerate(pressure_reference_values) do (zone_id, pressure_model) | ||
| boundary_zone = system.boundary_zones[zone_id] | ||
| calculate_flow_rate_and_pressure!(pressure_model, system, boundary_zone, v, u, dt) | ||
| end | ||
|
|
||
| return system | ||
| end | ||
|
|
||
| function calculate_flow_rate_and_pressure!(pressure_model, system, boundary_zone, v, u, dt) | ||
| return pressure_model | ||
| end | ||
|
|
||
| function calculate_flow_rate_and_pressure!(pressure_model::RCRWindkesselModel, system, | ||
| boundary_zone, v, u, dt) | ||
| (; particle_spacing) = system.initial_condition | ||
| (; characteristic_resistance, peripheral_resistance, compliance, | ||
| flow_rate, pressure) = pressure_model | ||
| (; face_normal) = boundary_zone | ||
|
|
||
| # Find particles within the current boundary zone | ||
| candidates = findall(particle -> boundary_zone == | ||
| current_boundary_zone(system, particle), | ||
| each_integrated_particle(system)) | ||
|
|
||
| # Assuming negligible transverse velocity gradients within the boundary zone, | ||
| # the full area of the zone is taken as the representative cross-sectional | ||
| # area for volumetric flow-rate estimation. | ||
| 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 (pressure_model::RCRWindkesselModel)(x, t) | ||
| return pressure_model.pressure[] | ||
| end | ||
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| include("characteristic_variables.jl") | ||
| include("mirroring.jl") | ||
| include("boundary_zone.jl") | ||
| include("pressure_model.jl") |
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.