/ proof-of-concept / cymsim_old
Sign in
proof-of-concept / cymsim_old
cymsim_old / src / cymsim / __init__.py
73 lines · 2.2 KBBlameHistoryRaw
1"""cymsim: simulation of a drumstick strike on a plate or cymbal.
3A plate is described by a ``Design`` (material, bounding box, outline,
4thickness field, stress-free profile) and sampled on a grid into a ``Plate``.
5Two models share that discretization. The *linear model* computes the modes
6of the plate once (``compute_modes``) and synthesizes any strike from them in
7about a second (``synthesize``). The *full model* steps the geometrically
8nonlinear plate equations in time with PyTorch, on a GPU when one is available
9(``simulate``); it is slower by orders of magnitude but captures the pitch
10glide and the wash of a hard hit. Both return a ``Sound``.
12 import cymsim
13 plate = cymsim.presets.crash_16().evaluate(spacing=0.008)
14 modes = cymsim.compute_modes(plate, fmax=16000)
15 sound = cymsim.synthesize(modes, cymsim.Strike(velocity=3.0), cymsim.Listener(distance=0.5))
16 sound.to_wav("crash.wav")
17"""
19from . import constants, loss, presets
20from .design import Design, DesignError
21from .grid import Grid, make_grid
22from .linear import Modes, compute_modes, synthesize
23from .material import ALUMINUM, BRONZE, MILD_STEEL, STAINLESS_STEEL, Material, Thermal
24from .params import Listener, Strike
25from .plate import Plate
26from .sound import Sound
27from .spectrogram import Spectrogram
29__version__ = "0.1.0"
31__all__ = [
32 "Design",
33 "DesignError",
34 "Grid",
35 "make_grid",
36 "Material",
37 "Thermal",
38 "STAINLESS_STEEL",
39 "MILD_STEEL",
40 "BRONZE",
41 "ALUMINUM",
42 "Plate",
43 "Strike",
44 "Listener",
45 "Modes",
46 "compute_modes",
47 "synthesize",
48 "simulate",
49 "Simulation",
50 "Sound",
51 "Spectrogram",
52 "presets",
53 "constants",
54 "loss",
55 "plot",
59def simulate(*args, **kwargs):
60 """The full model; see ``cymsim.full.simulate``. Requires ``torch`` (``pip install cymsim[full]``)."""
61 from .full import simulate as _simulate
63 return _simulate(*args, **kwargs)
66def __getattr__(name):
67 import importlib
69 if name == "Simulation":
70 return importlib.import_module(".full.simulation", __name__).Simulation
71 if name == "plot":
72 return importlib.import_module(".plot", __name__)
73 raise AttributeError(f"module 'cymsim' has no attribute {name!r}")
↑↓ move↵openescclose