pywfe.Model Class

Introduction

The pywfe.model class is the main object in this package. It brings together most WFE functionality into a single API. The class represents a waveguide and is initialised with the mesh information for a single segment.

Initialisation

Model.__init__(K, M, dof, null=None, nullf=None, axis=0, logging_level=20, solver='transfer_matrix')

Initialise a Model object.

Parameters:
Knp.ndarray

Stiffness matrix \(\mathbf{K}\) of shape \((N, N)\).

Mnp.ndarray

Mass matrix \(\mathbf{M}\) of shape \((N, N)\).

dofdict

A dictionary containing the following keys:

  • ‘coord’ : array-like, shape \((n_{dim}, N)\) Coordinates of the degrees of freedom, where \(n_{dim}\) is the number of spatial dimensions and \(N\) is the total number of degrees of freedom in the initial total mesh.

  • ‘node’ : array-like, shape \((N,)\) Node number that the degree of freedom sits on.

  • ‘fieldvar’ : array-like, shape \((N,)\) Field variable for the degree of freedom (e.g., pressure, displacement in x, displacement in y).

  • ‘index’ : array-like, shape \((N,)\) Index of the degree of freedom, used to keep track of the degrees of freedom when sorted.

nullndarray, optional

Null space constraint matrix (for boundary conditions) of shape \((N, N)\). The default is None.

nullfndarray, optional

Force null space constraint matrix (for boundary conditions) of shape \((N, N)\). The default is None.

axisint, optional

The waveguide axis. Moves dof[‘coord’][axis] to dof[‘coord’][0]. The default is 0.

logging_levelint, optional

Logging level. The default is 20.

solverstr, optional

The form of the eigenvalue to use. The default is “transfer_matrix”. Options are currently ‘transfer_matrix’ or ‘polynomial’.

Returns:
None.

Attributes

Model.K

Sorted stiffness matrix

Model.M

Sorted mass matrix

Model.dof

Sorted dof dictionary

Model.node

dictionary of node information

Model.K_sub

dictionary containing substructured stiffness matrices 'LL', 'LR, 'RL', 'RR', 'LI', 'IL', 'RI', 'IR', 'II'

Model.M_sub

dictionary containing substructured mass matrices.

Model.eigensolution

The eigensolution at a given frequency. Gives values and vectors corresponding to propagation constants and mode shapes

Model.force

The force vector corresponding to forces at each dof

Methods

class pywfe.Model(K, M, dof, null=None, nullf=None, axis=0, logging_level=20, solver='transfer_matrix')

Bases: object

The main high level api in the pywfe package.

Methods

dispersion_relation(frequency_array[, ...])

Calculate frequency-wavenumber relation

displacements(x_r[, f, dofs])

gets the displacements for all degrees of freedom at specified x and f.

dofs_to_indices(dofs)

Generates indices for selected dofs

excited_amplitudes([f])

Find the excited amplitudes subject to a given force and frequency.

forces(x_r[, f, dofs])

Gets the total force on each degree of freedom.

form_dsm(f)

Forms the DSM of the model at a given frequency

frequency_sweep(f_arr[, x_r, quantities, ...])

Solves various quantities over specified frequency and response range.

generate_eigensolution(f)

Generates the sorted eigensolution at a given frequency.

left_dofs()

get the dofs on the left face of the segment

modal_displacements(x_r[, f, dofs])

Calculate the modal displacements at a given distance and frequency.

modal_forces(x_r[, f, dofs])

Generates the modal forces at given distance and frequency

phase_velocity(frequency_array[, direction, ...])

gets the phase velocity curves for a given frequency array

propagated_amplitudes(x_r[, f])

Calculate the propagated and superimposed amplitudes for a given distance and frequency.

save(folder[, source])

Save the model to a folder

see()

Creates interactive matplotlib widget to visualise mesh and inspect degrees of freedom.

select_dofs([fieldvar, where])

Select the model degrees of freedom that correspond to specified field variable.

selection_index(dof)

Get the dof indices for a given selection.

transfer_function(f_arr, x_r[, dofs, derivative])

Gets the displacement over frequency at specified distance and dofs.

wavenumbers([f, direction, imag_threshold])

Calculates the wavenumbers of the system at a given frequency

solver

Description of solver.

K

Sorted stiffness matrix

M

Sorted mass matrix

dof

Sorted dof dictionary

K_sub

dictionary containing substructured stiffness matrices 'LL', 'LR, 'RL', 'RR', 'LI', 'IL', 'RI', 'IR', 'II'

M_sub

dictionary containing substructured mass matrices.

node

dictionary of node information

delta

Waveguide segment length

N

Number of dofs on both left and right faces combined

eigensolution

The eigensolution at a given frequency. Gives values and vectors corresponding to propagation constants and mode shapes

force

The force vector corresponding to forces at each dof

dofs_to_indices(dofs)

Generates indices for selected dofs

Parameters:
dofsstr or list or dict

‘all’ specifies all dofs. A list of integers is interpreted as the dof indices. A dof dictionary, created with model.select_dofs()

Returns:
indsnp.ndarray

array of dof indices.

form_dsm(f)

Forms the DSM of the model at a given frequency

Parameters:
ffloat

frequency at which to form the DSM.

Returns:
DSMndarray

(ndof, ndof) sized array of type complex. The condensed DSM.

generate_eigensolution(f)

Generates the sorted eigensolution at a given frequency. If frequency is None or the presently calculated frequency, then reuse the previously calculated eigensolution.

Parameters:
ffloat

The frequency at which to calculate the eigensolution.

