Skip to main content

A physics simulation library for modeling and analyzing physical systems

Project description

PhySimLab - Physics Simulation Laboratory

PyPI version License: Apache 2.0 Python Version Downloads

physimlab is a comprehensive physics simulation package for ball drop experiments with advanced aerodynamics, Magnus effect, and ground interaction physics.

๐Ÿš€ Features

๐Ÿ“Š Advanced Physics

  • Aerodynamics: Multi-regime drag coefficient, Reynolds number, Mach number calculations
  • Magnus Effect: Spin-induced lift forces with advanced correlations
  • Thermodynamics: Temperature and humidity effects on air properties (ISA model)
  • Ground Physics: Hertzian contact mechanics, advanced friction modeling, surface geometry
  • Wind Effects: Power law wind profiles, gust modeling, atmospheric turbulence
  • Virtual Mass: Added mass effects for realistic acceleration behavior
  • Compressibility: High-speed flow corrections

๐ŸŽฏ Multiple Scenarios

  • Ball Drop: Standard drop simulation with advanced bounce physics
  • Wind Tunnel: Aerodynamics testing with controlled airflow and turbulence
  • Terminal Velocity: Free fall with complete drag force analysis
  • Projectile Motion: Trajectory simulation with full aerodynamic effects
  • Spin Analysis: Rotational dynamics with advanced decay modeling

๐Ÿ“ˆ Rich Output

  • CSV Data: Full trajectory data with all physics parameters
  • Interactive HTML: Plotly-powered reports with 3D visualization
  • Animated GIFs: Real-time trajectory animations
  • High-Quality Plots: Publication-ready static plots
  • JSON Summary: Machine-readable results and configuration
  • Detailed Statistics: Energy conservation, stability analysis, timestep monitoring

๐Ÿ”ง Advanced Numerical Methods

  • Adaptive Integration: RK45 Dormand-Prince with error control
  • Fixed-Step Euler: For comparison and simple cases
  • Stability Monitoring: Energy-based stability checks
  • Adaptive Timestep: Automatic step size control

๐Ÿ Python Library

import physimlab

# Simple usage with configuration file
result = physimlab.run_simulation(config_path="config.json")
print(f"Flight time: {result['summary']['flight_time']:.2f} s")

# Advanced usage with configuration
result = physimlab.run_simulation(
    config_path="config.json",
    output_dir="./results"
)

# Batch simulations with parameter sweep
results = physimlab.batch_simulation(
    config_path="config.json",
    parameters=[
        {"name": "mass", "min": 0.1, "max": 1.0, "steps": 5},
        {"name": "radius", "min": 0.05, "max": 0.2, "steps": 3}
    ]
)

# Compare results
comparison = physimlab.compare_results(
    "./result1", 
    "./result2"
)

# Access detailed results
summary = result['summary']
data = result['data']
config = result['config']
detailed_stats = result.get('detailed_stats', {})

print(f"Flight time: {summary['flight_time']:.3f} seconds")
print(f"Max height: {summary['max_height']:.2f} meters")
print(f"Horizontal range: {summary['horizontal_range']:.2f} meters")
print(f"Max Reynolds number: {detailed_stats.get('max_reynolds', 0):.2e}")
print(f"Energy conserved: {detailed_stats.get('energy_conserved', True)}")

# Save outputs
output_files = result['output_files']
print(f"CSV data: {output_files['data']}")
print(f"HTML report: {output_files['html']}")

๐Ÿ–ฅ๏ธ Command Line Interface

# Basic usage (configuration file required)
$ physimlab run --config config.json
$ physimlab run --config config.yaml

# Advanced usage
$ physimlab run --config config.json --output ./results
$ physimlab batch --config config.json --param mass 0.1 0.5 5
$ physimlab compare ./result1 ./result2

# Information and management
$ physimlab list
$ physimlab info drop
$ physimlab version
$ physimlab init my_project --scenario drop

# Enhanced output options
$ physimlab run --config config.json --quiet          # Minimal output
$ physimlab run --config config.json --verbose        # Detailed output

๐Ÿ“ฆ Installation

PyPI (Recommended)

pip install physimlab

Development Version

pip install git+https://github.com/rehanguha/physimlab.git

From Source

git clone https://github.com/rehanguha/physimlab.git
cd physimlab
pip install -e .

๐ŸŽฎ Quick Start

1. Basic Simulation

# Run with configuration file (required)
physimlab run --config config.json

# Run with custom configuration
physimlab run --config my_config.json --output ./results

2. Python API

import physimlab

# Run simulation with configuration
result = physimlab.run_simulation(config_path="config.json")

# Access results
summary = result['summary']
print(f"Flight time: {summary['flight_time']:.3f} seconds")
print(f"Max height: {summary['max_height']:.2f} meters")
print(f"Horizontal range: {summary['horizontal_range']:.2f} meters")

# Get output files
output_files = result['output_files']
print(f"Data saved to: {output_files['data']}")

3. Configuration File

Create a config.json file:

{
  "scenario": "drop",
  "object": {
    "type": "sphere",
    "mass": 0.5,
    "radius": 0.1,
    "spin_rate": 8.0
  },
  "initial_height": 100,
  "environment": {
    "gravity": 9.81,
    "temperature": 288.15,
    "humidity": 0.5
  },
  "simulation": {
    "time_step": 0.001,
    "max_time": 30.0,
    "tolerance": 1e-6
  }
}

๐Ÿ“‹ CLI Reference

physimlab run

Run a ball drop simulation with specified configuration.

physimlab run --config CONFIG [OPTIONS]

Required:

  • --config, -c: Configuration file path (JSON or YAML)

Options:

  • --output, -o: Output directory (auto-generated if not specified)
  • --quiet, -q: Minimal output
  • --verbose, -v: Verbose output

Note: Configuration file is required. Individual parameters (height, mass, radius, spin) are no longer supported - use configuration files instead.

physimlab batch

Run batch simulations with parameter sweep.

physimlab batch --config CONFIG --param PARAM [PARAM ...]

Required:

  • --config: Base configuration file
  • --param, -p: Parameter to vary: name min max steps

Example:

physimlab batch --config config.json --param mass 0.1 0.5 5

physimlab compare

Compare two simulation results.

physimlab compare RESULT1 RESULT2

Arguments:

  • RESULT1: First result directory
  • RESULT2: Second result directory

physimlab list

List available scenarios.

physimlab list

Available scenarios:

  • drop: Ball drop simulation with aerodynamics
  • wind-tunnel: Wind tunnel aerodynamics test
  • terminal-velocity: Terminal velocity measurement
  • projectile: Projectile motion with drag

physimlab info

Show information about a scenario.

physimlab info [SCENARIO]

Arguments:

  • SCENARIO: Scenario to show information for (default: drop)

physimlab version

Show version information.

physimlab version

physimlab init

Initialize a new physimlab project.

physimlab init NAME --output DIR --scenario SCENARIO

Arguments:

  • NAME: Project name

Options:

  • --output, -o: Output directory (default: current directory)
  • --scenario, -s: Default scenario (default: drop)

๐Ÿ”ฌ Physics Models

Aerodynamics

  • Air Density: Ideal gas law with humidity effects
  • Viscosity: Sutherland's formula for temperature dependence
  • Speed of Sound: Temperature-dependent calculation
  • Reynolds Number: Flow regime characterization
  • Drag Coefficient: Reynolds number-dependent model
  • Magnus Force: Spin-induced lift calculation

Mechanics

  • Gravity: Altitude-dependent gravitational acceleration
  • Terminal Velocity: Drag vs. gravity equilibrium
  • Spin Decay: Air resistance effects on rotation

Environment

  • Temperature Effects: On air density, viscosity, and speed of sound
  • Humidity Effects: On air density calculations
  • Wind Effects: Crosswind and relative velocity calculations

๐Ÿ“Š Output Formats

CSV Data

Full trajectory data with all calculated physics parameters:

Time,X,Y,Z,Vx,Vy,Vz,Speed,OmegaZ,AirDensity,Reynolds,Cd,Mach
0.000,0.035,0.000,100.035,7.071,0.001,7.022,9.965,50.206,1.209,234928,0.160,0.026
...

JSON Summary

Machine-readable summary and configuration:

{
  "summary": {
    "flight_time": 19.995,
    "max_height": 102.56,
    "horizontal_range": 45.77,
    "max_velocity": 42.90,
    "ground_contacts": 6,
    "max_mach": 0.126,
    "is_stable": true,
    "energy_conserved": true
  },
  "config": { ... },
  "timestamp": "2026-02-24T16:51:32"
}

HTML Report

