pyforce.offline package

Submodules

pyforce.offline.geim module

class pyforce.offline.geim.GEIM(domain, V: dolfinx.fem.FunctionSpace, name: str, s=0.01)[source]

Bases: object

This class is used to perform the offline phase of the Generalised Empirical Interpolation Method (GEIM) to a scalar field. Given a list of training snapshots, this class generates the magic functions and sensors through a greedy algorithm.

Parameters:
  • domain (dolfinx.mesh) – Mesh of the problem onto which the sensors are generated.

  • V (FunctionSpace) – Functional space of the snapshots.

  • name (str) – Name of the snapshots (e.g., temperature T)

  • s (float) – Standard deviation of the gaussian kernel for the sensors

assemble_penalisation_matrix(train_snap: FunctionsList, Mmax: int, verbose: bool = False)[source]

Construct penalisation matrix for the TR-GEIM

offline(train_snap: FunctionsList, Mmax: int, xm=None, sampleEvery=5, verbose=False)[source]

The greedy algorithm chooses the magic functions and magic sensors by minimising the reconstruction error.

Parameters:
  • train_snap (FunctionsList) – List of snapshots serving as training set.

  • Mmax (int) – Integer input indicating the maximum number of functions and sensors to define

  • xm (list, optional (default = None)) – User-defined available positions for the sensors, if None the positions are taken from the mesh elements.

  • sampleEvery (int, optional (default = 5)) – If xm is not None, sampling rate for the selection of points from the mesh

  • verbose (boolean, optional (Default = False)) – If True, print of the progress is enabled.

Returns:

  • maxAbsErr (np.ndarray) – Maximum absolute error measured in \(L^2\)

  • maxRelErr (np.ndarray) – Maximum relative error measured in \(L^2\)

  • beta_coeff (np.ndarray) – Matrix of the reduced coefficients \(\{ \beta_m \}_{m=1}^M\), obtained by greedy procedure

reconstruct(snap: dolfinx.fem.Function, Mmax: int)[source]

Computes the reduced coefficients \(\{\beta_m\}_{m=1}^{M_{max}}\) with ‘Mmax’ magic functions/sensors (synthetic) and returns the vector measurement from the snapshots \(u\)

\[y_m = v_m(u) \qquad m = 1, \dots, M_{max}\]
Parameters:
  • snap (Function) – Function from which the measuremets are computed.

  • Mmax (int) – Maximum number of sensors to use

Returns:

  • beta_coeff (np.ndarray) – Array of coefficients for the interpolant \(\{\beta_m\}_{m=1}^{M_{max}}\)

  • Measure (np.ndarray) – Array with the evaluation of the snap \(u\) at the sensors locations

test_error(test_snap: FunctionsList, Mmax: int | None = None, verbose=False)[source]

The absolute and relative error on the test set is computed, by solving the GEIM system

\[\mathbb{B}\boldsymbol{\beta} = \mathbf{y}\]
Parameters:
  • test_snap (FunctionsList) – List of functions belonging to the test set to reconstruct with GEIM

  • Mmax (int, optional (default = None)) – Maximum number of magic functions to use (if None is set to the number of magic functions/sensors)

  • verbose (boolean, optional (default = False)) – If true, output is printed.

Returns:

  • meanAbsErr (np.ndarray) – Average absolute error measured in \(L^2\)

  • meanRelErr (np.ndarray) – Average relative error measured in \(L^2\)

  • coeff_matrix – Matrix of the reduced coefficients, obtained by the solving the GEIM linear system

pyforce.offline.geim.computeLebesgue(magic_fun: FunctionsList, magic_sens: FunctionsList)[source]

The Lebesgue constant \(\Lambda_M\) is computed from the magic functions and sensors, to measure the good properties of the interpolation procedure. This function follows the implementation reported in https://www.sciencedirect.com/science/article/pii/S0045782515000389?via%3Dihub.

Parameters:
Returns:

Lebesgue – Array containing the Lebesgue constant at different number of sensors

Return type:

np.ndarray

pyforce.offline.pbdw module

class pyforce.offline.pbdw.PBDW(basis_functions: FunctionsList, basis_sensors: FunctionsList, is_H1: bool = False)[source]

