fenicsx package

Subpackages

Submodules

fenicsx.backends module

class fenicsx.backends.LoopProgress(msg: str, final: float = 100)[source]

Bases: object

A class to make progress bar.

Parameters:
  • msg (str) – Message to be displayed

  • final (float, optional (Default = 100)) – Maximum value for the iterations

update(step: float, percentage: bool = True)[source]

Update message to display and clears the previous one.

Parameters:
  • step (float) – Interger or float value to add at the counter.

  • percentage (boolean, optional (Default = True)) – Indicates if the bar should be displayed in %.

class fenicsx.backends.norms(V: dolfinx.fem.FunctionSpace, is_H1=False, metadata_degree=4)[source]

Bases: object

A class to compute norms and inner products. \(L^2\) and \(H^1\) (semi and full are implemented for both scalar and vector fields), whereas the average and the integral are available for scalar only.

Parameters:
  • V (FunctionSpace) – Functional Space onto which the Function are defined.

  • is_H1 (boolean, optional (Default = False)) – If the function belongs to \(H^1\), the forms for the inner products and norms are computed.

H1innerProd(u: dolfinx.fem.Function, v: dolfinx.fem.Function, semi=True)[source]

Computes the \(H^1\) semi or full inner product of the functions u and v over the domain

\[\langle u, v \,\rangle_{H^1} = \int_\Omega \nabla u \cdot \nabla v\,d\Omega\]
\[(u,v)_{H^1} = \int_\Omega u\cdot v \,d\Omega + \int_\Omega \nabla u\cdot \nabla v \,d\Omega\]
Parameters:
  • u (Function) – Function belonging to the same functional space V

  • v (Function) – Function belonging to the same functional space V

  • semi (boolean, optional (Default = True)) – Indicates if the semi norm must be computed.

Returns:

value\(H^1\) inner product of the functions

Return type:

float

H1norm(u: dolfinx.fem.Function, semi=True)[source]

Computes the \(H^1\) semi or full norm of the function u over the domain

\[| u |_{H^1} = \sqrt{\int_\Omega \nabla u \cdot \nabla u\,d\Omega}\]
\[\| u \|_{H^1} = \sqrt{\int_\Omega \nabla u \cdot \nabla u\,d\Omega + \int_\Omega u \cdot u\,d\Omega}\]
Parameters:
  • u (Function) – Function belonging to the same functional space V

  • semi (boolean, optional (Default = True)) – Indicates if the semi norm must be computed.

Returns:

value\(H^1\) norm of the function

Return type:

float

L2innerProd(u: dolfinx.fem.Function, v: dolfinx.fem.Function)[source]

Computes the \(L^2\) inner product of the functions u and v over the domain

\[(u,v)_{L^2}=\int_\Omega u\cdot v \,d\Omega\]
Parameters:
  • u (Function) – Function belonging to the same functional space V

  • v (Function) – Function belonging to the same functional space V

Returns:

value\(L^2\) inner product between the functions

Return type:

float

L2norm(u: dolfinx.fem.Function)[source]

Computes the \(L^2\) norm of the function u over the domain

\[\| u\|_{L^2} = \sqrt{\int_\Omega u \cdot u\,d\Omega}\]
Parameters:

u (Function) – Function belonging to the same functional space V

Returns:

value\(L^2\) norm of the function

Return type:

float

Linftynorm(u: dolfinx.fem.Function)[source]

Computes the \(L^\infty\) norm of a given function u over the domain

\[\| u \|_{L^\infty}=\max\limits_\Omega |u|\]
Parameters:

u (Function) – Function belonging to the same functional space V

Returns:

value\(L^\infty\) norm of the function

Return type:

float

average(u: dolfinx.fem.Function)[source]

Computes the integral average of a given scalar function u over the domain

\[\langle u \rangle = \frac{1}{|\Omega|}\int_\Omega u \,d\Omega\]
Parameters:

u (Function) – Function belonging to the same functional space V (it must be a scalar!)

Returns:

ave_value – Average over the domain

Return type:

float

integral(u: dolfinx.fem.Function)[source]

Computes the integral of a given scalar function u over the domain

\[\int_\Omega u \,d\Omega\]
Parameters:

u (Function) – Function belonging to the same functional space V (it must be a scalar!)

Returns:

val – Integral over the domain

Return type:

float

fenicsx.plotting module

fenicsx.plotting.PlotScalar(fun: dolfinx.fem.Function, filename: str | None = None, format: str = 'png', varname: str | None = None, clim=None, colormap=<matplotlib.colors.LinearSegmentedColormap object>, resolution=[1080, 720], show=False)[source]

Python function to plot a scalar field.

Parameters:
  • fun (Function) – Field to plot.

  • varname (str) – Name of the variable.

  • filename (str) – Name of the file to save.

  • clim (optional (Default = None)) – Colorbar limit, if None the mininum and maximum of fun are computed

  • colormap (optional (Default = jet)) – Colormap for the plot

  • resolution (list, optional (Default = [1080, 720])) – Resolution of the image

fenicsx.plotting.extract_cells(domain: dolfinx.mesh.Mesh, points: ndarray)[source]

This function can be used to extract data along a line defined by the variables points, crossing the domain.

Parameters:
  • domain (dolfinx.mesh.Mesh) – Domain to extract data from.

  • points (np.ndarray) – Points listing the line from which data are extracted.

Returns:

  • xPlot (np.ndarray) – Coordinate denoting the cell from which data are extracted.

  • cells (list) – List of cells of the mesh.

fenicsx.plotting.get_scalar_grid(fun: dolfinx.fem.Function, varname: str, real=True)[source]

This function extracts the dofs of a scalar function for the plot using pyvista.

Parameters:
  • fun (Function) – Function from which the dofs are extracted.

  • varname (str) – Name of the variable.

  • real (boolean, optional (Default = True)) – Real dofs are considered, if False imaginary dofs are used.

Returns:

u_grid – Unstructured grid of values for the selected function.

Return type:

pyvista.UnstructuredGrid

Module contents

models/fenicsx.

OFELIA: FEniCSx models for MultiPhysics.