File size: 1,419 Bytes
b99b9ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from __future__ import annotations

from typing import Callable

from physix.systems.base import PhysicalSystem, SystemTier
from physix.systems.tier1 import FreeFall, FreeFallWithDrag, SimplePendulum
from physix.systems.tier2 import DampedPendulum, DampedSpring, SpringMass
from physix.systems.tier3 import ChargedInBField, ProjectileWithDrag


SystemFactory = Callable[[], PhysicalSystem]


SYSTEM_REGISTRY: dict[str, SystemFactory] = {
    "free_fall": FreeFall,
    "free_fall_drag": FreeFallWithDrag,
    "simple_pendulum": SimplePendulum,
    "damped_pendulum": DampedPendulum,
    "spring_mass": SpringMass,
    "damped_spring": DampedSpring,
    "projectile_drag": ProjectileWithDrag,
    "charged_b_field": ChargedInBField,
}

SUPPORTED_SYSTEMS: tuple[str, ...] = (
    "free_fall",
    "damped_spring",
    "simple_pendulum",
)


def get_system(system_id: str) -> PhysicalSystem:
    if system_id not in SYSTEM_REGISTRY:
        valid = ", ".join(sorted(SYSTEM_REGISTRY))
        raise KeyError(f"Unknown system_id={system_id!r}. Valid: {valid}")
    return SYSTEM_REGISTRY[system_id]()


def list_systems() -> list[str]:
    return list(SYSTEM_REGISTRY)


def list_systems_by_tier(tier: SystemTier) -> list[str]:
    return [sid for sid, cls in SYSTEM_REGISTRY.items() if cls().tier == tier]


def list_supported_systems() -> list[str]:
    return [sid for sid in SUPPORTED_SYSTEMS if sid in SYSTEM_REGISTRY]