romtools.hyper_reduction.deim#
Implementation of DEIM technique for hyper-reduction
Functions
Given a function basis \(\mathbf{U}\) and sample indices defining \(\mathbf{P}\), we compute |
|
|
Implementation of the discrete empirical method as described in Algorithm 1 of S. |
|
Given a test basis \(\mathbf{\Phi}\), a function basis \(\mathbf{U}\), and sample indices defining \(\mathbf{P}\), we compute |
|
Version of DEIM for multi-state systems. |
|
For multistate systems. Constructs an independent DEIM basis for each state variable using uniform sample indices :param test_basis: \((n_{var}, m, k)\) array, where \(n_{var}\) is the number of state variables, \(m\) is the number of DOFs and \(k\) is the number of basis functions. Test basis in projection scheme :param function_basis: \((n_{var}, m, n)\) array, where \(n_{var}\) is the number of state variables, \(m\) is the number of DOFs and \(n\) is the number of basis functions. Basis for function to be approximated. :param sample_indices: \((n_s, )\) array, where \(n_s\) is the number of sample points. Sampling points. |
|
Select interpolation indices using QDEIM for a matrix-form basis. |
Classes
|
Serial discrete empirical interpolation operator. |
|
Tensor-native DEIM operator using pivoted-QR point selection. |
- class romtools.hyper_reduction.deim.DEIM(function_basis, sample_indices=None, rcond=None, sample_all_states=True, basis_mode='per_state')[source]#
Bases:
objectSerial discrete empirical interpolation operator.
The public class API follows the romtools tensor convention. Function snapshots have shape
(n_vars, n_dofs, n_snapshots)and tensor-form function bases have shape(n_vars, n_dofs, n_basis).basis_mode="per_state"is the default. A separate POD/function basis and DEIM sampling problem is constructed for each state variable. The state-specific sample sets are unioned into a common spatial sample mesh, and every state is sampled on that mesh. This avoids mixing quantities with different physical units in a single POD/SVD and allows the states to have different basis dimensions when constructed from snapshots.basis_mode="global"retains the coupled formulation in which the first two tensor axes are collapsed in explicit C order and a single global basis is used. Global mode can exploit cross-state correlations but requires the state variables to be consistently nondimensionalized or weighted.Notes
Function snapshots are snapshots of the quantity being approximated, such as a nonlinear term or residual. They are not necessarily the state snapshots used to construct a ROM trial basis.
- property basis_mode#
Return
"per_state"or"global".
- property basis_sizes#
Return the number of function-basis vectors associated with each state.
- classmethod from_basis(function_basis, sample_indices=None, rcond=None, sample_all_states=True, basis_mode='per_state')[source]#
Construct a serial DEIM operator from a tensor-form function basis.
- Parameters:
function_basis –
(n_vars, n_dofs, n_basis)function basis. Inper_statemode, each state slice is treated as an independent basis. The tensor form therefore requires a common basis dimension across states when bases are supplied directly.sample_indices – Optional rank-1 integer array. In
per_statemode and in shared-sampleglobalmode these are spatial indices. Withbasis_mode="global"andsample_all_states=Falsethese are flattened state-DOF indices in C order.rcond – Relative cutoff passed to
numpy.linalg.pinv().sample_all_states – If
True(default), sample every state at each selected spatial point.Falseis supported only in global mode.basis_mode –
"per_state"(default) constructs independent DEIM operators for each state and unions their sample points."global"constructs one coupled operator.
- Returns:
Constructed interpolation operator.
- Return type:
- classmethod from_snapshots(function_snapshots, truncater=None, sample_indices=None, rcond=None, sample_all_states=True, basis_mode='per_state')[source]#
Construct a serial DEIM operator from tensor-form function snapshots.
- Parameters:
function_snapshots –
(n_vars, n_dofs, n_snapshots)snapshots of the function to be approximated.truncater – Optional implementation of the
LeftSingularVectorTruncaterprotocol. Inper_statemode the truncater is applied independently to each state’s SVD, so energy-based truncation may produce different basis dimensions for different states. If omitted, all available modes are retained.sample_indices – Optional rank-1 integer array. In
per_statemode and in shared-sampleglobalmode these are spatial indices. Withbasis_mode="global"andsample_all_states=Falsethese are flattened state-DOF indices in C order.rcond – Relative cutoff passed to
numpy.linalg.pinv().sample_all_states – If
True(default), sample every state at each selected spatial point.Falseis supported only in global mode.basis_mode –
"per_state"(default) performs a separate POD and DEIM selection for each state before taking the union of sample points."global"performs one POD on the C-order flattened multistate snapshots.
- Returns:
Constructed interpolation operator.
- Return type:
- property function_basis#
Return a copy of the function basis or per-state function bases.
In
globalmode this is a rank-3 romtools tensor. Inper_statemode this is a tuple of rank-2 arrays because the state-specific basis dimensions may differ.
- project_test_basis(test_basis)[source]#
Construct the sampled test basis used for hyper-reduction.
test_basismust have romtools tensor shape(n_vars, n_dofs, n_test_basis). With shared-state sampling the result has shape(n_vars, n_sample_points, n_test_basis). With independent flattened sampling it has shape(n_samples, n_test_basis).
- reconstruct(sampled_values)[source]#
Reconstruct full-order tensor values from sampled values.
With shared-state sampling,
sampled_valuesmust have shape(n_vars, n_sample_points)or(n_vars, n_sample_points, n_snapshots). The return value has shape(n_vars, n_dofs)or(n_vars, n_dofs, n_snapshots).In global mode with
sample_all_states=False, sampled values have shape(n_samples,)or(n_samples, n_snapshots)because the samples are arbitrary flattened state-DOF entries. The reconstructed result is still returned in romtools tensor form.
- reconstruction_matrix()[source]#
Return the flattened DEIM reconstruction matrix.
The row and column ordering follows the romtools C-order state-major convention. In
per_statemode this is a block-diagonal matrix whose blocks areU_i @ pinv(U_i[sample_indices, :]). The common union sample mesh therefore acts as an oversampled DEIM system for each state.
- property sample_all_states#
Whether all states are sampled at every selected spatial point.
- property sample_indices#
Return the sample indices.
These are spatial indices in
per_statemode and wheneversample_all_states=True. They are flattened C-order state-DOF indices only for global mode withsample_all_states=False.
- property state_sample_indices#
Return the pre-union DEIM/QDEIM sample points for each state.
This is a tuple in automatically sampled
per_statemode andNonefor a global basis or when a sample mesh was supplied by the user.
- class romtools.hyper_reduction.deim.QDEIM(function_basis, sample_indices=None, rcond=None, sample_all_states=True, basis_mode='per_state')[source]#
Bases:
DEIMTensor-native DEIM operator using pivoted-QR point selection.
Basis construction, tensor handling, and shared-state sampling are inherited from
DEIM; only the DEIM selection performed on each applicable basis differs.
- romtools.hyper_reduction.deim.deim_get_approximation_matrix(function_basis, sample_indices)[source]#
Given a function basis \(\mathbf{U}\) and sample indices defining \(\mathbf{P}\), we compute
\[\mathbf{U} \mathrm{pinv}( \mathbf{P}^T \mathbf{U})\]which comprises the matrix needed for the DEIM approximation to \(\mathbf{f}\)
- Parameters:
function_basis – \((m, n)\) array, where \(m\) is the number of DOFs and \(n\) the number of basis functions. Basis for function to be approximated.
sample_indices – \((n_s, )\) array, where \(n_s\) is the number of sample points. Sampling points.
- Returns:
\((n, n_s)\) array. DEIM approximation basis
- Return type:
deim_matrix
- romtools.hyper_reduction.deim.deim_get_indices(U, comm=None)[source]#
Implementation of the discrete empirical method as described in Algorithm 1 of S. Chaturantabut and D. C. Sorensen, “Discrete Empirical Interpolation for nonlinear model reduction,” doi: 10.1109/CDC.2009.5400045.
- Parameters:
U – \(\mathbf{U} \in \mathbb{R}^{m \times n}\), where \(m\) is the number of DOFs and \(n\) is the number of samples. Function basis in matrix format.
comm – Optional communicator object. If none, algorithm assumes shared-memory data.
- Returns:
\(\mathrm{indices} \in \mathbb{I}^{n}\): sample mesh indices.
Otherwise:
Sample mesh local indices and the corresponding owing ranks.
- Return type:
If
comm == None
- romtools.hyper_reduction.deim.deim_get_test_basis(test_basis, function_basis, sample_indices, comm=None)[source]#
Given a test basis \(\mathbf{\Phi}\), a function basis \(\mathbf{U}\), and sample indices defining \(\mathbf{P}\), we compute
\[[ \mathbf{\Phi}^T \mathbf{U} \mathrm{pinv}( \mathbf{P}^T \mathbf{U}) ]^T\]which comprises the “test basis” for the DEIM approximation for \(\mathbf{\Phi}^T \mathbf{f}\)
- Parameters:
test_basis – \((m, k)\) array, where \(m\) is the number of DOFs and \(k\) is the number of basis functions. Test basis in projection scheme
function_basis – \((m, n)\) array, where \(m\) is the number of DOFs and \(n\) is the number of basis functions. Basis for function to be approximated.
sample_indices – \((n_s, )\) array, where \(n_s\) is the number of sample points. Sampling points.
comm – Optional communicator object. If none, algorithm assumes shared-memory data.
- Returns:
- \((n_s, k)\) array, where
\(n_s\) is the number of sample points and \(k\) the number of basis functions. DEIM test basis matrix.
- Return type:
deim_test_basis
- romtools.hyper_reduction.deim.multi_state_deim_get_indices(U, comm=None)[source]#
Version of DEIM for multi-state systems.
We perform DEIM on each state variable, and then return the union of all indices. Repeated indices are removed.
- Parameters:
U – \(\mathbf{U} \in \mathbb{R}^{l \times m \times n}\), where \(l\) is the number of variables, \(m\) is the number of DOFs and \(n\) the number of samples. Multi-dimensional function basis in tensor format.
- Returns:
\(\mathrm{indices} \in \mathbb{I}^{n}\): sample mesh indices.
Otherwise:
Sample mesh local indices and the corresponding owing ranks.
- Return type:
If
comm == None
- romtools.hyper_reduction.deim.multi_state_deim_get_test_basis(test_basis, function_basis, sample_indices)[source]#
For multistate systems. Constructs an independent DEIM basis for each state variable using uniform sample indices :param test_basis: \((n_{var}, m, k)\) array, where
\(n_{var}\) is the number of state variables, \(m\) is the number of DOFs and \(k\) is the number of basis functions. Test basis in projection scheme
- Parameters:
function_basis – \((n_{var}, m, n)\) array, where \(n_{var}\) is the number of state variables, \(m\) is the number of DOFs and \(n\) is the number of basis functions. Basis for function to be approximated.
sample_indices – \((n_s, )\) array, where \(n_s\) is the number of sample points. Sampling points.
- Returns:
- \((n_{var}, n_s, k)\) array, where
\(n_{var}\) is the number of state variables, \(n_s\) is the number of sample points, and \(k\) the number of basis functions. DEIM test basis matrix.
- Return type:
deim_test_basis
- romtools.hyper_reduction.deim.qdeim_get_indices(function_basis)[source]#
Select interpolation indices using QDEIM for a matrix-form basis.
QDEIM applies a column-pivoted QR factorization to the transpose of the function basis. The first
n_basispivot indices define the interpolation points.- Parameters:
function_basis –
(n_dofs, n_basis)function basis.- Returns:
Rank-1 integer array of interpolation indices.
- Return type:
numpy.ndarray