arteryfe package

Submodules

arteryfe.artery module

class arteryfe.artery.Artery(root_vessel, end_vessel, rc, qc, Ru, Rd, L, k1, k2, k3, rho, Re, nu, p0)

Bases: object

Represents an artery whose flow rate and area are calculated using the 1D system of blood flow equations in conservation form.

Parameters:
  • root_vessel (boolean) – True if the artery is a root vessel in the artery network (has no parent)
  • end_vessel (boolean) – True if the artery is a terminal vessel in the artery network (has no daughters)
  • rc (float) – Characteristic radius (length)
  • qc (float) – Characteristic flow
  • Ru (float) – Upstream radius
  • Rd (float) – Downstream radius
  • L (float) – Vessel length
  • k1 (float) – First constant from the relation Eh/r0
  • k2 (float) – Second constant from the relation Eh/r0
  • k3 (float) – Third constant from the relation Eh/R0
  • rho (float) – Density of blood
  • Re (float) – Reynolds’ number
  • nu (float) – Viscosity of blood
  • p0 (float) – Diastolic pressure
A_out

Outlet area (only in use for end arteries)

CFL_term(x, A, q)

Computes the CFL number.

Parameters:
  • x (float) – Point at which the condition is to be checked
  • A (float) – Area value at x
  • q (float) – Flow rate value at x
Returns:

return – CFL number

Return type:

float

U_in

Inlet boundary conditions (only for non-root arteries (daughters))

U_out

Outlet boundary conditions (only for parent arteries)

adjust_dex(x, A, q, margin=0.05)

Adjusts spatial step at a bifurcation to respect the CFL condition.

Parameters:
  • x (float) – Point at which the condition is to be checked
  • A (float) – Area value at x
  • q (float) – Flow rate value at x
  • margin (float) – Margin of CFL number
check_CFL(x, A, q)

Checks the CFL condition.

Parameters:
  • x (float) – Point at which the condition is to be checked
  • A (float) – Area value at x
  • q (float) – Flow rate value at x
Returns:

return – True if the CFL condition is fulfilled

Return type:

boolean

compute_outlet_pressure(A)

Computes pressure at the outlet.

Parameters:A (float) – Area value at the outlet
Returns:return – Pressure at the outlet
Return type:float
compute_pressure(f, A0, A)

Computes pressure.

Parameters:
  • f (numpy.array) – Elasticity relation
  • A0 (numpy.array) – Area at rest A : numpy.array Area
Returns:

return – Pressure at the outlet

Return type:

float

define_geometry(Nx, Nt, T, N_cycles)

Initialises the artery geometry by creating the spatial refinement, temporal refinement and FEniCS objects.

Parameters:
  • Nx (int) – Number of spatial points per artery
  • Nt (int) – Number of time steps per cardiac cycle
  • T (float) – Duration of one cardiac cycle
  • N_cycles (int) – Number of cardiac cycles in the simulation
define_solution(q0, theta=0.5, bc_tol=1e-14)

Defines FEniCS Function objects, boundary conditions and variational form of the problem.

Parameters:
  • q0 (float) – Initial flow rate in the root vessel
  • theta (float) – Weighting parameter for the Crank-Nicolson method, in the interval [0, 1]
  • bc_tol (float) – Inlet and outlet boundary thickness (tolerance)
q_in

Inlet flow rate (only for a root artery)

solve()

Calls FEniCS’s solve() function for the variational form.

update_pressure()

Calculates pressure.

update_solution()

Stores current solution U as previous solution Un.

arteryfe.artery_network module

class arteryfe.artery_network.ArteryNetwork(order, rc, qc, Ru, Rd, L, k1, k2, k3, rho, Re, nu, p0, R1, R2, CT)

Bases: object

Builds an artery network from the given parameters. Arteries in the network are assigned indices from left to right and top to bottomself.

