Skip to content

Add time avg wss etc. - #248

Open
jorgensd wants to merge 1 commit into
dokken/hemodynamics-in-dolfinxfrom
dokken/further-hemodynamics
Open

jorgensd wants to merge 1 commit into
dokken/hemodynamics-in-dolfinxfrom
dokken/further-hemodynamics

Conversation

@jorgensd

Copy link
Copy Markdown
Collaborator

This continues the DOLFINx port of postprocessing_fenics/compute_hemodynamics.py in
postprocessing_fenicsx/compute_hemodynamics.py. It adds the time-averaged indices computed from
the wall shear stress (WSS) samples, and it splits the WSS expression into reusable UFL functions.

Changes

WSS as UFL functions

  • cauchy_stress(u, p, mu_f) returns 2 mu_f sym(grad(u)) - p I.
  • wall_shear_stress(sigma, n) returns the tangential part of the traction the fluid exerts on the
    wall, F - (F·n) n with F = -sigma n. The pressure term gives F = p n, which is purely
    normal, so p drops out exactly. sigma can be passed with or without its pressure part.
  • Stress now uses these helpers with only the viscous part of sigma. Its behaviour is
    unchanged, and the compiled kernel still doesn't need p.

HemodynamicIndices

  • add(tau, t) adds a WSS sample. compute() returns TAWSS, OSI, RRT, ECAP and TWSSG as named
    scalar DG Functions, using the definitions in https://kvslab.github.io/VaMPy/quantities.html.
  • Time steps may vary. With T = t_N - t_0:
    • <tau> and <|tau|> are trapezoidal time averages.
    • TWSSG takes tau as linear in time between samples, so it is sum_k |tau_k - tau_{k-1}| / T.
  • No division by zero. OSI, RRT and ECAP are set to zero where their denominator is zero. That
    happens where there is no WSS at all (TAWSS = 0) or where the WSS averages to zero over time
    (|<tau>| = 0, which affects RRT only).
  • Dof-by-dof computation. The scalar output space is built from the WSS space's sub-element.
    The constructor asserts that it has the same dofmap, so each index is a row-wise numpy operation
    on tau.x.array.reshape(-1, 3). This replaces the legacy FunctionAssigner/sub(0).collapse()
    handling and the project_dg call for TWSSG. For a Lagrange space the dofs are point
    evaluations, so computing an index dof by dof gives exactly the interpolation of that nonlinear
    index. UFL expressions here would add cost and no accuracy.

Intended use:

stress = Stress(u, V_sub, mu_f, entity_map)
indices = HemodynamicIndices(V_sub)
for t in times:
    ...  # update u
    indices.add(stress(), t)
results = indices.compute()

Differences from the legacy implementation

  • Time averaging: legacy used plain averages over the samples, which assumes equal time steps.
    The trapezoidal rule weights each sample by its time step. With equal steps the only change is
    that the first and last samples get half weight.
  • TWSSG: legacy started tau_prev at zero. That added a spurious |tau_0| / dt term for the
    first sample, and the sum was divided by the number of samples. Now only the N−1 intervals
    between samples contribute, so values come out lower than legacy.
  • Division by zero: legacy gave inf/nan where the WSS is zero. Now those indices are 0.
    For RRT this is a convention: its true value at |<tau>| = 0 is unbounded.

Tests

The tests live in the module for now, because tests/ runs in the legacy-FEniCS environment in CI.

  • test_wall_shear_stress_independent_of_pressure: uses a nonlinear P2 velocity and a P1 pressure
    that varies in space. The full cauchy_stress(u, p, mu) and Stress give the same WSS.
  • test_hemodynamic_indices: feeds samples tau_k = c_k v, with a fixed vector v per dof, sign
    changes in c_k and unequal time steps. All five indices are compared with their closed-form
    trapezoidal values, and OSI is checked to lie in [0, ½].
  • test_hemodynamic_indices_zero_wall_shear_stress: covers dofs with no WSS and dofs whose WSS
    oscillates with zero time average. It runs compute() under np.errstate(all="raise").

Not included

  • Reading input and writing output. The plan is io4dolfinx (vtkhdf), storing P2 data on a
    degree-2 geometry mesh from reconstruct_mesh. That replaces the legacy refined-P1 to P2
    transfer.
  • The driver loop and command-line entry point.

🤖 Generated with the help of Claude Code

@jorgensd
jorgensd added this pull request to stack #249 November 19, 2026 20:29
@jorgensd
jorgensd requested a review from keiyamamo November 19, 2026 20:30

This branch has not been deployed

No deployments
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