A physics simulation library for modeling and analyzing physical systems
Project description
PhySimLab - Physics Simulation Laboratory
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 directoryRESULT2: Second result directory
physimlab list
List available scenarios.
physimlab list
Available scenarios:
drop: Ball drop simulation with aerodynamicswind-tunnel: Wind tunnel aerodynamics testterminal-velocity: Terminal velocity measurementprojectile: 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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- 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:
- GitHub Issues: https://github.com/rehanguha/physimlab/issues
- Documentation: GitHub README
๐ท๏ธ Keywords
physics simulation, aerodynamics, ball drop, Magnus effect, terminal velocity, projectile motion, scientific computing, Python package, CLI tool, data visualization
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5191b9bf1dcb939662f22e7c7d2395768d4effae4bac5536f38bc006f70d562
|
|
| MD5 |
78b2af1d380f40bd93b2c64392e1d425
|
|
| BLAKE2b-256 |
61f05acd254b8bfd2dfb67d8b42445836d07621a251cba6767b7d49169793cd4
|
Provenance
The following attestation bundles were made for physimlab-0.1.0.tar.gz:
Publisher:
python-publish.yml on rehanguha/physimlab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
physimlab-0.1.0.tar.gz -
Subject digest:
d5191b9bf1dcb939662f22e7c7d2395768d4effae4bac5536f38bc006f70d562 - Sigstore transparency entry: 1004928499
- Sigstore integration time:
-
Permalink:
rehanguha/physimlab@b9fdce308034ebb5791059e8ae7403217e215331 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rehanguha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b9fdce308034ebb5791059e8ae7403217e215331 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b84b449c67d546db87b8cd4a43f6cfee6b78aa8cb4f40585f42d768b9cf35110
|
|
| MD5 |
1362945996137abc059b56081bf6d76c
|
|
| BLAKE2b-256 |
13c9379c121a8f8d6b4d14c92d259638c295e56892f5d74de03fb90a15da46af
|
Provenance
The following attestation bundles were made for physimlab-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on rehanguha/physimlab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
physimlab-0.1.0-py3-none-any.whl -
Subject digest:
b84b449c67d546db87b8cd4a43f6cfee6b78aa8cb4f40585f42d768b9cf35110 - Sigstore transparency entry: 1004928501
- Sigstore integration time:
-
Permalink:
rehanguha/physimlab@b9fdce308034ebb5791059e8ae7403217e215331 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rehanguha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b9fdce308034ebb5791059e8ae7403217e215331 -
Trigger Event:
release
-
Statement type: