opalib 0.4.2__tar.gz → 0.5.3__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.
Files changed (35) hide show
  1. {opalib-0.4.2 → opalib-0.5.3}/PKG-INFO +1 -1
  2. {opalib-0.4.2 → opalib-0.5.3}/pyproject.toml +1 -1
  3. opalib-0.5.3/src/opalib/physics.py +223 -0
  4. {opalib-0.4.2 → opalib-0.5.3}/src/opalib.egg-info/PKG-INFO +1 -1
  5. opalib-0.4.2/src/opalib/physics.py +0 -72
  6. {opalib-0.4.2 → opalib-0.5.3}/LICENSE +0 -0
  7. {opalib-0.4.2 → opalib-0.5.3}/README.md +0 -0
  8. {opalib-0.4.2 → opalib-0.5.3}/setup.cfg +0 -0
  9. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/__init__.py +0 -0
  10. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/bio_clients.py +0 -0
  11. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/enum_extender.py +0 -0
  12. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/examples/example_1.py +0 -0
  13. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/examples/example_2.py +0 -0
  14. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/examples/mesh_formats.py +0 -0
  15. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/format.py +0 -0
  16. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/http.py +0 -0
  17. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/ieee754.py +0 -0
  18. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/libdeflate.py +0 -0
  19. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/promise.py +0 -0
  20. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/tests/bio_clients_test.py +0 -0
  21. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/tests/enum_test.py +0 -0
  22. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/tests/format_test.py +0 -0
  23. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/tests/http_test.py +0 -0
  24. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/tests/ieee754_test.py +0 -0
  25. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/tests/libdeflate_test.py +0 -0
  26. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/tests/physics_test.py +0 -0
  27. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/tests/units_test.py +0 -0
  28. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/tests/util_test.py +0 -0
  29. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/tests/web_test.py +0 -0
  30. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/units.py +0 -0
  31. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/util.py +0 -0
  32. {opalib-0.4.2 → opalib-0.5.3}/src/opalib/web.py +0 -0
  33. {opalib-0.4.2 → opalib-0.5.3}/src/opalib.egg-info/SOURCES.txt +0 -0
  34. {opalib-0.4.2 → opalib-0.5.3}/src/opalib.egg-info/dependency_links.txt +0 -0
  35. {opalib-0.4.2 → opalib-0.5.3}/src/opalib.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opalib
3
- Version: 0.4.2
3
+ Version: 0.5.3
4
4
  Summary: A library to do multiple things
5
5
  Author-email: Donovan <donovandelisle7@gmail.com>
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "opalib"
3
- version = "0.4.2"
3
+ version = "0.5.3"
4
4
  description = "A library to do multiple things"
