Skip to content

flags

cosmic_warp.core.flags

Simulation flags for enabling/disabling physics modules and features.

SimulationFlags

Flags to control which physics modules are active in the simulation.

create_flags

create_flags(
    gravity: bool,
    j2_perturbation: bool,
    gravity_gradient: bool,
    magnetic_torque: bool,
    drag: bool,
    check_bounds: bool,
    check_planet_impact: bool,
    device: str = "cuda",
) -> array

Create simulation flags array for multiple environments.

Parameters:

Name Type Description Default
gravity bool

Enable gravitational forces

required
j2_perturbation bool

Enable J2 perturbation (requires gravity=True)

required
gravity_gradient bool

Enable gravity gradient torque

required
magnetic_torque bool

Enable magnetic torque (requires vehicle.magnetic_dipole set)

required
drag bool

Enable atmospheric drag force (uses vehicle.area_drag and vehicle.cd)

required
check_bounds bool

Check position bounds

required
check_planet_impact bool

Check for impact with the central body

required
device str

Device to allocate on ("cuda" or "cpu")

'cuda'

Returns:

Type Description
array

WARP array with SimulationFlags struct

Source code in cosmic_warp/core/flags.py
def create_flags(
    gravity: bool,
    j2_perturbation: bool,
    gravity_gradient: bool,
    magnetic_torque: bool,
    drag: bool,
    check_bounds: bool,
    check_planet_impact: bool,
    device: str = "cuda"
) -> wp.array:
    """
    Create simulation flags array for multiple environments.

    Args:
        gravity: Enable gravitational forces
        j2_perturbation: Enable J2 perturbation (requires gravity=True)
        gravity_gradient: Enable gravity gradient torque
        magnetic_torque: Enable magnetic torque (requires vehicle.magnetic_dipole set)
        drag: Enable atmospheric drag force (uses vehicle.area_drag and vehicle.cd)
        check_bounds: Check position bounds
        check_planet_impact: Check for impact with the central body
        device: Device to allocate on ("cuda" or "cpu")

    Returns:
        WARP array with SimulationFlags struct
    """
    # Allocate on device and initialize via a small kernel to ensure values
    # are written on the device-side struct (avoids host->device view issues).
    flags = wp.zeros(1, dtype=SimulationFlags, device=device)

    wp.launch(
        kernel=_init_flags_kernel,
        dim=1,
        inputs=[
            flags,
            bool(gravity),
            bool(j2_perturbation),
            bool(gravity_gradient),
            bool(magnetic_torque),
            bool(drag),
            bool(check_bounds),
            bool(check_planet_impact),
        ],
        device=device,
    )

    return flags