Bases: object

A class implementing the a priori error analysis of the Parameterised-Background Data-Weak (PBDW) formulation, given a list of sensors’ Riesz representation \(\{g_m\}_{m=1}^M\) for the update space and basis functions \(\{\zeta_n\}_{n=1}^N\) for the reduced one. In particular, the following matrices are defined \((n,n' = 1,\dots,N)\) and \((m,m' = 1,\dots,M)\)

\[\mathbb{A}_{mm'}=\left(g_m,\,g_{m'}\right)_{\mathcal{U}}\]
\[\mathbb{K}_{mn}=\left(g_m,\,\zeta_{n}\right)_{\mathcal{U}}\]
\[\mathbb{Z}_{nn'}=\left(\zeta_{n},\,\zeta_{n'}\right)_{\mathcal{U}}\]

given \(\mathcal{U}\) as the functional space.

Parameters:
  • basis_functions (FunctionsList) – List of functions spanning the reduced space

  • basis_sensors (FunctionsList) – List of sensors representation spanning the update space

  • is_H1 (boolean, optional (default=False)) – If True, the Riesz representation in \(H^1\) is used.

compute_infsup(N: int, M: int)[source]

Compute the inf-sup constant \(\beta_{N,M}\) for the couple basis functions (dimension \(N\)) - basis sensors (dimension \(M\)). It’s the square root of the minimum eigenvalue of the following eigenvalue problem

\[\mathbb{K}^T\mathbb{A}^{-1}\mathbb{K}\mathbf{z}_k = \lambda_k \mathbb{Z}\mathbf{z}_k \qquad\Longrightarrow\qquad \beta_{N,M} = \min\limits_{k=1,\dots,N} \sqrt{\lambda_k}\]
Parameters:
  • N (int) – Dimension of the reduced space to use

  • M (int) – Dimension of the update space to use

Returns:

inf_sup – Inf-sup constant \(\{\beta_{N,m}\}_{m=1}^M\) (fixed \(N\)), measuring how good the update space spanned by basis sensors is.

Return type:

np.ndarray

pyforce.offline.pod module

class pyforce.offline.pod.DiscretePOD(train_snap: FunctionsList, name: str, Nmax=None, random=False)[source]

Bases: object

A class to perform the POD on a list of snapshots \(u(\mathbf{x};\,\boldsymbol{\mu})\) dependent on some parameter \(\boldsymbol{\mu}\). This class is used for several kind of inputs (FunctionsList, vectors, images, matrices…).

The snapshots are represented by a matrix \(\mathbb{S}\in\mathbb{R}^{\mathcal{N}_h\times N_s}\), such that

\[\mathbb{S}_{ij} = u(\mathbf{x}_i;\,\boldsymbol{\mu}_j)\]

in which the dependence on \(\mathbf{x}_i\) can be a true spatial dependence or the dofs of a matrix/image.

The basis functions are computed using the svd, i.e.

\[\mathbb{U}, \Sigma, \mathbb{V}^\dagger = \text{svd}(\mathbb{S})\]

The basis functions are orthogonal in \(l_2\) sense, hence the matrix containing the modes is orthogonal.

Parameters:
  • train_snap (FunctionsMatrix or FunctionsList) – List of snapshots onto which the POD is performed.

  • name (str) – Name of the field.

  • Nmax (int, optional (default=None)) – If None the full matrices are stored, else only the first Nmax.

  • random (bool, optional (default = False)) – If True and if Nmax is provided, the randomised SVD is used.

projection(snap: ndarray, N: int | None = None)[source]

The reduced coefficients \(\mathbf{V}^\dagger_\star\in\mathbb{R}^{N\times N_\star}\) of snap\(=\mathbb{S}_\star\in\mathbb{R}^{\mathcal{N}_h\times N_\star}\) using N modes \(\mathbb{U}\in\mathbb{R}^{\mathcal{N}_h\times N}\) are computed using projection in \(l_2\), i.e.

\[\mathbf{V}^\dagger_\star = \Sigma^{-1}\mathbb{U}^T\mathbb{S}_\star\]
Parameters:
  • snap (np.ndarray) – Matrix object to project onto the reduced space of dimension N. Must be \((\mathcal{N}_h, N_\star)\).

  • N (int, optional (default = None)) – Dimension of the reduced space, modes to be used. If None all the modes are used.

