MechanicsDSL is an innovative computational physics framework that allows users to define complex physical systems using a user-friendly, LaTeX-inspired syntax. With capabilities such as automatic equation derivation, multiple code generation options, and GPU acceleration, it simplifies the simulation process for professionals and educators alike.
MechanicsDSL provides a powerful computational physics framework designed for physicists, researchers, and educators to effortlessly define and simulate complex physical systems. Leveraging a user-friendly, LaTeX-inspired syntax, this framework automates the generation of high-performance simulations, ranging from pendulums to planetary orbits, as well as complex fluid dynamics.
Key Features
- Symbolic Engine: Derives equations of motion automatically from Lagrangians or Hamiltonians.
- Multiple Code Generators: Supports generation of C++, Rust, Julia, CUDA, WebAssembly, Unity, Unreal, Modelica, and more.
- GPU Acceleration: Utilizes a JAX backend for JIT compilation and automatic differentiation, enhancing performance.
- Inverse Problems: Facilitates parameter estimation, sensitivity analysis, and MCMC uncertainty quantification.
- Jupyter Notebook Integration: Employs
%%mechanicsdslmagic commands for seamless use in Jupyter notebooks. - Real-time API: Implements a FastAPI server with WebSocket streaming for real-time simulation interactions.
- IDE Support: Offers an LSP server for Visual Studio Code, complete with autocomplete and diagnostics capabilities.
- Plugin Architecture: Features an extensible system that allows for custom physics domains and solvers.
Core Capabilities
MechanicsDSL encompasses a range of areas in physics, including:
- Classical Mechanics: Features modules for Lagrangian and Hamiltonian mechanics, stability analysis, and perturbation theory.
- Quantum Mechanics: Addresses bound states, scattering, quantum tunneling, and semiclassical phenomena.
- Electromagnetism: Covers charged particles, wave behavior, antennas, and waveguides.
- General Relativity: Helps simulate black holes, geodesics, lensing effects, and cosmological models.
- Thermodynamics: Includes heat engine simulations, equations of state, and phase transitions.
- Fluid Dynamics: Integrates an SPH solver for simulating incompressible fluids.
Quick Start
Example of the Figure-8 Three-Body Orbit
Here’s how to define and simulate a gravitational three-body system in MechanicsDSL:
from mechanics_dsl import PhysicsCompiler
# Define the system using LaTeX-inspired DSL
figure8_code = r"""
\system{figure8_orbit}
\defvar{x1}{Position}{m} \defvar{y1}{Position}{m}
\defvar{x2}{Position}{m} \defvar{y2}{Position}{m}
\defvar{x3}{Position}{m} \defvar{y3}{Position}{m}
\defvar{m}{Mass}{kg} \defvar{G}{Grav}{1}
\parameter{m}{1.0}{kg} \parameter{G}{1.0}{1}
\lagrangian{
0.5 * m * (\dot{x1}^2 + \dot{y1}^2 + \dot{x2}^2 + \dot{y2}^2 + \dot{x3}^2 + \dot{y3}^2)
+ G*m^2/\sqrt{(x1-x2)^2 + (y1-y2)^2}
+ G*m^2/\sqrt{(x2-x3)^2 + (y2-y3)^2}
+ G*m^2/\sqrt{(x1-x3)^2 + (y1-y3)^2}
}
"""
# Compile and simulate
compiler = PhysicsCompiler()
compiler.compile_dsl(figure8_code)
compiler.simulator.set_initial_conditions({
'x1': 0.97000436, 'y1': -0.24308753, 'x1_dot': 0.466203685, 'y1_dot': 0.43236573,
'x2': -0.97000436, 'y2': 0.24308753, 'x2_dot': 0.466203685, 'y2_dot': 0.43236573,
'x3': 0.0, 'y3': 0.0, 'x3_dot': -0.93240737, 'y3_dot': -0.86473146
})
solution = compiler.simulate(t_span=(0, 6.326), num_points=2000)
Fluid Dynamics Simulation
Simulating fluid dynamics is straightforward with the integrated SPH solver:
from mechanics_dsl import PhysicsCompiler
fluid_code = r"""
\system{dam_break}
\parameter{h}{0.04}{m}
\parameter{g}{9.81}{m/s^2}
\fluid{water}
\region{rectangle}{x=0.0 .. 0.4, y=0.0 .. 0.8}
\particle_mass{0.02}
\equation_of_state{tait}
\boundary{walls}
\region{line}{x=-0.05, y=0.0 .. 1.5}
\region{line}{x=1.5, y=0.0 .. 1.5}
\region{line}{x=-0.05 .. 1.5, y=-0.05}
"""
compiler = PhysicsCompiler()
compiler.compile_dsl(fluid_code)
compiler.compile_to_cpp("dam_break.cpp", target="standard", compile_binary=True)
For additional tutorials and examples, see the documentation. MechanicsDSL enables comprehensive exploration and simulation of physical systems, making it an invaluable tool for anyone engaged in computational physics.
No comments yet.
Sign in to be the first to comment.