Skip to main content

powerio_tx/
lib.rs

1//! Typed balanced network models and format implementations.
2//!
3//! Readers and writers cover MATPOWER `.m`, PowerModels JSON, PSS/E `.raw`,
4//! PowerWorld `.aux`, pandapower JSON, PyPSA CSV, egret JSON, PSLF `.epc`,
5//! PSS/E RAWX 35, PowSybl XIIDM and JIIDM 1.0 through 1.17, CIM CGMES 2.4.15 and 3.0,
6//! Surge JSON,
7//! and DeepMind OPFData JSON. PowerWorld `.pwb`, OPFData files, and the IEEE
8//! Common Data Format are read
9//! only. GO Challenge 3 defines a calculation and therefore parses only
10//! through the top level `powerio::parse`, which returns its declared
11//! `AcScucInstance` or `AcScucSolution`. `.pwd` display files parse through
12//! the facade's `parse`, which returns `powerio.GeoLayer`.
13//! Each reader produces a [`BalancedNetwork`]. The top level `powerio` facade
14//! owns universal parsing and `emit`; this component crate supplies the typed
15//! transmission implementation.
16//!
17//! A reader that retains source text can return those bytes when writing the
18//! same format. Matrix and problem instance builders live in separate crates.
19//!
20//! SINCAL adapters are provided by `powerio_tnd::formats::sincal` and the
21//! `powerio` facade. This model crate is independent of SQLite and integration.
22//!
23//! ```
24//! use powerio_core::Source;
25//! use powerio_tx::{parse, parse_format_id};
26//!
27//! let src = "\
28//! function mpc = example
29//! mpc.version = '2';
30//! mpc.baseMVA = 100;
31//! mpc.bus = [
32//! \t1\t3\t0\t0\t0\t0\t1\t1\t0\t230\t1\t1.1\t0.9;
33//! \t2\t1\t0\t0\t0\t0\t1\t1\t0\t230\t1\t1.1\t0.9;
34//! ];
35//! mpc.branch = [
36//! \t1\t2\t0.01\t0.1\t0\t0\t0\t0\t0\t0\t1\t-360\t360;
37//! ];
38//! ";
39//! let source = Source::from_memory("example.m", src.as_bytes().to_vec())?
40//!     .with_format(parse_format_id("matpower")?);
41//! let module = parse(source)?;
42//! assert_eq!(module.value().buses().len(), 2);
43//! # Ok::<(), powerio_core::Error>(())
44//! ```
45
46/// The powerio crate version, for provenance fields written by downstream
47/// crates whose own version can drift from the core's.
48pub const VERSION: &str = env!("CARGO_PKG_VERSION");
49
50mod collect;
51pub mod contingency;
52pub mod dc;
53pub mod diagnostics;
54pub mod dynamic;
55pub mod error;
56pub mod format;
57pub mod gen_cost;
58pub mod geo;
59pub mod hvdc;
60pub mod indexed;
61pub mod islands;
62pub mod lcc;
63pub mod merge;
64pub mod network;
65mod normalize;
66mod operations;
67#[doc(hidden)]
68pub mod version;
69
70/// Unsupported implementation details shared with other PowerIO crates.
71///
72/// These items can change without notice and are not part of the
73/// `powerio-tx` API. Applications should use the top level `powerio` facade.
74#[doc(hidden)]
75pub mod __internal {
76    use powerio_core::ComponentId;
77
78    #[doc(hidden)]
79    pub use crate::format::goc3::{Goc3Document, Goc3Record, parse_goc3_instance_network};
80
81    use crate::{BalancedNetwork, Generator, Load, OmittedFieldName};
82
83    #[doc(hidden)]
84    pub fn edit_load_assignment<R>(
85        network: &mut BalancedNetwork,
86        index: usize,
87        component: &ComponentId,
88        field: OmittedFieldName,
89        edit: impl FnOnce(&mut Load) -> R,
90    ) -> R {
91        network.edit_load_assignment(index, component, field, edit)
92    }
93
94    #[doc(hidden)]
95    pub fn edit_generator_assignment<R>(
96        network: &mut BalancedNetwork,
97        index: usize,
98        component: &ComponentId,
99        field: OmittedFieldName,
100        edit: impl FnOnce(&mut Generator) -> R,
101    ) -> R {
102        network.edit_generator_assignment(index, component, field, edit)
103    }
104}
105
106pub use contingency::{
107    AutomaticOrder, AutomaticSpec, AutomaticTarget, BranchRef, Change, ChangeOp, ChangeUnit,
108    ContingencyAction, ContingencyCase, ContingencyParsed, ContingencyResolution, ContingencySet,
109    DefaultDispatch, DispatchBlock, DispatchEntry, DispatchLevel, DispatchedAction, Expanded,
110    InterfaceMember, JoinName, MonitorScope, MonitorStatement, MonitoredParsed,
111    MonitoredResolution, MonitoredSet, PsseEquipmentIndex, ResolvedCase, ResolvedComponent,
112    ResolvedInterface, ResolvedVoltageScope, RetainedStatement, ScaledQuantity, SelectorGroup,
113    SharedPsseEquipmentIndex, SkipRule, Subsystem, SubsystemDispatchRule, SubsystemParsed,
114    SubsystemSelector, SubsystemSet, UnresolvedAction, UnresolvedMonitor, UnresolvedMonitorReason,
115    UnresolvedReason,
116};
117pub use dc::BranchSusceptanceFormula;
118pub use diagnostics::{Diagnostic, DiagnosticCode, DiagnosticSeverity, EmitFamily};
119pub use error::{Error, ErrorCategory, Result};
120pub use format::routing::{
121    Detection, JSON_CLASSES, JsonClass, classify_json_bytes, classify_json_text,
122    parse_distribution_format, parse_transmission_format,
123};
124#[cfg(test)]
125pub(crate) use format::test_parse::{parse_file, parse_str};
126pub use format::{
127    EmitOptions, PwdDisplay, PwdSubstation, SOURCE_FORMAT_NAMES, TargetFormat, emit,
128    emit_with_options, parse, parse_format_id, parse_target_format,
129};
130
131#[doc(hidden)]
132pub use format::{
133    __emit_pypsa_csv, __emit_pypsa_csv_with_options, __parse_opfdata_json,
134    __parse_pypsa_csv_time_series,
135};
136pub use gen_cost::{GenCostPatch, GenCostPolicyReport, MissingGenCostPolicy, parse_gen_cost_csv};
137pub use geo::{
138    Canvas, CoordinateSpace, CoordsKind, ElementKey, GeoApplyReport, GeoFeature, GeoGeometry,
139    GeoLayer, GeoMeta, GeoParsed, GeoTarget, Location, apply_substation_points,
140    to_geo_layer_from_aux_substations, to_geo_layer_from_pwd, to_lonlat_from_pwd_mercator,
141};
142pub use hvdc::{HvdcInjections, HvdcTerminalInjection, HvdcTerminalPowers, HvdcTreatment};
143pub use indexed::{ConnectivityReport, IndexCore, IndexedNetwork};
144pub use islands::{Island, IslandPartition, IslandReferencePolicy, IslandReferenceReport};
145pub use lcc::{LccConverterState, LccOperatingPoint};
146pub use merge::{
147    BusGroup, BusMerge, BusMergeRule, MergeSurvivor, MergedCharging, MergedFlows,
148    PSSE_DEFAULT_ZERO_IMPEDANCE_THRESHOLD, RemovalReason, RemovedBranch, RemovedFlow,
149    RemovedFlowMethod, RemovedFlows, RemovedSwitch, ZeroImpedanceRule,
150};
151pub use network::{
152    AcDcConverterControlMode, ActivePowerControl, Area, BalancedNetwork, BoundaryLine,
153    BoundaryLineGeneration, Branch, BranchCharging, BranchCurrentRatings, BranchRatingSet,
154    BranchSolution, Bus, BusBreakerBus, BusId, BusType, BusbarSection, CalculatedBus, CaseMetadata,
155    ComponentAlias, ComponentMetadata, ConnectivityNode, CurveStyle, DEFAULT_BASE_FREQUENCY,
156    DcBusbar, DcConverterOperatingMode, DcConverterUnit, DcGround, DcLine, DcNode, DcPolarity,
157    DcSeriesDevice, DcSwitch, DcSwitchKind, DcTerminal, DcTopologicalNode, DetailedConnectivity,
158    DroopCurve, DroopCurveSegment, ExternalIdentifier, Extras, GenCaps, GenCost, Generator,
159    GeneratorEnergySource, Hvdc, HvdcConverter, HvdcConverterKind, HvdcConvertersMode, Impedance,
160    ImpedanceCorrection, ImpedanceCorrectionPoint, ImpedanceCorrectionVariable, InternalConnection,
161    Junction, LineCommutatedConverter, LineCommutatedConverterOperatingMode,
162    LineCommutatedConverterReactiveModel, Load, LoadVoltageModel, LoadingLimits,
163    MinMaxReactiveLimits, OmittedField, OmittedFieldName, OperationalLimitGroup,
164    ReactiveCapabilityCurve, ReactiveCapabilityCurvePoint, ReactiveLimits, Shunt, ShuntBlock,
165    SolverParams, SourceFormat, StaticVarCompensator, StaticVarCompensatorRegulationMode, Storage,
166    Subnetwork, Substation, Switch, SwitchKind, SwitchedShuntControl, SwitchedShuntMode,
167    TapChanger, TapChangerKind, TapChangerRegulationMode, TapChangerStep, TemporaryLimit, Terminal,
168    TerminalReference, TieLine, TopologyEndpoint, TopologyKind, TopologySwitch, Transformer3W,
169    TransformerControl, TransformerControlMode, VoltageLevel, VoltageSourceConverter, Winding,
170    calc_series_admittance_of, repair_values,
171};
172pub use normalize::{
173    AngleDifferenceBounds, ClosedSwitchPolicy, NormalizeOptions, NormalizeReport,
174    NormalizeSettings, NormalizeSourceRows, NormalizedNetwork, POWER_MODELS_ANGLE_BOUND_PAD,
175    correct_angle_difference_bounds, stated_angle_difference_bounds,
176};
177pub use operations::{BusSubset, Selector, ZeroImpedanceReduction};