API Reference#

Top-level package for 1D networks simulations with FEniCSx.

class networks_fenicsx.HydraulicNetworkAssembler(mesh: NetworkMesh, flux_degree: int = 1, pressure_degree: int = 0)[source]#

Assembler for the variational formulation of an hydraulic network.

\[\begin{split}R q + \frac{\mathrm{d}}{\mathrm{d}s} p = 0 \\ \frac{\mathrm{d}}{\mathrm{d}s} q = f\end{split}\]
Parameters:
  • mesh – The network mesh

  • flux_degree – The polynomial degree for the flux functions

  • pressure_degree – The polynomial degree for the pressure functions

assemble(A: Mat | None = None, b: Mat | None = None, assemble_lhs: bool = True, assemble_rhs: bool = True, kind: str | Sequence[Sequence[str]] | None = None) tuple[Mat, Vec][source]#

Assemble system matrix and rhs vector.

Note

If neither A or b is provided, they are created inside this class.

Parameters:
bilinear_form(i: int, j: int) Form[source]#

Extract the i,j bilinear form.

property bilinear_forms: Sequence[Sequence[Form]]#

Nested list of the compiled, bilinear forms.

compute_forms(p_bc_ex: Callable[[ndarray[tuple[int, ...], dtype[floating]]], ndarray[tuple[int, ...], dtype[inexact]]] | Expression | Expr, f: Expr | None = None, jit_options: dict | None = None, form_compiler_options: dict | None = None)[source]#

Compute forms for hydraulic network model

\[\begin{split}R q + \frac{\mathrm{d}}{\mathrm{d}s} p = 0\\ \frac{\mathrm{d}}{\mathrm{d}s} q = f\end{split}\]

on graph G, with bifurcation condition q_in = q_out and jump vectors the bifurcation conditions

Parameters:
  • f – source term

  • p_bc – neumann bc for pressure

property flux_spaces: list[FunctionSpace]#

List of function spaces for each flux function. The ith function corresponds to the edges of the networkx.DiGraph that were colored with color i.

property function_spaces: list[FunctionSpace]#

List of all function-spaces in the order [flux, pressure, lm], the same order as used by the assemble()

linear_form(i: int) Form[source]#

Return the i-th block of the linear form

property linear_forms: Sequence[Form]#

Extract the linear form.

property lm_space: FunctionSpace#

The function space of the bifurcation Lagrange multipliers

property network: NetworkMesh#

Return the underlying network mesh.

property pressure_space: FunctionSpace#

The function space of the pressure function

class networks_fenicsx.NetworkMesh(graph: ~networkx.classes.digraph.DiGraph, N: int, color_strategy: str | ~typing.Callable[[~networkx.classes.graph.Graph, dict[int, int]], ~typing.Iterable[int]] | None = None, comm: ~mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>, graph_rank: int = 0)[source]#

A representation of a Directional Networkx graph in DOLFINx.

Stores the resulting mesh, subdomains, and facet markers for bifurcations and boundary nodes. Has a submesh for each edge in the Networkx graph.

Parameters:
  • graph – The directional networkx graph to convert.

  • N – Number of elements per segment.

  • color_strategy – Strategy to use for coloring the graph edges. If set to None, no-graphcoloring is used (not recommended).

  • comm – The MPI communicator to distribute the mesh on.

  • graph_rank – The MPI rank of the process that holds the graph.

property comm: Comm#

MPI-communicator of the network mesh

property lm_map: EntityMap#

Entity map for the Lagrange multiplier mesh

property lm_mesh: Mesh#

Lagrange multiplier mesh, a point-cloud mesh including each bifurcation.

property tangent#

Return DG-0 field containing the tangent vector of the graph.

class networks_fenicsx.Solver(assembler: HydraulicNetworkAssembler, petsc_options_prefix: str = 'NetworkSolver_', petsc_options: dict | None = None, kind: str | Sequence[Sequence[str]] | None = None)[source]#

PETSc solver interface for the Network problems.

Parameters:
  • assembler – The hydraulic network assembler.

  • petsc_options_prefix – Prefix for PETSc options.

  • petsc_options – Dictionary of PETSc options.

  • kind – Kind of PETSc matrix and vectors to create.

property A: Mat#

System matrix.

assemble(lhs: bool = True, rhs: bool = True)[source]#

Assemble the system matrix and rhs vector.

Parameters:
  • lhs – Whether to assemble the system matrix.

  • rhs – Whether to assemble the rhs vector.

property assembler: HydraulicNetworkAssembler#

The hydraulic network assembler.

property b: Vec#

Right-hand side vector.

solve(functions: list[Function] | None = None) list[Function][source]#

Solve the linear system of equations and assign them to a set of corresponding DOLFINx functions.

Parameters:

functions – List of DOLFINx functions to assign the solution to. If not provided they are created based on the assembler information.

Returns:

The functions.