orbitx/physics/electrofunctions.py
def bus_electricity(component_resistances: np.ndarray) -> OhmicVars:
    """Given resistances for each component, calculate the V, I, R for the electrical bus as a whole."""

    # Calculate 1/resistance for each component, then sum them all up into a single scalar.
    # We shouldn't have to guard against divide-by-zero here, because resistances shouldn't
    # be zero. If we _do_ divide by zero, we've configured np.seterr elsewhere to raise an exception.
    sum_of_reciprocals = np.sum(np.reciprocal(component_resistances))

    if sum_of_reciprocals == 0:
        # There are no components connected, so this simplifies our calculations.
        return OhmicVars(resistance=np.inf, current=0, voltage=electroconstants.NOMINAL_BUS_VOLTAGE)

    bus_resistance = 1/sum_of_reciprocals

    # Assuming the hab reactor has an internal resistance, calculate the voltage drop given the bus load.
    # This equation is derived from https://en.wikipedia.org/wiki/Internal_resistance, specifically
    # R_reactor_internal = (V_bus_nominal / V_bus_loaded - 1) * R_bus_loaded
    # If we solve for V_bus_loaded (since we know the value of all other variables):
    # V_bus_loaded = V_bus_nominal / (R_reactor_internal / R_bus_loaded + 1)
    bus_voltage = (
        electroconstants.NOMINAL_BUS_VOLTAGE /
        (electroconstants.REACTOR_INTERNAL_RESISTANCE / bus_resistance + 1)
    )

    # Ohm's law gives us this.
    bus_current = bus_voltage / bus_resistance
    return OhmicVars(voltage=bus_voltage, current=bus_current, resistance=bus_resistance)
Given resistances for each component, calculate the V, I, R for the electrical bus as a whole.
Given resistances for each component, calculate the V, I, R for the electrical bus as a whole.
Given resistances for each component calculate the V I R for the electrical bus as a whole .
def bus_electricity(component_resistances: np.ndarray) -> OhmicVars:
    sum_of_reciprocals = np.sum(np.reciprocal(component_resistances))
    if sum_of_reciprocals == 0:
        return OhmicVars(resistance=np.inf, current=0, voltage=electroconstants.NOMINAL_BUS_VOLTAGE)
    bus_resistance = 1/sum_of_reciprocals
    bus_voltage = (
        electroconstants.NOMINAL_BUS_VOLTAGE /
        (electroconstants.REACTOR_INTERNAL_RESISTANCE / bus_resistance + 1)
    )
    bus_current = bus_voltage / bus_resistance
    return OhmicVars(voltage=bus_voltage, current=bus_current, resistance=bus_resistance)
def bus_electricity ( component_resistances : np . ndarray ) -> OhmicVars : sum_of_reciprocals = np . sum ( np . reciprocal ( component_resistances ) ) if sum_of_reciprocals == 0 : return OhmicVars ( resistance = np . inf , current = 0 , voltage = electroconstants . NOMINAL_BUS_VOLTAGE ) bus_resistance = 1 / sum_of_reciprocals bus_voltage = ( electroconstants . NOMINAL_BUS_VOLTAGE / ( electroconstants . REACTOR_INTERNAL_RESISTANCE / bus_resistance + 1 ) ) bus_current = bus_voltage / bus_resistance return OhmicVars ( voltage = bus_voltage , current = bus_current , resistance = bus_resistance )
Given resistances for each component, calculate the V, I, R for the electrical bus as a whole.
Given resistances for each component calculate the V I R for the electrical bus as a whole .
"""Given resistances for each component, calculate the V, I, R for the electrical bus as a whole.""" # Calculate 1/resistance for each component, then sum them all up into a single scalar. # We shouldn't have to guard against divide-by-zero here, because resistances shouldn't # be zero. If we _do_ divide by zero, we've configured np.seterr elsewhere to raise an exception. # There are no components connected, so this simplifies our calculations. # Assuming the hab reactor has an internal resistance, calculate the voltage drop given the bus load. # This equation is derived from https://en.wikipedia.org/wiki/Internal_resistance, specifically # R_reactor_internal = (V_bus_nominal / V_bus_loaded - 1) * R_bus_loaded # If we solve for V_bus_loaded (since we know the value of all other variables): # V_bus_loaded = V_bus_nominal / (R_reactor_internal / R_bus_loaded + 1) # Ohm's law gives us this.
component_resistances
np.ndarray