Returns:

coeff – Modal POD coefficients of snap, \(\mathbf{V}^\dagger_\star\).

Return type:

np.ndarray

reconstruct(Vh_star: ndarray)[source]

The reduced coefficients \(\mathbf{V}^\dagger_\star\in\mathbb{R}^{N\times N_\star}\) are used to decode into the Full Order space \(\mathbb{R}^{\mathcal{N}_h}\) using N modes \(\mathbb{U}\in\mathbb{R}^{\mathcal{N}_h\times N}\).

\[\mathbb{S}_\star = \mathbb{U}\Sigma\mathbf{V}^\dagger_\star\]
Parameters:

Vh_star (np.ndarray) – Matrix object containing the POD coefficients. Must be \((N, N_\star)\).

Returns:

snaps – Reconstructed field returned as an element of \(\mathbf{R}^{\mathcal{N_h}\times N_\star}\).

Return type:

np.ndarray

train_error(train_snap: FunctionsList, maxBasis: int, verbose=False)[source]

The maximum absolute \(E_N\) and relative \(\varepsilon_N\) error on the train set is computed, by projecting it onto the reduced space in \(l^2\)-sense

\[E_N = \max\limits_{\boldsymbol{\mu}\in\Xi_{\text{train}}} \left\| u(\mathbf{x};\,\boldsymbol{\mu}) - \sum_{n=1}^N \alpha_n(\boldsymbol{\mu})\cdot \psi_n(\mathbf{x})\right\|_{2}\]
\[\varepsilon_N = \max\limits_{\boldsymbol{\mu}\in\Xi_{\text{train}}} \frac{\left\| u(\mathbf{x};\,\boldsymbol{\mu}) - \sum_{n=1}^N \alpha_n(\boldsymbol{\mu})\cdot \psi_n(\mathbf{x})\right\|_{2}}{\left\| u(\mathbf{x};\,\boldsymbol{\mu})\right\|_{2}}\]
Parameters:
  • train_snap (FunctionsMatrix or FunctionsList) – List of snapshots to project and compute errors

  • maxBasis (int) – Integer input indicating the maximum number of modes to use.

  • verbose (boolean, optional (Default = False)) – If True, print of the progress is enabled.

Returns:

  • maxAbsErr (np.ndarray) – Maximum absolute errors as a function of the dimension of the reduced space.

  • maxRelErr (np.ndarray) – Maximum absolute errors as a function of the dimension of the reduced space.

class pyforce.offline.pod.POD(train_snap: FunctionsList, name: str, use_scipy=False, verbose=False)[source]

Bases: object

A class to perform the POD on a list of snapshots \(u(\mathbf{x};\,\boldsymbol{\mu})\) dependent on some parameter \(\boldsymbol{\mu}\in\mathcal{P}\subset\mathbb{R}^p\). This class is used for FunctionsList, the POD modes are obtained from the eigendecomposition of the correlation matrix \(C\in\mathbb{R}^{N_s\times N_s}\)

\[C_{ij} = \left(u(\cdot;\,\boldsymbol{\mu}_i),\,u(\cdot;\,\boldsymbol{\mu}_j)\right)_{L^2}\qquad i,j = 1, \dots, N_s\]
\[C \boldsymbol{\eta_n} = \lambda_n \boldsymbol{\eta_n}\qquad\qquad\qquad n = 1, \dots, N_s\]

The eigenvalues \(\lambda_n\) and eigenvectors \(\boldsymbol{\eta_n}\) are immediately computed.

Parameters:
  • train_snap (FunctionsList) – List of snapshots onto which the POD is performed.

  • name (str) – Name of the field.

  • verbose (boolean, optional (Default = False)) – If True, print of the progress is enabled.

GramSchmidt(fun: dolfinx.fem.Function) ndarray[source]

Perform a step of the Gram-Schmidt process on POD modes \(\{\psi_k\}_{k=1}^r\) adding fun \(=f\) to enforce the orthonormality in \(L^2\)