Interactive Plotly report with rich formatting:

  • 2D and 3D trajectory plots
  • Velocity and height over time
  • Physics parameter visualization
  • Summary statistics with enhanced formatting
  • Rich terminal output display

Static Plots

High-quality matplotlib plots:

  • Trajectory visualization
  • Velocity components over time
  • Physics parameters analysis
  • Publication-ready formatting

Output Files Structure

When running simulations, outputs are organized as:

outputs/
โ”œโ”€โ”€ data.csv              # Full trajectory data
โ”œโ”€โ”€ summary.json          # Results summary
โ”œโ”€โ”€ report.html           # Interactive HTML report
โ”œโ”€โ”€ plots/                # Static matplotlib plots
โ”‚   โ”œโ”€โ”€ trajectory.png
โ”‚   โ”œโ”€โ”€ velocity.png
โ”‚   โ””โ”€โ”€ physics.png
โ””โ”€โ”€ animation.gif         # Trajectory animation

๐Ÿ—๏ธ Package Structure

physimlab/
โ”œโ”€โ”€ __init__.py         # Package entry point
โ”œโ”€โ”€ cli.py              # Typer CLI interface with rich formatting
โ”œโ”€โ”€ core.py             # Main simulation engine and API functions
โ”œโ”€โ”€ config/             # Configuration handling
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ loader.py       # JSON/YAML loading and validation
โ”œโ”€โ”€ objects/            # Physical object definitions
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ output/             # Output management and reporting
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ manager.py      # File saving and organization
โ”‚   โ””โ”€โ”€ result.py       # Result object with plotting capabilities
โ”œโ”€โ”€ physics/            # Physics calculations
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ aerodynamics.py # Drag, lift, air properties, Magnus effect
โ”‚   โ””โ”€โ”€ mechanics.py    # Gravity, motion, collisions, spin decay
โ”œโ”€โ”€ scenarios/          # Predefined simulation scenarios
โ”‚   โ””โ”€โ”€ __init__.py
โ””โ”€โ”€ utils/              # Utilities and constants
    โ”œโ”€โ”€ __init__.py
    โ”œโ”€โ”€ constants.py    # Physical constants
    โ””โ”€โ”€ helpers.py      # Formatting and utility functions

๐Ÿงช Testing

Run the test suite:

pip install physimlab[dev]
pytest

Run with coverage:

pytest --cov=physimlab --cov-report=html

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

๐Ÿ“„ License

physimlab is licensed under the Apache License 2.0.

Copyright 2026 Rehan Guha

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

๐Ÿ™ Acknowledgments

  • NumPy: Numerical computations
  • Pandas: Data handling and CSV export
  • Matplotlib: Static plotting
  • Plotly: Interactive visualization
  • Typer: CLI interface
  • Rich: Beautiful terminal output

๐Ÿ“ž Support

For questions, bug reports, or feature requests:

๐Ÿท๏ธ Keywords

physics simulation, aerodynamics, ball drop, Magnus effect, terminal velocity, projectile motion, scientific computing, Python package, CLI tool, data visualization

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

physimlab-0.1.0.tar.gz (98.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

physimlab-0.1.0-py3-none-any.whl (79.5 kB view details)

Uploaded Python 3

File details

Details for the file physimlab-0.1.0.tar.gz.

File metadata

  • Download URL: physimlab-0.1.0.tar.gz
  • Upload date:
  • Size: 98.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for physimlab-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d5191b9bf1dcb939662f22e7c7d2395768d4effae4bac5536f38bc006f70d562
MD5 78b2af1d380f40bd93b2c64392e1d425
BLAKE2b-256 61f05acd254b8bfd2dfb67d8b42445836d07621a251cba6767b7d49169793cd4

See more details on using hashes here.

Provenance

The following attestation bundles were made for physimlab-0.1.0.tar.gz:

Publisher: python-publish.yml on rehanguha/physimlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file physimlab-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: physimlab-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 79.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for physimlab-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b84b449c67d546db87b8cd4a43f6cfee6b78aa8cb4f40585f42d768b9cf35110
MD5 1362945996137abc059b56081bf6d76c
BLAKE2b-256 13c9379c121a8f8d6b4d14c92d259638c295e56892f5d74de03fb90a15da46af

See more details on using hashes here.

Provenance

The following attestation bundles were made for physimlab-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on rehanguha/physimlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page