BPOD

class modred.bpod.BPODHandles(inner_product=None, put_array=<function save_array_text>, get_array=<function load_array_text>, max_vecs_per_node=None, verbosity=1)[source]

Balanced Proper Orthogonal Decomposition implemented for large datasets.

Kwargs:

inner_product: Function that computes inner product of two vector objects.

put_array: Function to put an array out of modred, e.g., write it to file.

get_array: Function to get an array into modred, e.g., load it from file.

max_vecs_per_node: Maximum number of vectors that can be stored in memory, per node.

verbosity: 1 prints progress and warnings, 0 prints almost nothing.

Computes direct and adjoint BPOD modes from direct and adjoint vector objects (or handles). Uses vectorspace.VectorSpaceHandles for low level functions.

Usage:

myBPOD = BPODHandles(inner_product=my_inner_product)
myBPOD.compute_decomp(direct_vec_handles, adjoint_vec_handles)
myBPOD.compute_direct_modes(range(50), direct_modes)
myBPOD.compute_adjoint_modes(range(50), adjoint_modes)

See also compute_BPOD_arrays() and vectors.

compute_SVD(atol=1e-13, rtol=None)[source]

Computes singular value decomposition of the Hankel array.

Kwargs:

atol: Level below which Hankel singular values are truncated.

rtol: Maximum relative difference between largest and smallest Hankel singular values. Smaller ones are truncated.

Useful if you already have the Hankel array and want to avoid recomputing it.

Usage:

my_BPOD.Hankel_array = pre_existing_Hankel_array
my_BPOD.compute_SVD()
my_BPOD.compute_direct_modes(
    range(10), mode_handles, direct_vec_handles=direct_vec_handles)
compute_adjoint_modes(mode_indices, mode_handles, adjoint_vec_handles=None)[source]

Computes adjoint BPOD modes and calls put on them using mode handles.

Args:

mode_indices: List of indices describing which adjoint modes to compute, e.g. range(10) or [3, 0, 5].

mode_handles: List of handles for adjoint modes to compute.

Kwargs:
adjoint_vec_handles: List of handles for adjoint vector objects. Optional if given when calling compute_decomp().
compute_adjoint_proj_coeffs()[source]

Computes biorthogonal projection of adjoint vector objects onto adjoint BPOD modes, using direct BPOD modes.

Returns:
adjoint_proj_coeffs: Array of projection coefficients for adjoint vector objects, expressed as a linear combination of adjoint BPOD modes. Columns correspond to adjoint vector objects, rows correspond to adjoint BPOD modes.
compute_decomp(direct_vec_handles, adjoint_vec_handles, num_inputs=1, num_outputs=1, atol=1e-13, rtol=None)[source]

Computes Hankel array H=Y^*X and its singular value decomposition UEV^*=H.

Args:

direct_vec_handles: List of handles for direct vector objects (X). They should be stacked so that if there are p inputs, the first p handles should all correspond to the same timestep. For instance, these are often all initial conditions of p different impulse responses.

adjoint_vec_handles: List of handles for adjoint vector objects (Y). They should be stacked so that if there are a outputs, the first q handles should all correspond to the same timestep. For instance, these are often all initial conditions of p different adjointimpulse responses.

Kwargs:

num_inputs: Number of inputs to the system.

num_outputs: Number of outputs of the system.

atol: Level below which Hankel singular values are truncated.

rtol: Maximum relative difference between largest and smallest Hankel singular values. Smaller ones are truncated.

Returns:

sing_vals: 1D array of Hankel singular values (E).

L_sing_vecs: Array of left singular vectors of Hankel array (U).

R_sing_vecs: Array of right singular vectors of Hankel array (V).

compute_direct_modes(mode_indices, mode_handles, direct_vec_handles=None)[source]

Computes direct BPOD modes and calls put on them using mode handles.

Args:

mode_indices: List of indices describing which direct modes to compute, e.g. range(10) or [3, 0, 5].

mode_handles: List of handles for direct modes to compute.

Kwargs:
direct_vec_handles: List of handles for direct vector objects. Optional if given when calling compute_decomp().
compute_direct_proj_coeffs()[source]

Computes biorthogonal projection of direct vector objects onto direct BPOD modes, using adjoint BPOD modes.

Returns:
direct_proj_coeffs: Array of projection coefficients for direct vector objects, expressed as a linear combination of direct BPOD modes. Columns correspond to direct vector objects, rows correspond to direct BPOD modes.
get_Hankel_array(src)[source]

Gets the Hankel array from source (memory or file).

Args:
src: Source from which to retrieve Hankel singular values.
get_adjoint_proj_coeffs(src)[source]

Gets the adjoint projection coefficients from source (memory or file).

Args:
src: Source from which to retrieve adjoint projection coefficients.
get_decomp(sing_vals_src, L_sing_vecs_src, R_sing_vecs_src)[source]

Gets the decomposition arrays from sources (memory or file).

Args:

sing_vals_src: Source from which to retrieve Hankel singular values.

L_sing_vecs_src: Source from which to retrieve left singular vectors of Hankel array.

R_sing_vecs_src: Source from which to retrieve right singular vectors of Hankel array.

get_direct_proj_coeffs(src)[source]

Gets the direct projection coefficients from source (memory or file).

Args:
src: Source from which to retrieve direct projection coefficients.
put_Hankel_array(dest)[source]

Puts Hankel array to dest.

put_L_sing_vecs(dest)[source]

Puts left singular vectors of Hankel array to dest.

put_R_sing_vecs(dest)[source]

Puts right singular vectors of Hankel array to dest.

put_adjoint_proj_coeffs(dest)[source]

Puts adjoint projection coefficients to dest

put_decomp(sing_vals_dest, L_sing_vecs_dest, R_sing_vecs_dest)[source]

Puts the decomposition arrays in destinations (memory or file).

Args:

sing_vals_dest: Destination in which to put Hankel singular values.

L_sing_vecs_dest: Destination in which to put left singular vectors of Hankel array.

R_sing_vecs_dest: Destination in which to put right singular vectors of Hankel array.

put_direct_proj_coeffs(dest)[source]

Puts direct projection coefficients to dest

put_sing_vals(dest)[source]

Puts Hankel singular values to dest.

sanity_check(test_vec_handle)[source]

Checks that user-supplied vector handle and vector satisfy requirements.

Args:
test_vec_handle: A vector handle to test.

See vectorspace.VectorSpaceHandles.sanity_check().

modred.bpod.compute_BPOD_arrays(direct_vecs, adjoint_vecs, num_inputs=1, num_outputs=1, direct_mode_indices=None, adjoint_mode_indices=None, inner_product_weights=None, atol=1e-13, rtol=None)[source]

Computes BPOD modes using data stored in arrays, using method of snapshots.

Args:

direct_vecs: Array whose columns are direct data vectors (X). They should be stacked so that if there are p inputs, the first p columns should all correspond to the same timestep. For instance, these are often all initial conditions of p different impulse responses.

adjoint_vecs: Array whose columns are adjoint data vectors (Y). They should be stacked so that if there are q outputs, the first q columns should all correspond to the same timestep. For instance, these are often all initial conditions of q different adjoint impulse responses.

Kwargs:

num_inputs: Number of inputs to the system.

num_outputs: Number of outputs of the system.

direct_mode_indices: List of indices describing which direct modes to compute. Examples are range(10) or [3, 0, 6, 8]. If no mode indices are specified, then all modes will be computed.

adjoint_mode_indices: List of indices describing which adjoint modes to compute. Examples are range(10) or [3, 0, 6, 8]. If no mode indices are specified, then all modes will be computed.

inner_product_weights: 1D or 2D array of inner product weights. Corresponds to W in inner product v_1^* W v_2.

atol: Level below which Hankel singular values are truncated.

rtol: Maximum relative difference between largest and smallest Hankel singular values. Smaller ones are truncated.

Returns:

res: Results of BPOD computation, stored in a namedtuple with the following attributes:

  • sing_vals: 1D array of Hankel singular values (E).
  • direct_modes: Array whose columns are direct modes.
  • adjoint_modes: Array whose columns are adjoint modes.
  • direct_proj_coeffs: Array of projection coefficients for direct vector objects, expressed as a linear combination of direct BPOD modes. Columns correspond to direct vector objects, rows correspond to direct BPOD modes.
  • adjoint_proj_coeffs: Array of projection coefficients for adjoint
    vector objects, expressed as a linear combination of adjoint BPOD modes. Columns correspond to adjoint vector objects, rows correspond to adjoint BPOD modes.
  • L_sing_vecs: Array whose columns are left singular vectors of Hankel array (U).
  • R_sing_vecs: Array whose columns are right singular vectors of Hankel array (V).
  • Hankel_array: Hankel array (Y^* W X).

Attributes can be accessed using calls like res.direct_modes. To see all available attributes, use print(res).

See also BPODHandles.