\[\psi_{r+1} = f - \sum_{k=1}^r \frac{(f, \psi_k)_{L^2}}{(\psi_k, \psi_k)_{L^2}}\psi_k\]
Parameters:

fun (Function) – Function to add to the POD basis.

Returns:

normalised_fun – Orthonormalised function \(\psi_{r+1}\) with respect to the POD basis \(\{\psi_k\}_{k=1}^r\).

Return type:

Function

compute_basis(train_snap: FunctionsList, maxBasis: int, normalise=False) None[source]

Computes the POD modes.

To enforce the orthonormality in \(L^2\), the Gram-Schmidt procedure can be used, if the number of modes to be used is high the numerical error in the eigendecomposition may be too large and the orthonormality is lost.

Parameters:
  • train_snap (FunctionsList) – List of snapshots onto which the POD is performed.

  • maxBasis (int) – Integer input indicating the number of modes to define.

  • normalise (boolean, optional (Default = False)) – If True, the Gram-Schmidt procedure is used to normalise the POD modes.

mode(train_snap: FunctionsList, r: int) dolfinx.fem.Function[source]

Computes the r-th POD mode, according to the following formula

\[\psi_{r} (\mathbf{x})= \frac{1}{\lambda_r}\sum_{i=1}^{N_s} \eta_{r, i}\,u(\mathbf{x};\,\boldsymbol{\mu}_i)\]
Parameters:
  • train_snap (FunctionsList) – List of snapshots onto which the POD is performed.

  • r (int) – Integer input indicating the mode to define.

projection(u: dolfinx.fem.Function, N: int) ndarray[source]

The reduced coefficients \(\{\alpha_k\}_{k=1}^N\) of u using N modes \(\{\psi_k\}_{k=1}^N\) are computed using projection in \(L_2\), i.e.

\[\alpha_k(\boldsymbol{\mu}) = (u(\cdot;\,\boldsymbol{\mu}), \,\psi_k)_{L^2}\qquad k = 1, \dots, N\]
Parameters:
  • u (Function) – Function object to project onto the reduced space of dimension N.

  • N (int) – Dimension of the reduced space, modes to be used.

Returns:

coeff – Modal POD coefficients of u, \(\{\alpha_k\}_{k=1}^N\).

Return type:

np.ndarray

test_error(test_snap: FunctionsList, maxBasis: int, verbose: bool = False)[source]

The average absolute \(E_N\) and relative \(\varepsilon_N\) error on the test set is computed, by projecting it onto the reduced space in \(L^2\)-sense

\[E_N = \left\langle \left\| u(\mathbf{x};\,\boldsymbol{\mu}) - \sum_{n=1}^N \alpha_n(\boldsymbol{\mu})\cdot \psi_n(\mathbf{x})\right\|_{L^2} \right\rangle_{\boldsymbol{\mu}\in\Xi_{\text{test}}}\]
\[\varepsilon_N =\left\langle \frac{\left\| u(\mathbf{x};\,\boldsymbol{\mu}) - \sum_{n=1}^N \alpha_n(\boldsymbol{\mu})\cdot \psi_n(\mathbf{x})\right\|_{L^2}}{\left\| u(\mathbf{x};\,\boldsymbol{\mu})\right\|_{L^2}} \right\rangle_{\boldsymbol{\mu}\in\Xi_{\text{test}}}\]
Parameters:
  • test_snap (FunctionsList) – List of snapshots onto which the test error of the POD basis is performed.

  • maxBasis (int) – Integer input indicating the maximum number of modes to use.

  • verbose (boolean, optional (Default = False)) – If True, print of the progress is enabled.

Returns:

  • meanAbsErr (np.ndarray) – Maximum absolute errors as a function of the dimension of the reduced space.

  • maxRelErr (np.ndarray) – Maximum absolute errors as a function of the dimension of the reduced space.

  • coeff_matrix (np.ndarray) – Matrix of the modal coefficients, obtained by projection in \(L^2\).

train_error(train_snap: FunctionsList, maxBasis: int, verbose: bool = False) tuple[ndarray, ndarray, ndarray][source]

The maximum absolute \(E_N\) and relative \(\varepsilon_N\) error on the train set is computed, by projecting it onto the reduced space in \(L^2\)-sense

