powerio-prob 0.11.7

Problem instance builders for power system analysis and optimization.
Documentation
//! The codes this crate emits.
//!
//! The record, the code grammar, and the severity ladder live in
//! `powerio-core`. This crate raises failures only: a wrapped hub or matrix
//! failure keeps its own code, so the entries here are the three an instance
//! build raises itself.

pub use powerio_core::{DiagnosticInfo, DiagnosticSeverity, check_registry};

pub mod codes {
    powerio_core::diagnostic_codes! {
        BUILD_OPERATING_POINT_SHAPE_MISMATCH = "BUILD.OPERATING_POINT.SHAPE_MISMATCH", Error,
            "an operating point column disagrees with the resolved identity layout",
            category = Data;
        BUILD_OPERATING_POINT_IDENTITY_UNKNOWN = "BUILD.OPERATING_POINT.IDENTITY_UNKNOWN", Error,
            "an operating point names an element identity the network does not declare",
            category = Data;
        VALIDATE_UPDATE_COMPONENT_TYPE = "VALIDATE.UPDATE.COMPONENT_TYPE", Error,
            "an update names the wrong component type for its field", category = Data;
        VALIDATE_UPDATE_COMPONENT_UNKNOWN = "VALIDATE.UPDATE.COMPONENT_UNKNOWN", Error,
            "an update names no component in the target value", category = Data;
        VALIDATE_UPDATE_STABLE_ID_REQUIRED = "VALIDATE.UPDATE.STABLE_ID_REQUIRED", Error,
            "an update cannot target a table row position or an unidentified component",
            category = Data;
        VALIDATE_UPDATE_COMPONENT_AMBIGUOUS = "VALIDATE.UPDATE.COMPONENT_AMBIGUOUS", Error,
            "an update identity resolves to more than one component", category = Data;
        VALIDATE_UPDATE_FIELD_UNSUPPORTED = "VALIDATE.UPDATE.FIELD_UNSUPPORTED", Error,
            "the target electrical model does not define the requested field", category = Data;
        VALIDATE_UPDATE_VALUE_INVALID = "VALIDATE.UPDATE.VALUE_INVALID", Error,
            "an update replacement value is outside the field's domain", category = Data;
        VALIDATE_UPDATE_TERMINAL_UNKNOWN = "VALIDATE.UPDATE.TERMINAL_UNKNOWN", Error,
            "an update names no terminal on its component", category = Data;
        VALIDATE_UPDATE_DUPLICATE_FIELD = "VALIDATE.UPDATE.DUPLICATE_FIELD", Error,
            "an atomic update batch assigns one component field more than once", category = Data;
        VALIDATE_UPDATE_ALLOCATION_FAILED = "VALIDATE.UPDATE.ALLOCATION_FAILED", Error,
            "an aggregate load update has no valid allocation basis", category = Data;
        BUILD_INSTANCE_NO_GENERATORS = "BUILD.INSTANCE.NO_GENERATORS", Error,
            "the case has no generator for the problem to dispatch", category = Data;
        BUILD_INSTANCE_NO_REFERENCE_BUS = "BUILD.INSTANCE.NO_REFERENCE_BUS", Error,
            "the network states no reference (slack) bus", category = Data;
        BUILD_INSTANCE_VOLTAGE_CONTROL_CONFLICT = "BUILD.INSTANCE.VOLTAGE_CONTROL_CONFLICT", Error,
            "in service generators at one bus state conflicting voltage setpoints",
            category = Data;
        BUILD_INSTANCE_SHAPE_MISMATCH = "BUILD.INSTANCE.SHAPE_MISMATCH", Error,
            "a calculation input disagrees with the network's element tables",
            category = Data;
        BUILD_INSTANCE_SWITCHING_OPTIONS_INVALID =
            "BUILD.INSTANCE.SWITCHING_OPTIONS_INVALID", Error,
            "a switching option names an unknown or repeated branch, or states an invalid cost, current limit, or budget",
            category = Data;
        BUILD_INSTANCE_TOPOLOGY_INVALID = "BUILD.INSTANCE.TOPOLOGY_INVALID", Error,
            "a final branch status vector violates the fixed branches, budgets, or islanding policy",
            category = Data;
        BUILD_LINDIST3FLOW_EXPLICIT_NEUTRAL = "BUILD.LINDIST3FLOW.EXPLICIT_NEUTRAL", Error,
            "LinDist3Flow requires a neutral-reduced conductor model", category = Data;
        BUILD_LINDIST3FLOW_UNSUPPORTED_COMPONENT =
            "BUILD.LINDIST3FLOW.UNSUPPORTED_COMPONENT", Error,
            "a network component is outside the implemented LinDist3Flow slice",
            category = Data;
        BUILD_LINDIST3FLOW_TOPOLOGY_INVALID = "BUILD.LINDIST3FLOW.TOPOLOGY_INVALID", Error,
            "the conductor-resolved network is not a valid source-covered graph", category = Data;
        BUILD_LINDIST3FLOW_MESH_APPROXIMATION =
            "BUILD.LINDIST3FLOW.MESH_APPROXIMATION", Warning,
            "a meshed LinDist3Flow model omits angle and loop-consistency equations";
        BUILD_LINDIST3FLOW_REFERENCE_INVALID = "BUILD.LINDIST3FLOW.REFERENCE_INVALID", Error,
            "the LinDist3Flow coefficient reference is missing or invalid", category = Data;
        BUILD_LINDIST3FLOW_POLICY_UNAVAILABLE = "BUILD.LINDIST3FLOW.POLICY_UNAVAILABLE", Error,
            "the requested LinDist3Flow projection policy is not implemented", category = Data;
        BUILD_LINDIST3FLOW_PREPARATION_FAILED =
            "BUILD.LINDIST3FLOW.PREPARATION_FAILED", Error,
            "a selected LinDist3Flow component preparation failed", category = Data;
        BUILD_LINDIST3FLOW_COMPONENT_LOWERED =
            "BUILD.LINDIST3FLOW.COMPONENT_LOWERED", Warning,
            "a distribution component was lowered to the LinDist3Flow vocabulary";
        BUILD_LINDIST3FLOW_COMPONENT_APPROXIMATED =
            "BUILD.LINDIST3FLOW.COMPONENT_APPROXIMATED", Warning,
            "a distribution component was approximated for LinDist3Flow";
        BUILD_LINDIST3FLOW_COMPONENT_OMITTED =
            "BUILD.LINDIST3FLOW.COMPONENT_OMITTED", Warning,
            "source data with no retained LinDist3Flow role was omitted";
        BUILD_LINDIST3FLOW_FIXED_DISPATCH_REQUIRED =
            "BUILD.LINDIST3FLOW.FIXED_DISPATCH_REQUIRED", Error,
            "fixed-dispatch LinDist3Flow requires fixed generator active and reactive power",
            category = Data;
        BUILD_LINDIST3FLOW_OBJECTIVE_UNSUPPORTED =
            "BUILD.LINDIST3FLOW.OBJECTIVE_UNSUPPORTED", Error,
            "the LinDist3Flow objective is outside the implemented formulation",
            category = Data;
        BUILD_LINDIST3FLOW_COST_MISSING = "BUILD.LINDIST3FLOW.COST_MISSING", Warning,
            "a dispatched resource has no active-power cost and contributes zero to the objective";
        BUILD_LINDIST3FLOW_DEVICE_INVALID = "BUILD.LINDIST3FLOW.DEVICE_INVALID", Error,
            "a LinDist3Flow device has inconsistent connection, channel, bound, or rating data",
            category = Data;
        BUILD_OPERATOR_ZERO_IMPEDANCE = "BUILD.OPERATOR.ZERO_IMPEDANCE", Error,
            "a zero impedance branch has no finite DC operator row", category = Data;
        BUILD_OPERATOR_NOT_A_NUMBER = "BUILD.OPERATOR.NOT_A_NUMBER", Error,
            "a branch value produced a non-finite operator entry", category = Data;
        BUILD_SOLUTION_SHAPE_MISMATCH = "BUILD.SOLUTION.SHAPE_MISMATCH", Error,
            "a solution column disagrees with the instance's element tables",
            category = Data;
        BUILD_SOLUTION_LIMIT_CHECK_INVALID = "BUILD.SOLUTION.LIMIT_CHECK_INVALID", Error,
            "a semantic limit check is inconsistent with its instance or reported values",
            category = Data;
        BUILD_SOLUTION_MULTIPLIER_INVALID = "BUILD.SOLUTION.MULTIPLIER_INVALID", Error,
            "a constraint multiplier is negative or non-finite", category = Data;
        BUILD_SOLUTION_TOPOLOGY_MISMATCH = "BUILD.SOLUTION.TOPOLOGY_MISMATCH", Error,
            "an AC solution does not solve the switching instance's fixed-topology problem",
            category = Data;
        BUILD_SOLUTION_VALUE_INVALID = "BUILD.SOLUTION.VALUE_INVALID", Error,
            "a solution value is non-finite, or an open branch carries flow", category = Data;
        TRANSFORM_INSTANCE_DATA_DISCARDED = "TRANSFORM.INSTANCE.DATA_DISCARDED", Warning,
            "the derived calculation does not carry part of the source instance";
        TRANSFORM_INSTANCE_ASSUMPTION = "TRANSFORM.INSTANCE.ASSUMPTION", Warning,
            "the derived calculation rests on a stated modeling assumption";
        BUILD_INSTANCE_UNSUPPORTED_COST_MODEL = "BUILD.INSTANCE.UNSUPPORTED_COST_MODEL", Error,
            "a generator cost model the instance builder cannot state", category = Data;
        BUILD_INSTANCE_PIECEWISE_COST_INVALID = "BUILD.INSTANCE.PIECEWISE_COST_INVALID", Error,
            "a piecewise linear generator cost row is malformed", category = Data;
        BUILD_INSTANCE_PIECEWISE_COST_NONCONVEX = "BUILD.INSTANCE.PIECEWISE_COST_NONCONVEX", Error,
            "a piecewise linear generator cost row is nonconvex", category = Data;
        BUILD_INSTANCE_CONCAVE_COST = "BUILD.INSTANCE.CONCAVE_COST", Error,
            "a generator cost row states a concave curve", category = Data;
        READ_INSTANCE_IO_FAILED = "READ.INSTANCE.IO_FAILED", Error,
            "an instance file could not be read", category = Io;
        REQUEST_GOC3_FORMAT_UNKNOWN = "REQUEST.GOC3.FORMAT_UNKNOWN", Error,
            "the named GOC3 source format is not one this build reads",
            category = Request;
    }

    // The bus merge codes, which the balanced model crate owns now that the
    // merge lives there. They stay constants of this module, which names
    // them since 0.11.0.

    /// `CANONICALIZE.MERGE.ZERO_IMPEDANCE`, from the `powerio-tx` registry.
    pub const CANONICALIZE_MERGE_ZERO_IMPEDANCE: powerio_core::DiagnosticInfo =
        powerio_tx::diagnostics::codes::CANONICALIZE_MERGE_ZERO_IMPEDANCE;
    /// `CANONICALIZE.MERGE.ATTRIBUTE_CONFLICT`, from the `powerio-tx` registry.
    pub const CANONICALIZE_MERGE_ATTRIBUTE_CONFLICT: powerio_core::DiagnosticInfo =
        powerio_tx::diagnostics::codes::CANONICALIZE_MERGE_ATTRIBUTE_CONFLICT;
}

/// Every code this crate declares.
#[must_use]
pub fn registry() -> Vec<&'static DiagnosticInfo> {
    codes::ALL.to_vec()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn the_registry_is_sound() {
        let problems = check_registry(registry());
        assert!(problems.is_empty(), "{problems:#?}");
    }
}