Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

API — LinDistFlow

LinDistFlowResult

Dataclass returned by the LinDistFlow solver.

FieldTypeDescription
successboolWhether the solve completed
messagestrStatus message
source_busstrName of the source/root bus
voltage_vdict[BusPhaseLabel, float]Bus-phase voltage magnitudes (V)
p_flow_wdict[BranchPhaseLabel, float]Branch active power flows (W)
q_flow_vardict[BranchPhaseLabel, float]Branch reactive power flows (var)
p_net_wdict[BusPhaseLabel, float]Net active power at each bus (W)
q_net_vardict[BusPhaseLabel, float]Net reactive power at each bus (var)

Type aliases:

solve_lindistflow

Main solver function.

def solve_lindistflow(
    system: DistributionSystem,
    *,
    p_net_w: dict[BusPhaseLabel, float] | None = None,
    q_net_var: dict[BusPhaseLabel, float] | None = None,
    include_neutral: bool = False,
    include_shunt: bool = True,
    include_transformers: bool = True,
    frequency_hz: float = 60.0,
    debug: bool = False,
) -> LinDistFlowResult:

Parameters:

ParameterDefaultDescription
p_net_wNoneNet active power per node (W). Auto-built from components if omitted.
q_net_varNoneNet reactive power per node (var). Auto-built from components if omitted.
include_neutralFalseInclude neutral phase nodes in Y-bus
include_shuntTrueInclude line charging in Y-bus
include_transformersTrueInclude transformers in Y-bus
frequency_hz60.0System frequency
debugFalsePrint diagnostic information

When p_net_w and q_net_var are both None, the solver automatically calls build_lindistflow_net_injections_from_components to extract loads, solar, batteries, and capacitors.

build_lindistflow_net_injections_from_components

def build_lindistflow_net_injections_from_components(
    system: DistributionSystem,
    *,
    include_loads: bool = True,
    include_solar: bool = True,
    include_battery: bool = True,
    include_capacitor: bool = True,
) -> tuple[dict[BusPhaseLabel, float], dict[BusPhaseLabel, float]]:

Returns (p_net_w, q_net_var) from system components.

Sign convention:

Example:

from gdm_flow import build_lindistflow_net_injections_from_components

p_net, q_net = build_lindistflow_net_injections_from_components(
    system,
    include_loads=True,
    include_solar=True,
)

# Modify injections
p_net[("bus_3", "A")] += 1000.0  # Add 1 kW load

from gdm_flow import solve_lindistflow
result = solve_lindistflow(system, p_net_w=p_net, q_net_var=q_net)