Skip to content

Commit 411fdaa

Browse files
committed
1.22.3 modifiers and forces
1 parent 41d1839 commit 411fdaa

File tree

8 files changed

+78
-5
lines changed

8 files changed

+78
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Axinite uses a derivative of the **semantic versioning system** to record change
55
- Patch increments represent bug fixes, modifications that don't directly affect users, progress towards a milestone/goal, or other small changes.
66

77
Although releases are only created for every minor or major increment, patch increments are still uploaded to PyPI.
8-
# 1.22.1-1.22.2 (1/29/25)
8+
# 1.22.1-1.22.3 (1/29/25)
9+
- Created modifier utilities (normal force, magnetic force, modifier_from)
910
- Added `energy_of` methods for energy of specific bodies
1011
- Added `can_see` methods for line of sight checks
1112
# 1.22 (1/26/35)

axinite/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from axinite.body import Body
99
from axinite.functions import vector_magnitude_jit, unit_vector_jit, gravitational_force_jit, body_dtype, \
1010
get_inner_bodies, _body, create_outer_bodies, timestep, interpret_distance, interpret_mass, interpret_time, \
11-
timesteps, clip_scalar, G, state, time_to, mass_to, distance_to, round_limit, gravitational_forces
11+
timesteps, clip_scalar, G, state, time_to, mass_to, distance_to, round_limit, gravitational_forces, locate_body
1212
import axinite.functions as functions
1313
from axinite.load import load
1414
from axinite.backends.euler import euler_backend, euler_nojit_backend

axinite/functions.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,11 @@ def gravitational_forces(bodies, body, i, n):
326326
f = np.zeros(3)
327327
for j, other in enumerate(bodies):
328328
if i != j: f += ax.gravitational_force_jit(body["m"], other["m"], body["r"][n] - other["r"][n])
329-
return f
329+
return f
330+
331+
@njit
332+
def locate_body(body, bodies):
333+
for i, b in enumerate(bodies):
334+
if b["n"] == body["n"]:
335+
return i
336+
return -1

axinite/utils/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
from axinite.utils.autopilots import rocket_autopilot
1+
from axinite.utils.autopilots import rocket_autopilot
2+
from axinite.utils.normal import normal_force_modifier
3+
from axinite.utils.magnetic import magnetic_force_modifier
4+
from axinite.utils.modifier import modifier_from

axinite/utils/magnetic.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import numpy as np
2+
import axinite as ax
3+
4+
def magnetic_force_modifier(charges, magnetic_field):
5+
"""
6+
Returns a modifier function to calculate the magnetic force between bodies in a magnetic field.
7+
8+
Args:
9+
charges (np.ndarray): An array mapping body indexes to their charges.
10+
magnetic_field (np.ndarray): The magnetic field vector.
11+
12+
Returns:
13+
function: A modifier function to calculate the magnetic force.
14+
"""
15+
def modifier(body, f, bodies, t, delta, limit, n):
16+
charge = charges[ax.locate_body(body, bodies)]
17+
18+
for i, other in enumerate(bodies):
19+
other_charge = charges[i]
20+
if other_charge == 0:
21+
continue
22+
23+
distance_vector = other["r"][n-1] - body["r"][n-1]
24+
distance = np.linalg.norm(distance_vector)
25+
26+
force = charge * other_charge * np.cross(magnetic_field, distance_vector) / distance**2
27+
f += force
28+
29+
return f
30+
return modifier

axinite/utils/modifier.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import axinite as ax
2+
3+
def modifier_from(functions: list[tuple['function', 'function']]) -> 'function':
4+
def modifier(body, f, bodies, t, delta, limit, n):
5+
for function in functions:
6+
if function[0](body, f, bodies, t, delta, limit, n):
7+
f = function[1](body, f, bodies, t, delta, limit, n)
8+
return f
9+
return modifier

axinite/utils/normal.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import numpy as np
2+
import axinite as ax
3+
4+
def normal_force_modifier():
5+
"""
6+
Returns a modifier function to calculate the normal force between bodies.
7+
8+
Returns:
9+
function: A modifier function to calculate the normal force.
10+
"""
11+
def modifier(body, f, bodies, t, delta, limit, n):
12+
for other in bodies:
13+
if np.array_equal(body["r"][n-1], other["r"][n-1]):
14+
continue
15+
16+
distance_vector = other["r"][n-1] - body["r"][n-1]
17+
distance = np.linalg.norm(distance_vector)
18+
normal_vector = distance_vector / distance
19+
force_magnitude = body["m"] * other["m"] * ax.G / distance**2
20+
f += force_magnitude * normal_vector
21+
22+
return f
23+
return modifier

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "axinite"
7-
version = "1.22.2"
7+
version = "1.22.3"
88
dependencies = ["numpy", "numba", "vpython", "plotly"]
99
authors = [{ name = "Jewels", email = "jewels@jewels86.me" }]
1010
maintainers = [{ name = "Jewels", email = "jewels@jewels86.me" }]

0 commit comments

Comments
 (0)