Skip to content

aggregation

cosmic_warp.physics.aggregation

compute_forces

compute_forces(
    state: State,
    vehicle: VehicleConfig,
    flags: SimulationFlags,
    thrust_force_body: vec3d,
) -> vec3d

Compute total forces acting on spacecraft.

Parameters:

Name Type Description Default
state State

Current spacecraft state

required
vehicle VehicleConfig

Vehicle configuration (mass, etc.)

required
flags SimulationFlags

Simulation flags

required
thrust_force_body vec3d

Total thruster force in the body frame [N] (from thruster_wrench, computed once per step)

required

Returns:

Type Description
vec3d

Total force vector in inertial frame [N]

Source code in cosmic_warp/physics/aggregation.py
@wp.func
def compute_forces(
    state: State,
    vehicle: VehicleConfig,
    flags: SimulationFlags,
    thrust_force_body: wp.vec3d
) -> wp.vec3d:
    """
    Compute total forces acting on spacecraft.

    Args:
        state: Current spacecraft state
        vehicle: Vehicle configuration (mass, etc.)
        flags: Simulation flags
        thrust_force_body: Total thruster force in the body frame [N]
            (from thruster_wrench, computed once per step)

    Returns:
        Total force vector in inertial frame [N]
    """
    F_tot = compute_nongravity_forces(state, vehicle, flags, thrust_force_body)

    # Gravitational force (already in inertial frame)
    if flags.gravity:
        F_tot += gravity_force(state, flags)

    return F_tot

compute_nongravity_forces

compute_nongravity_forces(
    state: State,
    vehicle: VehicleConfig,
    flags: SimulationFlags,
    thrust_force_body: vec3d,
) -> vec3d

Forces that do not scale with the spacecraft mass (drag and thrust), in the inertial frame [N]. Split out so integrators can treat them apart from gravity, which is proportional to the (changing) mass.

Source code in cosmic_warp/physics/aggregation.py
@wp.func
def compute_nongravity_forces(
    state: State,
    vehicle: VehicleConfig,
    flags: SimulationFlags,
    thrust_force_body: wp.vec3d
) -> wp.vec3d:
    """
    Forces that do not scale with the spacecraft mass (drag and thrust), in
    the inertial frame [N]. Split out so integrators can treat them apart
    from gravity, which is proportional to the (changing) mass.
    """
    F_tot = wp.vec3d()

    # Atmospheric drag (already in inertial frame)
    if flags.drag:
        F_tot += drag_force(state, vehicle)

    # Thrust force (body frame, needs rotation to inertial frame)
    F_tot += wp.quat_rotate(state.quat, thrust_force_body)

    return F_tot

compute_torques

compute_torques(
    state: State,
    vehicle: VehicleConfig,
    flags: SimulationFlags,
    thrust_torque: vec3d,
) -> vec3d

Compute total torques acting on spacecraft.

Parameters:

Name Type Description Default
state State

Current spacecraft state

required
vehicle VehicleConfig

Vehicle configuration (inertia, etc.)

required
flags SimulationFlags

Simulation flags

required
thrust_torque vec3d

Total thruster torque in the body frame [N*m] (from thruster_wrench, computed once per step)

required

Returns:

Type Description
vec3d

Total torque vector in body frame [N*m]

Source code in cosmic_warp/physics/aggregation.py
@wp.func
def compute_torques(
    state: State,
    vehicle: VehicleConfig,
    flags: SimulationFlags,
    thrust_torque: wp.vec3d,
) -> wp.vec3d:
    """
    Compute total torques acting on spacecraft.

    Args:
        state: Current spacecraft state
        vehicle: Vehicle configuration (inertia, etc.)
        flags: Simulation flags
        thrust_torque: Total thruster torque in the body frame [N*m]
            (from thruster_wrench, computed once per step)

    Returns:
        Total torque vector in body frame [N*m]
    """
    M_tot = thrust_torque

    # Gravity gradient torque
    if flags.gravity_gradient:
        M_tot += gravity_gradient_torque(state, vehicle)

    # Magnetic torque
    if flags.magnetic_torque:
        M_tot += magnetic_torque(state, vehicle)

    return M_tot