\[E_N = \max\limits_{\boldsymbol{\mu}\in\Xi_{\text{train}}} \left\| u(\mathbf{x};\,\boldsymbol{\mu}) - \sum_{n=1}^N \alpha_n(\boldsymbol{\mu})\cdot \psi_n(\mathbf{x})\right\|_{L^2}\]
\[\varepsilon_N = \max\limits_{\boldsymbol{\mu}\in\Xi_{\text{train}}} \frac{\left\| u(\mathbf{x};\,\boldsymbol{\mu}) - \sum_{n=1}^N \alpha_n(\boldsymbol{\mu})\cdot \psi_n(\mathbf{x})\right\|_{L^2}}{\left\| u(\mathbf{x};\,\boldsymbol{\mu})\right\|_{L^2}}\]
Parameters:
  • train_snap (FunctionsList) – List of snapshots onto which the train error of the POD basis is performed.

  • maxBasis (int) – Integer input indicating the maximum number of modes to use.

  • verbose (boolean, optional (Default = False)) – If True, print of the progress is enabled.

Returns:

  • maxAbsErr (np.ndarray) – Maximum absolute errors as a function of the dimension of the reduced space.

  • maxRelErr (np.ndarray) – Maximum absolute errors as a function of the dimension of the reduced space.

  • coeff_matrix (np.ndarray) – Matrix of the modal coefficients, obtained by projection in \(L^2\).

pyforce.offline.sensors module

class pyforce.offline.sensors.GaussianSensors(domain, V: dolfinx.fem.FunctionSpace, s: float, assemble_riesz: bool = False)[source]

Bases: object

A class to define normalised gaussian sensors in terms of functional to mimic measurements of scalar fields. The measurement procedure is described through a linear functional with gaussian kernel, i.e.

\[v_k = v(u;\,\mathbf{x}_k,s) = \int_\Omega u(\mathbf{x})\cdot g(\mathbf{x};\,\mathbf{x}_k,s)\,d\Omega \qquad \text{ given } g(\mathbf{x};\,\mathbf{x}_k,s) = \frac{e^{-\frac{\|{\mathbf{x}-\mathbf{x}_k}\|_2^2}{2s^2}}}{\displaystyle\int_\Omega e^{-\frac{\|{\mathbf{x}-\mathbf{x}_k}\|_2^2}{2s^2}}\,d\Omega}\]

such that \(v(1;\,\mathbf{x}_k,s) = 1\).

Parameters:
  • domain (dolfinx.mesh) – Mesh onto which the sensors are defined.

  • V (FunctionSpace) – Functional space onto which the kernel of the sensors are interpolated.

  • s (float) – Standard deviation of the gaussian kernel.

  • assemble_riesz (boolean, optional (Default: False)) – Logic variable indicating whether or not to assemble the variational forms for the Riesz representations.

action(fun: dolfinx.fem.Function, sens: FunctionsList)[source]

Given an input function fun \(=f\) and a list of sensors \(\{v_m\}_{m=1}^M\), the action of the sensor is applied to the function, as an inner product in \(L^2\):

\[y_m = v_m\left(f\right)\qquad m = 1, \dots, M\]
Parameters:
  • fun (Function) – Function onto which the action is applied.

  • sens (FunctionsList) – List of available sensors

Returns:

measure – Vector \(\mathbf{y}\in\mathbb{R}^M\), whose dimension is equal to the number of input sensors.

Return type:

np.ndarray

action_single(fun: dolfinx.fem.Function, sensor: dolfinx.fem.Function)[source]

Given an input function fun \(=f\) and a sensors \(v_m\), the action of the sensor is applied to the function, as an inner product in \(L^2\):

\[y_m = v_m\left(f\right)\]
Parameters:
  • fun (Function) – Function onto which the action is applied.

  • sensor (Function) – Riesz representation of the sensor

Returns:

measure – Scalar \(y_m\) with the measure of the function with respect to the sensor \(v_m\).

Return type:

float

create(xm: list | None = None, sampleEvery: int = 10, is_H1: bool = False, verbose=False) FunctionsList[source]

This function creates the list of sensors (using Riesz representation either in \(L^2\) or in \(H^1\)), either by sampling from the mesh or from a prescribed list of positions.

Parameters:
  • xm (list, optional (Default: None)) – Possible List of positions for the sensors inside the domain.

  • sampleEvery (int, optional (Default: 10)) – Integers indicating sampling rate to be used on the mesh, if x_m is None.

  • is_H1 (bool, optional (Default: False)) – If True, the Riesz representation in \(H^1\) is used.

  • verbose (boolean, optional (Default = False)) – If True, printing is enabled.

Returns:

sens_list – List of kernel functions using a Riesz representation in \(L^2\)

Return type:

FunctionsList

define(x_m: ndarray) dolfinx.fem.Function[source]

Given a position \(x_m\) defines the kernel function of the sensor as a Gaussian with given point spread s

\[g(\mathbf{x};\,\mathbf{x}_m,s) = \frac{e^{-\frac{\|{\mathbf{x}-\mathbf{x}_m}\|_2^2}{2s^2}}}{\displaystyle\int_\Omega e^{-\frac{\|{\mathbf{x}-\mathbf{x}_m}\|_2^2}{2s^2}}\,d\Omega}\]

This kernel function is the Riesz representation \(q_m\) in \(L^2\) of the functional, i.e.

\[(q_m, \varphi)_{L^2} = \int_\Omega q_m\cdot \varphi \,d\Omega = v_m(\varphi)\qquad \forall \varphi\in L^2\]
define_riesz(x_m: ndarray) dolfinx.fem.Function[source]

Given a position \(x_m\) defines the kernel function \(q_m\) of the sensor as the Riesz representation in \(H^1\) of the functional, i.e.

\[(q_m, \varphi)_{H^1} = \int_\Omega q_m\cdot \varphi \,d\Omega + \int_\Omega \nabla q_m\cdot \nabla \varphi \,d\Omega = v_m(\varphi)\qquad \forall \varphi\in H^1\]
class pyforce.offline.sensors.SGREEDY(domain, basis: FunctionsList, V: dolfinx.fem.FunctionSpace, name: str, s: float)[source]

Bases: object

A class to perform the SGREEDY algorithm, given a list of basis functions \(\{\phi_n\}_{n=1}^N\).

Parameters:
  • domain (dolfinx.mesh) – Mesh for the sensor placement.

  • basis (FunctionsList) – List of basis functions \(\{\phi_n\}_{n=1}^N\), previously generated.

  • V (FunctionSpace) – Functional space of the functions.

  • name (str) – Name of the snapshots (e.g., temperature T)

  • s (float) – Standard deviation of the gaussian kernel for the sensors

approx_loop(Mmax: int, is_H1: bool = True)[source]

Approximation loop for the selection of sensors position with a Riesz representation \(\{g_m\}_{m=1}^M\) either in \(L^2\) or \(H^1\). At each step m, the next position is selected by the following

\[\mathbf{x}_{m+1} = \text{arg }\max\limits_{\mathbf{x}\in \Omega^\star}\left(\min\limits_{i=1, \dots, m} \| \mathbf{x}-\mathbf{x}_i\|_2\right)\]

given $Omega^starsubsetOmega$ a subset of the whole domain, in which sensors are allowed to be placed. Once the position is known, the functional and its Riesz representation are straightforwardly defined.

Parameters:
  • Mmax (int) – Maximum number of sensors allows.

  • is_H1 (bool, optional (Default: False)) – If True, the Riesz representation in \(H^1\) is used.

generate(N: int, Mmax: int, tol: float = 0.2, xm: list | None = None, sampleEvery: int = 10, is_H1: bool = False, verbose=False)[source]

Selection of sensors position with a Riesz representation \(\{g_m\}_{m=1}^M\) either in \(L^2\) or \(H^1\). The positions of the sensors are either freely selected on the mesh or given as input.

Parameters:
  • N (int) – Dimension of the reduced space.

  • Mmax (int) – Maximum number of sensors to select.

  • tol (float, optional (Default=0.2)) – Tolerance to exit the stability loop

  • xm (list, optional (Default=None)) – If not None, list of available positions for the sensors.

  • sampleEvery (int, optional (Default = 10)) – Sampling points on the mesh.

  • is_H1 (bool, optional (Default: False)) – If True, the Riesz representation in \(H^1\) is used.

  • verbose (boolean, optional (Default = False)) – If True, printing is enabled.