5
5
  authors = [
6
6
  { name="Donovan", email="donovandelisle7@gmail.com" }
@@ -0,0 +1,223 @@
1
+ """
2
+ opalib.physics - all of the major fields of physics calculations.
3
+ """
4
+
5
+ import math
6
+ from typing import Optional, Union, List
7
+
8
+ # SCIENTIFIC CONSTANTS
9
+ G_CONSTANT = 6.67430e-11 # Gravitational Constant (m^3 kg^-1 s^-2)
10
+ C_SPEED_LIGHT = 299792458 # Speed of Light in vacuum (m/s)
11
+ H_PLANCK = 6.62607015e-34 # Planck Constant (J*s)
12
+ K_BOLTZMANN = 1.380649e-23 # Boltzmann Constant (J/K)
13
+ E_CHARGE = 1.60217663e-19 # Elementary Charge (Coulombs)
14
+ EPSILON_0 = 8.85418781e-12 # Vacuum Permittivity (F/m)
15
+ K_COULOMB = 8.98755179e9 # Coulomb Constant (N*m^2/C^2)
16
+ G_EARTH = 9.80665 # Standard Earth gravity (m/s^2)
17
+ R_UNIVERSAL = 8.3144626 # Universal Gas Constant (J/mol*K)
18
+
19
+ # KINEMATICS & PROJECTILE MOTION (w/ CUSTOM GRAVITY)
20
+ def kinematic_v(u: float, a: float, t: float) -> float:
21
+ """Solves v = u + at (Final Velocity)"""
22
+ return u + (a * t)
23
+
24
+ def kinematic_s(u: float, t: float, a: float) -> float:
25
+ """Solves s = ut + 0.5at^2 (Displacement)"""
26
+ return (u * t) + (0.5 * a * (t ** 2))
27
+
28
+ def kinematic_v2(u: float, a: float, s: float) -> float:
29
+ """Solves v^2 = u^2 + 2as. Returns final velocity v (handles negatives safely)."""
30
+ val = (u ** 2) + (2 * a * s)
31
+ return math.sqrt(val) if val >= 0 else 0.0
32
+
33
+ def kinematic_s_no_a(u: float, v: float, t: float) -> float:
34
+ """Solves s = 0.5 * (u + v) * t"""
35
+ return 0.5 * (u + v) * t
36
+
37
+ def time_of_flight(v0: float, theta_deg: float, g: float = G_EARTH) -> float:
38
+ """Solves t = (2 * v0 * sin(theta)) / g. Returns inf if gravity is zero."""
39
+ if g <= 0: return float('inf')
40
+ return (2 * v0 * math.sin(math.radians(theta_deg))) / g
41
+
42
+ def horizontal_range(v0: float, theta_deg: float, g: float = G_EARTH) -> float:
43
+ """Solves R = (v0^2 * sin(2*theta)) / g. Returns inf if gravity is zero."""
44
+ if g <= 0: return float('inf')
45
+ return (v0**2 * math.sin(2 * math.radians(theta_deg))) / g
46
+
47
+ def max_height(v0: float, theta_deg: float, g: float = G_EARTH) -> float:
48
+ """Solves H = (v0^2 * sin^2(theta)) / (2g). Returns inf if gravity is zero."""
49
+ if g <= 0: return float('inf')
50
+ return (v0**2 * (math.sin(math.radians(theta_deg))**2)) / (2 * g)
51
+
52
+ def free_fall_time(height: float, g: float = G_EARTH) -> float:
53
+ """Solves t = sqrt(2h / g). Airtime when dropping straight down."""
54
+ if g <= 0 or height < 0: return float('inf')
55
+ return math.sqrt((2 * height) / g)
56
+
57
+ # DYNAMICS, FORCE, & ENERGY
58
+ def newton_second_law(m: Optional[float] = None, a: Optional[float] = None, f: Optional[float] = None) -> float:
59
+ """Solves F = m * a for whichever single parameter is omitted (None)."""
60
+ if f is None and m is not None and a is not None: return m * a
61
+ if m is None and f is not None and a is not None: return f / a if a != 0 else float('inf')
62
+ if a is None and f is not None and m is not None: return f / m if m != 0 else float('inf')
63
+ raise ValueError("Provide exactly two arguments.")
64
+
65
+ def kinetic_energy(m: float, v: float) -> float:
66
+ """Solves KE = 0.5 * m * v^2"""
67
+ return 0.5 * m * (v ** 2)
68
+
69
+ def potential_energy(m: float, h: float, g: float = G_EARTH) -> float:
70
+ """Solves PE = m * g * h"""
71
+ return m * g * h
72
+
73
+ def spring_potential_energy(k: float, x: float) -> float:
74
+ """Solves PE_spring = 0.5 * k * x^2 (Hooke's Law Energy)"""
75
+ return 0.5 * k * (x ** 2)
76
+
77
+ def hookes_law_force(k: float, x: float) -> float:
78
+ """Solves F = -k * x (Spring Restoring Force)"""
79
+ return -k * x
80
+
81
+ def momentum(m: float, v: float) -> float:
82
+ """Solves p = m * v"""
83
+ return m * v
84
+
85
+ def impulse(force: float, time_delta: float) -> float:
86
+ """Solves J = F * delta_t"""
87
+ return force * time_delta
88
+
89
+ def work_done(force: float, distance: float, theta_deg: float = 0.0) -> float:
90
+ """Solves W = F * d * cos(theta)"""
91
+ return force * distance * math.cos(math.radians(theta_deg))
92
+
93
+ def power(work: float, time: float) -> float:
94
+ """Solves P = W / t"""
95
+ return work / time if time != 0 else float('inf')
96
+
97
+ def friction_force(mu: float, normal_force: float) -> float:
98
+ """Solves F_f = mu * F_N (Static/Kinetic Friction)"""
99
+ return mu * normal_force
100
+
101
+ # ROTATIONAL MECHANICS
102
+ def angular_velocity(theta_rad: float, time: float) -> float:
103
+ """Solves omega = delta_theta / t"""
104
+ return theta_rad / time if time != 0 else float('inf')
105
+
106
+ def centripetal_acceleration(v_linear: float, radius: float) -> float:
107
+ """Solves a_c = v^2 / r"""
108
+ return (v_linear ** 2) / radius if radius != 0 else float('inf')
109
+
110
+ def centripetal_force(m: float, v_linear: float, radius: float) -> float:
111
+ """Solves F_c = m * v^2 / r"""
112
+ return (m * (v_linear ** 2)) / radius if radius != 0 else float('inf')
113
+
114
+ def torque(force: float, radius: float, theta_deg: float = 90.0) -> float:
115
+ """Solves tau = r * F * sin(theta)"""
116
+ return radius * force * math.sin(math.radians(theta_deg))
117
+
118
+ def pendulum_period(length: float, g: float = G_EARTH) -> float:
119
+ """Solves T = 2 * pi * sqrt(L / g)"""
120
+ if g <= 0 or length < 0: return float('inf')
121
+ return 2 * math.pi * math.sqrt(length / g)
122
+
123
+ def mass_spring_period(m: float, k: float) -> float:
124
+ """Solves T = 2 * pi * sqrt(m / k)"""
125
+ if k <= 0 or m < 0: return float('inf')
126
+ return 2 * math.pi * math.sqrt(m / k)
127
+
128
+ # GRAVITATION & ORBITAL SPACE PHYSICS
129
+ def gravitational_force(m1: float, m2: float, r: float) -> float:
130
+ """Solves F = G * m1 * m2 / r^2"""
131
+ return (G_CONSTANT * m1 * m2) / (r ** 2) if r != 0 else float('inf')
132
+
133
+ def calculate_surface_gravity(mass: float, radius: float) -> float:
134
+ """Solves g = G * M / r^2"""
135
+ return (G_CONSTANT * mass) / (radius ** 2) if radius != 0 else float('inf')
136
+
137
+ def orbital_velocity(m_central: float, r: float) -> float:
138
+ """Solves v = sqrt(G * M / r)"""
139
+ if r <= 0: return float('inf')
140
+ return math.sqrt((G_CONSTANT * m_central) / r)
141
+
142
+ def escape_velocity(m_central: float, r: float) -> float:
143
+ """Solves v_e = sqrt(2 * G * M / r)"""
144
+ if r <= 0: return float('inf')
145
+ return math.sqrt((2 * G_CONSTANT * m_central) / r)
146
+
147
+ # FLUID DYNAMICS & HYDROSTATICS
148
+ def fluid_pressure(density: float, depth: float, g: float = G_EARTH, p_atm: float = 101325.0) -> float:
149
+ """Solves P = P_0 + rho * g * h"""
150
+ return p_atm + (density * g * depth)
151
+
152
+ def buoyant_force(fluid_density: float, volume_submerged: float, g: float = G_EARTH) -> float:
153
+ """Solves F_b = rho * V * g (Archimedes' Principle)"""
154
+ return fluid_density * volume_submerged * g
155
+
156
+ def torricelli_velocity(h: float, g: float = G_EARTH) -> float:
157
+ """Solves v = sqrt(2 * g * h) (Fluid draining velocity)"""
158
+ val = 2 * g * h
159
+ return math.sqrt(val) if val >= 0 else 0.0
160
+
161
+ # THERMODYNAMICS & GASES
162
+ def ideal_gas_law(p: Optional[float] = None, v: Optional[float] = None,
163
+ n: Optional[float] = None, t: Optional[float] = None) -> float:
164
+ """Solves PV = nRT for whichever single argument is left out (None)."""
165
+ if p is None: return (n * R_UNIVERSAL * t) / v
166
+ if v is None: return (n * R_UNIVERSAL * t) / p
167
+ if n is None: return (p * v) / (R_UNIVERSAL * t)
168
+ if t is None: return (p * v) / (n * R_UNIVERSAL)
169
+ raise ValueError("Provide exactly three arguments.")
170
+
171
+ def heat_energy(m: float, c: float, delta_t: float) -> float:
172
+ """Solves Q = m * c * delta_T (Specific Heat Capacity transfer)"""
173
+ return m * c * delta_t
174
+
175
+ # ELECTRICITY & CIRCUIT PROPERTIES
176
+ def ohms_law(v: Optional[float] = None, i: Optional[float] = None, r: Optional[float] = None) -> float:
177
+ """Solves V = I * R for whichever single parameter is omitted (None)."""
178
+ if v is None: return i * r
179
+ if i is None: return v / r if r != 0 else float('inf')
180
+ if r is None: return v / i if i != 0 else float('inf')
181
+ raise ValueError("Provide exactly two arguments.")
182
+
183
+ def electrical_power(v: float, i: float) -> float:
184
+ """Solves P = V * I"""
185
+ return v * i
186
+
187
+ def coulomb_law(q1: float, q2: float, r: float) -> float:
188
+ """Solves F = k * |q1 * q2| / r^2 (Electrostatic Force)"""
189
+ return (K_COULOMB * abs(q1 * q2)) / (r ** 2) if r != 0 else float('inf')
190
+
191
+ def series_resistance(resistors: List[float]) -> float:
192
+ """Calculates total resistance in series: R1 + R2 + ..."""
193
+ return sum(resistors)
194
+
195
+ def parallel_resistance(resistors: List[float]) -> float:
196
+ """Calculates total resistance in parallel: 1 / (1/R1 + 1/R2 + ...)"""
197
+ if 0.0 in resistors: return 0.0
198
+ return 1.0 / sum(1.0 / r for r in resistors)
199
+
200
+ # WAVES & OPTICS
201
+ def wave_speed(frequency: float, wavelength: float) -> float:
202
+ """Solves v = f * lambda"""
203
+ return frequency * wavelength
204
+
205
+ def snells_law_n2(n1: float, theta1_deg: float, theta2_deg: float) -> float:
206
+ """Solves n1 * sin(theta1) = n2 * sin(theta2) for refractive index n2."""
207
+ sin_t2 = math.sin(math.radians(theta2_deg))
208
+ if sin_t2 == 0: return float('inf')
209
+ return (n1 * math.sin(math.radians(theta1_deg))) / sin_t2
210
+
211
+ # MODERN & QUANTUM PHYSICS
212
+ def mass_energy_equivalence(m: float) -> float:
213
+ """Solves E = m * c^2"""
214
+ return m * (C_SPEED_LIGHT ** 2)
215
+
216
+ def photon_energy(frequency: float) -> float:
217
+ """Solves E = h * f"""
218
+ return H_PLANCK * frequency
219
+
220
+ def de_broglie_wavelength(m: float, v: float) -> float:
221
+ """Solves lambda = h / (m * v)"""
222
+ p = m * v
223
+ return H_PLANCK / p if p != 0 else float('inf')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opalib
3
- Version: 0.4.2
3
+ Version: 0.5.3
4
4
  Summary: A library to do multiple things
5
5
  Author-email: Donovan <donovandelisle7@gmail.com>
6
6
  License-Expression: MIT
@@ -1,72 +0,0 @@
1
- """opalib.physics - simple physics helpers for motion and gravity calculations."""
2
-
3
- from math import radians, sin, sqrt
4
- from typing import Dict
5
-
6
- GRAVITY_EARTH = 9.80665
7
- GRAVITY_MOON = 1.62
8
- GRAVITY_MARS = 3.71
9
-
10
- __all__ = [
11
- "GRAVITY_EARTH",
12
- "GRAVITY_MOON",
13
- "GRAVITY_MARS",
14
- "force",
15
- "kinetic_energy",
16
- "potential_energy",
17
- "fall_time",
18
- "projectile_max_height",
19
- "projectile_range",
20
- "projectile_time_of_flight",
21
- ]
22
-
23
-
24
- def force(mass: float, acceleration: float) -> float:
25
- """Calculate force from mass and acceleration (F = m * a)."""
26
- return mass * acceleration
27
-
28
-
29
- def kinetic_energy(mass: float, velocity: float) -> float:
30
- """Calculate kinetic energy in joules (1/2 m v^2)."""
31
- return 0.5 * mass * velocity * velocity
32
-
33
-
34
- def potential_energy(mass: float, height: float, gravity: float = GRAVITY_EARTH) -> float:
35
- """Calculate gravitational potential energy in joules (m * g * h)."""
36
- return mass * gravity * height
37
-
38
-
39
- def fall_time(height: float, gravity: float = GRAVITY_EARTH) -> float:
40
- """Estimate free-fall time from a height using t = sqrt(2h/g)."""
41
- if height < 0:
42
- raise ValueError("Height must be non-negative")
43
- return sqrt(2 * height / gravity)
44
-
45
-
46
- def projectile_range(velocity: float, angle_deg: float, gravity: float = GRAVITY_EARTH) -> float:
47
- """Compute the horizontal range of a projectile launched at an angle."""
48
- angle_rad = radians(angle_deg)
49
- return (velocity * velocity * sin(2 * angle_rad)) / gravity
50
-
51
-
52
- def projectile_max_height(velocity: float, angle_deg: float, gravity: float = GRAVITY_EARTH) -> float:
53
- """Compute the maximum height reached by a projectile."""
54
- angle_rad = radians(angle_deg)
55
- return (velocity * velocity * sin(angle_rad) ** 2) / (2 * gravity)
56
-
57
-
58
- def projectile_time_of_flight(velocity: float, angle_deg: float, gravity: float = GRAVITY_EARTH) -> float:
59
- """Compute the total flight time for a projectile."""
60
- angle_rad = radians(angle_deg)
61
- return (2 * velocity * sin(angle_rad)) / gravity
62
-
63
-
64
- def jump_max_height(jump_power: float, gravity: float = GRAVITY_EARTH) -> float:
65
- """Estimate maximum vertical height achievable from an initial vertical velocity.
66
-
67
- Uses h = v^2 / (2*g). `jump_power` is treated as initial vertical velocity.
68
- """
69
- try:
70
- return (jump_power * jump_power) / (2 * gravity)
71
- except Exception:
72
- return 0.0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes