Modal Dynamics#
prophys.physics solves the eigenproblem of structural dynamics,
K q = lambda M q, exactly and with exact gradients. A stiffness or a mass
can be a constant, a parameter, a random variable or any expression, so a
natural frequency can be calibrated, made uncertain or optimized like every
other quantity of a model. A whole Monte Carlo sample axis of matrices is one
native call.
Four modes of a ring of twelve lumped nodes on an elastic foundation, each
computed by eigensystem() and drawn as the ring
deformed by its mode shape. The foundation spring lifts the breathing mode to
23 Hz, the oval mode (two nodal diameters) sits at 161 Hz. The dashed circle
is the undeformed ring, the small blocks are the twelve nodes.
from prophys import physics
values, modes = physics.eigensystem(K, M) # eigenvalues ascending, modes mass normalized
omega = physics.natural_frequencies(K, M) # sqrt(lambda_i) [rad/s]
x = physics.modal_superposition(K, M, force, omega_grid, damping=0.03) # complex response
indices, macs = physics.track_modes(reference_modes, swept_modes) # match modes by MAC
Four functions cover the chain of a modal analysis:
eigensystem() and
natural_frequencies(): exact eigenpairs with
exact mode based gradients, batched over a sample axis.
modal_superposition(): the complex response to
a harmonic force, with a damping ratio per mode that can be learned.
track_modes(): which mode of a perturbed design
is which mode of the reference, by the modal assurance criterion.
The whine of an electric motor: a resonance under a clamp tolerance, calibrated, assessed and redesigned by gradient.
The ring and its modes#
Every figure on this page is computed from one small model, the structure of the stator in Example: Stator Whine of an Inverter Driven Motor: twelve nodes on a ring, coupled by the bending of the ring (a periodic second difference) and each held by a foundation spring.
import numpy as np
from prophys import physics
N, K_BENDING, K_FOUNDATION, MASS = 12, 1.0e6, 2.0e4, 1.0
idx = np.arange(N)
diff = np.zeros((N, N))
diff[idx, (idx + 1) % N] = 1.0
diff[idx, idx] = -2.0
diff[idx, (idx - 1) % N] = 1.0
K0 = K_BENDING * (diff.T @ diff) + K_FOUNDATION * np.eye(N)
M0 = MASS * np.eye(N)
values, modes = physics.eigensystem(K0, M0)
omega = physics.natural_frequencies(K0, M0)
The eigenvector columns are normalized in the mass inner product,
q_i^T M q_j = delta_ij, the convention of the mode superposition and
mode tracking literature.
Gradients through the eigensystem#
The gradient of a natural frequency with respect to anything inside the stiffness or the mass is exact, so an eigensystem can sit inside a model that is calibrated or optimized:
import jax
import jax.numpy as jnp
def oval_frequency(scale):
"""The oval mode frequency [Hz] of the ring for a stiffness scale."""
omega = physics.natural_frequencies(scale * K0, M0)
return jnp.asarray(omega.evaluate())[3] / (2 * jnp.pi)
jax.grad(oval_frequency)(1.0) # 80.37 Hz per unit scale, half the frequency, as theory says
Batched eigensystems#
One leading batch dimension broadcasts. A Monte Carlo sample axis on the stiffness or the mass becomes one native call that returns the eigenpairs of all samples together, which is how a manufacturing tolerance turns into a distribution of resonances:
draws = np.exp(0.1 * np.random.default_rng(0).normal(size=256)) # a lognormal stiffness tolerance
values, modes = physics.eigensystem(draws[:, None, None] * K0, M0) # [256, 12] and [256, 12, 12]
The frequency response#
modal_superposition() evaluates the response of a
classically damped structure to a harmonic force as the exact sum over its
modes, with a damping ratio zeta_i per mode:
x(omega) = sum_i phi_i (phi_i^T f) / (m_i (omega_i^2 - omega^2 + 2j zeta_i omega_i omega))
The response of node 0 to a unit radial force on the same node, for three damping ratios. Every peak sits at a natural frequency (the thin vertical lines), and its height is set by the damping.
Gradients flow to the stiffness, the mass, the force, the frequency and the damping, so a damping ratio can be a parameter fitted to measured responses:
import prophys as prp
zeta = prp.Param("zeta", init=0.05, transform="softplus") # a learnable damping ratio
omega = 2 * np.pi * np.linspace(0.0, 700.0, 701)
force = np.zeros(N)
force[0] = 1.0 # a unit radial force on node 0
response = physics.modal_superposition(K0, M0, force, omega, zeta) # complex, [701, 12]
With an array frequency the response has shape [..., F, n], with a
scalar it has shape [..., n]. The modal mass m_i = phi_i^T M phi_i is
computed from M itself, so any consistent set of modes gives the same
response, and the sum does not depend on the sign convention of the
eigenvectors.
The response over frequency and a stiffness scale between 0.7 and 1.3, evaluated in one call with the scale as the batch axis. The resonance ridges (orange) move with the square root of the scale, the exact sensitivity of a natural frequency to a uniform stiffness change. Where a ridge crosses a frequency of interest is a differentiable question, so a crossing probability, its tail and a redesign can all be computed by gradient.
Tracking modes across a sweep#
A tolerance, damage or a design change can reorder the modes, so mode i
of one design need not be mode i of the next.
track_modes() matches every reference mode to its
counterpart by the modal assurance criterion,
MAC = (r^T c)^2 / ((r^T r)(c^T c)), which is one when two shapes agree up
to sign and scale and zero when they are orthogonal. The matching is greedy
from the best pair and deterministic.
reference = np.asarray(modes.evaluate()) # [n, n], the nominal design
swept = physics.eigensystem(draws[:, None, None] * K0, M0)[1] # [B, n, n], one native call
indices, macs = physics.track_modes(reference, swept) # [B, n] indices and MAC values
Tracking is a post processing step: it takes evaluated mode matrices and returns indices and MAC values, not a differentiable expression. In Example: Stator Whine of an Inverter Driven Motor the oval pair stays tracked with a MAC of one across the whole production spread.
What is exact, precisely#
Eigenvalue and eigenvector gradients
The eigenpairs come from the native eigensolver, and their gradients are
the exact mode based derivatives of the eigensystem (Fox and Kapoor 1968,
Dailey 1989). The eigenvalue gradient is
d lambda_i = q_i^T dK q_i - lambda_i q_i^T dM q_i, and the eigenvector
gradient follows the projection formula. The kernel evaluates both, never
by finite differences.
Repeated and clustered eigenvalues
Eigenvalues whose relative gap is below cluster_tol have no unique
eigenvectors. The kernel works inside such a cluster in the basis that
diagonalizes the perturbation, which keeps the returned modes and their
gradients exact to first order. A quantity that does not change when the
modes rotate inside the cluster, such as a natural frequency, a superposed
response or an energy, therefore has an exact gradient through it. The
individual eigenvectors of an exactly repeated pair are only defined up to
that rotation. This is a property of the mathematics, not of the solver,
and track_modes() reports it as a MAC below one.
When the solver refuses
PHY102 is raised for a mass matrix that is not positive definite, and
PHY103 when the eigensolver exhausts its sweep budget on extremely
scaled or ill conditioned matrices. Both are listed with every other code
on the Diagnostics page.
Reference#
- prophys.physics.eigensystem(stiffness, mass, *, cluster_tol=1e-08)[source]#
Solve the generalized symmetric eigenproblem
K q = lambda M q, with exact gradients.stiffnessis[..., n, n]symmetric,mass[..., n, n]symmetric positive definite. The native solver factors the mass by Cholesky and diagonalizes the transformed problem by cyclic Jacobi rotations until the off diagonal part falls below1e-12of the matrix norm, within a fixed sweep budget whose exhaustion is an error, so the eigenpairs are accurate to the rounding level of the matrices. The eigenvalues are returned ascending and each eigenvector column is normalized in the mass inner product (q_i^T M q_j = delta_ij), the convention of the mode superposition and mode tracking literature, with its largest entry positive. The derivatives are exact at every order the kernel declares, in forward and reverse mode, evaluated by the native kernel and never by finite differences: the first eigenvalue derivative isd lambda_i = q_i^T dK q_i - lambda_i q_i^T dM q_iand the first eigenvector derivative follows the projection formula of Fox and Kapoor 1968, Dailey 1989.Repeated or clustered eigenvalues (a consecutive gap below
cluster_toltimes the larger of their magnitude and the largest eigenvalue magnitude, which also groups the rigid body modes of a free structure) take the mass orthonormal gauge inside the cluster. The derivatives of every functional invariant under rotations inside a cluster, such as the sum of its eigenvalues or the projector on its modes, are exact at every order, and they are the quantities to differentiate. The derivative of one eigenvalue of a cluster \(\mathcal C\) with modes \(Q_C\) is the diagonal of \(Q_C^\top\, dK\, Q_C - \lambda\, Q_C^\top\, dM\, Q_C\) in the basis of the solver, in forward and reverse mode. It is exact for every perturbation that keeps the cluster repeated, such as one that keeps the symmetry of a structure. Along a perturbation that splits the cluster its eigenvalues are not differentiable, and the value returned is the derivative of the Rayleigh quotients of the solver basis, which depends on that basis. The reverse mode derivative of an eigenvector functional that depends on the basis of a cluster is refused. Stiffness and mass may be parameters, random variables or expressions, and their leading dimensions broadcast (a Monte Carlo sample axis of either matrix becomes one native call). The two outputs share one solve per evaluation.- Parameters:
- Returns:
The pair
(eigenvalues, eigenvectors),[..., n]ascending and[..., n, n]with modeiin columni.- Raises:
prophys.diagnostics.ProphysError – With code
PHY102when the mass matrix is not positive definite,PHY103when the sweep budget of the native eigensolver is exhausted,PHY104when a matrix holds a non finite entry, andPHY106for the reverse mode derivative of an eigenvector functional that depends on the basis of a cluster.- Return type:
- prophys.physics.natural_frequencies(stiffness, mass, *, cluster_tol=1e-08)[source]#
Angular natural frequencies
omega_i = sqrt(lambda_i)ofK q = lambda M q.A convenience over
eigensystem()for stiffness and mass matrices. The stiffness must be positive definite on the constrained system (no rigid body modes): a non positive eigenvalue marks a matrix that is not a stiffness of a constrained structure and yields a non finite frequency.- Parameters:
- Returns:
The angular frequencies
[..., n], ascending.- Return type:
- prophys.physics.modal_superposition(stiffness, mass, force, frequency, damping=0.05, *, cluster_tol=1e-08)[source]#
Frequency response of a structure by exact modal superposition.
With the eigenpairs of
eigensystem()the response to forcefat frequencyomegaisx(omega) = sum_i phi_i (phi_i^T f) / (m_i (omega_i^2 - omega^2 + 2j zeta_i omega_i omega))the classic superposition of the modal responses of classically damped structures. The modal amplitude of mode
iis(phi_i^T f) / (m_i (omega_i^2 - omega^2 + 2j zeta_i omega_i omega))with modal massm_i = phi_i^T M phi_i(one for the mass normalized modes returned here, computed fromMall the same so any consistent mode set gives the same response) and per mode damping ratiozeta_i. The sum is exact and complex valued, and gradients flow to the stiffness, the mass, the force, the frequency and the damping, so a damping ratio can be a learnable parameter calibrated against measured responses. Resonance peaks sit at theomega_i, with amplitudes controlled byzeta_i. The response carries the mode shapes, so it is invariant under the sign convention of the eigenvectors.- Parameters:
stiffness (Any) – Stiffness matrix,
[..., n, n].mass (Any) – Mass matrix,
[..., n, n].force (Any) – Force vector,
[..., n].frequency (Any) – Excitation frequency, a scalar or an array
[..., F]broadcast against the leading dimensions of the matrices.damping (Any) – Per mode damping ratio, a scalar,
[..., n]or a parameter or expression evaluating to either.cluster_tol (float) – Relative eigenvalue gap below which consecutive eigenvalues form one cluster in the gradients.
- Returns:
The complex response,
[..., F, n]for an arrayfrequencyand[..., n]for a scalar.- Return type:
- prophys.physics.track_modes(reference, modes)[source]#
Match modes to a reference set by the modal assurance criterion.
Manufacturing tolerance reorders modes across a parameter sweep, so mode
iof one design is not modeiof the next. The MAC of a reference moderand a candidate modecis(r^T c)^2 / ((r^T r)(c^T c)), one when the shapes coincide up to a sign and scale and zero when they are orthogonal. Every reference column is matched to its highest MAC candidate, greedy from the globally best pair, which is deterministic. This is a post processing step of a sweep: it takes evaluated mode matrices (expressions are evaluated first) and returns indices, not a differentiable expression.- Parameters:
- Returns:
for each reference mode the index of its matched candidate column and the MAC of the match. A batched
modesinput gives[B, r]indices and[B, r]MAC values.- Return type:
The pair
(indices, mac)- Raises:
ValueError – If the mode matrices do not share their first dimension.