Metadata-Version: 2.5
Name: physu
Version: 0.8.0
Summary: A modular Python physics library with strict unit and dimensional validation powered by Pint.
Project-URL: Homepage, https://github.com/taxnam23
Project-URL: Repository, https://github.com/taxnam23/physu
Project-URL: Issues, https://github.com/taxnam23/physu/issues
Author-email: taxnam23 <tarfanam342@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: acoustics,dimensional-analysis,dynamics,electromagnetism,energy,fluid-mechanics,fluids,kinematics,optics,physics,pint,scientific-computing,thermodynamics,units,waves
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Physics
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: pint>=0.23
Provides-Extra: dev
Requires-Dist: mypy>=1.11; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# physu

A modular Python physics library with strict unit and dimensional validation powered by [Pint](https://pint.readthedocs.io/).

## Features

- **Strict dimensional safety:** Rejects incompatible dimensions (such as mass where velocity is expected) via `pint.DimensionalityError`.
- **Physical domain validation:** Rejects non-physical inputs (negative time, zero radius, unreachable trajectories, `NaN`, or non-finite values) via `PhysicalDomainError` (a `ValueError` subclass).
- **Centralized `UnitRegistry`:** Shares a single `physu.ureg` across all modules and normalizes strings (`"72 km/h"`), `physu.ureg` quantities, and quantities from external Pint registries.
- **Clean SI outputs:** Calculations return normalized SI `pint.Quantity` objects that can be converted to any compatible unit with `.to(...)`.

## Installation

```bash
pip install physu
```

For local development (including `pytest`, `ruff`, and `mypy`):

```bash
pip install -e ".[dev]"
```

Requires Python `>= 3.10`.

## Examples

Runnable scripts covering every module and submodule live in [examples/](examples/):

- [units_and_validation.py](examples/units_and_validation.py) — drone telemetry normalization and sensor error handling
- [kinematics_1d.py](examples/kinematics_1d.py) — highway emergency braking and bridge drop check
- [kinematics_2d_and_circular.py](examples/kinematics_2d_and_circular.py) — firefighter hose targeting and washing machine spin G-load
- [dynamics_forces_and_friction.py](examples/dynamics_forces_and_friction.py) — inclined ramp winch sizing and crate slip threshold
- [dynamics_elasticity_momentum_gravitation.py](examples/dynamics_elasticity_momentum_gravitation.py) — vehicle suspension sag, rear-end impact force, and CubeSat LEO orbit
- [energy_work_and_power.py](examples/energy_work_and_power.py) — crane hoist motor sizing, spring coaster launch, and LEO escape speed
- [thermodynamics.py](examples/thermodynamics.py) — rail expansion gap, steel quenching bath, scuba cylinder pressure, Carnot limit, and window heat loss
- [electromagnetism.py](examples/electromagnetism.py) — flash capacitor bank, copper feeder cable, proton cyclotron solenoid, and substation transformer
- [waves.py](examples/waves.py) — vehicle suspension SHM, guitar harmonics, PA decibel level, ultrasound reflection, and supersonic Mach cone
- [optics.py](examples/optics.py) — optical fiber TIR, projector lens, thin-film interference, spectrometer grating, and telescope Rayleigh limit
- [fluids.py](examples/fluids.py) — ocean pressure, iceberg buoyancy, Venturi flow, Poiseuille/Stokes viscosity, and capillary meniscus

## Modules

- **`physu.units`**: Centralized `ureg`, `Quantity`, `to_quantity`, `check_dimension`, `convert_to`, `to_si`, and `to_unit`.
- **`physu.exceptions`**: `PhysuError` and `PhysicalDomainError`.
- **`physu.validation`**: `validate_quantity`, `require_non_negative`, `require_positive`, `require_non_zero`, and `require_range`.
- **`physu.constants`**: Fundamental SI / CODATA 2022 constants (`STANDARD_GRAVITY`, `SPEED_OF_LIGHT`, `GRAVITATIONAL_CONSTANT`, `PLANCK_CONSTANT`, `ELEMENTARY_CHARGE`, `BOLTZMANN_CONSTANT`, `AVOGADRO_CONSTANT`, `MOLAR_GAS_CONSTANT`, `STANDARD_ATMOSPHERE`, `STEFAN_BOLTZMANN_CONSTANT`, `ELECTRON_MASS`, `PROTON_MASS`, `VACUUM_PERMITTIVITY`, `VACUUM_PERMEABILITY`, `COULOMB_CONSTANT`).
- **`physu.kinematics`**:
  - `uniform`: MRU (`displacement`, `position`, `average_velocity`, `travel_time`)
  - `accelerated`: MRUA / SUVAT (`final_velocity`, `displacement`, `position`, `displacement_from_velocities`, `acceleration`, `torricelli_velocity`, `time_to_velocity`, `time_to_displacement`)
  - `vertical`: Free fall and vertical throw (`vertical_position`, `vertical_velocity`, `free_fall_distance`, `free_fall_speed`, `free_fall_time`, `time_to_peak`, `max_height`, `time_to_height`)
  - `projectile`: 2D projectile motion (`velocity_components`, `projectile_flight_time`, `projectile_max_height`, `projectile_range`, `projectile_position`, `projectile_velocity`)
  - `circular`: Uniform circular motion (`tangential_speed`, `angular_velocity_from_speed`, `centripetal_acceleration`, `period_from_frequency`, `frequency_from_period`, `angular_velocity_from_period`, `angular_velocity_from_frequency`, `period_from_angular_velocity`, `frequency_from_angular_velocity`, `angular_displacement`, `arc_length`)
- **`physu.dynamics`**:
  - `newton`: Newton's laws, weight, and inclined planes (`force`, `acceleration`, `mass`, `weight`, `inclined_parallel_force`, `inclined_normal_force`)
  - `friction`: Static and kinetic friction (`max_static_friction`, `kinetic_friction`, `friction_coefficient`, `normal_force`, `critical_incline_angle`)
  - `elasticity`: Hooke's law and springs (`spring_force`, `spring_force_magnitude`, `spring_constant`, `spring_displacement`, `series_spring_constant`, `parallel_spring_constant`)
  - `momentum`: Linear momentum, impulse, and 1D collisions (`linear_momentum`, `impulse`, `momentum_change`, `average_force`, `collision_velocities`, `elastic_collision_velocities`, `inelastic_collision_velocity`)
  - `gravitation`: Universal gravitation and circular dynamics (`gravitational_force`, `gravitational_field_strength`, `orbital_speed`, `centripetal_force`)
- **`physu.energy`**:
  - `work`: Mechanical work and work-energy theorem (`mechanical_work`, `net_work`, `gravitational_work`, `elastic_work`)
  - `kinetic`: Translational kinetic energy (`kinetic_energy`, `kinetic_energy_from_momentum`, `speed_from_kinetic_energy`, `momentum_from_kinetic_energy`)
  - `potential`: Gravitational and elastic potential energy (`gravitational_potential_energy`, `universal_gravitational_potential_energy`, `elastic_potential_energy`)
  - `conservation`: Mechanical energy conservation and efficiency (`mechanical_energy`, `non_conservative_work`, `final_speed_conservation`, `final_height_conservation`, `escape_speed`, `mechanical_efficiency`)
  - `power`: Mechanical power (`average_power`, `instantaneous_power`, `work_from_power`, `force_from_power`, `velocity_from_power`)
- **`physu.thermodynamics`**:
  - `temperature`: Temperature scales and thermal expansion (`to_kelvin`, `to_celsius`, `to_fahrenheit`, `temperature_difference`, `linear_thermal_expansion`, `volumetric_thermal_expansion`)
  - `calorimetry`: Sensible heat, latent heat, and thermal equilibrium (`sensible_heat`, `latent_heat`, `specific_heat_capacity`, `equilibrium_temperature`)
  - `ideal_gas`: Ideal gas law and kinetic theory (`ideal_gas_pressure`, `ideal_gas_volume`, `ideal_gas_moles`, `ideal_gas_temperature`, `combined_gas_law`, `rms_molecular_speed`, `average_molecular_kinetic_energy`)
  - `laws`: First/second laws, process work, and engines (`internal_energy_change`, `isobaric_work`, `isothermal_work`, `thermal_efficiency`, `carnot_efficiency`, `isothermal_entropy_change`)
  - `heat_transfer`: Conduction and thermal radiation (`conduction_heat_rate`, `radiation_power`)
- **`physu.electromagnetism`**:
  - `electrostatics`: Coulomb's law, electric fields, potential, work, and Gauss flux (`coulomb_force`, `electric_field_point_charge`, `electric_force`, `uniform_electric_field`, `electric_potential_point_charge`, `electric_potential_energy`, `electric_work`, `electric_flux`, `gauss_electric_flux`)
  - `circuits`: Ohm's law, wire resistivity, DC power, Joule heating, and resistor networks (`ohms_law_voltage`, `ohms_law_current`, `ohms_law_resistance`, `wire_resistance`, `electric_power`, `joule_heating`, `series_resistance`, `parallel_resistance`, `voltage_divider`)
  - `capacitance`: Capacitors, dielectrics, stored energy, networks, and RC transients (`capacitance`, `capacitor_charge`, `capacitor_voltage`, `parallel_plate_capacitance`, `capacitor_energy`, `series_capacitance`, `parallel_capacitance`, `rc_time_constant`, `rc_charging_voltage`, `rc_discharging_voltage`)
  - `magnetism`: Lorentz force, cyclotron motion, and magnetic fields (`lorentz_magnetic_force`, `magnetic_force_on_wire`, `cyclotron_radius`, `cyclotron_frequency`, `magnetic_field_wire`, `magnetic_field_loop_center`, `magnetic_field_solenoid`, `force_per_length_parallel_wires`)
  - `induction`: Magnetic flux, Faraday's law, inductors, RL/LC circuits, and ideal transformers (`magnetic_flux`, `faraday_emf`, `motional_emf`, `solenoid_inductance`, `inductor_energy`, `series_inductance`, `parallel_inductance`, `rl_time_constant`, `lc_resonant_frequency`, `transformer_voltage`, `transformer_current`)
- **`physu.waves`**:
  - `oscillations`: Simple harmonic motion and pendulums (`spring_mass_angular_frequency`, `spring_mass_period`, `simple_pendulum_period`, `physical_pendulum_period`, `shm_displacement`, `shm_velocity`, `shm_acceleration`, `shm_max_speed`, `shm_max_acceleration`, `shm_energy`, `shm_speed_at_position`)
  - `mechanical`: Wave kinematics, strings, and intensity (`wave_speed`, `wavelength`, `wave_frequency`, `wavenumber`, `wave_phase_speed`, `string_wave_speed`, `string_wave_power`, `wave_intensity`, `spherical_wave_intensity`)
  - `standing`: Standing waves, harmonics, string tension, and beats (`string_harmonic_frequency`, `open_pipe_harmonic_frequency`, `closed_pipe_harmonic_frequency`, `string_harmonic_wavelength`, `closed_pipe_harmonic_wavelength`, `fundamental_tension_for_frequency`, `beat_frequency`)
  - `acoustics`: Sound speed, decibels, and impedance (`speed_of_sound_ideal_gas`, `sound_intensity_level`, `intensity_from_sound_level`, `sound_pressure_level`, `acoustic_impedance`, `acoustic_reflection_coefficient`)
  - `doppler`: Acoustic and relativistic Doppler shifts and Mach cone (`doppler_frequency`, `relativistic_doppler_frequency`, `mach_number`, `mach_angle`)
- **`physu.optics`**:
  - `refraction`: Optical media, Snell's law, critical angle, and Brewster angle (`speed_in_medium`, `wavelength_in_medium`, `refractive_index`, `snell_refraction_angle`, `critical_angle`, `brewster_angle`)
  - `lenses`: Thin lenses, spherical mirrors, magnification, and optical power (`thin_lens_image_distance`, `thin_lens_focal_length`, `lateral_magnification`, `optical_power`, `combined_optical_power`, `lensmaker_focal_length`, `mirror_focal_length`)
  - `interference`: Young's double slit, thin films, and Michelson interferometer (`double_slit_angle`, `double_slit_fringe_position`, `double_slit_fringe_spacing`, `thin_film_constructive_thickness`, `michelson_displacement`)
  - `diffraction`: Single slit, gratings, Rayleigh resolution, and Bragg's law (`single_slit_minimum_angle`, `diffraction_grating_angle`, `grating_spacing_from_density`, `rayleigh_angular_resolution`, `bragg_diffraction_angle`)
  - `polarization`: Malus's law, polarizer stacks, and degree of polarization (`malus_intensity`, `unpolarized_polarizer_intensity`, `polarizer_stack_intensity`, `polarization_degree`)
- **`physu.fluids`**:
  - `hydrostatics`: Density, hydrostatic pressure, Pascal's principle, and head (`fluid_density`, `specific_gravity`, `hydrostatic_gauge_pressure`, `hydrostatic_pressure`, `pascal_hydraulic_force`, `pressure_head`)
  - `buoyancy`: Archimedes' principle, apparent weight, and floating equilibrium (`buoyant_force`, `apparent_weight`, `floating_submerged_fraction`, `submerged_volume_floating`)
  - `dynamics`: Continuity, flow rates, Bernoulli, and Torricelli efflux (`volumetric_flow_rate`, `flow_speed`, `mass_flow_rate`, `continuity_speed`, `dynamic_pressure`, `bernoulli_pressure`, `torricelli_efflux_speed`)
  - `viscosity`: Viscosity, Reynolds number, Poiseuille flow, and Stokes drag (`kinematic_viscosity`, `reynolds_number`, `poiseuille_flow_rate`, `stokes_drag_force`, `stokes_terminal_velocity`)
  - `capillarity`: Surface tension, Young-Laplace pressure, and capillary rise (`surface_tension_force`, `laplace_bubble_pressure`, `capillary_rise_height`)

## Development

```bash
pytest
ruff check src tests
mypy src
```

## License

[MIT](LICENSE)