Parameters:
  • order (int) – Number of arterial levels
  • rc (float) – Characteristic radius (length)
  • qc (float) – Characteristic flow
  • Ru (list of float) – Upstream radii of each artery in the network
  • Rd (list of float) – Downstream radii of each artery in the network
  • L (list of float) – Vessel lengths
  • k1 (float) – First constant from the relation Eh/r0
  • k2 (float) – Second constant from the relation Eh/r0
  • k3 (float) – Third constant from the relation Eh/R0
  • rho (float) – Density of blood
  • Re (float) – Reynolds’ number
  • nu (float) – Viscosity of blood
  • p0 (float) – Diastolic pressure
  • R1 (float) – First resistance from Windkessel model
  • R2 (float) – Second resistance from Windkessel model
  • CT (float) – Compliance from Windkessel model
adjust_bifurcation_step(p, d1, d2, margin=0.05)

Chooses spatial step at a bifurcation to respect the CFL condition for all three arteries

Parameters:
  • p (Artery) – Parent artery in the bifurcation
  • d1 (Artery) – First daughter artery in the bifurcation
  • d2 (Artery) – Second daughter artery in the bifurcation
  • margin (float) – Margin of CFL number
compute_A_out(a, k_max=100, tol=1e-12)

Computes the area for artery a at the outlet

Parameters:
  • a (Artery) – Artery on which the flux term is computed
  • k_max (int) – Maximum number of iterations in Piccards scheme
  • tol (float) – Tolerance for Piccards fixed point iteration scheme
Returns:

return – Outlet boundary value of A at time step t_(n+1)

Return type:

float

compute_U_half(a, x0, x1, U0, U1)

Computes the solution for a given artery a in the network at a half time step.

Parameters:
  • a (Artery) – Artery on which the flux term is computed
  • x0 (float) – Left point
  • x1 (float) – Right point
  • U0 (numpy.array) – Value of solution at x0
  • U1 (numpy.array) – Value of solution at x1
  • x (float) – Point of evaluation
Returns:

return – Solution for artery a at the middle point after half a time step

Return type:

numpy.array

daughter_arteries(i)

Find and return the indices of the daughter arteries of artery i.

Parameters:i (int) – Index of the parent artery
Returns:return – Daughter artery indices
Return type:int
define_geometry(Nx, Nt, T, N_cycles)

Calls define_geometry() for each artery in the network.

Parameters:
  • Nx (int) – Number of spatial points per artery
  • Nt (int) – Number of time steps per cardiac cycle
  • T (float) – Duration of one cardiac cycle
  • N_cycles (int) – Number of cardiac cycles in the simulation
define_solution(output_location, q0, theta=0.5)

Calls define_solution() for each artery in the network.

Parameters:
  • output_location (string) – Output data directory
  • q0 (float) – Initial flow rate in the root vessel
  • theta (float) – Weighting parameter for the Crank-Nicolson method, in the interval [0, 1]
define_x()

Calls initial_x() for each bifurcation in the artery network

dump_metadata(Nt_store, N_cycles_store, store_area, store_pressure)

Save metadata for the interpretation of XDMF files.

Parameters:
  • Nt_store (int) – Number of time steps to store
  • N_cycles_store (int) – Number of cardiac cycles to store
  • store_area (boolean) – Store area if True
  • store_pressure (boolean) – Store pressure if True
flux(a, U, x)

Computes the flux term F(U) for a given artery a in the network.

Parameters:
  • a (Artery) – Artery on which the flux term is computed
  • U (numpy.array) – Value of solution
  • x (float) – Point of evaluation
Returns:

return – Flux term F(U) for artery a at point x

Return type:

numpy.array

initial_x(p, d1, d2)

Computes an initial guess for x at a bifurcation point. Set same value at time t_(n+1) and t_(n+1/2) as time t_n. At point M+-1/2, set same value as in point M.

Parameters:
  • p (Artery) – Parent artery in the bifurcation
  • d1 (Artery) – First daughter artery in the bifurcation
  • d2 (Artery) – Second daughter artery in the bifurcation
Returns:

return – Initial guess for the 18 variables at a bifurcation

Return type:

numpy.array

jacobian(p, d1, d2, x)

Computes the analytical Jacobian of the system of equations at a bifurcation.

Parameters:
  • p (Artery) – Parent artery in the bifurcation
  • d1 (Artery) – First daughter artery in the bifurcation
  • d2 (Artery) – Second daughter artery in the bifurcation
  • x (numpy.array) – Current solution
Returns:

return – Jacobian matrix

Return type:

numpy.array

newton(p, d1, d2, x=<sphinx.ext.autodoc.importer._MockObject object>, k_max=30, tol=1e-10)

Computes the solution of the system of equations at a bifurcation using Newton’s method.

Parameters:
  • p (Artery) – Parent artery in the bifurcation
  • d1 (Artery) – First daughter artery in the bifurcation
  • d2 (Artery) – Second daughter artery in the bifurcation
  • x (numpy.array) – Current solution
  • k_max (int) – Maximum number of iterations
  • tol (float) – Tolerance for the solution
Returns:

return – Solution to the system of equations

Return type:

numpy.array

parent_artery(i)

Find and return the index of the partent artery of artery i.

Parameters:i (int) – Index of the daughter artery
Returns:return – Parent artery index
Return type:int
problem_function(p, d1, d2, x)

Computes the solution f(x) = y of the system of equations at a bifurcation.

Parameters:
  • p (Artery) – Parent artery in the bifurcation
  • d1 (Artery) – First daughter artery in the bifurcation
  • d2 (Artery) – Second daughter artery in the bifurcation
  • x (numpy.array) – Current solution
Returns:

return – Function value f(x)

Return type:

numpy.array

set_bcs(q_in)

Updates all boundary values using the appropriate boundary conditions.

Parameters:q_in (float) – Inflow rate in the root vessel at time t_(n+1)
set_inner_bc(ip, i1, i2)

Calls newton() for each bifurcation to calculate the boundary values for each artery at the bifurcation.

Parameters:
  • ip (int) – Parent artery index in the bifurcation
  • i1 (int) – First daughter artery index in the bifurcation
  • i2 (int) – Second daughter artery index in the bifurcation
sister_artery(i)

Find and return the index of the sister artery of artery i.

Parameters:i (int) – Index of the artery
Returns:return – Sister artery index
Return type:int
solve(q_ins, Nt_store, N_cycles_store=1, store_area=False, store_pressure=True)

Call solve for each artery in the network.

Parameters:
  • q_ins (numpy.array) – Array containing inflow rates for the root artery at every time step
  • Nt_store (int) – Number of time steps to store
  • N_cycles_store (int) – Number of cardiac cycles to store
  • store_area (boolean) – Store area if True
  • store_pressure (boolean) – Store pressure if True
source(a, U, x)

Computes the source term S(U) for a given artery a in the network.

Parameters:
  • a (Artery) – Artery on which the flux term is computed
  • U (numpy.array) – Value of solution
  • x (float) – Point of evaluation
Returns:

return – Source term S(U) for artery a at point x

Return type:

numpy.array

arteryfe.utils module

arteryfe.utils.XDMF_to_matrix(Nx, Nt, mesh_location, location, name)

Read XDMF-file and store it in a Numpy array.

Parameters:
  • Nx (int) – Number of spatial points per artery
  • Nt (int) – Number of time steps per cardiac cycle
  • mesh_location (string) – File name of the mesh to be loaded
  • location (string) – File name of the XDMF file
  • name (string) – Name of the function in the XDMF file
Returns:

return – Array containing the values loaded from the XDMF file

Return type:

numpy.array

arteryfe.utils.is_near(a, b, tol=1e-11, reltol=1e-10)

Check near-equality between two floats to a certain tolerance. Name contains ‘is’ to differentiate it from DOLFIN near()-function.

Parameters:
  • a (float) – First number
  • b (float) – Second number
  • tol (float) – Tolerance for near-equality
  • reltol (float) – Relative tolerance for near-equality
Returns:

return – True if a and b are near-equal

Return type:

boolean

arteryfe.utils.mmHg_to_unit(p)

Converts pressure value in mmHg to g cm-1 s-2.

Parameters:p (float) – Pressure value in mmHg
Returns:return – Pressure value in g cm-1 s-2
Return type:float
arteryfe.utils.nondimensionalise(rc, qc, rho, x, nature)

Nondimensionalise a parameter using the characteristic parameters.

Parameters:
  • rc (float) – Characteristic radius (length)
  • qc (float) – Characteristic flow
  • rho (float) – Density of blood
  • x (float) – Parameter to redimensionalise
  • nature (string) – Nature of parameter to be redimensionalised
Returns:

return – Dimensionless quantity

Return type:

float

arteryfe.utils.nondimensionalise_parameters(rc, qc, Ru, Rd, L, k1, k2, k3, rho, nu, p0, R1, R2, CT, q_ins, T)

Nondimensionalise parameters.

Parameters:
  • rc (float) – Characteristic radius (length)
  • qc (float) – Characteristic flow
  • Ru (float) – Upstream radius
  • Rd (float) – Downstream radius
  • L (float) – Vessel length
  • k1 (float) – First constant from the relation Eh/r0
  • k2 (float) – Second constant from the relation Eh/r0
  • k3 (float) – Third constant from the relation Eh/R0
  • rho (float) – Density of blood
  • Re (float) – Reynolds’ number
  • nu (float) – Viscosity of blood
  • p0 (float) – Diastolic pressure
Returns:

return – Tuple of dimensionless quantities, including Reynold’s number

Return type:

tuple

arteryfe.utils.plot_matrix(t, x, M, label, output)

Creates and stores a plot of a numpy array.

Parameters:
  • t (numpy.array) – Array containing time point values
  • x (numpy.array) – Array containing spatial point values
  • M (numpy.array) – Array to be plotted, with dimension (t, x)
  • output (string) – File name to store plot
arteryfe.utils.print_progress(n_cycle, n, dt)

Print progress of simulation.

Parameters:
  • n_cycle (int) – Current cardiac cycle
  • n (int) – Current iteration within cardiac cycle
  • dt (float) – Current time step
arteryfe.utils.read_file(f, u, label, i)

Wrapper function for DOLFIN’s read_checkpoint() to avoid print of warnings.

Parameters:
  • f (XDMFFile) – XDMFFile to write to
  • u (Function) – Function to write to f
  • label (string) – Label for the Function
  • i (int) – Index of time point
arteryfe.utils.read_inlet(data_location, Nt)

Read inlet flow rate data from file and returns

Parameters:
  • data_location (string) – Location of inlet flow data file
  • Nt (int) – Number of time steps
Returns:

return – Length of a cardiac cycle, inlet flow rate data

Return type:

tuple

arteryfe.utils.read_output(filename)

Read data file generated in the output folder.

Parameters:rc (string) – Data file name
Returns:return – Tuple of all parameters stored in the file
Return type:tuple
arteryfe.utils.redimensionalise(rc, qc, rho, x, nature)

Redimensionalise a parameter using the characteristic parameters.

Parameters:
  • rc (float) – Characteristic radius (length)
  • qc (float) – Characteristic flow
  • rho (float) – Density of blood
  • x (float) – Parameter to redimensionalise
  • nature (string) – Nature of parameter to be redimensionalised
Returns:

return – Redimensionalised quantity

Return type:

float

arteryfe.utils.unit_to_mmHg(p)

Converts pressure value in g cm-1 s-2 to mmHg.

Parameters:p (float) – Pressure value in g cm-1 s-2
Returns:return – Pressure value in mmHg
Return type:float
arteryfe.utils.write_file(f, u, label, t)

Wrapper function for DOLFIN’s write_checkpoint() to avoid print of warnings.

Parameters:
  • f (XDMFFile) – XDMFFile to write to
  • u (Function) – Function to write to f
  • label (string) – Label for the Function
  • t (float) – Time point

Module contents