Metadata-Version: 2.4
Name: physimlab
Version: 0.1.0
Summary: A physics simulation library for modeling and analyzing physical systems
Author-email: Rehan Guha <rehanguha29@gmail.com>
License: Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (which shall not include communications that are clearly marked or
              otherwise designated in writing by the copyright owner as "Not a Work").
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based upon (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control
              systems, and issue tracking systems that are managed by, or on behalf
              of, the Licensor for the purpose of discussing and improving the Work,
              but excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to use, reproduce, modify, display, perform,
              sublicense, and distribute the Work and such Derivative Works in
              Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright notice to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Support. You may choose to offer, and charge a
              fee for, warranty, support, indemnity or other liability obligations
              and/or rights consistent with this License. However, in accepting
              such obligations, You may act only on Your own behalf and on Your
              sole responsibility, not on behalf of any other Contributor, and
              only if You agree to indemnify, defend, and hold each Contributor
              harmless for any liability incurred by, or claims asserted against,
              such Contributor by reason of your accepting any such warranty or support.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in comments for the
              particular file format. We also recommend that a file or class name
              and description of purpose be included on the same "printed page" as
              the copyright notice for easier identification within third-party
              archives.
        
           Copyright [yyyy] [name of copyright owner]
        
           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.
Project-URL: Homepage, https://github.com/rehanguha/physimlab
Project-URL: Repository, https://github.com/rehanguha/physimlab
Project-URL: Issues, https://github.com/rehanguha/physimlab/issues
Keywords: physics,simulation,mechanics,aerodynamics,science
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Physics
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.21.0
Requires-Dist: matplotlib>=3.5.0
Requires-Dist: pandas>=1.3.0
Requires-Dist: scipy>=1.7.0
Requires-Dist: typer[all]>=0.7.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: black>=22.0.0; extra == "dev"
Requires-Dist: flake8>=5.0.0; extra == "dev"
Requires-Dist: mypy>=0.991; extra == "dev"
Dynamic: license-file

# PhySimLab - Physics Simulation Laboratory

[![PyPI version](https://badge.fury.io/py/physimlab.svg)](https://badge.fury.io/py/physimlab)
[![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Python Version](https://img.shields.io/pypi/pyversions/physimlab.svg)](https://pypi.org/project/physimlab/)
[![Downloads](https://pepy.tech/badge/physimlab)](https://pepy.tech/project/physimlab)

**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
```python
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
```bash
# 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)
```bash
pip install physimlab
```

### Development Version
```bash
pip install git+https://github.com/rehanguha/physimlab.git
```

### From Source
```bash
git clone https://github.com/rehanguha/physimlab.git
cd physimlab
pip install -e .
```

## 🎮 Quick Start

### 1. Basic Simulation
```bash
# 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
```python
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:
```json
{
  "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.

```bash
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.

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

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

**Example:**
```bash
physimlab batch --config config.json --param mass 0.1 0.5 5
```

### `physimlab compare`
Compare two simulation results.

```bash
physimlab compare RESULT1 RESULT2
```

**Arguments:**
- `RESULT1`: First result directory
- `RESULT2`: Second result directory

### `physimlab list`
List available scenarios.

```bash
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.

```bash
physimlab info [SCENARIO]
```

**Arguments:**
- `SCENARIO`: Scenario to show information for (default: drop)

### `physimlab version`
Show version information.

```bash
physimlab version
```

### `physimlab init`
Initialize a new physimlab project.

```bash
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:
```csv
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:
```json
{
  "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:
```bash
pip install physimlab[dev]
pytest
```

Run with coverage:
```bash
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](LICENSE).

```
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](https://github.com/rehanguha/physimlab/issues)
- **Documentation**: [GitHub README](https://github.com/rehanguha/physimlab/blob/main/README.md)

## 🏷️ Keywords

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