Welcome to magpie-python’s documentation!¶
magpie¶
Version: 0.0.5¶
- Provides
A function for exploring rectangular plates with generalised boundary conditions
magpieA function for generating a biharmonic sparse matrix
bhmatA function for generating impulse responses of a given plate
modal_time_integrationA function for generating estimating the young’s modulus of a given plate
youngcalc
Credits¶
- Authors:
Michele Ducceschi Matthew Hamilton Alexis Mousseau
- magpie.bhmat(BCs: ndarray, Nxy: ndarray, h: float, Lz: float, E: float, nu: float, format: str = 'dia')¶
Generate a biharmonic matrix for a plate of given parameters
- Parameters:
BCs (np.ndarray or list) – boundary conditions as a numpy array of 4 rows and 2 columns. The first column represents the transversal condition and the second column the rotational condition. e.g.
BCs = np.zeros(4,2)would be a free conditions.Nxy (np.ndarray:) – Number of grad points [Nx Ny]
h (float) – Grid spacing
Lz (float) – plate thickness
E (float) – Young’s mod [Pa]
nu (float) – poisson’s ratio
- Returns:
biharmonic matrix size (Nx Ny)
- Return type:
scipy.sparse:
- Example:
1Lz = 5e-3 2E = 9.0e+9 # -- Young's mod [Pa] 3nu = 0.3 # -- poisson's ratio 4h = np.sqrt(Lx * Ly) * 0.01 # -- grid spacing 5BCs = np.ones((4, 2)) * 1e15 # -- elastic constants around the edges 6 7Nx = 250 8Ny = 250 9 10biHarm = bhmat(BCs, [Nx, Ny], h, Lz, E, nu)
- magpie.magpie(rho: float, E: float, nu: float, ldim: list, h: float, BCs: ndarray, Nm: int = 0, plot_type: str = None, base_mode: float = 0.0)¶
The central magpie function which will compute angular mode frequencies, eigen vectors of the first N modes.
- Parameters:
rho (float) – density [kg/m^3]
E (float) – Young’s mod [Pa]
nu (float) – poisson’s ratio
ldim (list) – plate dimensions in meters [Lx, Ly, Lz], where Lz is thickness
h (float) – grid spacing. A good convention is to use a percentage of the square root of the Area \(\sqrt{Lx*Ly} * p\) where 0.0 < p < 1.0
BCs – boundary conditions as a numpy array of 4 rows and 2 columns. The first column represents the transversal condition and the second column the rotational condition. e.g.
BCs = np.zeros(4,2) # free conditions
BCs = np.array([[0,0], [1e15,1e15], [0,0], [0,0],])
- Parameters:
Nm (int) – Number of modes, if 0 maximum number of modes are calculated
plot_type (str) – style to plot mode shapes ‘chladni’ or ‘3D’
- Returns:
[Om, Q, {'x': Nx, 'y': Ny}, biharm]where Om is an array of modes as angular frequencies. Q is the eigenvectors of those modes. A dictionary of the number of points in the x and y axis is returned a long with the biharmonicbiharm- Return type:
list of
[numpy.ndarray, numpy.ndarray, dict, numpy.ndarray]- Example:
1BCs = np.ones((4, 2)) * 1e15 2 3rho = 7820 4E = 200e9 5nu = 0.3 6h = 0.01 7 8[Om, Q, N, biharm] = magpie(rho,E,nu,[1,0.8,5e-3],0.01,BCs,5)
- magpie.modal_time_integration(rho: float, E: float, nu: float, ldim: list, BCs: ndarray, sig: list, maxFreq: float, pos: dict, T: float = 0.25, fs: float = 44100, AmpF: float = 30, twid: float = 0.0006, file_path: str = None)¶
Generate an impulse response using modal time integration
- Parameters:
rho (float) – density [kg/m^3]
E (float) – Young’s mod [Pa]
nu (float) – poisson’s ratio
ldim (list) – plate dimensions in meters [Lx, Ly, Lz], where Lz is thickness
BCs (np.ndarray) – boundary conditions as a numpy array of 4 rows and 2 columns. The first column represents the transversal condition and the second column the rotational condition. e.g. BCs = np.zeros(4,2) would be a free conditions
sig (list) – A 2 element list representing frerquency dependant loss coefficients where T60 = 3*log(10)./(sig[0]+Om.^2*sig[1])
maxFreq (float) – Maximum frequency to consider when creating the simulation
pos – dictionary of input output coordinates. Expectes the keys
1pos = { 2 'in': [x, y], 3 'l': [x, y], 4 'r': [x, y] 5}
- Returns:
velocity and displacement impulse responses
- Return type:
tuple of class: numpy.ndarray
The x and y are normalised coefficientsa that should be greater than 0 and less than 1
- Parameters:
T – Time in seconds of the simulation
fs – sampling rate of the ouput
AmpF – amplitude of the input force
twid – length in seconds of the input force
file_path – output .wav file path
- Returns:
[velocity, displacement] where velocity is the output velocity signal and displacement is the output displacement signal. Both output signals are returned as numpy arrays
import sounddevice as sd rho = 8765 # -- density [kg/m^3] E = 101e9 # -- Young's mod [Pa] nu = 0.3 # -- poisson's ratio ldim = [0.151, 0.08, 0.81e-3] # elastic constants around the edges (this allows to set the various bcs) BCs = np.zeros((4, 2)) * 1e15 # -- elastic constants around the edges BCs[1, :] = 1e15 sig = [5e-3, 3e-9] # -- damping parameters: T60 = 3*log(10)./(sig0+Om.^2*sig1) maxFreq = 15000.0 # max frequency to consider in hz # -- input / output locations, FRACTIONS of [Lx Ly] (values must be >0 and <1) pos = { 'in': [0.54, 0.78], 'l': [0.57, 0.75], 'r': [0.56, 0.65] } simulation_time = 1.0 audio, _ = modal_time_integration(rho, E, nu, ldim, BCs, sig, maxFreq, pos, T=simulation_time) norm_gain = np.abs(audio).max() audio /= norm_gain sd.play(audio, 44100) sleep(simulation_time)
- magpie.youngcalc(rho: float, ldim: list, h: float, BCs: ndarray, ExpFreq: list, Ntrain: int, should_plot: bool = False)¶
Estimate Young’s modulus (E) of an experimental plate starting from a batch of experimentally measured frequencies, leveraging MAGPIE
- Parameters:
rho (float) – the experimental plate density
ldim (list) – a 3 x 1 array containing the Lx Ly Lz dimensions
h (float) – the grid spacing of the FD scheme
BCs (np.array) – a 4 x 2 array containing the rigidities of the boundary supports of the experimental plate
ExpFreq (np.array) – an array contaning the first Nmodes measured modal frequencies
Ntrain (int) – an integer. Must be <= Nmodes. It is the number of training modes out of the available batch
- Returns:
The estimated young’s modulus for the given plate
- Return type:
float
- Example:
ExpFreq = [73.2 148 376 431 559 910] #-- these are measured from a plate rho = 8765 #-- density [kg/(m ** 3)] Lx = 0.1 Ly = 0.08 Lz = 0.00081 BCs = np.array([[0,0], [1e15,1e15], [0,0], [0,0],]) ldim = [Lx Ly Lz] h = np.sqrt(Lx*Ly)*0.01 #-- grid spacing [m] E = youngcalc(rho, ldim, h, BCs, ExpFreq, 3)