georgedouzas / sage-physics

A Python package to create and simulate physics models.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sage-physics

Category Tools
Development black ruff mypy docformatter
Package version pythonversion downloads
Documentation mkdocs
Communication gitter discussions

Introduction

A Python package to create and simulate physics models.

Prerequisites

An installation of SageMath with version > 10.0 is required.

Installation

You can install sage-physics either as a normal user or for development purposes.

User

For user installation, sage-physics is currently available on the PyPi's repository, and you can install it via pip:

sage --pip install sage-physics

You can then start the Sage REPL with the command sage and use sage-physics through the Sage REPL:

import sagephys

Development

Development installation requires to clone the repository and change directory to the project's root:

git clone https://github.com/georgedouzas/sage-physics.git
cd sage-physics

Then create a Python virtual environment using the sage command:

sage -python -m venv --system-site-packages .venv

Finally, use PDM to select the virtual environment and install the project as well as the main and development dependencies:

pdm use .venv
pdm install

You can then start the Sage REPL with the command PYTHONPATH=src sage and use sage-physics through the Sage REPL:

import sagephys

Usage

One of the sage-physics main goals is to provide a unified interface for various physics models. For example let's define two independent harmonic oscillators that oscillate in the axes x and y:

from sage.all import var, assume
from sagephys.classical_mechanics import NewtonianPointParticlesModel
k, x_particle1, y_particle2 = var('k x_particle1 y_particle2')
assume(k > 0)
forces = {
    'particle1': {'elastic': [- k * x_particle1, 0, 0]},
    'particle2': {'elastic': [0, -k * y_particle2, 0]}
}
model = NewtonianPointParticlesModel(forces)

We can get the dynamical equations:

model.analyze()
model.equations_

We can also try to solve them:

model.solve()

About

A Python package to create and simulate physics models.

License:MIT License


Languages

Language:Python 100.0%