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//! ```
21//! use powerio_core::Source;
22//! use powerio_tx::{parse, parse_format_id};
23//!
24//! let src = "\
25//! function mpc = example
26//! mpc.version = '2';
27//! mpc.baseMVA = 100;
28//! mpc.bus = [
29//! \t1\t3\t0\t0\t0\t0\t1\t1\t0\t230\t1\t1.1\t0.9;
30//! \t2\t1\t0\t0\t0\t0\t1\t1\t0\t230\t1\t1.1\t0.9;
31//! ];
32//! mpc.branch = [
33//! \t1\t2\t0.01\t0.1\t0\t0\t0\t0\t0\t0\t1\t-360\t360;
34//! ];
35//! ";
36//! let source = Source::from_memory("example.m", src.as_bytes().to_vec())?
37//!     .with_format(parse_format_id("matpower")?);
38//! let module = parse(source)?;
39//! assert_eq!(module.value().buses().len(), 2);
40//! # Ok::<(), powerio_core::Error>(())
41//! ```
42
43/// The powerio crate version, for provenance fields written by downstream
44/// crates whose own version can drift from the core's.
45pub const VERSION: &str = env!("CARGO_PKG_VERSION");
46
47mod collect;
48pub mod contingency;
49pub mod dc;
50pub mod diagnostics;
51pub mod error;
52pub mod format;
53pub mod gen_cost;
54pub mod geo;
55pub mod indexed;
56pub mod network;
57mod normalize;
58mod operations;
59#[doc(hidden)]
60pub mod version;
61
62/// Unsupported implementation details shared with other PowerIO crates.
63///
64/// These items can change without notice and are not part of the
65/// `powerio-tx` API. Applications should use the top level `powerio` facade.
66#[doc(hidden)]
67pub mod __internal {
68    use powerio_core::ComponentId;
69
70    #[doc(hidden)]
71    pub use crate::format::goc3::{Goc3Document, Goc3Record, parse_goc3_instance_network};
72
73    use crate::{BalancedNetwork, Generator, Load, OmittedFieldName};
74
75    #[doc(hidden)]
76    pub fn edit_load_assignment<R>(
77        network: &mut BalancedNetwork,
78        index: usize,
79        component: &ComponentId,
80        field: OmittedFieldName,
81        edit: impl FnOnce(&mut Load) -> R,
82    ) -> R {
83        network.edit_load_assignment(index, component, field, edit)
84    }
85
86    #[doc(hidden)]
87    pub fn edit_generator_assignment<R>(
88        network: &mut BalancedNetwork,
89        index: usize,
90        component: &ComponentId,
91        field: OmittedFieldName,
92        edit: impl FnOnce(&mut Generator) -> R,
93    ) -> R {
94        network.edit_generator_assignment(index, component, field, edit)
95    }
96}
97
98pub use contingency::{
99    AutomaticOrder, AutomaticSpec, AutomaticTarget, BranchRef, Change, ChangeOp, ChangeUnit,
100    ContingencyAction, ContingencyCase, ContingencyParsed, ContingencyResolution, ContingencySet,
101    Expanded, InterfaceMember, JoinName, MonitorScope, MonitorStatement, MonitoredParsed,
102    MonitoredResolution, MonitoredSet, PsseEquipmentIndex, ResolvedCase, ResolvedComponent,
103    ResolvedInterface, ResolvedVoltageScope, RetainedStatement, SelectorGroup, SkipRule, Subsystem,
104    SubsystemParsed, SubsystemSelector, SubsystemSet, UnresolvedAction, UnresolvedMonitor,
105    UnresolvedMonitorReason, UnresolvedReason,
106};
107pub use dc::BranchSusceptanceFormula;
108pub use diagnostics::{Diagnostic, DiagnosticCode, DiagnosticSeverity, EmitFamily};
109pub use error::{Error, ErrorCategory, Result};
110pub use format::routing::{
111    Detection, JSON_CLASSES, JsonClass, classify_json_bytes, classify_json_text,
112    parse_distribution_format, parse_transmission_format,
113};
114#[cfg(test)]
115pub(crate) use format::test_parse::{parse_file, parse_str};
116pub use format::{
117    EmitOptions, PwdDisplay, PwdSubstation, SOURCE_FORMAT_NAMES, TargetFormat, emit,
118    emit_with_options, parse, parse_format_id, parse_target_format,
119};
120
121#[doc(hidden)]
122pub use format::{
123    __emit_pypsa_csv, __emit_pypsa_csv_with_options, __parse_opfdata_json,
124    __parse_pypsa_csv_time_series,
125};
126pub use gen_cost::{GenCostPatch, GenCostPolicyReport, MissingGenCostPolicy, parse_gen_cost_csv};
127pub use geo::{
128    Canvas, CoordinateSpace, CoordsKind, ElementKey, GeoApplyReport, GeoFeature, GeoGeometry,
129    GeoLayer, GeoMeta, GeoParsed, GeoTarget, Location, apply_substation_points,
130    to_geo_layer_from_aux_substations, to_geo_layer_from_pwd, to_lonlat_from_pwd_mercator,
131};
132pub use indexed::{ConnectivityReport, IndexCore, IndexedNetwork};
133pub use network::{
134    AcDcConverterControlMode, ActivePowerControl, Area, BalancedNetwork, BoundaryLine,
135    BoundaryLineGeneration, Branch, BranchCharging, BranchCurrentRatings, BranchRatingSet,
136    BranchSolution, Bus, BusBreakerBus, BusId, BusType, BusbarSection, CalculatedBus, CaseMetadata,
137    ComponentAlias, ComponentMetadata, ConnectivityNode, CurveStyle, DEFAULT_BASE_FREQUENCY,
138    DcBusbar, DcConverterOperatingMode, DcConverterUnit, DcGround, DcLine, DcNode, DcPolarity,
139    DcSeriesDevice, DcSwitch, DcSwitchKind, DcTerminal, DcTopologicalNode, DetailedConnectivity,
140    DroopCurve, DroopCurveSegment, ExternalIdentifier, Extras, GenCaps, GenCost, Generator,
141    GeneratorEnergySource, Hvdc, HvdcConverter, HvdcConverterKind, HvdcConvertersMode, Impedance,
142    InternalConnection, Junction, LineCommutatedConverter, LineCommutatedConverterOperatingMode,
143    LineCommutatedConverterReactiveModel, Load, LoadVoltageModel, LoadingLimits,
144    MinMaxReactiveLimits, OmittedField, OmittedFieldName, OperationalLimitGroup,
145    ReactiveCapabilityCurve, ReactiveCapabilityCurvePoint, ReactiveLimits, Shunt, ShuntBlock,
146    SolverParams, SourceFormat, StaticVarCompensator, StaticVarCompensatorRegulationMode, Storage,
147    Subnetwork, Substation, Switch, SwitchKind, SwitchedShuntControl, SwitchedShuntMode,
148    TapChanger, TapChangerKind, TapChangerRegulationMode, TapChangerStep, TemporaryLimit, Terminal,
149    TerminalReference, TieLine, TopologyEndpoint, TopologyKind, TopologySwitch, Transformer3W,
150    TransformerControl, TransformerControlMode, VoltageLevel, VoltageSourceConverter, Winding,
151    calc_series_admittance_of, repair_values,
152};
153pub use normalize::{
154    NormalizeOptions, NormalizeSourceRows, NormalizedNetwork, POWER_MODELS_ANGLE_BOUND_PAD,
155    correct_angle_difference_bounds,
156};
157pub use operations::Selector;