Concepts
What a CGMES profile set is, why a model is many files, how mRIDs identify objects, and how cim-kit stores objects sparsely behind generated typed views.
If you know CGMES, skip to how cim-kit represents it.
The standards, briefly#
The Common Information Model (CIM) is an IEC family of standards describing power systems as classes, attributes and associations.
| Standard | What it gives you |
|---|---|
| IEC 61970-301 | The base semantic model: what an ACLineSegment is |
| IEC 61970-501 | How that model is published as machine-readable RDFS |
| IEC 61970-552 | CIM/XML, the file format models are exchanged in |
CGMES (IEC 61970-600) is ENTSO-E's profile set on top of CIM. CGMES 3.0 is the current interop target; CGMES 2.4.15 is the vintage most of Europe exchanges. cim-kit generates its typed model from the RDFS vocabularies ENTSO-E publishes.
A model is a set of files#
A CGMES model is split across profiles, each shipped as its own instance file:
| Profile | Carries |
|---|---|
| EQ Equipment | What exists and how it is connected — ratings, impedances, containment |
| SSH Steady State Hypothesis | The operating point — dispatch, switch positions, tap positions |
| TP Topology | Which terminals are electrically joined into nodes |
| SV State Variables | Power-flow results — voltages, flows |
| EQBD Equipment Boundary | The shared border between modelling authorities |
| DL / GL | Diagram layout / geographical location |
| DY Dynamics | Machine and control models |
| OP / SC | Operational limits / short-circuit data |
The same object appears in several of them under one identifier: a SynchronousMachine gets its ratings from EQ and its dispatch from SSH. So the unit of work is a Dataset: loading several files merges each object's attributes, and load order does not matter — except where two files give one single-valued attribute two different values, which is reported as CIM0018.
Identity: the mRID#
Every CIM object carries a master resource identifier, which IEC 61970-552 requires to be a UUID. A file writes rdf:ID="_<uuid>" when it introduces the object and rdf:about="#_<uuid>" when it only adds to one defined elsewhere.
Published files also use:
- UUIDs without hyphens —
rdf:ID="_1fa19c281c8f4e1eaad9e1cab70f923e"in the CGMES 2.4.15 boundary sets. That is the UUID1fa19c28-1c8f-4e1e-aad9-e1cab70f923e. - Absolute IRIs —
rdf:resource="http://host/EQ.xml#_<uuid>". The fragment is the object.
Mrid compares by the sixteen UUID bytes and remembers the spelling, so the same object spelled two ways is one object, and re-export writes back what the document had.
A value's spelling is remembered too#
CIM/XML carries no datatypes, and published models write numbers as 2.62637E-05, 0e+000 or 250.000000; ENTSO-E's RDF-Syntax User Guide says the notation carries the intended precision. Real keeps the number and its written form; only the number is the value:
# use cim_kit::value::Value;
# use cim_kit::schema::Primitive;
let read = Value::parse_primitive(Primitive::Float, "0e+000")?;
assert_eq!(read.as_f64(), Some(0.0));
assert_eq!(read.to_lexical().as_deref(), Some("0e+000"));
assert_eq!(read, Value::from(0.0));
# Ok::<(), cim_kit::value::ParseValueError>(())Re-export reproduces the text that was read, a diff never reports a reformatting as a change, and a value built in memory renders canonically.
rdf:ID versus rdf:about is not a per-file choice#
One Topology file writes TopologicalNode with rdf:ID (Topology introduces it) and Terminal with rdf:about (Equipment did). The RDFS marks the second kind cims:stereotype Description; cim-kit reads the stereotype rather than deriving the form from the profile.
How cim-kit represents it#
Sparse storage, not a struct per class#
Across the conformity corpus, 250,698 objects carry 1.1 million values — four each on average, against a mean of 21 flattened fields per concrete class. An Object is therefore a vector of (attribute, value) slots sorted by attribute id: memory is proportional to real content, and one object holds the union of several profiles' attributes.
Typed views over that storage#
Generated zero-cost views provide the typed API:
use cim_kit::prelude::*;
use cim_kit::cgmes3::views::ACLineSegment;
fn impedances(grid: &Dataset) {
for line in grid.view::<ACLineSegment>() {
let r: Option<f64> = line.r(); // typed from the profile
let name: Option<&str> = line.name(); // inherited from IdentifiedObject
println!("{name:?}: r={r:?}");
}
}ACLineSegment<'a> wraps &'a Object; accessors borrow for the view's lifetime.
Associations are identifiers, not pointers#
IEC 61970-501 serializes one side of each association. Following it forwards is a lookup that allocates nothing:
use cim_kit::prelude::*;
use cim_kit::cgmes3::views::Terminal;
fn owners(grid: &Dataset) {
for terminal in grid.view::<Terminal>() {
if let Some(equipment) = terminal.conducting_equipment_in(grid) {
println!("{:?}", equipment.name());
}
}
}Following it backwards needs an index, built once:
use cim_kit::prelude::*;
use cim_kit::cgmes3::{attributes, views::Substation};
fn voltage_levels_of_each_substation(grid: &Dataset) {
let inverse = cim_kit::InverseIndex::build(grid);
for substation in grid.view::<Substation>() {
let levels = inverse.referrers(attributes::voltage_level::Substation, substation.mrid());
println!("{:?}: {} voltage level(s)", substation.name(), levels.len());
}
}Compounds are values, not references#
Types without identity — a StreetAddress inside Location.mainAddress — are written inline as rdf:parseType="Resource", may nest, and are stored as values:
use cim_kit::prelude::*;
use cim_kit::cgmes3::views::Location;
fn towns(grid: &Dataset) {
for location in grid.view::<Location>() {
if let Some(town) = location.main_address().and_then(|a| a.town_detail()) {
println!("{:?} in {:?}", location.name(), town.name());
}
}
}Named constants spelled as the standard spells them#
UnitMultiplier.M (mega) and UnitMultiplier.m (milli) differ only by case, so generated constants keep the CIM identifier exactly rather than converting to SCREAMING_SNAKE_CASE.
Provenance: which file a value came from#
IdentifiedObject.mRID is declared in ten of eleven CGMES 3.0 profiles, so declarations alone cannot say which file a value belongs in. Each stored value records which profiles' files it came from; export writes it to that provenance intersected with the profiles that declare the attribute. Each object also records the file that contributed it, so in a merged common grid model each authority's equipment goes back to its own file.
This is what lets save_as_loaded reproduce the file set a model was read from.