MechanicsDSL is a computational physics framework that simplifies the process of defining physical systems using a LaTeX-inspired syntax. With tools to generate high-performance simulations, it handles everything from pendulums to fluid dynamics, enabling users to describe their systems once and simulate them anywhere.
MechanicsDSL is an open-source computational physics framework designed to facilitate the modeling, simulation, and visualization of classical mechanics problems. Employing a LaTeX-inspired syntax, this project allows for an intuitive definition of intricate physical systems, ensuring a seamless transition from symbolic descriptions to high-performance numerical simulations. Whether modeling pendulums or planetary orbits, MechanicsDSL provides a versatile environment for researchers and educators alike.
Key Features
| Symbolic Engine | Automatically derives equations of motion from Lagrangians or Hamiltonians, simplifying complex problem setups.
| Fluid Dynamics | Integrated Smoothed Particle Hydrodynamics (SPH) solver for simulating dam breaks, waves, and other fluid phenomena.
| High Performance | Generates optimized C++, OpenMP, and WebAssembly code, allowing for efficient simulations in various environments.
| Rich Visualization | Offers capabilities for phase space plots, energy analysis, and smooth animations, enhancing the understanding of dynamical systems.
| Research Ready | Validated against analytical solutions and conservation laws to ensure accuracy and reliability in simulations.
Quick Start Examples
Figure-8 Three-Body Orbit
Utilize the framework to define a gravitational three-body system:
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,
'x2': -0.97000436, 'y2': 0.24308753,
'x3': 0.0, 'y3': 0.0
})
solution = compiler.simulate(t_span=(0, 6.326), num_points=2000)
Dam Break Simulation
Initiate fluid dynamics simulations with the built-in 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)
Comprehensive Analysis Tools
MechanicsDSL provides extensive capabilities in classical mechanics, covering topics such as Lagrangian and Hamiltonian formulations, stability analysis, collision dynamics, and more, across 17 specialized modules.
Documentation and Community
For further details, tutorials, and API references, visit the full documentation at Read the Docs. Contributions and collaboration are encouraged, with guidelines available in the project repository.
No comments yet.
Sign in to be the first to comment.