pyforce.offline.weak_greedy module

class pyforce.offline.weak_greedy.WeakGreedy(V: dolfinx.fem.FunctionSpace, name: str)[source]

Bases: object

GrahmSchmidt(fun: dolfinx.fem.Function)[source]

Perform a step of the Gram-Schmidt process on basis functions \(\{\psi_k\}_{k=1}^r\) adding fun \(=f\) to enforce the orthonormality in \(L^2\)

\[\psi_{r+1} = f - \sum_{k=1}^r \frac{(f, \psi_k)_{L^2}}{(\psi_k, \psi_k)_{L^2}}\psi_k\]
Parameters:

fun (Function) – Function to add to the WeakGreedy basis.

Returns:

normalised_fun – Orthonormalised function \(\psi_{r+1}\) with respect to the WeakGreedy basis \(\{\psi_k\}_{k=1}^r\).

Return type:

Function

compute_basis(train_snap: FunctionsList, N: int, verbose=False)[source]

Computes the WeakGreedy (WG) basis functions (orthonormalised using Grahm-Schmidt), as the set of snapshots that minimises the reconstruction error.

Parameters:
  • train_snap (FunctionsList) – List of snapshots onto which the WG algorithm is performed.

  • N (int) – Integer input indicating the maximum number of modes to define

Returns:

  • maxAbsErr – Maximum absolute error measured in \(L^2\)

  • maxRelErr – Maximum relative error measured in \(L^2\)

  • alpha_coeff – Matrix of the reduced coefficients, obtained by the \(L^2\) projection

projection(u: dolfinx.fem.Function, maxBasis: int)[source]

The reduced coefficients \(\{\alpha_k\}_{k=1}^N\) of u using N basis functions \(\{\psi_k\}_{k=1}^N\) are computed using projection in \(L_2\), i.e.

\[\alpha_k(\boldsymbol{\mu}) = (u(\cdot;\,\boldsymbol{\mu}), \,\psi_k)_{L^2}\qquad k = 1, \dots, N\]
Parameters:
  • u (Function) – Function object to project onto the reduced space of dimension N.

  • maxBasis (int) – Dimension of the reduced space, modes to be used.

Returns:

coeff – Reduced coefficients of u, \(\{\alpha_k\}_{k=1}^N\).

Return type:

np.ndarray

test_error(test_snap: FunctionsList, maxBasis: int, verbose=False)[source]

The maximum absolute \(E_N\) and relative \(\varepsilon_N\) error on the test set is computed, by projecting it onto the reduced space in \(L^2\)-sense

\[E_N = \max\limits_{\boldsymbol{\mu}\in\Xi_{\text{test}}} \left\| u(\mathbf{x};\,\boldsymbol{\mu}) - \sum_{n=1}^N \alpha_n(\boldsymbol{\mu})\cdot \psi_n(\mathbf{x})\right\|_{L^2}\]
\[\varepsilon_N = \max\limits_{\boldsymbol{\mu}\in\Xi_{\text{test}}} \frac{\left\| u(\mathbf{x};\,\boldsymbol{\mu}) - \sum_{n=1}^N \alpha_n(\boldsymbol{\mu})\cdot \psi_n(\mathbf{x})\right\|_{L^2}}{\left\| u(\mathbf{x};\,\boldsymbol{\mu})\right\|_{L^2}}\]
Parameters:
  • test_snap (FunctionsList) – List of snapshots onto which the test error of the POD basis is performed.

  • maxBasis (int) – Integer input indicating the maximum number of modes to use.

  • verbose (boolean, optional (Default = False)) – If True, print of the progress is enabled.

Returns:

  • meanAbsErr (np.ndarray) – Maximum absolute errors as a function of the dimension of the reduced space.

  • maxRelErr (np.ndarray) – Maximum absolute errors as a function of the dimension of the reduced space.

  • coeff_matrix (np.ndarray) – Matrix of the modal coefficients, obtained by projection in \(L^2\).

Module contents

pyforce/offline.

Offline phase of the pyforce library.