physu 0.2.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {physu-0.2.0 → physu-0.4.0}/PKG-INFO +22 -8
- {physu-0.2.0 → physu-0.4.0}/README.md +20 -6
- physu-0.4.0/changelogs/0.3.md +19 -0
- physu-0.4.0/changelogs/0.4.md +17 -0
- physu-0.4.0/examples/dynamics_elasticity_momentum_gravitation.py +59 -0
- physu-0.4.0/examples/dynamics_forces_and_friction.py +41 -0
- physu-0.4.0/examples/energy_work_and_power.py +60 -0
- physu-0.4.0/examples/kinematics_1d.py +46 -0
- physu-0.4.0/examples/kinematics_2d_and_circular.py +52 -0
- physu-0.4.0/examples/thermodynamics.py +87 -0
- physu-0.4.0/examples/units_and_validation.py +71 -0
- {physu-0.2.0 → physu-0.4.0}/pyproject.toml +3 -1
- {physu-0.2.0 → physu-0.4.0}/src/physu/__init__.py +4 -2
- {physu-0.2.0 → physu-0.4.0}/src/physu/constants.py +7 -1
- physu-0.4.0/src/physu/energy/__init__.py +67 -0
- physu-0.4.0/src/physu/energy/conservation.py +208 -0
- physu-0.4.0/src/physu/energy/kinetic.py +120 -0
- physu-0.4.0/src/physu/energy/potential.py +99 -0
- physu-0.4.0/src/physu/energy/power.py +150 -0
- physu-0.4.0/src/physu/energy/work.py +129 -0
- physu-0.4.0/src/physu/thermodynamics/__init__.py +73 -0
- physu-0.4.0/src/physu/thermodynamics/calorimetry.py +167 -0
- physu-0.4.0/src/physu/thermodynamics/heat_transfer.py +105 -0
- physu-0.4.0/src/physu/thermodynamics/ideal_gas.py +252 -0
- physu-0.4.0/src/physu/thermodynamics/laws.py +154 -0
- physu-0.4.0/src/physu/thermodynamics/temperature.py +205 -0
- {physu-0.2.0 → physu-0.4.0}/tests/test_constants.py +3 -0
- physu-0.4.0/tests/test_energy.py +279 -0
- physu-0.4.0/tests/test_thermodynamics.py +325 -0
- physu-0.2.0/examples/dynamics_elasticity_momentum_gravitation.py +0 -59
- physu-0.2.0/examples/dynamics_forces_and_friction.py +0 -47
- physu-0.2.0/examples/kinematics_1d.py +0 -57
- physu-0.2.0/examples/kinematics_2d_and_circular.py +0 -52
- physu-0.2.0/examples/units_and_validation.py +0 -53
- {physu-0.2.0 → physu-0.4.0}/.gitignore +0 -0
- {physu-0.2.0 → physu-0.4.0}/AGENTS.md +0 -0
- {physu-0.2.0 → physu-0.4.0}/LICENSE +0 -0
- {physu-0.2.0 → physu-0.4.0}/changelogs/0.1.md +0 -0
- {physu-0.2.0 → physu-0.4.0}/changelogs/0.2.md +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/dynamics/__init__.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/dynamics/elasticity.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/dynamics/friction.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/dynamics/gravitation.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/dynamics/momentum.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/dynamics/newton.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/exceptions.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/kinematics/__init__.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/kinematics/accelerated.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/kinematics/circular.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/kinematics/projectile.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/kinematics/uniform.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/kinematics/vertical.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/py.typed +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/units.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/src/physu/validation.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/tests/test_dynamics.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/tests/test_kinematics.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/tests/test_units.py +0 -0
- {physu-0.2.0 → physu-0.4.0}/tests/test_validation.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: physu
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: A modular Python physics library with strict unit and dimensional validation powered by Pint.
|
|
5
5
|
Project-URL: Homepage, https://github.com/taxnam23
|
|
6
6
|
Project-URL: Repository, https://github.com/taxnam23/physu
|
|
@@ -8,7 +8,7 @@ Project-URL: Issues, https://github.com/taxnam23/physu/issues
|
|
|
8
8
|
Author-email: taxnam23 <tarfanam342@gmail.com>
|
|
9
9
|
License-Expression: MIT
|
|
10
10
|
License-File: LICENSE
|
|
11
|
-
Keywords: dimensional-analysis,dynamics,kinematics,physics,pint,scientific-computing,units
|
|
11
|
+
Keywords: dimensional-analysis,dynamics,energy,kinematics,physics,pint,scientific-computing,thermodynamics,units
|
|
12
12
|
Classifier: Development Status :: 3 - Alpha
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
14
14
|
Classifier: Intended Audience :: Education
|
|
@@ -59,18 +59,20 @@ Requires Python `>= 3.10`.
|
|
|
59
59
|
|
|
60
60
|
Runnable scripts covering every module and submodule live in [examples/](examples/):
|
|
61
61
|
|
|
62
|
-
- [units_and_validation.py](examples/units_and_validation.py) —
|
|
63
|
-
- [kinematics_1d.py](examples/kinematics_1d.py) —
|
|
64
|
-
- [kinematics_2d_and_circular.py](examples/kinematics_2d_and_circular.py) —
|
|
65
|
-
- [dynamics_forces_and_friction.py](examples/dynamics_forces_and_friction.py) —
|
|
66
|
-
- [dynamics_elasticity_momentum_gravitation.py](examples/dynamics_elasticity_momentum_gravitation.py) —
|
|
62
|
+
- [units_and_validation.py](examples/units_and_validation.py) — drone telemetry normalization and sensor error handling
|
|
63
|
+
- [kinematics_1d.py](examples/kinematics_1d.py) — highway emergency braking and bridge drop check
|
|
64
|
+
- [kinematics_2d_and_circular.py](examples/kinematics_2d_and_circular.py) — firefighter hose targeting and washing machine spin G-load
|
|
65
|
+
- [dynamics_forces_and_friction.py](examples/dynamics_forces_and_friction.py) — inclined ramp winch sizing and crate slip threshold
|
|
66
|
+
- [dynamics_elasticity_momentum_gravitation.py](examples/dynamics_elasticity_momentum_gravitation.py) — vehicle suspension sag, rear-end impact force, and CubeSat LEO orbit
|
|
67
|
+
- [energy_work_and_power.py](examples/energy_work_and_power.py) — crane hoist motor sizing, spring coaster launch, and LEO escape speed
|
|
68
|
+
- [thermodynamics.py](examples/thermodynamics.py) — rail expansion gap, steel quenching bath, scuba cylinder pressure, Carnot limit, and window heat loss
|
|
67
69
|
|
|
68
70
|
## Modules
|
|
69
71
|
|
|
70
72
|
- **`physu.units`**: Centralized `ureg`, `Quantity`, `to_quantity`, `check_dimension`, `convert_to`, `to_si`, and `to_unit`.
|
|
71
73
|
- **`physu.exceptions`**: `PhysuError` and `PhysicalDomainError`.
|
|
72
74
|
- **`physu.validation`**: `validate_quantity`, `require_non_negative`, `require_positive`, `require_non_zero`, and `require_range`.
|
|
73
|
-
- **`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`, `ELECTRON_MASS`, `PROTON_MASS`, `VACUUM_PERMITTIVITY`, `VACUUM_PERMEABILITY`).
|
|
75
|
+
- **`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`).
|
|
74
76
|
- **`physu.kinematics`**:
|
|
75
77
|
- `uniform`: MRU (`displacement`, `position`, `average_velocity`, `travel_time`)
|
|
76
78
|
- `accelerated`: MRUA / SUVAT (`final_velocity`, `displacement`, `position`, `displacement_from_velocities`, `acceleration`, `torricelli_velocity`, `time_to_velocity`, `time_to_displacement`)
|
|
@@ -83,6 +85,18 @@ Runnable scripts covering every module and submodule live in [examples/](example
|
|
|
83
85
|
- `elasticity`: Hooke's law and springs (`spring_force`, `spring_force_magnitude`, `spring_constant`, `spring_displacement`, `series_spring_constant`, `parallel_spring_constant`)
|
|
84
86
|
- `momentum`: Linear momentum, impulse, and 1D collisions (`linear_momentum`, `impulse`, `momentum_change`, `average_force`, `collision_velocities`, `elastic_collision_velocities`, `inelastic_collision_velocity`)
|
|
85
87
|
- `gravitation`: Universal gravitation and circular dynamics (`gravitational_force`, `gravitational_field_strength`, `orbital_speed`, `centripetal_force`)
|
|
88
|
+
- **`physu.energy`**:
|
|
89
|
+
- `work`: Mechanical work and work-energy theorem (`mechanical_work`, `net_work`, `gravitational_work`, `elastic_work`)
|
|
90
|
+
- `kinetic`: Translational kinetic energy (`kinetic_energy`, `kinetic_energy_from_momentum`, `speed_from_kinetic_energy`, `momentum_from_kinetic_energy`)
|
|
91
|
+
- `potential`: Gravitational and elastic potential energy (`gravitational_potential_energy`, `universal_gravitational_potential_energy`, `elastic_potential_energy`)
|
|
92
|
+
- `conservation`: Mechanical energy conservation and efficiency (`mechanical_energy`, `non_conservative_work`, `final_speed_conservation`, `final_height_conservation`, `escape_speed`, `mechanical_efficiency`)
|
|
93
|
+
- `power`: Mechanical power (`average_power`, `instantaneous_power`, `work_from_power`, `force_from_power`, `velocity_from_power`)
|
|
94
|
+
- **`physu.thermodynamics`**:
|
|
95
|
+
- `temperature`: Temperature scales and thermal expansion (`to_kelvin`, `to_celsius`, `to_fahrenheit`, `temperature_difference`, `linear_thermal_expansion`, `volumetric_thermal_expansion`)
|
|
96
|
+
- `calorimetry`: Sensible heat, latent heat, and thermal equilibrium (`sensible_heat`, `latent_heat`, `specific_heat_capacity`, `equilibrium_temperature`)
|
|
97
|
+
- `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`)
|
|
98
|
+
- `laws`: First/second laws, process work, and engines (`internal_energy_change`, `isobaric_work`, `isothermal_work`, `thermal_efficiency`, `carnot_efficiency`, `isothermal_entropy_change`)
|
|
99
|
+
- `heat_transfer`: Conduction and thermal radiation (`conduction_heat_rate`, `radiation_power`)
|
|
86
100
|
|
|
87
101
|
## Development
|
|
88
102
|
|
|
@@ -27,18 +27,20 @@ Requires Python `>= 3.10`.
|
|
|
27
27
|
|
|
28
28
|
Runnable scripts covering every module and submodule live in [examples/](examples/):
|
|
29
29
|
|
|
30
|
-
- [units_and_validation.py](examples/units_and_validation.py) —
|
|
31
|
-
- [kinematics_1d.py](examples/kinematics_1d.py) —
|
|
32
|
-
- [kinematics_2d_and_circular.py](examples/kinematics_2d_and_circular.py) —
|
|
33
|
-
- [dynamics_forces_and_friction.py](examples/dynamics_forces_and_friction.py) —
|
|
34
|
-
- [dynamics_elasticity_momentum_gravitation.py](examples/dynamics_elasticity_momentum_gravitation.py) —
|
|
30
|
+
- [units_and_validation.py](examples/units_and_validation.py) — drone telemetry normalization and sensor error handling
|
|
31
|
+
- [kinematics_1d.py](examples/kinematics_1d.py) — highway emergency braking and bridge drop check
|
|
32
|
+
- [kinematics_2d_and_circular.py](examples/kinematics_2d_and_circular.py) — firefighter hose targeting and washing machine spin G-load
|
|
33
|
+
- [dynamics_forces_and_friction.py](examples/dynamics_forces_and_friction.py) — inclined ramp winch sizing and crate slip threshold
|
|
34
|
+
- [dynamics_elasticity_momentum_gravitation.py](examples/dynamics_elasticity_momentum_gravitation.py) — vehicle suspension sag, rear-end impact force, and CubeSat LEO orbit
|
|
35
|
+
- [energy_work_and_power.py](examples/energy_work_and_power.py) — crane hoist motor sizing, spring coaster launch, and LEO escape speed
|
|
36
|
+
- [thermodynamics.py](examples/thermodynamics.py) — rail expansion gap, steel quenching bath, scuba cylinder pressure, Carnot limit, and window heat loss
|
|
35
37
|
|
|
36
38
|
## Modules
|
|
37
39
|
|
|
38
40
|
- **`physu.units`**: Centralized `ureg`, `Quantity`, `to_quantity`, `check_dimension`, `convert_to`, `to_si`, and `to_unit`.
|
|
39
41
|
- **`physu.exceptions`**: `PhysuError` and `PhysicalDomainError`.
|
|
40
42
|
- **`physu.validation`**: `validate_quantity`, `require_non_negative`, `require_positive`, `require_non_zero`, and `require_range`.
|
|
41
|
-
- **`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`, `ELECTRON_MASS`, `PROTON_MASS`, `VACUUM_PERMITTIVITY`, `VACUUM_PERMEABILITY`).
|
|
43
|
+
- **`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`).
|
|
42
44
|
- **`physu.kinematics`**:
|
|
43
45
|
- `uniform`: MRU (`displacement`, `position`, `average_velocity`, `travel_time`)
|
|
44
46
|
- `accelerated`: MRUA / SUVAT (`final_velocity`, `displacement`, `position`, `displacement_from_velocities`, `acceleration`, `torricelli_velocity`, `time_to_velocity`, `time_to_displacement`)
|
|
@@ -51,6 +53,18 @@ Runnable scripts covering every module and submodule live in [examples/](example
|
|
|
51
53
|
- `elasticity`: Hooke's law and springs (`spring_force`, `spring_force_magnitude`, `spring_constant`, `spring_displacement`, `series_spring_constant`, `parallel_spring_constant`)
|
|
52
54
|
- `momentum`: Linear momentum, impulse, and 1D collisions (`linear_momentum`, `impulse`, `momentum_change`, `average_force`, `collision_velocities`, `elastic_collision_velocities`, `inelastic_collision_velocity`)
|
|
53
55
|
- `gravitation`: Universal gravitation and circular dynamics (`gravitational_force`, `gravitational_field_strength`, `orbital_speed`, `centripetal_force`)
|
|
56
|
+
- **`physu.energy`**:
|
|
57
|
+
- `work`: Mechanical work and work-energy theorem (`mechanical_work`, `net_work`, `gravitational_work`, `elastic_work`)
|
|
58
|
+
- `kinetic`: Translational kinetic energy (`kinetic_energy`, `kinetic_energy_from_momentum`, `speed_from_kinetic_energy`, `momentum_from_kinetic_energy`)
|
|
59
|
+
- `potential`: Gravitational and elastic potential energy (`gravitational_potential_energy`, `universal_gravitational_potential_energy`, `elastic_potential_energy`)
|
|
60
|
+
- `conservation`: Mechanical energy conservation and efficiency (`mechanical_energy`, `non_conservative_work`, `final_speed_conservation`, `final_height_conservation`, `escape_speed`, `mechanical_efficiency`)
|
|
61
|
+
- `power`: Mechanical power (`average_power`, `instantaneous_power`, `work_from_power`, `force_from_power`, `velocity_from_power`)
|
|
62
|
+
- **`physu.thermodynamics`**:
|
|
63
|
+
- `temperature`: Temperature scales and thermal expansion (`to_kelvin`, `to_celsius`, `to_fahrenheit`, `temperature_difference`, `linear_thermal_expansion`, `volumetric_thermal_expansion`)
|
|
64
|
+
- `calorimetry`: Sensible heat, latent heat, and thermal equilibrium (`sensible_heat`, `latent_heat`, `specific_heat_capacity`, `equilibrium_temperature`)
|
|
65
|
+
- `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`)
|
|
66
|
+
- `laws`: First/second laws, process work, and engines (`internal_energy_change`, `isobaric_work`, `isothermal_work`, `thermal_efficiency`, `carnot_efficiency`, `isothermal_entropy_change`)
|
|
67
|
+
- `heat_transfer`: Conduction and thermal radiation (`conduction_heat_rate`, `radiation_power`)
|
|
54
68
|
|
|
55
69
|
## Development
|
|
56
70
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# `physu` 0.3.0 (2026-11-17)
|
|
2
|
+
|
|
3
|
+
Adds mechanical work, energy, conservation, and power (`physu.energy`), plus real-world runnable examples across every domain.
|
|
4
|
+
|
|
5
|
+
## Added
|
|
6
|
+
|
|
7
|
+
### Energy (`physu.energy`)
|
|
8
|
+
- **`work`**: Constant-force work (`mechanical_work`), work-energy theorem (`net_work`), `gravitational_work`, and `elastic_work`.
|
|
9
|
+
- **`kinetic`**: Translational kinetic energy (`kinetic_energy`, `kinetic_energy_from_momentum`, `speed_from_kinetic_energy`, `momentum_from_kinetic_energy`).
|
|
10
|
+
- **`potential`**: Near-surface and universal gravitational potential energy (`gravitational_potential_energy`, `universal_gravitational_potential_energy`) and `elastic_potential_energy`.
|
|
11
|
+
- **`conservation`**: Total mechanical energy (`mechanical_energy`), `non_conservative_work`, conservation solvers (`final_speed_conservation`, `final_height_conservation`), `escape_speed`, and `mechanical_efficiency`.
|
|
12
|
+
- **`power`**: Mechanical power (`average_power`, `instantaneous_power`, `work_from_power`, `force_from_power`, `velocity_from_power`).
|
|
13
|
+
|
|
14
|
+
### Examples & Tests
|
|
15
|
+
- Added real-world energy/power sizing script [energy_work_and_power.py](../examples/energy_work_and_power.py).
|
|
16
|
+
- Added unit tests in `tests/test_energy.py` (50 tests total across the suite), verified with `ruff` and strict `mypy`.
|
|
17
|
+
|
|
18
|
+
## Changed
|
|
19
|
+
- Replaced dry per-function prints across `examples/` with realistic real-world engineering and everyday physics scenarios, and updated `README.md`.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# `physu` 0.4.0 (2026-11-17)
|
|
2
|
+
|
|
3
|
+
Adds thermodynamics (`physu.thermodynamics`) with safe handling of Pint offset temperature units, plus `STEFAN_BOLTZMANN_CONSTANT` and real-world examples.
|
|
4
|
+
|
|
5
|
+
## Added
|
|
6
|
+
|
|
7
|
+
### Thermodynamics (`physu.thermodynamics`)
|
|
8
|
+
- **`temperature`**: Absolute-zero-validated temperature conversions (`to_kelvin`, `to_celsius`, `to_fahrenheit`), offset-safe `temperature_difference`, and thermal expansion (`linear_thermal_expansion`, `volumetric_thermal_expansion`).
|
|
9
|
+
- **`calorimetry`**: Sensible heat (`sensible_heat`), phase-change `latent_heat`, `specific_heat_capacity`, and multi-body `equilibrium_temperature`.
|
|
10
|
+
- **`ideal_gas`**: Ideal gas law solvers (`ideal_gas_pressure`, `ideal_gas_volume`, `ideal_gas_moles`, `ideal_gas_temperature`), `combined_gas_law`, `rms_molecular_speed`, and `average_molecular_kinetic_energy`.
|
|
11
|
+
- **`laws`**: First law (`internal_energy_change`), `isobaric_work`, `isothermal_work`, `thermal_efficiency`, `carnot_efficiency`, and `isothermal_entropy_change`.
|
|
12
|
+
- **`heat_transfer`**: Fourier conduction (`conduction_heat_rate`) and Stefan-Boltzmann thermal radiation (`radiation_power`).
|
|
13
|
+
|
|
14
|
+
### Constants, Examples & Tests
|
|
15
|
+
- Added `STEFAN_BOLTZMANN_CONSTANT` to `physu.constants`.
|
|
16
|
+
- Added real-world thermodynamics script [thermodynamics.py](../examples/thermodynamics.py) and updated `README.md`.
|
|
17
|
+
- Added unit tests in `tests/test_thermodynamics.py` and `tests/test_constants.py` (61 tests total across the suite), verified with `ruff` and strict `mypy`.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Real-world examples: vehicle suspension sag, rear-end impact, and CubeSat orbit."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from physu.dynamics import (
|
|
6
|
+
average_force,
|
|
7
|
+
centripetal_force,
|
|
8
|
+
gravitational_field_strength,
|
|
9
|
+
inelastic_collision_velocity,
|
|
10
|
+
momentum_change,
|
|
11
|
+
newton,
|
|
12
|
+
orbital_speed,
|
|
13
|
+
parallel_spring_constant,
|
|
14
|
+
spring_displacement,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main() -> None:
|
|
19
|
+
"""Run three practical dynamics calculations."""
|
|
20
|
+
# 1. Rear suspension sag on a loaded utility van (two parallel coil springs)
|
|
21
|
+
rear_axle_load = newton.weight("650 kg")
|
|
22
|
+
k_eq = parallel_spring_constant(["28 kN/m", "28 kN/m"])
|
|
23
|
+
# Upward spring restoring force balances downward axle weight (+rear_axle_load)
|
|
24
|
+
sag = spring_displacement(rear_axle_load, k_eq)
|
|
25
|
+
|
|
26
|
+
print("=== Rear Suspension Compression ===")
|
|
27
|
+
print(f"Combined stiffness: {k_eq.to('kN/m'):.1f} | Sag under 650 kg: {sag.to('cm'):.2f}")
|
|
28
|
+
|
|
29
|
+
# 2. Low-speed rear-end collision force estimate (inelastic bumper lock)
|
|
30
|
+
car1_mass = "1500 kg"
|
|
31
|
+
car1_speed = "36 km/h"
|
|
32
|
+
car2_mass = "1200 kg"
|
|
33
|
+
impact_duration = "120 ms"
|
|
34
|
+
|
|
35
|
+
v_after = inelastic_collision_velocity(car1_mass, car1_speed, car2_mass, "0 m/s")
|
|
36
|
+
impulse_car2 = momentum_change(car2_mass, "0 m/s", v_after)
|
|
37
|
+
avg_impact_force = average_force(impulse_car2, impact_duration)
|
|
38
|
+
|
|
39
|
+
print("\n=== Low-Speed Rear-End Collision ===")
|
|
40
|
+
print(f"Shared speed right after impact: {v_after.to('km/h'):.1f}")
|
|
41
|
+
print(f"Average force over {impact_duration}: {avg_impact_force.to('kN'):.2f}")
|
|
42
|
+
|
|
43
|
+
# 3. 12 kg CubeSat in a 550 km Low Earth Orbit (Earth radius 6371 km)
|
|
44
|
+
earth_mass = "5.9722e24 kg"
|
|
45
|
+
orbit_radius = "6921 km"
|
|
46
|
+
cubesat_mass = "12 kg"
|
|
47
|
+
|
|
48
|
+
local_g = gravitational_field_strength(earth_mass, orbit_radius)
|
|
49
|
+
v_orbit = orbital_speed(earth_mass, orbit_radius)
|
|
50
|
+
f_gravity_orbit = centripetal_force(cubesat_mass, orbit_radius, tangential_speed=v_orbit)
|
|
51
|
+
|
|
52
|
+
print("\n=== CubeSat Orbit Check (550 km altitude) ===")
|
|
53
|
+
print(f"Local gravity at 550 km: {local_g:.2f}")
|
|
54
|
+
print(f"Orbital velocity: {v_orbit.to('km/s'):.2f}")
|
|
55
|
+
print(f"Centripetal gravitational force on 12 kg CubeSat: {f_gravity_orbit:.2f}")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if __name__ == "__main__":
|
|
59
|
+
main()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Real-world example: loading a heavy crate up an inclined steel ramp."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from physu.dynamics import (
|
|
6
|
+
critical_incline_angle,
|
|
7
|
+
inclined_normal_force,
|
|
8
|
+
inclined_parallel_force,
|
|
9
|
+
kinetic_friction,
|
|
10
|
+
max_static_friction,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def main() -> None:
|
|
15
|
+
"""Evaluate slip risk and winch pulling forces on a 18-degree loading ramp."""
|
|
16
|
+
crate_mass = "450 kg"
|
|
17
|
+
ramp_angle = "18 deg"
|
|
18
|
+
mu_static = 0.42
|
|
19
|
+
mu_kinetic = 0.30
|
|
20
|
+
|
|
21
|
+
repose_angle = critical_incline_angle(mu_static).to("deg")
|
|
22
|
+
gravity_pull = inclined_parallel_force(crate_mass, ramp_angle)
|
|
23
|
+
normal = inclined_normal_force(crate_mass, ramp_angle)
|
|
24
|
+
max_hold = max_static_friction(mu_static, normal)
|
|
25
|
+
sliding_friction = kinetic_friction(mu_kinetic, normal)
|
|
26
|
+
|
|
27
|
+
# Pulling force up the ramp must overcome gravity component + friction
|
|
28
|
+
breakaway_pull = gravity_pull + max_hold
|
|
29
|
+
steady_winch_pull = gravity_pull + sliding_friction
|
|
30
|
+
|
|
31
|
+
print("=== Inclined Ramp Winch Sizing (450 kg crate, 18 deg) ===")
|
|
32
|
+
print(f"Self-slip threshold (angle of repose): {repose_angle:.2f}")
|
|
33
|
+
holds_stationary = "YES" if repose_angle.magnitude > 18.0 else "NO"
|
|
34
|
+
print(f"Crate holds stationary without brakes? {holds_stationary}")
|
|
35
|
+
print(f"Gravity component down ramp: {gravity_pull:.1f} | Normal force: {normal:.1f}")
|
|
36
|
+
print(f"Breakaway winch force needed: {breakaway_pull:.1f}")
|
|
37
|
+
print(f"Steady winch pull while moving: {steady_winch_pull:.1f}")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
main()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Real-world examples: crane hoist motor sizing, spring coaster launch, and escape speed."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from physu.energy import (
|
|
6
|
+
average_power,
|
|
7
|
+
elastic_potential_energy,
|
|
8
|
+
escape_speed,
|
|
9
|
+
final_speed_conservation,
|
|
10
|
+
gravitational_potential_energy,
|
|
11
|
+
speed_from_kinetic_energy,
|
|
12
|
+
)
|
|
13
|
+
from physu.units import to_unit
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def main() -> None:
|
|
17
|
+
"""Solve practical engineering energy and power sizing problems."""
|
|
18
|
+
# 1. Construction crane lifting a 1.2-tonne steel I-beam up 18 m in 25 s
|
|
19
|
+
beam_mass = "1200 kg"
|
|
20
|
+
lift_height = "18 m"
|
|
21
|
+
lift_duration = "25 s"
|
|
22
|
+
hoist_efficiency = 0.82
|
|
23
|
+
|
|
24
|
+
useful_energy = gravitational_potential_energy(beam_mass, lift_height)
|
|
25
|
+
useful_power = average_power(useful_energy, lift_duration)
|
|
26
|
+
required_motor_power = to_unit(useful_power / hoist_efficiency, "kW")
|
|
27
|
+
electrical_energy_per_lift = to_unit(useful_energy / hoist_efficiency, "kWh")
|
|
28
|
+
|
|
29
|
+
print("=== Construction Crane Hoist Sizing ===")
|
|
30
|
+
print(f"Useful lifting energy: {useful_energy.to('kJ'):.1f}")
|
|
31
|
+
print(f"Output shaft power: {useful_power.to('kW'):.2f}")
|
|
32
|
+
print(
|
|
33
|
+
f"Required motor input (@82% eff.): {required_motor_power:.2f} "
|
|
34
|
+
f"({required_motor_power.to('hp'):.2f})"
|
|
35
|
+
)
|
|
36
|
+
print(f"Grid energy per lift: {electrical_energy_per_lift:.4f}")
|
|
37
|
+
|
|
38
|
+
# 2. Spring-launched coaster cart climbing a 12 m hill
|
|
39
|
+
cart_mass = "250 kg"
|
|
40
|
+
launcher_k = "32 kN/m"
|
|
41
|
+
spring_compression = "1.6 m"
|
|
42
|
+
hill_height = "12 m"
|
|
43
|
+
|
|
44
|
+
stored_elastic = elastic_potential_energy(launcher_k, spring_compression)
|
|
45
|
+
launch_speed = speed_from_kinetic_energy(stored_elastic, cart_mass)
|
|
46
|
+
crest_speed = final_speed_conservation(launch_speed, "0 m", hill_height)
|
|
47
|
+
|
|
48
|
+
print("\n=== Spring-Launched Coaster Cart ===")
|
|
49
|
+
print(f"Stored launcher energy: {stored_elastic.to('kJ'):.2f}")
|
|
50
|
+
print(f"Launch speed: {launch_speed:.2f} ({launch_speed.to('km/h'):.1f})")
|
|
51
|
+
print(f"Speed clearing 12 m crest (frictionless): {crest_speed:.2f}")
|
|
52
|
+
|
|
53
|
+
# 3. Minimum Earth escape speed from a 500 km orbital parking altitude
|
|
54
|
+
v_esc = escape_speed("5.9722e24 kg", "6871 km")
|
|
55
|
+
print("\n=== Deep-Space Departure from 500 km LEO ===")
|
|
56
|
+
print(f"Escape speed needed: {v_esc.to('km/s'):.2f}")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if __name__ == "__main__":
|
|
60
|
+
main()
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Real-world example: highway emergency braking check and bridge clearance drop."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from physu.kinematics import (
|
|
6
|
+
accelerated_displacement,
|
|
7
|
+
displacement,
|
|
8
|
+
free_fall_speed,
|
|
9
|
+
free_fall_time,
|
|
10
|
+
time_to_velocity,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def main() -> None:
|
|
15
|
+
"""Analyze safe highway braking distance and a dropped inspection sensor."""
|
|
16
|
+
# Scenario 1: Emergency braking on a wet highway
|
|
17
|
+
cruise_speed = "110 km/h"
|
|
18
|
+
reaction_time = "1.2 s"
|
|
19
|
+
braking_decel = "-6.5 m/s^2"
|
|
20
|
+
hazard_distance = "95 m"
|
|
21
|
+
|
|
22
|
+
reaction_dist = displacement(cruise_speed, reaction_time)
|
|
23
|
+
braking_time = time_to_velocity(cruise_speed, "0 m/s", braking_decel)
|
|
24
|
+
braking_dist = accelerated_displacement(cruise_speed, braking_decel, braking_time)
|
|
25
|
+
total_stopping_dist = reaction_dist + braking_dist
|
|
26
|
+
|
|
27
|
+
print("=== Highway Emergency Braking ===")
|
|
28
|
+
print(f"Cruise speed: {cruise_speed} | Reaction distance (1.2 s): {reaction_dist:.2f}")
|
|
29
|
+
print(f"Braking time: {braking_time:.2f} | Braking distance: {braking_dist:.2f}")
|
|
30
|
+
print(f"Total stopping distance: {total_stopping_dist:.2f} (hazard at {hazard_distance})")
|
|
31
|
+
margin = total_stopping_dist.to("m").magnitude
|
|
32
|
+
print(f"Clears hazard before impact? {'YES' if margin < 95.0 else 'NO'}")
|
|
33
|
+
|
|
34
|
+
# Scenario 2: Dropping an acoustic depth probe from a 38 m bridge
|
|
35
|
+
bridge_height = "38 m"
|
|
36
|
+
t_splash = free_fall_time(bridge_height)
|
|
37
|
+
v_splash = free_fall_speed(bridge_height)
|
|
38
|
+
|
|
39
|
+
print("\n=== Bridge Drop Sensor Check ===")
|
|
40
|
+
print(f"Drop height: {bridge_height}")
|
|
41
|
+
print(f"Time to water impact: {t_splash:.2f}")
|
|
42
|
+
print(f"Water entry speed: {v_splash:.2f} ({v_splash.to('km/h'):.1f})")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if __name__ == "__main__":
|
|
46
|
+
main()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Real-world example: firefighter hose targeting and washing machine spin G-force."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from physu.constants import STANDARD_GRAVITY
|
|
6
|
+
from physu.kinematics import (
|
|
7
|
+
centripetal_acceleration,
|
|
8
|
+
projectile_position,
|
|
9
|
+
projectile_range,
|
|
10
|
+
tangential_speed,
|
|
11
|
+
travel_time,
|
|
12
|
+
velocity_components,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def main() -> None:
|
|
17
|
+
"""Compute building-wall water stream height and drum spin G-load."""
|
|
18
|
+
# Scenario 1: Aiming a fire hose at a third-floor window 32 m away
|
|
19
|
+
nozzle_speed = "24 m/s"
|
|
20
|
+
aim_angle = "40 deg"
|
|
21
|
+
nozzle_height = "1.2 m"
|
|
22
|
+
building_distance = "32 m"
|
|
23
|
+
|
|
24
|
+
vx, _ = velocity_components(nozzle_speed, aim_angle)
|
|
25
|
+
t_reach_wall = travel_time(building_distance, vx)
|
|
26
|
+
x_wall, y_wall = projectile_position(
|
|
27
|
+
nozzle_speed,
|
|
28
|
+
aim_angle,
|
|
29
|
+
t_reach_wall,
|
|
30
|
+
initial_height=nozzle_height,
|
|
31
|
+
)
|
|
32
|
+
max_ground_range = projectile_range(nozzle_speed, aim_angle, initial_height=nozzle_height)
|
|
33
|
+
|
|
34
|
+
print("=== Firefighter Hose Targeting ===")
|
|
35
|
+
print(f"Jet reaches wall ({x_wall:.1f}) at t={t_reach_wall:.2f} and height={y_wall:.2f}")
|
|
36
|
+
print(f"Unobstructed ground range: {max_ground_range:.2f}")
|
|
37
|
+
|
|
38
|
+
# Scenario 2: Washing machine spin cycle G-force on wet laundry
|
|
39
|
+
drum_radius = "26 cm"
|
|
40
|
+
spin_rate = "1200 rpm"
|
|
41
|
+
|
|
42
|
+
rim_speed = tangential_speed(spin_rate, drum_radius)
|
|
43
|
+
a_c = centripetal_acceleration(drum_radius, angular_velocity=spin_rate)
|
|
44
|
+
g_force = (a_c / STANDARD_GRAVITY).to("dimensionless")
|
|
45
|
+
|
|
46
|
+
print("\n=== Washing Machine Spin Cycle (1200 rpm) ===")
|
|
47
|
+
print(f"Drum rim speed: {rim_speed:.2f} ({rim_speed.to('km/h'):.1f})")
|
|
48
|
+
print(f"Centripetal acceleration: {a_c:.1f} (~{g_force.magnitude:.0f} g)")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
main()
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Real-world thermodynamics examples: rail gaps, quenching, scuba tank, Carnot, and heat loss."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from physu.thermodynamics import (
|
|
6
|
+
carnot_efficiency,
|
|
7
|
+
combined_gas_law,
|
|
8
|
+
conduction_heat_rate,
|
|
9
|
+
equilibrium_temperature,
|
|
10
|
+
ideal_gas_moles,
|
|
11
|
+
linear_thermal_expansion,
|
|
12
|
+
radiation_power,
|
|
13
|
+
sensible_heat,
|
|
14
|
+
temperature_difference,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main() -> None:
|
|
19
|
+
"""Solve practical thermal engineering and everyday physics problems."""
|
|
20
|
+
# 1. Steel railway track thermal expansion gap between spring install and summer peak
|
|
21
|
+
rail_length = "25 m"
|
|
22
|
+
steel_alpha = "1.2e-5 / K"
|
|
23
|
+
rail_dt = temperature_difference("15 degC", "48 degC")
|
|
24
|
+
expansion_gap = linear_thermal_expansion(rail_length, steel_alpha, rail_dt)
|
|
25
|
+
|
|
26
|
+
print("=== Railway Track Expansion Gap (25 m steel rail) ===")
|
|
27
|
+
print(
|
|
28
|
+
f"Temperature swing: {rail_dt.to('delta_degC'):.1f} | "
|
|
29
|
+
f"Required gap: {expansion_gap.to('mm'):.2f}"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# 2. Quenching a 2.5 kg hot steel part (450 degC) in 12 kg of water (22 degC)
|
|
33
|
+
water_c = "4184 J / (kg * K)"
|
|
34
|
+
steel_c = "490 J / (kg * K)"
|
|
35
|
+
t_eq = equilibrium_temperature(
|
|
36
|
+
[
|
|
37
|
+
("2.5 kg", steel_c, "450 degC"),
|
|
38
|
+
("12 kg", water_c, "22 degC"),
|
|
39
|
+
]
|
|
40
|
+
)
|
|
41
|
+
water_gain = sensible_heat("12 kg", water_c, temperature_difference("22 degC", t_eq))
|
|
42
|
+
|
|
43
|
+
print("\n=== Steel Quenching Bath Equilibrium ===")
|
|
44
|
+
print(f"Final bath temperature: {t_eq.to('degC'):.2f}")
|
|
45
|
+
print(f"Heat absorbed by water: {water_gain.to('kJ'):.1f}")
|
|
46
|
+
|
|
47
|
+
# 3. Scuba tank pressure drop entering 8 degC ocean water
|
|
48
|
+
tank_volume = "12 liter"
|
|
49
|
+
fill_pressure = "200 bar"
|
|
50
|
+
fill_temp = "28 degC"
|
|
51
|
+
dive_temp = "8 degC"
|
|
52
|
+
|
|
53
|
+
air_moles = ideal_gas_moles(fill_pressure, tank_volume, fill_temp)
|
|
54
|
+
dive_pressure = combined_gas_law(
|
|
55
|
+
fill_pressure,
|
|
56
|
+
tank_volume,
|
|
57
|
+
fill_temp,
|
|
58
|
+
final_volume=tank_volume,
|
|
59
|
+
final_temperature=dive_temp,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
print("\n=== Scuba Cylinder Pressure Check ===")
|
|
63
|
+
print(f"Stored air: {air_moles:.1f} | Pressure at {dive_temp}: {dive_pressure.to('bar'):.1f}")
|
|
64
|
+
|
|
65
|
+
# 4. Steam power plant Carnot ceiling & winter window conduction / radiator output
|
|
66
|
+
max_eta = carnot_efficiency("35 degC", "540 degC")
|
|
67
|
+
window_loss = conduction_heat_rate(
|
|
68
|
+
"0.8 W / (m * K)",
|
|
69
|
+
"1.8 m^2",
|
|
70
|
+
temperature_difference("2 degC", "21 degC"),
|
|
71
|
+
"6 mm",
|
|
72
|
+
)
|
|
73
|
+
radiator_net = radiation_power(
|
|
74
|
+
0.92,
|
|
75
|
+
"1.4 m^2",
|
|
76
|
+
"55 degC",
|
|
77
|
+
ambient_temperature="21 degC",
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
print("\n=== Power Plant Limit & Home Heating ===")
|
|
81
|
+
print(f"Carnot ceiling (540 degC -> 35 degC): {max_eta.to('%'):.1f}")
|
|
82
|
+
print(f"Single-pane window heat loss: {window_loss.to('kW'):.2f}")
|
|
83
|
+
print(f"Net radiative heat output from radiator (55 degC): {radiator_net:.1f}")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if __name__ == "__main__":
|
|
87
|
+
main()
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Real-world example: validating and normalizing mixed-unit drone telemetry payloads."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import pint
|
|
6
|
+
|
|
7
|
+
from physu import PhysicalDomainError, Quantity, ureg
|
|
8
|
+
from physu.constants import STANDARD_GRAVITY
|
|
9
|
+
from physu.units import to_si, to_unit
|
|
10
|
+
from physu.validation import require_range, validate_quantity
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def parse_telemetry_packet(
|
|
14
|
+
payload: dict[str, object],
|
|
15
|
+
) -> tuple[pint.Quantity, pint.Quantity, pint.Quantity]:
|
|
16
|
+
"""Validate incoming drone telemetry and normalize units for the flight controller."""
|
|
17
|
+
battery_mass = validate_quantity(
|
|
18
|
+
payload["battery_mass"], # type: ignore[arg-type]
|
|
19
|
+
"[mass]",
|
|
20
|
+
name="battery_mass",
|
|
21
|
+
allow_negative=False,
|
|
22
|
+
allow_zero=False,
|
|
23
|
+
)
|
|
24
|
+
airspeed = validate_quantity(
|
|
25
|
+
payload["airspeed"], # type: ignore[arg-type]
|
|
26
|
+
"[velocity]",
|
|
27
|
+
name="airspeed",
|
|
28
|
+
allow_negative=False,
|
|
29
|
+
)
|
|
30
|
+
pitch_angle = require_range(
|
|
31
|
+
validate_quantity(payload["pitch"], "rad", name="pitch"), # type: ignore[arg-type]
|
|
32
|
+
min_value=Quantity(-45, "deg"),
|
|
33
|
+
max_value=Quantity(45, "deg"),
|
|
34
|
+
name="pitch",
|
|
35
|
+
)
|
|
36
|
+
return to_unit(battery_mass, "kg"), to_si(airspeed), to_unit(pitch_angle, "deg")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def main() -> None:
|
|
40
|
+
"""Validate valid and faulty telemetry packets from heterogeneous sensors."""
|
|
41
|
+
external_sensor_reg = pint.UnitRegistry()
|
|
42
|
+
|
|
43
|
+
valid_packet: dict[str, object] = {
|
|
44
|
+
"battery_mass": external_sensor_reg.Quantity(1450, "g"),
|
|
45
|
+
"airspeed": "65 km/h",
|
|
46
|
+
"pitch": 12 * ureg.deg,
|
|
47
|
+
}
|
|
48
|
+
mass, speed, pitch = parse_telemetry_packet(valid_packet)
|
|
49
|
+
hover_weight = to_unit(mass * STANDARD_GRAVITY, "N")
|
|
50
|
+
print(f"Valid telemetry -> mass={mass}, airspeed={speed:.2f}, pitch={pitch}")
|
|
51
|
+
print(f"Battery weight load on frame: {hover_weight:.2f}")
|
|
52
|
+
|
|
53
|
+
corrupted_packets: list[tuple[str, dict[str, object]]] = [
|
|
54
|
+
(
|
|
55
|
+
"unit mismatch (pressure sent instead of speed)",
|
|
56
|
+
{"battery_mass": "1.5 kg", "airspeed": "101 kPa", "pitch": "10 deg"},
|
|
57
|
+
),
|
|
58
|
+
(
|
|
59
|
+
"out-of-bounds pitch (nose dive)",
|
|
60
|
+
{"battery_mass": "1.5 kg", "airspeed": "15 m/s", "pitch": "-70 deg"},
|
|
61
|
+
),
|
|
62
|
+
]
|
|
63
|
+
for label, packet in corrupted_packets:
|
|
64
|
+
try:
|
|
65
|
+
parse_telemetry_packet(packet)
|
|
66
|
+
except (pint.DimensionalityError, PhysicalDomainError) as exc:
|
|
67
|
+
print(f"Rejected {label}: {exc}")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
if __name__ == "__main__":
|
|
71
|
+
main()
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "physu"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.0"
|
|
8
8
|
description = "A modular Python physics library with strict unit and dimensional validation powered by Pint."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -20,6 +20,8 @@ keywords = [
|
|
|
20
20
|
"dimensional-analysis",
|
|
21
21
|
"kinematics",
|
|
22
22
|
"dynamics",
|
|
23
|
+
"energy",
|
|
24
|
+
"thermodynamics",
|
|
23
25
|
"scientific-computing",
|
|
24
26
|
]
|
|
25
27
|
classifiers = [
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from . import constants, dynamics, exceptions, kinematics, units, validation
|
|
5
|
+
from . import constants, dynamics, energy, exceptions, kinematics, thermodynamics, units, validation
|
|
6
6
|
from .exceptions import PhysicalDomainError, PhysuError
|
|
7
7
|
from .units import Quantity, ureg
|
|
8
8
|
|
|
9
|
-
__version__ = "0.
|
|
9
|
+
__version__ = "0.4.0"
|
|
10
10
|
|
|
11
11
|
__all__ = [
|
|
12
12
|
"PhysicalDomainError",
|
|
@@ -15,8 +15,10 @@ __all__ = [
|
|
|
15
15
|
"__version__",
|
|
16
16
|
"constants",
|
|
17
17
|
"dynamics",
|
|
18
|
+
"energy",
|
|
18
19
|
"exceptions",
|
|
19
20
|
"kinematics",
|
|
21
|
+
"thermodynamics",
|
|
20
22
|
"units",
|
|
21
23
|
"ureg",
|
|
22
24
|
"validation",
|
|
@@ -9,7 +9,7 @@ import math
|
|
|
9
9
|
|
|
10
10
|
import pint
|
|
11
11
|
|
|
12
|
-
from .units import Quantity
|
|
12
|
+
from .units import Quantity, to_unit
|
|
13
13
|
|
|
14
14
|
# Mechanics & gravitation
|
|
15
15
|
STANDARD_GRAVITY: pint.Quantity = Quantity(9.80665, "m / s^2")
|
|
@@ -33,6 +33,11 @@ BOLTZMANN_CONSTANT: pint.Quantity = Quantity(1.380649e-23, "J / K")
|
|
|
33
33
|
AVOGADRO_CONSTANT: pint.Quantity = Quantity(6.02214076e23, "1 / mol")
|
|
34
34
|
MOLAR_GAS_CONSTANT: pint.Quantity = AVOGADRO_CONSTANT * BOLTZMANN_CONSTANT
|
|
35
35
|
STANDARD_ATMOSPHERE: pint.Quantity = Quantity(101_325, "Pa")
|
|
36
|
+
STEFAN_BOLTZMANN_CONSTANT: pint.Quantity = to_unit(
|
|
37
|
+
(2.0 * (math.pi**5) * (BOLTZMANN_CONSTANT**4))
|
|
38
|
+
/ (15.0 * (PLANCK_CONSTANT**3) * (SPEED_OF_LIGHT**2)),
|
|
39
|
+
"W / (m^2 * K^4)",
|
|
40
|
+
)
|
|
36
41
|
|
|
37
42
|
# Atomic & particle masses
|
|
38
43
|
ELECTRON_MASS: pint.Quantity = Quantity(9.1093837139e-31, "kg")
|
|
@@ -51,6 +56,7 @@ __all__ = [
|
|
|
51
56
|
"SPEED_OF_LIGHT",
|
|
52
57
|
"STANDARD_ATMOSPHERE",
|
|
53
58
|
"STANDARD_GRAVITY",
|
|
59
|
+
"STEFAN_BOLTZMANN_CONSTANT",
|
|
54
60
|
"VACUUM_PERMEABILITY",
|
|
55
61
|
"VACUUM_PERMITTIVITY",
|
|
56
62
|
]
|