Returns:
eigensolutionEigensolution (namedtuple)
The sorted eigensolution. The named tuple fields are:
  • lambda_[plus]/[minus] : +/- going eigenvalues

  • phi_[plus]/[minus] : +/- going right eigenvectors

  • psi_[plus]/[minus] : +/- going left eigenvectors

wavenumbers(f=None, direction='plus', imag_threshold=None)

Calculates the wavenumbers of the system at a given frequency

Parameters:
ffloat, optional

Frequency at which to calculated wavenumbers. The default is None.

directionstr, optional

Choose positive going or negative going waves. The default is “plus”.

imag_thresholdfloat, optional

Imaginary part of wavenumber above which will be set to np.nan. The default is None.

Returns:
kndarray

The array of wavenumbers at this frequency.

dispersion_relation(frequency_array, direction='plus', imag_threshold=None)

Calculate frequency-wavenumber relation

Parameters:
frequency_arrayndarray

Frequencies to calculate.

directionstr, optional

Choose positive going or negative going waves. The default is “plus”.

imag_thresholdfloat, optional

Imaginary part of wavenumber above which will be set to np.nan. The default is None.

Returns:
wavenumbersndarray

(nfreq, n_waves) sized array of type complex.

phase_velocity(frequency_array, direction='plus', imag_threshold=None)

gets the phase velocity curves for a given frequency array

Parameters:
frequency_arraynp.ndarray

DESCRIPTION.

directionstr, optional

Direction of the waves. The default is ‘plus’.

imag_thresholdfloat, optional

Imaginary threshold above which set to np.nan. The default is None.

Returns:
ndarray

phase velocity.

excited_amplitudes(f=None)

Find the excited amplitudes subject to a given force and frequency. If the solution has already been calculated for the same inputs, reuse the old solution.

Parameters:
ffloat, optional

Frequency. The default is None.

Returns:
e_plusndarray

Positive excited wave amplitudes.

e_minusndarray

Negative excited wave amplitudes.

propagated_amplitudes(x_r, f=None)

Calculate the propagated and superimposed amplitudes for a given distance and frequency.

Parameters:
x_rfloat

Axial response distance.

ffloat, optional

Frequency. The default is None.

Returns:
b_plus, b_minusndarray

Positive and negative amplitudes.

modal_displacements(x_r, f=None, dofs='all')

Calculate the modal displacements at a given distance and frequency. Each column corresponds to a different wavemode, each row is a different degree of freedom.

Parameters:
x_rfloat

Axial response distance.

ffloat, optional

Frequency. The default is None.

Returns:
q_j_plus, q_j_minusndarray

The modal displacements for positive and negative going waves.

displacements(x_r, f=None, dofs='all')

gets the displacements for all degrees of freedom at specified x and f.

Parameters:
x_rfloat

response distance (can be array like).

ffloat, optional

Frequency. The default is None.

Returns:
ndarray

displacements for each degree of freedom.

modal_forces(x_r, f=None, dofs='all')

Generates the modal forces at given distance and frequency

Parameters:
x_rfloat

Response distance.

ffloat, optional

Frequency. The default is None.

Returns:
np.ndarray

modal force array.

forces(x_r, f=None, dofs='all')

Gets the total force on each degree of freedom.

Parameters:
x_rfloat

Response distance.

ffloat, optional

Frequency. The default is None.

Returns:
np.ndarray

forces.

frequency_sweep(f_arr, x_r=0, quantities=['displacements'], mac=False, dofs='all')

Solves various quantities over specified frequency and response range. Includes Modal Assurance Critereon (MAC) sorting.

Parameters:
f_arrnp.ndarray

Array of frequencies.

x_rfloat or np.ndarray, optional

Response distance. The default is 0.

quantitieslist of str

A list of strings specifying the quantities to be calculated. These are:

  • phi_plus: the (positive going) eigenvectors.

  • excited_amplitudes: see pywfe.Model.excited_amplitudes.

  • propagated_amplitudes: see pywfe.Model.propagated_amplitudes.

  • modal_displacements: see pywfe.Model.modal_displacements.

  • wavenumbers: see pywfe.Model.wavenumbers.

  • displacements: see pywfe.Model.displacements.

  • forces: see pywfe.Model.forces.

macbool, optional

Whether to sort modal quantities according to MAC. The default is False.

dofslist, optional

Select specific degrees of freedom. The default is ‘all’.

Returns:
dict

Dictionary of output for specified quantities.

transfer_function(f_arr, x_r, dofs='all', derivative=0)

Gets the displacement over frequency at specified distance and dofs.

Parameters:
f_arrnp.ndarray

Frequency array.

x_rfloat or np.ndarray

Response distance.

dofslist, optional

List of dofs to return. The default is “all”.

Returns:
ndarray

Displacements over frequency and distance.

select_dofs(fieldvar=None, where=None)

Select the model degrees of freedom that correspond to specified field variable.

Parameters:
fieldvarstr or list, optional

The fieldvariable or list thereof to select for. The default is None.

wherenp.ndarray of type bool, optional

Optional argument to select specific nodes, same length as coords. For example, selecting specific region by [coordinate array] > value. The default is None.

Returns:
dofsdict

Reduced dof dictionary.

left_dofs()

get the dofs on the left face of the segment

Returns:
dofsdict

dof dictionary.

selection_index(dof)

Get the dof indices for a given selection.

Parameters:
dofdict

dof dictionary.

Returns:
np.ndarray

1D array of indices for selected dofs.

see()

Creates interactive matplotlib widget to visualise mesh and inspect degrees of freedom.

Returns:
None.
save(folder, source='local')

Save the model to a folder

Parameters:
folderstr

folder name.

sourcestr, optional

Save to 'local' or 'database'. The default is ‘local’.

Returns:
None.