From b74c8c5c452d33fbe4ea7b92240284ea13355d83 Mon Sep 17 00:00:00 2001 From: Romain Courtier Date: Mon, 2 Dec 2024 10:56:19 +0100 Subject: [PATCH 1/7] Fix duplicate rdf:ID in same xml file Signed-off-by: Romain Courtier --- .../MicroGridTestConfiguration_BC_BE_EQ_V2.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgmes/cgmes-conformity/src/main/resources/conformity-modified/cas-1.1.3-data-4.0.3/MicroGrid/BaseCase/BC_BE_v2_transformer_at_boundary/MicroGridTestConfiguration_BC_BE_EQ_V2.xml b/cgmes/cgmes-conformity/src/main/resources/conformity-modified/cas-1.1.3-data-4.0.3/MicroGrid/BaseCase/BC_BE_v2_transformer_at_boundary/MicroGridTestConfiguration_BC_BE_EQ_V2.xml index 7590882ad0c..eabb8e938eb 100644 --- a/cgmes/cgmes-conformity/src/main/resources/conformity-modified/cas-1.1.3-data-4.0.3/MicroGrid/BaseCase/BC_BE_v2_transformer_at_boundary/MicroGridTestConfiguration_BC_BE_EQ_V2.xml +++ b/cgmes/cgmes-conformity/src/main/resources/conformity-modified/cas-1.1.3-data-4.0.3/MicroGrid/BaseCase/BC_BE_v2_transformer_at_boundary/MicroGridTestConfiguration_BC_BE_EQ_V2.xml @@ -1427,7 +1427,7 @@ - + BE-TR2_1 BE-T_1 400.000000 From 52b7c7adaa3b78395a4c0eb6fe23b55fee7a163e Mon Sep 17 00:00:00 2001 From: Romain Courtier Date: Mon, 2 Dec 2024 11:35:41 +0100 Subject: [PATCH 2/7] Get transfomerEnds by transfomerId instead of all in a Map Signed-off-by: Romain Courtier --- .../powsybl/cgmes/conversion/Conversion.java | 33 ++++++++------- .../conversion/NodeContainerMapping.java | 4 +- .../cgmes/conversion/PhaseAngleClock.java | 21 +++++----- .../conversion/elements/hvdc/Adjacency.java | 20 +++++---- .../elements/hvdc/NodeEquipment.java | 16 +++---- .../microGridBaseCaseBE-target-deadband.txt | 2 +- .../cgmes/model/AbstractCgmesModel.java | 42 ++++++++----------- .../com/powsybl/cgmes/model/CgmesModel.java | 3 +- .../cgmes/model/CgmesModelFactory.java | 16 ++++--- .../cgmes/model/InMemoryCgmesModel.java | 4 +- .../src/main/resources/CIM14.sparql | 2 +- .../src/main/resources/CIM16.sparql | 2 +- .../src/test/resources/be.json | 32 +++++++------- 13 files changed, 98 insertions(+), 99 deletions(-) diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java index 628f4a8d15d..293d1aac5a4 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java @@ -687,21 +687,24 @@ private void convertEquivalentBranchesToLines(Context context, Set delay private void convertTransformers(Context context, Set delayedBoundaryNodes) { context.pushReportNode(CgmesReports.convertingElementTypeReport(context.getReportNode(), CgmesNames.POWER_TRANSFORMER)); - cgmes.groupedTransformerEnds().forEach((t, ends) -> { - if (LOG.isTraceEnabled()) { - LOG.trace("Transformer {}, {}-winding", t, ends.size()); - ends.forEach(e -> LOG.trace(e.tabulateLocals("TransformerEnd"))); - } - if (ends.size() == 2) { - convertTwoWindingsTransformers(context, ends, delayedBoundaryNodes); - } else if (ends.size() == 3) { - convertThreeWindingsTransformers(context, ends); - } else { - String what = "PowerTransformer " + t; - Supplier reason = () -> String.format("Has %d ends. Only 2 or 3 ends are supported", ends.size()); - context.invalid(what, reason); - } - }); + cgmes.transformers().stream() + .map(t -> cgmes.transformerEnds(t.getId("PowerTransformer"))) + .forEach(ends -> { + String transformerId = ends.get(0).getId("PowerTransformer"); + if (LOG.isTraceEnabled()) { + LOG.trace("Transformer {}, {}-winding", transformerId, ends.size()); + ends.forEach(e -> LOG.trace(e.tabulateLocals("TransformerEnd"))); + } + if (ends.size() == 2) { + convertTwoWindingsTransformers(context, ends, delayedBoundaryNodes); + } else if (ends.size() == 3) { + convertThreeWindingsTransformers(context, ends); + } else { + String what = "PowerTransformer " + transformerId; + Supplier reason = () -> String.format("Has %d ends. Only 2 or 3 ends are supported", ends.size()); + context.invalid(what, reason); + } + }); context.popReportNode(); } diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/NodeContainerMapping.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/NodeContainerMapping.java index 4ddeaf4200f..8b82008a027 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/NodeContainerMapping.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/NodeContainerMapping.java @@ -155,7 +155,9 @@ private void buildAdjacency(Map> voltageLevelAdjacency, Map< boolean fictitiousVoltageLevelForEveryNode = context.config().getCreateFictitiousVoltageLevelsForEveryNode(); context.cgmes().switches().forEach(sw -> addAdjacencyThroughSwitch(voltageLevelAdjacency, substationAdjacency, sw, fictitiousVoltageLevelForEveryNode)); - context.cgmes().groupedTransformerEnds().forEach((t, tends) -> addAdjacencyThroughTransformerEnds(substationAdjacency, tends)); + context.cgmes().transformers().stream() + .map(t -> context.cgmes().transformerEnds(t.getId("PowerTransformer"))) + .forEach(tends -> addAdjacencyThroughTransformerEnds(substationAdjacency, tends)); context.cgmes().acLineSegments().forEach(ac -> addAdjacencyThroughBranch(fictitiousVoltageLevelAdjacency, ac, fictitiousVoltageLevelForEveryNode)); context.cgmes().seriesCompensators().forEach(sc -> addAdjacencyThroughBranch(fictitiousVoltageLevelAdjacency, sc, fictitiousVoltageLevelForEveryNode)); diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/PhaseAngleClock.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/PhaseAngleClock.java index bdafeaf8d0f..95ad90b3020 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/PhaseAngleClock.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/PhaseAngleClock.java @@ -48,16 +48,17 @@ public void process(Network network, TripleStore tripleStore) { LOG.warn("PhaseAngleClock-PostProcessor: Unexpected null cgmesModel pointer"); return; } - - cgmes.groupedTransformerEnds().forEach((t, ends) -> { - if (ends.size() == 2) { - phaseAngleClockTwoWindingTransformer(ends, network); - } else if (ends.size() == 3) { - phaseAngleClockThreeWindingTransformer(ends, network); - } else { - throw new PowsyblException(String.format("Unexpected TransformerEnds: ends %d", ends.size())); - } - }); + cgmes.transformers().stream() + .map(t -> cgmes.transformerEnds(t.getId("PowerTransformer"))) + .forEach(ends -> { + if (ends.size() == 2) { + phaseAngleClockTwoWindingTransformer(ends, network); + } else if (ends.size() == 3) { + phaseAngleClockThreeWindingTransformer(ends, network); + } else { + throw new PowsyblException(String.format("Unexpected TransformerEnds: ends %d", ends.size())); + } + }); } private void phaseAngleClockTwoWindingTransformer(PropertyBags ends, Network network) { diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/hvdc/Adjacency.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/hvdc/Adjacency.java index d7d60448a7b..86cd12cb1c0 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/hvdc/Adjacency.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/hvdc/Adjacency.java @@ -44,15 +44,17 @@ enum AdjacentType { .forEach((key, value) -> computeAcDcConverterAdjacency(value.acNode, value.dcNode)); - cgmesModel.groupedTransformerEnds().forEach((t, ends) -> { - if (ends.size() == 2) { - computeTwoWindingsTransformerAdjacency(cgmesModel, ends); - } else if (ends.size() == 3) { - computeThreeWindingsTransformerAdjacency(cgmesModel, ends); - } else { - throw new PowsyblException(String.format("Unexpected TransformerEnds: ends %d", ends.size())); - } - }); + cgmesModel.transformers().stream() + .map(t -> cgmesModel.transformerEnds(t.getId("PowerTransformer"))) + .forEach(ends -> { + if (ends.size() == 2) { + computeTwoWindingsTransformerAdjacency(cgmesModel, ends); + } else if (ends.size() == 3) { + computeThreeWindingsTransformerAdjacency(cgmesModel, ends); + } else { + throw new PowsyblException(String.format("Unexpected TransformerEnds: ends %d", ends.size())); + } + }); } private void computeDcLineSegmentAdjacency(CgmesModel cgmesModel, PropertyBag equipment) { diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/hvdc/NodeEquipment.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/hvdc/NodeEquipment.java index c0db811141b..802dc77605b 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/hvdc/NodeEquipment.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/hvdc/NodeEquipment.java @@ -40,13 +40,15 @@ enum EquipmentType { .forEach(value -> addEquipment(adjacency, value.id, value.acNode, value.dcNode, EquipmentType.AC_DC_CONVERTER)); - cgmesModel.groupedTransformerEnds().forEach((t, ends) -> { - if (ends.size() == 2) { - computeTwoWindingsTransformer(cgmesModel, adjacency, ends); - } else if (ends.size() == 3) { - computeThreeWindingsTransformer(cgmesModel, adjacency, ends); - } - }); + cgmesModel.transformers().stream() + .map(t -> cgmesModel.transformerEnds(t.getId("PowerTransformer"))) + .forEach(ends -> { + if (ends.size() == 2) { + computeTwoWindingsTransformer(cgmesModel, adjacency, ends); + } else if (ends.size() == 3) { + computeThreeWindingsTransformer(cgmesModel, adjacency, ends); + } + }); } private void computeDcLineSegment(CgmesModel cgmesModel, Adjacency adjacency, PropertyBag equipment) { diff --git a/cgmes/cgmes-conversion/src/test/resources/functional-logs/microGridBaseCaseBE-target-deadband.txt b/cgmes/cgmes-conversion/src/test/resources/functional-logs/microGridBaseCaseBE-target-deadband.txt index d81410a9eda..cbe6753dbf4 100644 --- a/cgmes/cgmes-conversion/src/test/resources/functional-logs/microGridBaseCaseBE-target-deadband.txt +++ b/cgmes/cgmes-conversion/src/test/resources/functional-logs/microGridBaseCaseBE-target-deadband.txt @@ -33,9 +33,9 @@ Converting SvInjection. Converting ControlArea. + Converting RegulatingControl. + Equipment 6ebbef67-3061-4236-a6fd-6ccc4595f6c3 has a regulating control with bad target deadband: -35.0. Equipment 955d9cd0-4a10-4031-b008-60c0dc340a07 has a regulating control with bad target value for voltage: 0.0. Equipment 955d9cd0-4a10-4031-b008-60c0dc340a07 has a regulating control with bad target deadband: -0.5. - Equipment 6ebbef67-3061-4236-a6fd-6ccc4595f6c3 has a regulating control with bad target deadband: -35.0. Equipment fe25f43a-7341-446e-a71a-8ab7119ba806 has a regulating control with bad target value for voltage: 0.0. Fixing issues with dangling lines. Setting voltages and angles. diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java index 59b4095c8e3..664ec64d50f 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java @@ -44,11 +44,11 @@ public PropertyBags nonlinearShuntCompensatorPoints(String shuntId) { } @Override - public Map groupedTransformerEnds() { + public PropertyBags transformerEnds(String transformerId) { if (cachedGroupedTransformerEnds == null) { cachedGroupedTransformerEnds = computeGroupedTransformerEnds(); } - return cachedGroupedTransformerEnds; + return cachedGroupedTransformerEnds.getOrDefault(transformerId, new PropertyBags()); } @Override @@ -184,32 +184,24 @@ private Map computeGroupedTransformerEnds() { // instead of sorting after building each list, // use a sorted collection when inserting String endNumber = "endNumber"; - Map gends = new HashMap<>(); + Map groupedTransformerEnds = new HashMap<>(); powerTransformerRatioTapChanger = new HashMap<>(); powerTransformerPhaseTapChanger = new HashMap<>(); transformerEnds() - .forEach(end -> { - String id = end.getId("PowerTransformer"); - PropertyBags ends = gends.computeIfAbsent(id, x -> new PropertyBags()); - ends.add(end); - if (end.getId("PhaseTapChanger") != null) { - powerTransformerPhaseTapChanger.computeIfAbsent(id, s -> new String[3]); - powerTransformerPhaseTapChanger.get(id)[end.asInt(endNumber, 1) - 1] = end.getId("PhaseTapChanger"); - } - if (end.getId("RatioTapChanger") != null) { - powerTransformerRatioTapChanger.computeIfAbsent(id, s -> new String[3]); - powerTransformerRatioTapChanger.get(id)[end.asInt(endNumber, 1) - 1] = end.getId("RatioTapChanger"); - } - }); - gends.entrySet() - .forEach(tends -> { - PropertyBags tends1 = new PropertyBags( - tends.getValue().stream() - .sorted(Comparator.comparing(WindingType::endNumber)) - .toList()); - tends.setValue(tends1); - }); - return gends; + .forEach(end -> { + String transformerId = end.getId("PowerTransformer"); + groupedTransformerEnds.computeIfAbsent(transformerId, x -> new PropertyBags()) + .add(end); + if (end.getId("PhaseTapChanger") != null) { + powerTransformerPhaseTapChanger.computeIfAbsent(transformerId, s -> new String[3]); + powerTransformerPhaseTapChanger.get(transformerId)[end.asInt(endNumber, 1) - 1] = end.getId("PhaseTapChanger"); + } + if (end.getId("RatioTapChanger") != null) { + powerTransformerRatioTapChanger.computeIfAbsent(transformerId, s -> new String[3]); + powerTransformerRatioTapChanger.get(transformerId)[end.asInt(endNumber, 1) - 1] = end.getId("RatioTapChanger"); + } + }); + return groupedTransformerEnds; } protected void cacheNodes() { diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java index 0f1bb6928b4..0e87608a750 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java @@ -92,8 +92,7 @@ default PropertyBags fullModels() { PropertyBags transformerEnds(); - // Transformer ends grouped by transformer - Map groupedTransformerEnds(); + PropertyBags transformerEnds(String transformerId); PropertyBags ratioTapChangers(); diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModelFactory.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModelFactory.java index 245aed96f37..f4c8f2bbd2d 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModelFactory.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModelFactory.java @@ -100,15 +100,13 @@ public static CgmesModel copy(CgmesModel cgmes) { private static void buildCaches(CgmesModel cgmes) { // TODO This is rebuilding only some caches boolean isNodeBreaker = cgmes.isNodeBreaker(); - for (PropertyBags tends : cgmes.groupedTransformerEnds().values()) { - for (PropertyBag end : tends) { - CgmesTerminal t = cgmes.terminal(end.getId(CgmesNames.TERMINAL)); - cgmes.substation(t, isNodeBreaker); - if (isNodeBreaker) { - t.connectivityNode(); - } else { - t.topologicalNode(); - } + for (PropertyBag end : cgmes.transformerEnds()) { + CgmesTerminal t = cgmes.terminal(end.getId(CgmesNames.TERMINAL)); + cgmes.substation(t, isNodeBreaker); + if (isNodeBreaker) { + t.connectivityNode(); + } else { + t.topologicalNode(); } } } diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java index 17f9d4844ec..0f2447b4ae5 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java @@ -402,9 +402,9 @@ public PropertyBags transformerEnds() { } @Override - public Map groupedTransformerEnds() { + public PropertyBags transformerEnds(String tableId) { // FakeCgmesModeldoes not provide grouped transformer ends - return Collections.emptyMap(); + return new PropertyBags(); } @Override diff --git a/cgmes/cgmes-model/src/main/resources/CIM14.sparql b/cgmes/cgmes-model/src/main/resources/CIM14.sparql index 2f49406b1c2..9995e93a173 100644 --- a/cgmes/cgmes-model/src/main/resources/CIM14.sparql +++ b/cgmes/cgmes-model/src/main/resources/CIM14.sparql @@ -230,7 +230,7 @@ WHERE { OPTIONAL { ?PhaseTapChanger cim:PhaseTapChanger.TransformerWinding ?TransformerWinding } }} BIND ( ?TransformerWinding AS ?TransformerEnd ) -} +} ORDER BY ?PowerTransformer ?windingType # query: ratioTapChangers SELECT * diff --git a/cgmes/cgmes-model/src/main/resources/CIM16.sparql b/cgmes/cgmes-model/src/main/resources/CIM16.sparql index bae7ca1b6db..63ef7e394bf 100644 --- a/cgmes/cgmes-model/src/main/resources/CIM16.sparql +++ b/cgmes/cgmes-model/src/main/resources/CIM16.sparql @@ -562,7 +562,7 @@ WHERE { OPTIONAL { ?RatioTapChanger cim:RatioTapChanger.TransformerEnd ?TransformerEnd } OPTIONAL { ?PhaseTapChanger cim:PhaseTapChanger.TransformerEnd ?TransformerEnd } }} -} +} ORDER BY ?PowerTransformer ?endNumber # query: ratioTapChangers SELECT * diff --git a/matpower/matpower-converter/src/test/resources/be.json b/matpower/matpower-converter/src/test/resources/be.json index 11a0e62d8e3..ef6251a8021 100644 --- a/matpower/matpower-converter/src/test/resources/be.json +++ b/matpower/matpower-converter/src/test/resources/be.json @@ -257,15 +257,15 @@ "angMin" : 0.0, "angMax" : 0.0 }, { - "from" : 2, - "to" : 1, - "r" : 8.192122993395951E-4, - "x" : 0.04571631170550064, - "b" : -0.010613320515218202, - "rateA" : 143.891, + "from" : 6, + "to" : 2, + "r" : 0.0016923075000000005, + "x" : 0.009074315000000001, + "b" : 0.0, + "rateA" : 356.516, "rateB" : 0.0, - "rateC" : 154.891, - "ratio" : 1.0277920081967213, + "rateC" : 364.116, + "ratio" : 1.0526315789473684, "phaseShiftAngle" : 0.0, "status" : 1, "angMin" : 0.0, @@ -285,15 +285,15 @@ "angMin" : 0.0, "angMax" : 0.0 }, { - "from" : 6, - "to" : 2, - "r" : 0.0016923075000000005, - "x" : 0.009074315000000001, - "b" : 0.0, - "rateA" : 356.516, + "from" : 2, + "to" : 1, + "r" : 8.192122993395951E-4, + "x" : 0.04571631170550064, + "b" : -0.010613320515218202, + "rateA" : 143.891, "rateB" : 0.0, - "rateC" : 364.116, - "ratio" : 1.0526315789473684, + "rateC" : 154.891, + "ratio" : 1.0277920081967213, "phaseShiftAngle" : 0.0, "status" : 1, "angMin" : 0.0, From ef15765ae3f1bd16eec5968667e75f09f2c1f100 Mon Sep 17 00:00:00 2001 From: Romain Courtier Date: Mon, 2 Dec 2024 14:32:08 +0100 Subject: [PATCH 3/7] Get tapChangers by transfomerId instead of all in a Map Signed-off-by: Romain Courtier --- .../conformity/CgmesConformity1Catalog.java | 2 +- .../com/powsybl/cgmes/conversion/Context.java | 28 -------- .../powsybl/cgmes/conversion/Conversion.java | 2 - .../AbstractTransformerConversion.java | 41 ++++++----- .../elements/transformers/TapChanger.java | 14 +++- .../test/FakeTapChangerConversionTest.java | 7 +- .../model/test/Cim14SmallCasesCatalog.java | 2 +- .../cgmes/model/AbstractCgmesModel.java | 72 +++++++++++-------- .../com/powsybl/cgmes/model/CgmesModel.java | 8 +-- .../cgmes/model/InMemoryCgmesModel.java | 20 +++--- .../src/main/resources/CIM14.sparql | 12 +++- .../src/main/resources/CIM16.sparql | 8 ++- 12 files changed, 112 insertions(+), 104 deletions(-) diff --git a/cgmes/cgmes-conformity/src/main/java/com/powsybl/cgmes/conformity/CgmesConformity1Catalog.java b/cgmes/cgmes-conformity/src/main/java/com/powsybl/cgmes/conformity/CgmesConformity1Catalog.java index a32013acffc..c8ff3e96e68 100644 --- a/cgmes/cgmes-conformity/src/main/java/com/powsybl/cgmes/conformity/CgmesConformity1Catalog.java +++ b/cgmes/cgmes-conformity/src/main/java/com/powsybl/cgmes/conformity/CgmesConformity1Catalog.java @@ -437,7 +437,7 @@ public static InMemoryCgmesModel expectedMicroGridBaseCaseBE() { .ratioTapChangers("83cc66dd-8d93-4a2c-8103-f1f5a9cf7e2e", "955d9cd0-4a10-4031-b008-60c0dc340a07", "fe25f43a-7341-446e-a71a-8ab7119ba806") - .phaseTapChangers("6ebbef67-3061-4236-a6fd-6ccc4595f6c3") + .phaseTapChangers(new String[]{"6ebbef67-3061-4236-a6fd-6ccc4595f6c3"}) .energyConsumers("1c6beed6-1acf-42e7-ba55-0cc9f04bddd8", "b1480a00-b427-4001-a26c-51954d2bb7e9", "cb459405-cc14-4215-a45c-416789205904") diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Context.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Context.java index fec6eca4fd2..21a0ed1ca49 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Context.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Context.java @@ -12,13 +12,11 @@ import com.powsybl.cgmes.conversion.elements.hvdc.DcMapping; import com.powsybl.cgmes.conversion.naming.NamingStrategy; import com.powsybl.cgmes.model.CgmesModel; -import com.powsybl.cgmes.model.CgmesNames; import com.powsybl.cgmes.model.PowerFlow; import com.powsybl.commons.report.ReportNode; import com.powsybl.iidm.network.IdentifiableType; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.Terminal; -import com.powsybl.triplestore.api.PropertyBag; import com.powsybl.triplestore.api.PropertyBags; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,8 +60,6 @@ public Context(CgmesModel cgmes, Config config, Network network, ReportNode repo ratioTapChangerTables = new HashMap<>(); phaseTapChangerTables = new HashMap<>(); reactiveCapabilityCurveData = new HashMap<>(); - powerTransformerRatioTapChangers = new HashMap<>(); - powerTransformerPhaseTapChangers = new HashMap<>(); } public CgmesModel cgmes() { @@ -153,28 +149,6 @@ public PropertyBags reactiveCapabilityCurveData(String curveId) { return reactiveCapabilityCurveData.get(curveId); } - public void loadRatioTapChangers() { - cgmes.ratioTapChangers().forEach(ratio -> { - String id = ratio.getId(CgmesNames.RATIO_TAP_CHANGER); - powerTransformerRatioTapChangers.put(id, ratio); - }); - } - - public PropertyBag ratioTapChanger(String id) { - return powerTransformerRatioTapChangers.get(id); - } - - public void loadPhaseTapChangers() { - cgmes.phaseTapChangers().forEach(phase -> { - String id = phase.getId(CgmesNames.PHASE_TAP_CHANGER); - powerTransformerPhaseTapChangers.put(id, phase); - }); - } - - public PropertyBag phaseTapChanger(String id) { - return powerTransformerPhaseTapChangers.get(id); - } - public void loadRatioTapChangerTables() { PropertyBags rtcpoints = cgmes.ratioTapChangerTablesPoints(); if (rtcpoints == null) { @@ -316,8 +290,6 @@ private static void logIssue(ConversionIssueCategory category, String what, Supp private final Map ratioTapChangerTables; private final Map phaseTapChangerTables; private final Map reactiveCapabilityCurveData; - private final Map powerTransformerRatioTapChangers; - private final Map powerTransformerPhaseTapChangers; private static final Logger LOG = LoggerFactory.getLogger(Context.class); } diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java index 293d1aac5a4..e3fa5235280 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java @@ -472,8 +472,6 @@ private Network createNetwork() { private Context createContext(Network network, ReportNode reportNode) { Context context = new Context(cgmes, config, network, reportNode); context.dc().initialize(); - context.loadRatioTapChangers(); - context.loadPhaseTapChangers(); context.loadRatioTapChangerTables(); context.loadPhaseTapChangerTables(); context.loadReactiveCapabilityCurveData(); diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/AbstractTransformerConversion.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/AbstractTransformerConversion.java index 2f6a272dba5..9c42401b2eb 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/AbstractTransformerConversion.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/AbstractTransformerConversion.java @@ -9,20 +9,18 @@ package com.powsybl.cgmes.conversion.elements.transformers; import com.powsybl.cgmes.conversion.Context; -import com.powsybl.cgmes.conversion.Conversion; import com.powsybl.cgmes.conversion.RegulatingControlMappingForTransformers.CgmesRegulatingControlPhase; import com.powsybl.cgmes.conversion.RegulatingControlMappingForTransformers.CgmesRegulatingControlRatio; import com.powsybl.cgmes.conversion.elements.AbstractConductingEquipmentConversion; import com.powsybl.cgmes.extensions.CgmesTapChangers; import com.powsybl.cgmes.extensions.CgmesTapChangersAdder; -import com.powsybl.cgmes.model.CgmesNames; import com.powsybl.cgmes.model.WindingType; import com.powsybl.iidm.network.*; import com.powsybl.triplestore.api.PropertyBag; import com.powsybl.triplestore.api.PropertyBags; -import java.util.List; -import java.util.Optional; +import static com.powsybl.cgmes.conversion.Conversion.CGMES_PREFIX_ALIAS_PROPERTIES; +import static com.powsybl.cgmes.model.CgmesNames.*; /** * @author Luma ZamarreƱo {@literal } @@ -111,23 +109,30 @@ protected CgmesRegulatingControlPhase setContextRegulatingDataPhase(TapChanger t @Override protected void addAliasesAndProperties(Identifiable identifiable) { + // Add PowerTransformer aliases super.addAliasesAndProperties(identifiable); - for (PropertyBag p : ps) { - identifiable.addAlias(p.getId("TransformerEnd"), Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + CgmesNames.TRANSFORMER_END + WindingType.endNumber(p)); + + // Add PowerTransformerEnds aliases + String alias; + String aliasType; + for (PropertyBag end : ps) { + alias = end.getId("TransformerEnd"); + aliasType = CGMES_PREFIX_ALIAS_PROPERTIES + TRANSFORMER_END + WindingType.endNumber(end); + identifiable.addAlias(alias, aliasType); } - List ptcs = context.cgmes().phaseTapChangerListForPowerTransformer(identifiable.getId()); - if (ptcs != null) { - for (int i = 0; i < ptcs.size(); i++) { - int index = i + 1; - Optional.ofNullable(ptcs.get(i)).ifPresent(ptc -> identifiable.addAlias(ptc, Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + CgmesNames.PHASE_TAP_CHANGER + index, context.config().isEnsureIdAliasUnicity())); - } + + // Add RatioTapChangers aliases + for (PropertyBag rtc : context.cgmes().ratioTapChangers(identifiable.getId())) { + alias = rtc.getId("RatioTapChanger"); + aliasType = CGMES_PREFIX_ALIAS_PROPERTIES + RATIO_TAP_CHANGER + WindingType.endNumber(rtc); + identifiable.addAlias(alias, aliasType); } - List rtcs = context.cgmes().ratioTapChangerListForPowerTransformer(identifiable.getId()); - if (rtcs != null) { - for (int i = 0; i < rtcs.size(); i++) { - int index = i + 1; - Optional.ofNullable(rtcs.get(i)).ifPresent(rtc -> identifiable.addAlias(rtc, Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + CgmesNames.RATIO_TAP_CHANGER + index, context.config().isEnsureIdAliasUnicity())); - } + + // Add PhaseTapChangers aliases + for (PropertyBag ptc : context.cgmes().phaseTapChangers(identifiable.getId())) { + alias = ptc.getId("PhaseTapChanger"); + aliasType = CGMES_PREFIX_ALIAS_PROPERTIES + PHASE_TAP_CHANGER + WindingType.endNumber(ptc); + identifiable.addAlias(alias, aliasType); } } diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/TapChanger.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/TapChanger.java index c5bddf02320..7fc8a71be7c 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/TapChanger.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/TapChanger.java @@ -25,14 +25,24 @@ public class TapChanger { public static TapChanger ratioTapChangerFromEnd(PropertyBag end, Context context) { Objects.requireNonNull(end); Objects.requireNonNull(context); - PropertyBag rtc = context.ratioTapChanger(end.getId(CgmesNames.RATIO_TAP_CHANGER)); + PropertyBag rtc = context.cgmes() + .ratioTapChangers(end.getId("PowerTransformer")) + .stream() + .filter(tc -> end.getId(CgmesNames.TRANSFORMER_END).equals(tc.getId(CgmesNames.TRANSFORMER_END))) + .findFirst() + .orElse(null); return rtc != null ? AbstractCgmesTapChangerBuilder.newRatioTapChanger(rtc, context).build() : null; } public static TapChanger phaseTapChangerFromEnd(PropertyBag end, double x, Context context) { Objects.requireNonNull(end); Objects.requireNonNull(context); - PropertyBag ptc = context.phaseTapChanger(end.getId(CgmesNames.PHASE_TAP_CHANGER)); + PropertyBag ptc = context.cgmes() + .phaseTapChangers(end.getId("PowerTransformer")) + .stream() + .filter(tc -> end.getId(CgmesNames.TRANSFORMER_END).equals(tc.getId(CgmesNames.TRANSFORMER_END))) + .findFirst() + .orElse(null); return ptc != null ? AbstractCgmesTapChangerBuilder.newPhaseTapChanger(ptc, x, context).build() : null; } diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/FakeTapChangerConversionTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/FakeTapChangerConversionTest.java index c8b0838fbc2..4fd74881e97 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/FakeTapChangerConversionTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/FakeTapChangerConversionTest.java @@ -9,10 +9,9 @@ import com.powsybl.cgmes.model.CgmesModel; import com.powsybl.cgmes.model.InMemoryCgmesModel; +import com.powsybl.triplestore.api.PropertyBags; import org.junit.jupiter.api.Test; -import java.util.Collections; - import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -22,7 +21,7 @@ class FakeTapChangerConversionTest { @Test void fakeTapChangersEmpty() { CgmesModel cgmes = new InMemoryCgmesModel(); - assertEquals(Collections.emptyList(), cgmes.ratioTapChangerListForPowerTransformer("anyTransformer")); - assertEquals(Collections.emptyList(), cgmes.phaseTapChangerListForPowerTransformer("anyTransformer")); + assertEquals(new PropertyBags(), cgmes.ratioTapChangers("Fake transformer Id")); + assertEquals(new PropertyBags(), cgmes.phaseTapChangers("Fake transformer Id")); } } diff --git a/cgmes/cgmes-model-test/src/main/java/com/powsybl/cgmes/model/test/Cim14SmallCasesCatalog.java b/cgmes/cgmes-model-test/src/main/java/com/powsybl/cgmes/model/test/Cim14SmallCasesCatalog.java index 7f3be0ba245..093c3c962af 100644 --- a/cgmes/cgmes-model-test/src/main/java/com/powsybl/cgmes/model/test/Cim14SmallCasesCatalog.java +++ b/cgmes/cgmes-model-test/src/main/java/com/powsybl/cgmes/model/test/Cim14SmallCasesCatalog.java @@ -183,7 +183,7 @@ private static CgmesModel expectedM7Buses() { "_FVALDI11-FTDPRA11-2_AC") .transformers("_FP.AND11-FTDPRA11-1_PT") .transformerEnds("_FP.AND11-FTDPRA11-1_TW_EX", "_FP.AND11-FTDPRA11-1_TW_OR") - .phaseTapChangers("_FP.AND11-FTDPRA11-1_PTC_OR") + .phaseTapChangers(new String[] {"_FP.AND11-FTDPRA11-1_PTC_OR"}) .energyConsumers("_FP.ANC12_EC", "_FS.BIC11_EC", "_FTDPRC11_EC", "_FTILLC51_EC") .synchronousMachinesGenerators("_FSSV.T11_SM", "_FVALDT11_SM", "_FVERGT11_SM"); } diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java index 664ec64d50f..e2f4213aee3 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java @@ -51,6 +51,22 @@ public PropertyBags transformerEnds(String transformerId) { return cachedGroupedTransformerEnds.getOrDefault(transformerId, new PropertyBags()); } + @Override + public PropertyBags ratioTapChangers(String transformerId) { + if (cachedGroupedRatioTapChangers == null) { + cachedGroupedRatioTapChangers = computeGroupedRatioTapChangers(); + } + return cachedGroupedRatioTapChangers.getOrDefault(transformerId, new PropertyBags()); + } + + @Override + public PropertyBags phaseTapChangers(String transformerId) { + if (cachedGroupedPhaseTapChangers == null) { + cachedGroupedPhaseTapChangers = computeGroupedPhaseTapChangers(); + } + return cachedGroupedPhaseTapChangers.getOrDefault(transformerId, new PropertyBags()); + } + @Override public Collection computedTerminals() { if (cachedTerminals == null) { @@ -75,16 +91,6 @@ public CgmesDcTerminal dcTerminal(String dcTerminalId) { return cachedDcTerminals.get(dcTerminalId); } - @Override - public List ratioTapChangerListForPowerTransformer(String powerTransformerId) { - return powerTransformerRatioTapChanger.get(powerTransformerId) == null ? null : Arrays.asList(powerTransformerRatioTapChanger.get(powerTransformerId)); - } - - @Override - public List phaseTapChangerListForPowerTransformer(String powerTransformerId) { - return powerTransformerPhaseTapChanger.get(powerTransformerId) == null ? null : Arrays.asList(powerTransformerPhaseTapChanger.get(powerTransformerId)); - } - @Override public String substation(CgmesTerminal t, boolean nodeBreaker) { CgmesContainer c = container(t, nodeBreaker); @@ -180,30 +186,38 @@ private Map computeGroupedShuntCompensatorPoints() { } private Map computeGroupedTransformerEnds() { - // Alternative implementation: - // instead of sorting after building each list, - // use a sorted collection when inserting - String endNumber = "endNumber"; Map groupedTransformerEnds = new HashMap<>(); - powerTransformerRatioTapChanger = new HashMap<>(); - powerTransformerPhaseTapChanger = new HashMap<>(); transformerEnds() .forEach(end -> { - String transformerId = end.getId("PowerTransformer"); + String transformerId = end.getId(CgmesNames.POWER_TRANSFORMER); groupedTransformerEnds.computeIfAbsent(transformerId, x -> new PropertyBags()) .add(end); - if (end.getId("PhaseTapChanger") != null) { - powerTransformerPhaseTapChanger.computeIfAbsent(transformerId, s -> new String[3]); - powerTransformerPhaseTapChanger.get(transformerId)[end.asInt(endNumber, 1) - 1] = end.getId("PhaseTapChanger"); - } - if (end.getId("RatioTapChanger") != null) { - powerTransformerRatioTapChanger.computeIfAbsent(transformerId, s -> new String[3]); - powerTransformerRatioTapChanger.get(transformerId)[end.asInt(endNumber, 1) - 1] = end.getId("RatioTapChanger"); - } }); return groupedTransformerEnds; } + private Map computeGroupedRatioTapChangers() { + Map groupedRatioTapChangers = new HashMap<>(); + ratioTapChangers() + .forEach(rtc -> { + String transformerId = rtc.getId(CgmesNames.POWER_TRANSFORMER); + groupedRatioTapChangers.computeIfAbsent(transformerId, bag -> new PropertyBags()) + .add(rtc); + }); + return groupedRatioTapChangers; + } + + private Map computeGroupedPhaseTapChangers() { + Map groupedPhaseTapChangers = new HashMap<>(); + phaseTapChangers() + .forEach(ptc -> { + String transformerId = ptc.getId(CgmesNames.POWER_TRANSFORMER); + groupedPhaseTapChangers.computeIfAbsent(transformerId, bag -> new PropertyBags()) + .add(ptc); + }); + return groupedPhaseTapChangers; + } + protected void cacheNodes() { if (!cachedNodes) { cachedConnectivityNodes = connectivityNodes(); @@ -301,8 +315,8 @@ public void read(ReadOnlyDataSource ds, ReportNode reportNode) { protected void invalidateCaches() { cachedGroupedShuntCompensatorPoints = null; cachedGroupedTransformerEnds = null; - powerTransformerRatioTapChanger = null; - powerTransformerPhaseTapChanger = null; + cachedGroupedRatioTapChangers = null; + cachedGroupedPhaseTapChangers = null; cachedTerminals = null; cachedContainers = null; cachedBaseVoltages = null; @@ -319,6 +333,8 @@ protected void invalidateCaches() { // Caches private Map cachedGroupedShuntCompensatorPoints; private Map cachedGroupedTransformerEnds; + private Map cachedGroupedRatioTapChangers; + private Map cachedGroupedPhaseTapChangers; private Map cachedTerminals; private Map cachedContainers; private Map cachedBaseVoltages; @@ -327,8 +343,6 @@ protected void invalidateCaches() { protected PropertyBags cachedTopologicalNodes; private Map cachedNodesById; // equipmentId, sequenceNumber, terminalId - private Map powerTransformerRatioTapChanger; - private Map powerTransformerPhaseTapChanger; private Map cachedDcTerminals; private static final Logger LOG = LoggerFactory.getLogger(AbstractCgmesModel.class); diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java index 0e87608a750..93f48e0a45c 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java @@ -96,8 +96,12 @@ default PropertyBags fullModels() { PropertyBags ratioTapChangers(); + PropertyBags ratioTapChangers(String transformerId); + PropertyBags phaseTapChangers(); + PropertyBags phaseTapChangers(String transformerId); + PropertyBags regulatingControls(); PropertyBags energyConsumers(); @@ -224,10 +228,6 @@ default void write(DataSource ds, CgmesSubset subset) { // Helper mappings - List ratioTapChangerListForPowerTransformer(String powerTransformerId); - - List phaseTapChangerListForPowerTransformer(String powerTransformerId); - /** * Obtain the substation of a given terminal. * diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java index 0f2447b4ae5..cfc7d799542 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java @@ -412,11 +412,21 @@ public PropertyBags ratioTapChangers() { return ratioTapChangers; } + @Override + public PropertyBags ratioTapChangers(String transformerId) { + return new PropertyBags(); + } + @Override public PropertyBags phaseTapChangers() { return phaseTapChangers; } + @Override + public PropertyBags phaseTapChangers(String transformerId) { + return new PropertyBags(); + } + @Override public PropertyBags regulatingControls() { return regulatingControls; @@ -518,16 +528,6 @@ public PropertyBags phaseTapChangerTable(String tableId) { return new PropertyBags(); } - @Override - public List ratioTapChangerListForPowerTransformer(String powerTransformerId) { - return Collections.emptyList(); - } - - @Override - public List phaseTapChangerListForPowerTransformer(String powerTransformerId) { - return Collections.emptyList(); - } - @Override public PropertyBags acDcConverters() { return acDcConverters; diff --git a/cgmes/cgmes-model/src/main/resources/CIM14.sparql b/cgmes/cgmes-model/src/main/resources/CIM14.sparql index 9995e93a173..df164328c4f 100644 --- a/cgmes/cgmes-model/src/main/resources/CIM14.sparql +++ b/cgmes/cgmes-model/src/main/resources/CIM14.sparql @@ -226,8 +226,6 @@ WHERE { cim:TransformerWinding.x ?x ; cim:TransformerWinding.ratedU ?ratedU . ?Terminal cim:Terminal.ConductingEquipment ?TransformerWinding . - OPTIONAL { ?RatioTapChanger cim:RatioTapChanger.TransformerWinding ?TransformerWinding } - OPTIONAL { ?PhaseTapChanger cim:PhaseTapChanger.TransformerWinding ?TransformerWinding } }} BIND ( ?TransformerWinding AS ?TransformerEnd ) } ORDER BY ?PowerTransformer ?windingType @@ -244,6 +242,10 @@ WHERE { cim:TapChanger.neutralU ?neutralU ; cim:TapChanger.stepVoltageIncrement ?stepVoltageIncrement ; cim:RatioTapChanger.TransformerWinding ?TransformerWinding . + ?TransformerWinding + a cim:TransformerWinding ; + cim:TransformerWinding.windingType ?windingType ; + cim:TransformerWinding.MemberOf_PowerTransformer ?PowerTransformer . ?Terminal cim:Terminal.ConductingEquipment ?TransformerWinding . OPTIONAL { ?RatioTapChanger cim:TapChanger.RegulatingControl ?TapChangerControl } }} @@ -268,7 +270,11 @@ WHERE { cim:TapChanger.neutralU ?neutralU ; cim:PhaseTapChanger.phaseTapChangerType ?phaseTapChangerType ; cim:PhaseTapChanger.TransformerWinding ?TransformerWinding . - ?TransformerWinding cim:TransformerWinding.ratedU ?transformerWindingRatedU . + ?TransformerWinding + a cim:TransformerWinding ; + cim:TransformerWinding.ratedU ?transformerWindingRatedU ; + cim:TransformerWinding.windingType ?windingType ; + cim:TransformerWinding.MemberOf_PowerTransformer ?PowerTransformer . ?Terminal cim:Terminal.ConductingEquipment ?TransformerWinding . OPTIONAL { ?PhaseTapChanger cim:PhaseTapChanger.voltageStepIncrementOutOfPhase ?voltageStepIncrementOutOfPhase } OPTIONAL { ?PhaseTapChanger cim:TapChanger.stepVoltageIncrement ?voltageStepIncrement } diff --git a/cgmes/cgmes-model/src/main/resources/CIM16.sparql b/cgmes/cgmes-model/src/main/resources/CIM16.sparql index 63ef7e394bf..0b70d7fa8b0 100644 --- a/cgmes/cgmes-model/src/main/resources/CIM16.sparql +++ b/cgmes/cgmes-model/src/main/resources/CIM16.sparql @@ -559,8 +559,6 @@ WHERE { OPTIONAL { ?TransformerEnd cim:PowerTransformerEnd.phaseAngleClock ?phaseAngleClock } OPTIONAL { ?TransformerEnd cim:PowerTransformerEnd.g ?g } OPTIONAL { ?TransformerEnd cim:PowerTransformerEnd.ratedS ?ratedS } - OPTIONAL { ?RatioTapChanger cim:RatioTapChanger.TransformerEnd ?TransformerEnd } - OPTIONAL { ?PhaseTapChanger cim:PhaseTapChanger.TransformerEnd ?TransformerEnd } }} } ORDER BY ?PowerTransformer ?endNumber @@ -579,6 +577,10 @@ WHERE { cim:RatioTapChanger.stepVoltageIncrement ?stepVoltageIncrement ; cim:TapChanger.ltcFlag ?ltcFlag ; cim:RatioTapChanger.TransformerEnd ?TransformerEnd . + ?TransformerEnd + a cim:PowerTransformerEnd ; + cim:TransformerEnd.endNumber ?endNumber ; + cim:PowerTransformerEnd.PowerTransformer ?PowerTransformer . OPTIONAL { ?RatioTapChanger cim:TapChanger.TapChangerControl ?TapChangerControl . OPTIONAL { @@ -647,6 +649,8 @@ WHERE { cim:PhaseTapChanger.TransformerEnd ?TransformerEnd . ?TransformerEnd a cim:PowerTransformerEnd ; + cim:TransformerEnd.endNumber ?endNumber ; + cim:PowerTransformerEnd.PowerTransformer ?PowerTransformer ; cim:PowerTransformerEnd.ratedU ?transformerWindingRatedU . OPTIONAL { ?PhaseTapChanger From 1bb1bc84ddb8567d655817e741b3e31ac893c427 Mon Sep 17 00:00:00 2001 From: Romain Courtier Date: Mon, 2 Dec 2024 15:15:57 +0100 Subject: [PATCH 4/7] Get tapChangersTablePoints by tableId instead of all in a Map Signed-off-by: Romain Courtier --- .../com/powsybl/cgmes/conversion/Context.java | 34 ------------- .../powsybl/cgmes/conversion/Conversion.java | 2 - .../CgmesPhaseTapChangerBuilder.java | 8 ++-- .../CgmesRatioTapChangerBuilder.java | 8 ++-- .../cgmes/model/AbstractCgmesModel.java | 40 ++++++++++++++++ .../com/powsybl/cgmes/model/CgmesModel.java | 16 +++---- .../cgmes/model/InMemoryCgmesModel.java | 48 +++++++++---------- .../triplestore/CgmesModelTripleStore.java | 32 ++++--------- .../src/main/resources/CIM16.sparql | 35 +------------- 9 files changed, 92 insertions(+), 131 deletions(-) diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Context.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Context.java index 21a0ed1ca49..140f8c24b57 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Context.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Context.java @@ -57,8 +57,6 @@ public Context(CgmesModel cgmes, Config config, Network network, ReportNode repo regulatingControlMapping = new RegulatingControlMapping(this); nodeMapping = new NodeMapping(this); - ratioTapChangerTables = new HashMap<>(); - phaseTapChangerTables = new HashMap<>(); reactiveCapabilityCurveData = new HashMap<>(); } @@ -149,36 +147,6 @@ public PropertyBags reactiveCapabilityCurveData(String curveId) { return reactiveCapabilityCurveData.get(curveId); } - public void loadRatioTapChangerTables() { - PropertyBags rtcpoints = cgmes.ratioTapChangerTablesPoints(); - if (rtcpoints == null) { - return; - } - rtcpoints.forEach(p -> { - String tableId = p.getId("RatioTapChangerTable"); - ratioTapChangerTables.computeIfAbsent(tableId, tid -> new PropertyBags()).add(p); - }); - } - - public void loadPhaseTapChangerTables() { - PropertyBags ptcpoints = cgmes.phaseTapChangerTablesPoints(); - if (ptcpoints == null) { - return; - } - ptcpoints.forEach(p -> { - String tableId = p.getId("PhaseTapChangerTable"); - phaseTapChangerTables.computeIfAbsent(tableId, tid -> new PropertyBags()).add(p); - }); - } - - public PropertyBags ratioTapChangerTable(String tableId) { - return ratioTapChangerTables.get(tableId); - } - - public PropertyBags phaseTapChangerTable(String tableId) { - return phaseTapChangerTables.get(tableId); - } - // Handling issues found during conversion public ReportNode getReportNode() { @@ -287,8 +255,6 @@ private static void logIssue(ConversionIssueCategory category, String what, Supp private final LoadingLimitsMapping loadingLimitsMapping; private final RegulatingControlMapping regulatingControlMapping; - private final Map ratioTapChangerTables; - private final Map phaseTapChangerTables; private final Map reactiveCapabilityCurveData; private static final Logger LOG = LoggerFactory.getLogger(Context.class); diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java index e3fa5235280..e3663479ca4 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java @@ -472,8 +472,6 @@ private Network createNetwork() { private Context createContext(Network network, ReportNode reportNode) { Context context = new Context(cgmes, config, network, reportNode); context.dc().initialize(); - context.loadRatioTapChangerTables(); - context.loadPhaseTapChangerTables(); context.loadReactiveCapabilityCurveData(); return context; } diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/CgmesPhaseTapChangerBuilder.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/CgmesPhaseTapChangerBuilder.java index f016da66ba3..52a41452a6e 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/CgmesPhaseTapChangerBuilder.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/CgmesPhaseTapChangerBuilder.java @@ -70,13 +70,13 @@ protected void addSteps() { if (isLinear()) { addStepsLinear(); } else if (isTabular()) { - PropertyBags table = context.phaseTapChangerTable(tableId); - if (table == null) { + PropertyBags tablePoints = context.cgmes().phaseTapChangerTablePoints(tableId); + if (tablePoints.isEmpty()) { addStepsLinear(); return; } - if (isTableValid(tableId, table)) { - addStepsFromTable(table); + if (isTableValid(tableId, tablePoints)) { + addStepsFromTable(tablePoints); } else { addStepsLinear(); } diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/CgmesRatioTapChangerBuilder.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/CgmesRatioTapChangerBuilder.java index 459ee8b82c0..af4a2374048 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/CgmesRatioTapChangerBuilder.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/transformers/CgmesRatioTapChangerBuilder.java @@ -40,13 +40,13 @@ protected void addRegulationData() { protected void addSteps() { String tableId = p.getId(CgmesNames.RATIO_TAP_CHANGER_TABLE); if (tableId != null) { - PropertyBags table = context.ratioTapChangerTable(tableId); - if (table == null) { + PropertyBags tablePoints = context.cgmes().ratioTapChangerTablePoints(tableId); + if (tablePoints.isEmpty()) { addStepsFromLowHighIncrement(); return; } - if (isTableValid(tableId, table)) { - addStepsFromTable(table, tableId); + if (isTableValid(tableId, tablePoints)) { + addStepsFromTable(tablePoints, tableId); } else { addStepsFromLowHighIncrement(); } diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java index e2f4213aee3..fa024d23c21 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java @@ -59,6 +59,14 @@ public PropertyBags ratioTapChangers(String transformerId) { return cachedGroupedRatioTapChangers.getOrDefault(transformerId, new PropertyBags()); } + @Override + public PropertyBags ratioTapChangerTablePoints(String tableId) { + if (cachedGroupedRatioTapChangerTablePoints == null) { + cachedGroupedRatioTapChangerTablePoints = computeGroupedRatioTapChangerTablePoints(); + } + return cachedGroupedRatioTapChangerTablePoints.getOrDefault(tableId, new PropertyBags()); + } + @Override public PropertyBags phaseTapChangers(String transformerId) { if (cachedGroupedPhaseTapChangers == null) { @@ -67,6 +75,14 @@ public PropertyBags phaseTapChangers(String transformerId) { return cachedGroupedPhaseTapChangers.getOrDefault(transformerId, new PropertyBags()); } + @Override + public PropertyBags phaseTapChangerTablePoints(String tableId) { + if (cachedGroupedPhaseTapChangerTablePoints == null) { + cachedGroupedPhaseTapChangerTablePoints = computeGroupedPhaseTapChangerTablePoints(); + } + return cachedGroupedPhaseTapChangerTablePoints.getOrDefault(tableId, new PropertyBags()); + } + @Override public Collection computedTerminals() { if (cachedTerminals == null) { @@ -207,6 +223,17 @@ private Map computeGroupedRatioTapChangers() { return groupedRatioTapChangers; } + private Map computeGroupedRatioTapChangerTablePoints() { + Map groupedRatioTapChangerTablePoints = new HashMap<>(); + ratioTapChangerTablePoints() + .forEach(point -> { + String tableId = point.getId("RatioTapChangerTable"); + groupedRatioTapChangerTablePoints.computeIfAbsent(tableId, bag -> new PropertyBags()) + .add(point); + }); + return groupedRatioTapChangerTablePoints; + } + private Map computeGroupedPhaseTapChangers() { Map groupedPhaseTapChangers = new HashMap<>(); phaseTapChangers() @@ -218,6 +245,17 @@ private Map computeGroupedPhaseTapChangers() { return groupedPhaseTapChangers; } + private Map computeGroupedPhaseTapChangerTablePoints() { + Map groupedPhaseTapChangerTablePoints = new HashMap<>(); + phaseTapChangerTablePoints() + .forEach(point -> { + String tableId = point.getId("PhaseTapChangerTable"); + groupedPhaseTapChangerTablePoints.computeIfAbsent(tableId, bag -> new PropertyBags()) + .add(point); + }); + return groupedPhaseTapChangerTablePoints; + } + protected void cacheNodes() { if (!cachedNodes) { cachedConnectivityNodes = connectivityNodes(); @@ -334,7 +372,9 @@ protected void invalidateCaches() { private Map cachedGroupedShuntCompensatorPoints; private Map cachedGroupedTransformerEnds; private Map cachedGroupedRatioTapChangers; + private Map cachedGroupedRatioTapChangerTablePoints; private Map cachedGroupedPhaseTapChangers; + private Map cachedGroupedPhaseTapChangerTablePoints; private Map cachedTerminals; private Map cachedContainers; private Map cachedBaseVoltages; diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java index 93f48e0a45c..0b7888cbede 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java @@ -98,10 +98,18 @@ default PropertyBags fullModels() { PropertyBags ratioTapChangers(String transformerId); + PropertyBags ratioTapChangerTablePoints(); + + PropertyBags ratioTapChangerTablePoints(String tableId); + PropertyBags phaseTapChangers(); PropertyBags phaseTapChangers(String transformerId); + PropertyBags phaseTapChangerTablePoints(); + + PropertyBags phaseTapChangerTablePoints(String tableId); + PropertyBags regulatingControls(); PropertyBags energyConsumers(); @@ -160,14 +168,6 @@ default PropertyBags synchronousMachinesAll() { PropertyBags reactiveCapabilityCurveData(); - PropertyBags ratioTapChangerTablesPoints(); - - PropertyBags phaseTapChangerTablesPoints(); - - PropertyBags ratioTapChangerTable(String tableId); - - PropertyBags phaseTapChangerTable(String tableId); - PropertyBags controlAreas(); PropertyBags acDcConverters(); diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java index cfc7d799542..d6aa1b2a802 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java @@ -417,6 +417,18 @@ public PropertyBags ratioTapChangers(String transformerId) { return new PropertyBags(); } + @Override + public PropertyBags ratioTapChangerTablePoints() { + // FakeCgmesModel does not implement ratio tap changer tables + return new PropertyBags(); + } + + @Override + public PropertyBags ratioTapChangerTablePoints(String tableId) { + // FakeCgmesModel does not implement ratio tap changer tables + return new PropertyBags(); + } + @Override public PropertyBags phaseTapChangers() { return phaseTapChangers; @@ -427,6 +439,18 @@ public PropertyBags phaseTapChangers(String transformerId) { return new PropertyBags(); } + @Override + public PropertyBags phaseTapChangerTablePoints() { + // FakeCgmesModel does not implement phase tap changer tables + return new PropertyBags(); + } + + @Override + public PropertyBags phaseTapChangerTablePoints(String tableId) { + // FakeCgmesModel does not implement phase tap changer tables + return new PropertyBags(); + } + @Override public PropertyBags regulatingControls() { return regulatingControls; @@ -504,30 +528,6 @@ public PropertyBags reactiveCapabilityCurveData() { return new PropertyBags(); } - @Override - public PropertyBags ratioTapChangerTablesPoints() { - // FakeCgmesModel does not implement ratio tap changer tables - return new PropertyBags(); - } - - @Override - public PropertyBags phaseTapChangerTablesPoints() { - // FakeCgmesModel does not implement phase tap changer tables - return new PropertyBags(); - } - - @Override - public PropertyBags ratioTapChangerTable(String tableId) { - // FakeCgmesModel does not implement ratio tap changer tables - return new PropertyBags(); - } - - @Override - public PropertyBags phaseTapChangerTable(String tableId) { - // FakeCgmesModel does not implement phase tap changer tables - return new PropertyBags(); - } - @Override public PropertyBags acDcConverters() { return acDcConverters; diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/triplestore/CgmesModelTripleStore.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/triplestore/CgmesModelTripleStore.java index 7915a17dfe8..6691196d6e4 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/triplestore/CgmesModelTripleStore.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/triplestore/CgmesModelTripleStore.java @@ -467,11 +467,21 @@ public PropertyBags ratioTapChangers() { return namedQuery("ratioTapChangers"); } + @Override + public PropertyBags ratioTapChangerTablePoints() { + return namedQuery("ratioTapChangerTablePoints"); + } + @Override public PropertyBags phaseTapChangers() { return namedQuery("phaseTapChangers"); } + @Override + public PropertyBags phaseTapChangerTablePoints() { + return namedQuery("phaseTapChangerTablePoints"); + } + @Override public PropertyBags regulatingControls() { return namedQuery("regulatingControls"); @@ -542,28 +552,6 @@ public PropertyBags reactiveCapabilityCurveData() { return namedQuery("reactiveCapabilityCurveData"); } - @Override - public PropertyBags ratioTapChangerTablesPoints() { - return namedQuery("ratioTapChangerTablesPoints"); - } - - @Override - public PropertyBags phaseTapChangerTablesPoints() { - return namedQuery("phaseTapChangerTablesPoints"); - } - - @Override - public PropertyBags ratioTapChangerTable(String tableId) { - Objects.requireNonNull(tableId); - return namedQuery("ratioTapChangerTable", tableId); - } - - @Override - public PropertyBags phaseTapChangerTable(String tableId) { - Objects.requireNonNull(tableId); - return namedQuery("phaseTapChangerTable", tableId); - } - @Override public PropertyBags controlAreas() { return namedQuery("controlAreas"); diff --git a/cgmes/cgmes-model/src/main/resources/CIM16.sparql b/cgmes/cgmes-model/src/main/resources/CIM16.sparql index 0b70d7fa8b0..9a9c99321fc 100644 --- a/cgmes/cgmes-model/src/main/resources/CIM16.sparql +++ b/cgmes/cgmes-model/src/main/resources/CIM16.sparql @@ -604,22 +604,7 @@ OPTIONAL { GRAPH ?graphSV { }} } -# query: ratioTapChangerTable -SELECT * -WHERE { - ?RatioTapChangerTablePoint - a cim:RatioTapChangerTablePoint ; - cim:RatioTapChangerTablePoint.RatioTapChangerTable ?Table ; - cim:TapChangerTablePoint.step ?step . - FILTER regex(str(?Table), "{0}") - OPTIONAL { ?RatioTapChangerTablePoint cim:TapChangerTablePoint.ratio ?ratio } - OPTIONAL { ?RatioTapChangerTablePoint cim:TapChangerTablePoint.r ?r } - OPTIONAL { ?RatioTapChangerTablePoint cim:TapChangerTablePoint.x ?x } - OPTIONAL { ?RatioTapChangerTablePoint cim:TapChangerTablePoint.g ?g } - OPTIONAL { ?RatioTapChangerTablePoint cim:TapChangerTablePoint.b ?b } -} - -# query: ratioTapChangerTablesPoints +# query: ratioTapChangerTablePoints SELECT * WHERE { ?RatioTapChangerTablePoint @@ -690,23 +675,7 @@ OPTIONAL { GRAPH ?graphSV { }} } -# query: phaseTapChangerTable -SELECT * -WHERE { - ?PhaseTapChangerTablePoint - a cim:PhaseTapChangerTablePoint ; - cim:PhaseTapChangerTablePoint.PhaseTapChangerTable ?Table ; - cim:PhaseTapChangerTablePoint.angle ?angle ; - cim:TapChangerTablePoint.step ?step . - FILTER regex(str(?Table), "{0}") - OPTIONAL { ?PhaseTapChangerTablePoint cim:TapChangerTablePoint.ratio ?ratio } - OPTIONAL { ?PhaseTapChangerTablePoint cim:TapChangerTablePoint.r ?r } - OPTIONAL { ?PhaseTapChangerTablePoint cim:TapChangerTablePoint.x ?x } - OPTIONAL { ?PhaseTapChangerTablePoint cim:TapChangerTablePoint.g ?g } - OPTIONAL { ?PhaseTapChangerTablePoint cim:TapChangerTablePoint.b ?b } -} - -# query: phaseTapChangerTablesPoints +# query: phaseTapChangerTablePoints SELECT * WHERE { ?PhaseTapChangerTablePoint From 4ed95502fe213e935a3eece89a3927e894f30ede Mon Sep 17 00:00:00 2001 From: Romain Courtier Date: Mon, 2 Dec 2024 17:01:52 +0100 Subject: [PATCH 5/7] Get curveData by curveId instead of all in a Map Signed-off-by: Romain Courtier --- .../com/powsybl/cgmes/conversion/Context.java | 22 ------------------- .../powsybl/cgmes/conversion/Conversion.java | 1 - ...AbstractReactiveLimitsOwnerConversion.java | 2 +- .../cgmes/model/AbstractCgmesModel.java | 21 ++++++++++++++++++ .../com/powsybl/cgmes/model/CgmesModel.java | 4 +++- .../cgmes/model/InMemoryCgmesModel.java | 8 ++++++- .../triplestore/CgmesModelTripleStore.java | 4 ++-- .../src/main/resources/CIM16.sparql | 2 +- 8 files changed, 35 insertions(+), 29 deletions(-) diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Context.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Context.java index 140f8c24b57..b734bbbc12d 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Context.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Context.java @@ -17,12 +17,9 @@ import com.powsybl.iidm.network.IdentifiableType; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.Terminal; -import com.powsybl.triplestore.api.PropertyBags; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashMap; -import java.util.Map; import java.util.Objects; import java.util.function.Supplier; @@ -56,8 +53,6 @@ public Context(CgmesModel cgmes, Config config, Network network, ReportNode repo loadingLimitsMapping = new LoadingLimitsMapping(this); regulatingControlMapping = new RegulatingControlMapping(this); nodeMapping = new NodeMapping(this); - - reactiveCapabilityCurveData = new HashMap<>(); } public CgmesModel cgmes() { @@ -132,21 +127,6 @@ public static String boundarySubstationId(String nodeId) { return nodeId + "_S"; } - public void loadReactiveCapabilityCurveData() { - PropertyBags rccdata = cgmes.reactiveCapabilityCurveData(); - if (rccdata == null) { - return; - } - rccdata.forEach(p -> { - String curveId = p.getId("ReactiveCapabilityCurve"); - reactiveCapabilityCurveData.computeIfAbsent(curveId, cid -> new PropertyBags()).add(p); - }); - } - - public PropertyBags reactiveCapabilityCurveData(String curveId) { - return reactiveCapabilityCurveData.get(curveId); - } - // Handling issues found during conversion public ReportNode getReportNode() { @@ -255,7 +235,5 @@ private static void logIssue(ConversionIssueCategory category, String what, Supp private final LoadingLimitsMapping loadingLimitsMapping; private final RegulatingControlMapping regulatingControlMapping; - private final Map reactiveCapabilityCurveData; - private static final Logger LOG = LoggerFactory.getLogger(Context.class); } diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java index e3663479ca4..6e2dff988fe 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/Conversion.java @@ -472,7 +472,6 @@ private Network createNetwork() { private Context createContext(Network network, ReportNode reportNode) { Context context = new Context(cgmes, config, network, reportNode); context.dc().initialize(); - context.loadReactiveCapabilityCurveData(); return context; } diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/AbstractReactiveLimitsOwnerConversion.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/AbstractReactiveLimitsOwnerConversion.java index cc942b4e0fc..170f0ec1659 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/AbstractReactiveLimitsOwnerConversion.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/AbstractReactiveLimitsOwnerConversion.java @@ -64,7 +64,7 @@ protected void convertReactiveLimits(ReactiveLimitsHolder g) { // ReactiveCapabilityCurve. if (p.containsKey("ReactiveCapabilityCurve")) { String curveId = p.getId("ReactiveCapabilityCurve"); - PropertyBags curveData = context.reactiveCapabilityCurveData(curveId); + PropertyBags curveData = context.cgmes().curveData(curveId); Map> qRanges = new HashMap<>(); curveData.forEach(d -> getReactiveCapabilityCurveData(d, qRanges)); diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java index fa024d23c21..3ff812f979b 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java @@ -83,6 +83,14 @@ public PropertyBags phaseTapChangerTablePoints(String tableId) { return cachedGroupedPhaseTapChangerTablePoints.getOrDefault(tableId, new PropertyBags()); } + @Override + public PropertyBags curveData(String curveId) { + if (cachedGroupedCurveData == null) { + cachedGroupedCurveData = computeGroupedCurveData(); + } + return cachedGroupedCurveData.getOrDefault(curveId, new PropertyBags()); + } + @Override public Collection computedTerminals() { if (cachedTerminals == null) { @@ -256,6 +264,17 @@ private Map computeGroupedPhaseTapChangerTablePoints() { return groupedPhaseTapChangerTablePoints; } + private Map computeGroupedCurveData() { + Map groupedCurveData = new HashMap<>(); + curveData() + .forEach(data -> { + String curveId = data.getId("ReactiveCapabilityCurve"); + groupedCurveData.computeIfAbsent(curveId, bag -> new PropertyBags()) + .add(data); + }); + return groupedCurveData; + } + protected void cacheNodes() { if (!cachedNodes) { cachedConnectivityNodes = connectivityNodes(); @@ -355,6 +374,7 @@ protected void invalidateCaches() { cachedGroupedTransformerEnds = null; cachedGroupedRatioTapChangers = null; cachedGroupedPhaseTapChangers = null; + cachedGroupedCurveData = null; cachedTerminals = null; cachedContainers = null; cachedBaseVoltages = null; @@ -375,6 +395,7 @@ protected void invalidateCaches() { private Map cachedGroupedRatioTapChangerTablePoints; private Map cachedGroupedPhaseTapChangers; private Map cachedGroupedPhaseTapChangerTablePoints; + private Map cachedGroupedCurveData; private Map cachedTerminals; private Map cachedContainers; private Map cachedBaseVoltages; diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java index 0b7888cbede..5daf48f1010 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/CgmesModel.java @@ -166,7 +166,9 @@ default PropertyBags synchronousMachinesAll() { PropertyBags asynchronousMachines(); - PropertyBags reactiveCapabilityCurveData(); + PropertyBags curveData(); + + PropertyBags curveData(String curveId); PropertyBags controlAreas(); diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java index d6aa1b2a802..a2a5fd0128b 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java @@ -523,7 +523,13 @@ public PropertyBags modelProfiles() { } @Override - public PropertyBags reactiveCapabilityCurveData() { + public PropertyBags curveData() { + // FakeCgmesModel does not implement reactive capability curve + return new PropertyBags(); + } + + @Override + public PropertyBags curveData(String curveId) { // FakeCgmesModel does not implement reactive capability curve return new PropertyBags(); } diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/triplestore/CgmesModelTripleStore.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/triplestore/CgmesModelTripleStore.java index 6691196d6e4..c4ea611dd8e 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/triplestore/CgmesModelTripleStore.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/triplestore/CgmesModelTripleStore.java @@ -548,8 +548,8 @@ public PropertyBags asynchronousMachines() { } @Override - public PropertyBags reactiveCapabilityCurveData() { - return namedQuery("reactiveCapabilityCurveData"); + public PropertyBags curveData() { + return namedQuery("curveData"); } @Override diff --git a/cgmes/cgmes-model/src/main/resources/CIM16.sparql b/cgmes/cgmes-model/src/main/resources/CIM16.sparql index 9a9c99321fc..a57b50d10aa 100644 --- a/cgmes/cgmes-model/src/main/resources/CIM16.sparql +++ b/cgmes/cgmes-model/src/main/resources/CIM16.sparql @@ -945,7 +945,7 @@ WHERE { }} } -# query: reactiveCapabilityCurveData +# query: curveData SELECT * WHERE { ?CurveData From b4c9a6431cc479d7864326a6e001f9ec287768ac Mon Sep 17 00:00:00 2001 From: Romain Courtier Date: Wed, 4 Dec 2024 12:24:59 +0100 Subject: [PATCH 6/7] Create final caches and factorize the building of caches Signed-off-by: Romain Courtier --- .../cgmes/model/AbstractCgmesModel.java | 183 +++++------------- 1 file changed, 53 insertions(+), 130 deletions(-) diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java index 3ff812f979b..cdc74cac22e 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/AbstractCgmesModel.java @@ -25,6 +25,31 @@ */ public abstract class AbstractCgmesModel implements CgmesModel { + private final Properties properties; + private String baseName; + + // Caches + private final Map cachedGroupedTransformerEnds = new HashMap<>(); + private final Map cachedGroupedRatioTapChangers = new HashMap<>(); + private final Map cachedGroupedRatioTapChangerTablePoints = new HashMap<>(); + private final Map cachedGroupedPhaseTapChangers = new HashMap<>(); + private final Map cachedGroupedPhaseTapChangerTablePoints = new HashMap<>(); + private final Map cachedGroupedShuntCompensatorPoints = new HashMap<>(); + private final Map cachedGroupedCurveData = new HashMap<>(); + + private Map cachedTerminals; + private Map cachedContainers; + private Map cachedBaseVoltages; + protected boolean cachedNodes = false; + protected PropertyBags cachedConnectivityNodes; + protected PropertyBags cachedTopologicalNodes; + private Map cachedNodesById; + // equipmentId, sequenceNumber, terminalId + private Map cachedDcTerminals; + + private static final Logger LOG = LoggerFactory.getLogger(AbstractCgmesModel.class); + private static final String SUBSTATION = "Substation"; + protected AbstractCgmesModel() { // FIXME(Luma) we must remove properties from here. They are not used! this.properties = new Properties(); @@ -35,59 +60,38 @@ public Properties getProperties() { return this.properties; } - @Override - public PropertyBags nonlinearShuntCompensatorPoints(String shuntId) { - if (cachedGroupedShuntCompensatorPoints == null) { - cachedGroupedShuntCompensatorPoints = computeGroupedShuntCompensatorPoints(); - } - return cachedGroupedShuntCompensatorPoints.getOrDefault(shuntId, new PropertyBags()); - } - @Override public PropertyBags transformerEnds(String transformerId) { - if (cachedGroupedTransformerEnds == null) { - cachedGroupedTransformerEnds = computeGroupedTransformerEnds(); - } return cachedGroupedTransformerEnds.getOrDefault(transformerId, new PropertyBags()); } @Override public PropertyBags ratioTapChangers(String transformerId) { - if (cachedGroupedRatioTapChangers == null) { - cachedGroupedRatioTapChangers = computeGroupedRatioTapChangers(); - } return cachedGroupedRatioTapChangers.getOrDefault(transformerId, new PropertyBags()); } @Override public PropertyBags ratioTapChangerTablePoints(String tableId) { - if (cachedGroupedRatioTapChangerTablePoints == null) { - cachedGroupedRatioTapChangerTablePoints = computeGroupedRatioTapChangerTablePoints(); - } return cachedGroupedRatioTapChangerTablePoints.getOrDefault(tableId, new PropertyBags()); } @Override public PropertyBags phaseTapChangers(String transformerId) { - if (cachedGroupedPhaseTapChangers == null) { - cachedGroupedPhaseTapChangers = computeGroupedPhaseTapChangers(); - } return cachedGroupedPhaseTapChangers.getOrDefault(transformerId, new PropertyBags()); } @Override public PropertyBags phaseTapChangerTablePoints(String tableId) { - if (cachedGroupedPhaseTapChangerTablePoints == null) { - cachedGroupedPhaseTapChangerTablePoints = computeGroupedPhaseTapChangerTablePoints(); - } return cachedGroupedPhaseTapChangerTablePoints.getOrDefault(tableId, new PropertyBags()); } + @Override + public PropertyBags nonlinearShuntCompensatorPoints(String shuntId) { + return cachedGroupedShuntCompensatorPoints.getOrDefault(shuntId, new PropertyBags()); + } + @Override public PropertyBags curveData(String curveId) { - if (cachedGroupedCurveData == null) { - cachedGroupedCurveData = computeGroupedCurveData(); - } return cachedGroupedCurveData.getOrDefault(curveId, new PropertyBags()); } @@ -198,83 +202,6 @@ private CgmesContainer container(CgmesTerminal t, boolean nodeBreaker) { return (containerId == null) ? null : container(containerId); } - private Map computeGroupedShuntCompensatorPoints() { - Map groupedShuntCompensatorPoints = new HashMap<>(); - nonlinearShuntCompensatorPoints() - .forEach(point -> { - String shuntCompensator = point.getId("Shunt"); - groupedShuntCompensatorPoints.computeIfAbsent(shuntCompensator, bag -> new PropertyBags()) - .add(point); - }); - return groupedShuntCompensatorPoints; - } - - private Map computeGroupedTransformerEnds() { - Map groupedTransformerEnds = new HashMap<>(); - transformerEnds() - .forEach(end -> { - String transformerId = end.getId(CgmesNames.POWER_TRANSFORMER); - groupedTransformerEnds.computeIfAbsent(transformerId, x -> new PropertyBags()) - .add(end); - }); - return groupedTransformerEnds; - } - - private Map computeGroupedRatioTapChangers() { - Map groupedRatioTapChangers = new HashMap<>(); - ratioTapChangers() - .forEach(rtc -> { - String transformerId = rtc.getId(CgmesNames.POWER_TRANSFORMER); - groupedRatioTapChangers.computeIfAbsent(transformerId, bag -> new PropertyBags()) - .add(rtc); - }); - return groupedRatioTapChangers; - } - - private Map computeGroupedRatioTapChangerTablePoints() { - Map groupedRatioTapChangerTablePoints = new HashMap<>(); - ratioTapChangerTablePoints() - .forEach(point -> { - String tableId = point.getId("RatioTapChangerTable"); - groupedRatioTapChangerTablePoints.computeIfAbsent(tableId, bag -> new PropertyBags()) - .add(point); - }); - return groupedRatioTapChangerTablePoints; - } - - private Map computeGroupedPhaseTapChangers() { - Map groupedPhaseTapChangers = new HashMap<>(); - phaseTapChangers() - .forEach(ptc -> { - String transformerId = ptc.getId(CgmesNames.POWER_TRANSFORMER); - groupedPhaseTapChangers.computeIfAbsent(transformerId, bag -> new PropertyBags()) - .add(ptc); - }); - return groupedPhaseTapChangers; - } - - private Map computeGroupedPhaseTapChangerTablePoints() { - Map groupedPhaseTapChangerTablePoints = new HashMap<>(); - phaseTapChangerTablePoints() - .forEach(point -> { - String tableId = point.getId("PhaseTapChangerTable"); - groupedPhaseTapChangerTablePoints.computeIfAbsent(tableId, bag -> new PropertyBags()) - .add(point); - }); - return groupedPhaseTapChangerTablePoints; - } - - private Map computeGroupedCurveData() { - Map groupedCurveData = new HashMap<>(); - curveData() - .forEach(data -> { - String curveId = data.getId("ReactiveCapabilityCurve"); - groupedCurveData.computeIfAbsent(curveId, bag -> new PropertyBags()) - .add(data); - }); - return groupedCurveData; - } - protected void cacheNodes() { if (!cachedNodes) { cachedConnectivityNodes = connectivityNodes(); @@ -367,14 +294,17 @@ public void read(ReadOnlyDataSource ds, ReportNode reportNode) { throw new CgmesModelException(msg, e); } } + buildCaches(); } protected void invalidateCaches() { - cachedGroupedShuntCompensatorPoints = null; - cachedGroupedTransformerEnds = null; - cachedGroupedRatioTapChangers = null; - cachedGroupedPhaseTapChangers = null; - cachedGroupedCurveData = null; + cachedGroupedTransformerEnds.clear(); + cachedGroupedRatioTapChangers.clear(); + cachedGroupedRatioTapChangerTablePoints.clear(); + cachedGroupedPhaseTapChangers.clear(); + cachedGroupedPhaseTapChangerTablePoints.clear(); + cachedGroupedShuntCompensatorPoints.clear(); + cachedGroupedCurveData.clear(); cachedTerminals = null; cachedContainers = null; cachedBaseVoltages = null; @@ -385,27 +315,20 @@ protected void invalidateCaches() { cachedDcTerminals = null; } - private final Properties properties; - private String baseName; - - // Caches - private Map cachedGroupedShuntCompensatorPoints; - private Map cachedGroupedTransformerEnds; - private Map cachedGroupedRatioTapChangers; - private Map cachedGroupedRatioTapChangerTablePoints; - private Map cachedGroupedPhaseTapChangers; - private Map cachedGroupedPhaseTapChangerTablePoints; - private Map cachedGroupedCurveData; - private Map cachedTerminals; - private Map cachedContainers; - private Map cachedBaseVoltages; - protected boolean cachedNodes = false; - protected PropertyBags cachedConnectivityNodes; - protected PropertyBags cachedTopologicalNodes; - private Map cachedNodesById; - // equipmentId, sequenceNumber, terminalId - private Map cachedDcTerminals; + private void buildCaches() { + buildCache(cachedGroupedTransformerEnds, transformerEnds(), CgmesNames.POWER_TRANSFORMER); + buildCache(cachedGroupedRatioTapChangers, ratioTapChangers(), CgmesNames.POWER_TRANSFORMER); + buildCache(cachedGroupedRatioTapChangerTablePoints, ratioTapChangerTablePoints(), CgmesNames.RATIO_TAP_CHANGER_TABLE); + buildCache(cachedGroupedPhaseTapChangers, phaseTapChangers(), CgmesNames.POWER_TRANSFORMER); + buildCache(cachedGroupedPhaseTapChangerTablePoints, phaseTapChangerTablePoints(), CgmesNames.PHASE_TAP_CHANGER_TABLE); + buildCache(cachedGroupedShuntCompensatorPoints, nonlinearShuntCompensatorPoints(), "Shunt"); + buildCache(cachedGroupedCurveData, curveData(), "ReactiveCapabilityCurve"); + } - private static final Logger LOG = LoggerFactory.getLogger(AbstractCgmesModel.class); - private static final String SUBSTATION = "Substation"; + private void buildCache(Map cache, PropertyBags ps, String groupName) { + ps.forEach(p -> { + String groupId = p.getId(groupName); + cache.computeIfAbsent(groupId, b -> new PropertyBags()).add(p); + }); + } } From 8561bd6ccc7e90f03680539487749abf7ef4453a Mon Sep 17 00:00:00 2001 From: Romain Courtier Date: Mon, 9 Dec 2024 13:03:22 +0100 Subject: [PATCH 7/7] Rename methods to build InMemoryCgmesModel in order to avoid name collisions with queries methods Signed-off-by: Romain Courtier --- .../conformity/CgmesConformity1Catalog.java | 82 +++++++------- .../test/FakeSubstationsConversionTest.java | 2 +- .../model/test/Cim14SmallCasesCatalog.java | 104 +++++++++--------- .../cgmes/model/InMemoryCgmesModel.java | 72 ++++++------ 4 files changed, 130 insertions(+), 130 deletions(-) diff --git a/cgmes/cgmes-conformity/src/main/java/com/powsybl/cgmes/conformity/CgmesConformity1Catalog.java b/cgmes/cgmes-conformity/src/main/java/com/powsybl/cgmes/conformity/CgmesConformity1Catalog.java index c8ff3e96e68..dbcfd5b19bb 100644 --- a/cgmes/cgmes-conformity/src/main/java/com/powsybl/cgmes/conformity/CgmesConformity1Catalog.java +++ b/cgmes/cgmes-conformity/src/main/java/com/powsybl/cgmes/conformity/CgmesConformity1Catalog.java @@ -243,17 +243,17 @@ public static GridModelReferenceResources smallNodeBreakerHvdcOnlyEQ() { public static InMemoryCgmesModel expectedMicroGridBaseCaseBE() { return new InMemoryCgmesModel() - .modelId("MicroBaseCaseBE") - .version("unknown") - .substations("37e14a0f-5e34-4647-a062-8bfd9305fa9d", + .withModelId("MicroBaseCaseBE") + .withVersion("unknown") + .withSubstations("37e14a0f-5e34-4647-a062-8bfd9305fa9d", "87f7002b-056f-4a6a-a872-1744eea757e3") - .voltageLevels("469df5f7-058f-4451-a998-57a48e8a56fe", + .withVoltageLevels("469df5f7-058f-4451-a998-57a48e8a56fe", "4ba71b59-ee2f-450b-9f7d-cc2f1cc5e386", "8bbd7e74-ae20-4dce-8780-c20f8e18c2e0", "929ba893-c9dc-44d7-b1fd-30834bd3ab85", "b10b171b-3bc5-4849-bb1f-61ed9ea1ec7c", "d0486169-2205-40b2-895e-b672ecb9e5fc") - .terminals("02a244ca-8bcb-4e25-8613-e948b8ba1f22", + .withTerminals("02a244ca-8bcb-4e25-8613-e948b8ba1f22", "051d49ba-4360-4372-86bf-50eb8cf29778", "05a17350-55f5-4a00-9a50-8c0048a25495", "1182d878-2eaa-4eec-91be-ce7b2b1e7f9a", @@ -299,7 +299,7 @@ public static InMemoryCgmesModel expectedMicroGridBaseCaseBE() { "f3b56334-4638-49d3-a6a0-3f417422b8f5", "f9f29835-8a31-4310-9780-b1ad26f3cbb0", "fa9e0f4d-8a2f-45e1-9e36-3611600d1c94") - .operationalLimits("05b69cbf-0e24-4c98-bd81-9450c751be6f", + .withOperationalLimits("05b69cbf-0e24-4c98-bd81-9450c751be6f", "05b69cbf-0e24-4c98-bd81-9450c751be6f1", "0d6f26df-9f86-4df0-b00c-bfb23870257f", "0f8bff64-4cfe-4c94-9471-da94b2efcc4f", @@ -400,7 +400,7 @@ public static InMemoryCgmesModel expectedMicroGridBaseCaseBE() { "fdae97f0-ee12-4d0e-9bba-e994b2ca78fb", "fdae97f0-ee12-4d0e-9bba-e994b2ca78fb1") // Topological nodes only for voltage levels as connectivity node containers - .topologicalNodes("5c74cb26-ce2f-40c6-951d-89091eb781b6", + .withTopologicalNodes("5c74cb26-ce2f-40c6-951d-89091eb781b6", "99b219f3-4593-428b-a4da-124a54630178", "a81d08ed-f51d-4538-8d1e-fb2d0dbd128e", "e44141af-f1dc-44d3-bfa4-b674e5c953d7", @@ -414,18 +414,18 @@ public static InMemoryCgmesModel expectedMicroGridBaseCaseBE() { "1fa19c281c8f4e1eaad9e1cab70f923e", "1098b1c9-dc85-40ce-b65c-39ae02a3afaa") // No switches are defined, it is a bus branch model - .acLineSegments("17086487-56ba-4979-b8de-064025a6b4da", + .withAcLineSegments("17086487-56ba-4979-b8de-064025a6b4da", "78736387-5f60-4832-b3fe-d50daf81b0a6", "a16b4a6c-70b1-4abf-9a9d-bd0fa47f9fe4", "b18cd1aa-7808-49b9-a7cf-605eaf07b006", "b58bf21a-096a-4dae-9a01-3f03b60c24c7", "ed0c5d75-4a54-43c8-b782-b20d7431630b", "ffbabc27-1ccd-4fdc-b037-e341706c8d29") - .transformers("84ed55f4-61f5-4d9d-8755-bba7b877a246", + .withTransformers("84ed55f4-61f5-4d9d-8755-bba7b877a246", "a708c3bc-465d-4fe7-b6ef-6fa6408a62b0", "b94318f6-6d24-4f56-96b9-df2531ad6543", "e482b89a-fa84-4ea9-8e70-a83d44790957") - .transformerEnds("1912224a-9e98-41aa-84cf-00875bce7264", + .withTransformerEnds("1912224a-9e98-41aa-84cf-00875bce7264", "2e21d1ef-2287-434c-a767-1ca807cf2478", "35651e25-a77a-46a1-92f4-443d6acce90e", "49ca3fd4-1b54-4c5b-83fd-4dbd0f9fec9d", @@ -434,18 +434,18 @@ public static InMemoryCgmesModel expectedMicroGridBaseCaseBE() { "81a18364-0397-48d3-b850-22a0e34b410f", "e1f661c0-971d-4ce5-ad39-0ec427f288ab", "f58281c5-862a-465e-97ec-d809be6e24ab") - .ratioTapChangers("83cc66dd-8d93-4a2c-8103-f1f5a9cf7e2e", + .withRatioTapChangers("83cc66dd-8d93-4a2c-8103-f1f5a9cf7e2e", "955d9cd0-4a10-4031-b008-60c0dc340a07", "fe25f43a-7341-446e-a71a-8ab7119ba806") - .phaseTapChangers(new String[]{"6ebbef67-3061-4236-a6fd-6ccc4595f6c3"}) - .energyConsumers("1c6beed6-1acf-42e7-ba55-0cc9f04bddd8", + .withPhaseTapChangers("6ebbef67-3061-4236-a6fd-6ccc4595f6c3") + .withEnergyConsumers("1c6beed6-1acf-42e7-ba55-0cc9f04bddd8", "b1480a00-b427-4001-a26c-51954d2bb7e9", "cb459405-cc14-4215-a45c-416789205904") - .shuntCompensators("002b0a40-3957-46db-b84a-30420083558f", + .withShuntCompensators("002b0a40-3957-46db-b84a-30420083558f", "d771118f-36e9-4115-a128-cc3d9ce3e3da") - .synchronousMachinesGenerators("3a3b27be-b18b-4385-b557-6735d733baf0", + .withSynchronousMachinesGenerators("3a3b27be-b18b-4385-b557-6735d733baf0", "550ebe0d-f2b2-48c1-991f-cebea43a21aa") - .modelProfiles("urn:uuid:0eb1540d-5ca3-40ab-9bf7-c91ec4c5d7c3", + .withModelProfiles("urn:uuid:0eb1540d-5ca3-40ab-9bf7-c91ec4c5d7c3", UUID_STR_1, UUID_STR_1, UUID_STR_2, @@ -460,15 +460,15 @@ public static InMemoryCgmesModel expectedMicroGridBaseCaseBE() { private static InMemoryCgmesModel expectedMiniNodeBreaker() { return new InMemoryCgmesModel() - .modelId("MiniNodeBreakerBaseCaseComplete") - .version("unknown") - .nodeBreaker(true) - .substations("3f64f4e2-adfe-4d12-b082-68e7fe4b11c9", + .withModelId("MiniNodeBreakerBaseCaseComplete") + .withVersion("unknown") + .withNodeBreaker(true) + .withSubstations("3f64f4e2-adfe-4d12-b082-68e7fe4b11c9", "974565b1-ac55-4901-9f48-afc7ef5486df", "af9a4ae3-ba2e-4c34-8e47-5af894ee20f4", "b3e5b4de-b74d-43b4-8db9-784302a12acf", "d6056127-34f1-43a9-b029-23fddb913bd5") - .voltageLevels("051b93ae-9c15-4490-8cea-33395298f031", + .withVoltageLevels("051b93ae-9c15-4490-8cea-33395298f031", "0d68ac81-124d-4d21-afa8-6c503feef5b8", "347fb7af-642f-4c60-97d9-c03d440b6a82", "5d9d9d87-ce6b-4213-b4ec-d50de9790a59", @@ -478,7 +478,7 @@ private static InMemoryCgmesModel expectedMiniNodeBreaker() { "a43d15db-44a6-4fda-a525-2402ff43226f", "b2707f00-2554-41d2-bde2-7dd80a669e50", "cd28a27e-8b17-4f23-b9f5-03b6de15203f") - .terminals("01a240e9-5607-4844-9d53-5c8b08b5c9a8", + .withTerminals("01a240e9-5607-4844-9d53-5c8b08b5c9a8", "01df618d-a8cd-493e-ad4a-793ae42c427f", "01f33c90-d1ca-448f-9d62-13677c5c7a5f", "02820aae-8266-4c45-96de-5640eff65320", @@ -711,7 +711,7 @@ private static InMemoryCgmesModel expectedMiniNodeBreaker() { "fecfd76e-409a-42f1-bc4a-eb538bf07b8f", "fee53b4a-5459-4c52-9a84-c4c8c5af6c44", "ff096281-10e6-44c9-af78-8e2829cff084") - .operationalLimits("03f63965-4a6c-48c1-b859-b1247a48a49f", + .withOperationalLimits("03f63965-4a6c-48c1-b859-b1247a48a49f", "088eb5f2-e13b-4edf-a30a-ff48b7a8ae41", "10be2112-5068-4819-b82a-a640e4df11a6", "1162b24f-783f-4fe9-afce-24bac9cb061a", @@ -803,7 +803,7 @@ private static InMemoryCgmesModel expectedMiniNodeBreaker() { "f7db6e6d-a44e-4df1-b9ec-8b0711e96763", "fafc5f7d-b49f-497c-a4a4-d15df5eb8040", "febfc21c-435b-47a8-851c-c1b8e2400fa6") - .topologicalNodes("03163ede-7eec-457f-8641-365982227d7c", + .withTopologicalNodes("03163ede-7eec-457f-8641-365982227d7c", "37edd845-456f-4c3e-98d5-19af0c1cef1e", "764e0b8a-f2af-4092-b6aa-b4a19e55db98", "7f5515b2-ca6b-45af-93ee-f196686f0c66", @@ -817,7 +817,7 @@ private static InMemoryCgmesModel expectedMiniNodeBreaker() { // Boundary "8372a156-7579-4ea5-1111-24caf0d24603", "8372a156-7579-4ea5-2222-24caf0d24603") - .switches("052682ba-a4e5-41d5-9728-0fa4e2e01011", + .withSwitches("052682ba-a4e5-41d5-9728-0fa4e2e01011", "06917aa0-6cc2-4d46-b37b-6ed9fec32ccd", "0bc3b6a5-091e-4b8f-b9d9-a34d327473d0", "0f02c390-e5bc-4e8f-9936-2d269b8847ad", @@ -907,7 +907,7 @@ private static InMemoryCgmesModel expectedMiniNodeBreaker() { "fbdcf00d-8a07-4c62-9e39-86f459bea2be", "fdf5cfbe-9bf5-406a-8d04-fafe47afe31d", "fe1384c9-f1c1-4026-9f5d-10a3b22208b9") - .acLineSegments("05597934-b248-491e-803a-68ce6290f502", + .withAcLineSegments("05597934-b248-491e-803a-68ce6290f502", "1e7f52a9-21d0-4ebe-9a8a-b29281d5bfc9", "35df6abe-3087-4c27-a90a-12b5065333f3", "5150a037-e241-421f-98b2-fe60e5c90303", @@ -916,13 +916,13 @@ private static InMemoryCgmesModel expectedMiniNodeBreaker() { "e95a6228-ceac-4f0a-8b52-d35367b364dc", "efdd7f46-67e6-46e3-9dcd-a3b6f8c613a4", "f32baf36-7ea3-4b6a-9452-71e7f18779f8") - .transformers("411b5401-0a43-404a-acb4-05c3d7d0c95c", + .withTransformers("411b5401-0a43-404a-acb4-05c3d7d0c95c", "5d38b7ed-73fd-405a-9cdb-78425e003773", "6c89588b-3df5-4120-88e5-26164afb43e9", "813365c3-5be7-4ef0-a0a7-abd1ae6dc174", "ceb5d06a-a7ff-4102-a620-7f3ea5fb4a51", "f1e72854-ec35-46e9-b614-27db354e8dbb") - .transformerEnds("03916530-aaea-41c2-b0a2-770d44470839", + .withTransformerEnds("03916530-aaea-41c2-b0a2-770d44470839", "063fef99-e19b-4ebe-92a9-1e8927fdca2a", "0a33f633-7415-4f95-b3c2-f3ddbee92644", "3b446af6-630a-46ee-bc76-d5543509b355", @@ -936,16 +936,16 @@ private static InMemoryCgmesModel expectedMiniNodeBreaker() { "d2e671db-1ed5-4f8d-bbbf-54554b175428", "d99ae781-8809-4e59-b167-fc0106934b25", "fe6b71c8-5a63-4a10-a699-a6bf376e2e2f") - .ratioTapChangers("0522ca48-e644-4d3a-9721-22bb0abd1c8b", + .withRatioTapChangers("0522ca48-e644-4d3a-9721-22bb0abd1c8b", "4a8a5456-91ac-4bc9-b8e2-64eeeef78a1a", "8de2d157-15d1-42c7-b376-a8ae5b6c0e77") - .synchronousMachinesGenerators("2970a2b7-b840-4e9c-b405-0cb854cd2318", + .withSynchronousMachinesGenerators("2970a2b7-b840-4e9c-b405-0cb854cd2318", "392ea173-4f8e-48fa-b2a3-5c3721e93196", "ca67be42-750e-4ebf-bfaa-24d446e59a22") - .asynchronousMachines("062ece1f-ade5-4d20-9c3a-fd8f12d12ec1", + .withAsynchronousMachines("062ece1f-ade5-4d20-9c3a-fd8f12d12ec1", "ba62884d-8800-41a8-9c26-698297d7ebaa", "f184d87b-5565-45ee-89b4-29e8a42d3ad1") - .modelProfiles(UUID_STR_1, + .withModelProfiles(UUID_STR_1, UUID_STR_1, UUID_STR_2, UUID_STR_3, @@ -958,11 +958,11 @@ private static InMemoryCgmesModel expectedMiniNodeBreaker() { public static CgmesModel expectedMicroGridType4BE() { InMemoryCgmesModel m = expectedMicroGridBaseCaseBE(); - m.voltageLevels("69ef0dbd-da79-4eef-a02f-690cb8a28361"); - m.terminals("13dcec71-4b02-4c0c-93a7-8e16db4aa0b7", + m.withVoltageLevels("69ef0dbd-da79-4eef-a02f-690cb8a28361"); + m.withTerminals("13dcec71-4b02-4c0c-93a7-8e16db4aa0b7", "67bb74f1-8620-4a32-9d7d-a44092d11d22", "8171fc34-6891-40e0-92d1-da9f4ba69e26"); - m.operationalLimits( + m.withOperationalLimits( "0068a5c1-9212-4366-8e0e-cf621a92a8b7", "0068a5c1-9212-4366-8e0e-cf621a92a8b71", "08322f60-4e75-4a00-a4e0-0c55bf588919", @@ -1087,7 +1087,7 @@ public static CgmesModel expectedMicroGridType4BE() { "fd227658-0e1b-4ecd-952a-c6b0307b1ea11", "ff466d18-e4f5-439b-a50a-daec2fa41e2c", "ff466d18-e4f5-439b-a50a-daec2fa41e2c1"); - m.shuntCompensatorsPoints("46e3d51d-0a41-4e3f-8ce5-63e7bb165b73", + m.withShuntCompensatorsPoints("46e3d51d-0a41-4e3f-8ce5-63e7bb165b73", "7dc75c5a-74cc-434c-a125-860960b6ed35", "89e965d7-0348-4dc1-98d4-be3bf8891fad", "8b93ca77-3cc3-4c82-8524-2f8a13513e20", @@ -1112,8 +1112,8 @@ public static CgmesModel expectedMicroGridType4BE() { "7939fc42-08ef-4ce7-9912-97552a4db39a", "0d6f26df-9f86-4df0-b00c-bfb23870257f")); m.operationalLimits().removeIf(tl -> tlremove.contains(tl.getId("OperationalLimit"))); - m.topologicalNodes("23b65c6b-2351-4673-89e9-1895c7291543"); - m.transformerEnds( + m.withTopologicalNodes("23b65c6b-2351-4673-89e9-1895c7291543"); + m.withTransformerEnds( "3c59d1b0-1ee9-4ca3-9086-4fe102b51b21", "ba56158e-0c51-448d-999b-44cb0b3cebf5", "bf76ac9d-0144-48f5-a24a-34ae15a455fb", @@ -1128,12 +1128,12 @@ public static CgmesModel expectedMicroGridType4BE() { .removeIf(rtc -> rtc.getId("RatioTapChanger").equals("955d9cd0-4a10-4031-b008-60c0dc340a07")); m.phaseTapChangers() .removeIf(ptc -> ptc.getId("PhaseTapChanger").equals("6ebbef67-3061-4236-a6fd-6ccc4595f6c3")); - m.phaseTapChangers( + m.withPhaseTapChangers( "36b83adb-3d45-4693-8967-96627b5f9ec9", "63454a73-f439-45bb-951a-e7b193986571"); - m.staticVarCompensators("3c69652c-ff14-4550-9a87-b6fdaccbb5f4"); + m.withStaticVarCompensators("3c69652c-ff14-4550-9a87-b6fdaccbb5f4"); m.modelProfiles().clear(); - m.modelProfiles("urn:uuid:1a64ce59-b28c-4b43-bf21-50b51865d777", + m.withModelProfiles("urn:uuid:1a64ce59-b28c-4b43-bf21-50b51865d777", UUID_STR_1, UUID_STR_1, UUID_STR_2, diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/FakeSubstationsConversionTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/FakeSubstationsConversionTest.java index c206df8d5c0..05f8006bd83 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/FakeSubstationsConversionTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/FakeSubstationsConversionTest.java @@ -27,7 +27,7 @@ class FakeSubstationsConversionTest { @Test void fakeSubstations() { CgmesModel cgmes = new InMemoryCgmesModel() - .substations("Sub1", "Sub2", "Sub3"); + .withSubstations("Sub1", "Sub2", "Sub3"); Network n = new Conversion(cgmes).convert(); List actuals = n.getSubstationStream() .map(Substation::getId) diff --git a/cgmes/cgmes-model-test/src/main/java/com/powsybl/cgmes/model/test/Cim14SmallCasesCatalog.java b/cgmes/cgmes-model-test/src/main/java/com/powsybl/cgmes/model/test/Cim14SmallCasesCatalog.java index 093c3c962af..b5160e8859c 100644 --- a/cgmes/cgmes-model-test/src/main/java/com/powsybl/cgmes/model/test/Cim14SmallCasesCatalog.java +++ b/cgmes/cgmes-model-test/src/main/java/com/powsybl/cgmes/model/test/Cim14SmallCasesCatalog.java @@ -97,32 +97,32 @@ public static GridModelReferenceResources nordic32() { private static CgmesModel expectedSmall1() { return new InMemoryCgmesModel() - .modelId("Small1") - .version(VERSION) - .substations("_GEN______SS", "_INF______SS") - .voltageLevels("_GEN______VL", "_GRID_____VL", "_INF______VL") - .terminals("_GEN_____-GRID____-1_TW_EX_TE", + .withModelId("Small1") + .withVersion(VERSION) + .withSubstations("_GEN______SS", "_INF______SS") + .withVoltageLevels("_GEN______VL", "_GRID_____VL", "_INF______VL") + .withTerminals("_GEN_____-GRID____-1_TW_EX_TE", "_GEN_____-GRID____-1_TW_OR_TE", "_GEN______SM_TE", "_GRID____-INF_____-1_AC_TE_EX", "_GRID____-INF_____-1_AC_TE_OR", "_INF______SM_TE") - .operationalLimits("_GEN_____-GRID____-1_TW_EX_CL", "_GEN_____-GRID____-1_TW_OR_CL", + .withOperationalLimits("_GEN_____-GRID____-1_TW_EX_CL", "_GEN_____-GRID____-1_TW_OR_CL", "_GRID____-INF_____-1_AC_CL") - .topologicalNodes("_GEN______TN", "_GRID_____TN", "_INF______TN") - .acLineSegments("_GRID____-INF_____-1_AC") - .transformers("_GEN_____-GRID____-1_PT") - .transformerEnds("_GEN_____-GRID____-1_TW_EX", "_GEN_____-GRID____-1_TW_OR") - .synchronousMachinesGenerators("_GEN______SM", "_INF______SM"); + .withTopologicalNodes("_GEN______TN", "_GRID_____TN", "_INF______TN") + .withAcLineSegments("_GRID____-INF_____-1_AC") + .withTransformers("_GEN_____-GRID____-1_PT") + .withTransformerEnds("_GEN_____-GRID____-1_TW_EX", "_GEN_____-GRID____-1_TW_OR") + .withSynchronousMachinesGenerators("_GEN______SM", "_INF______SM"); } private static CgmesModel expectedM7Buses() { return new InMemoryCgmesModel() - .modelId("M7Buses") - .version(VERSION) - .substations("_FP.AND11_SS", "_FS.BIS11_SS", "_FSSV.O11_SS", "_FTILL511_SS", + .withModelId("M7Buses") + .withVersion(VERSION) + .withSubstations("_FP.AND11_SS", "_FS.BIS11_SS", "_FSSV.O11_SS", "_FTILL511_SS", "_FVALDI11_SS", "_FVERGE11_SS") - .voltageLevels("_FP.AND11_VL", "_FS.BIS11_VL", "_FSSV.O11_VL", "_FTDPRA11_VL", + .withVoltageLevels("_FP.AND11_VL", "_FS.BIS11_VL", "_FSSV.O11_VL", "_FTDPRA11_VL", "_FTILL511_VL", "_FVALDI11_VL", "_FVERGE11_VL") - .terminals("_FP.ANC12_EC_TE", "_FP.AND11-FP.AND12-A_SW_TE_EX", + .withTerminals("_FP.ANC12_EC_TE", "_FP.AND11-FP.AND12-A_SW_TE_EX", "_FP.AND11-FP.AND12-A_SW_TE_OR", "_FP.AND11-FTDPRA11-1_TW_EX_TE", "_FP.AND11-FTDPRA11-1_TW_OR_TE", "_FP.AND11-FVERGE11-1_AC_TE_EX", "_FP.AND11-FVERGE11-1_AC_TE_OR", @@ -151,7 +151,7 @@ private static CgmesModel expectedM7Buses() { "_FVALDI11-FVALDI12-A_SW_TE_OR", "_FVALDT11_SM_TE", "_FVERGE11-FVERGE12-A_SW_TE_EX", "_FVERGE11-FVERGE12-A_SW_TE_OR", "_FVERGT11_SM_TE") - .operationalLimits("_FP.AND11-FTDPRA11-1_TW_EX_CL", "_FP.AND11-FTDPRA11-1_TW_OR_CL", + .withOperationalLimits("_FP.AND11-FTDPRA11-1_TW_EX_CL", "_FP.AND11-FTDPRA11-1_TW_OR_CL", "_FP.AND11-FVERGE11-1_AC_CL", "_FP.AND11-FVERGE11-2_AC_CL", "_FS.BIS11-FVALDI11-1_AC_CL", "_FS.BIS11-FVALDI11-2_AC_CL", "_FSSV.O11-FP.AND11-1_AC_CL", @@ -161,19 +161,19 @@ private static CgmesModel expectedM7Buses() { "_FTILL511-FS.BIS11-1_AC_CL", "_FTILL511-FS.BIS11-2_AC_CL", "_FVALDI11-FTDPRA11-1_AC_CL", "_FVALDI11-FTDPRA11-2_AC_CL") - .topologicalNodes("_FP.AND11_TN", "_FP.AND12_TN", "_FS.BIS11_TN", + .withTopologicalNodes("_FP.AND11_TN", "_FP.AND12_TN", "_FS.BIS11_TN", "_FS.BIS12_TN", "_FSSV.O11_TN", "_FSSV.O12_TN", "_FTDPRA11_TN", "_FTDPRA12_TN", "_FTILL511_TN", "_FTILL512_TN", "_FVALDI11_TN", "_FVALDI12_TN", "_FVERGE11_TN", "_FVERGE12_TN") // Switch identifiers are repeated twice, one record per terminal - .switches("_FP.AND11-FP.AND12-A_SW", + .withSwitches("_FP.AND11-FP.AND12-A_SW", "_FS.BIS11-FS.BIS12-A_SW", "_FSSV.O11-FSSV.O12-A_SW", "_FTDPRA11-FTDPRA12-A_SW", "_FTILL511-FTILL512-A_SW", "_FVALDI11-FVALDI12-A_SW", "_FVERGE11-FVERGE12-A_SW") - .acLineSegments("_FP.AND11-FVERGE11-1_AC", "_FP.AND11-FVERGE11-2_AC", + .withAcLineSegments("_FP.AND11-FVERGE11-1_AC", "_FP.AND11-FVERGE11-2_AC", "_FS.BIS11-FVALDI11-1_AC", "_FS.BIS11-FVALDI11-2_AC", "_FSSV.O11-FP.AND11-1_AC", "_FSSV.O11-FP.AND11-2_AC", "_FSSV.O11-FTILL511-1_AC", "_FSSV.O11-FTILL511-2_AC", @@ -181,27 +181,27 @@ private static CgmesModel expectedM7Buses() { "_FTDPRA11-FVERGE11-2_AC", "_FTILL511-FS.BIS11-1_AC", "_FTILL511-FS.BIS11-2_AC", "_FVALDI11-FTDPRA11-1_AC", "_FVALDI11-FTDPRA11-2_AC") - .transformers("_FP.AND11-FTDPRA11-1_PT") - .transformerEnds("_FP.AND11-FTDPRA11-1_TW_EX", "_FP.AND11-FTDPRA11-1_TW_OR") - .phaseTapChangers(new String[] {"_FP.AND11-FTDPRA11-1_PTC_OR"}) - .energyConsumers("_FP.ANC12_EC", "_FS.BIC11_EC", "_FTDPRC11_EC", "_FTILLC51_EC") - .synchronousMachinesGenerators("_FSSV.T11_SM", "_FVALDT11_SM", "_FVERGT11_SM"); + .withTransformers("_FP.AND11-FTDPRA11-1_PT") + .withTransformerEnds("_FP.AND11-FTDPRA11-1_TW_EX", "_FP.AND11-FTDPRA11-1_TW_OR") + .withPhaseTapChangers("_FP.AND11-FTDPRA11-1_PTC_OR") + .withEnergyConsumers("_FP.ANC12_EC", "_FS.BIC11_EC", "_FTDPRC11_EC", "_FTILLC51_EC") + .withSynchronousMachinesGenerators("_FSSV.T11_SM", "_FVALDT11_SM", "_FVERGT11_SM"); } private static CgmesModel expectedIeee14() { return new InMemoryCgmesModel() - .modelId("IEEE14") - .version(VERSION) - .substations( + .withModelId("IEEE14") + .withVersion(VERSION) + .withSubstations( "_BUS___10_SS", "_BUS___11_SS", "_BUS___12_SS", "_BUS___13_SS", "_BUS___14_SS", "_BUS____1_SS", "_BUS____2_SS", "_BUS____3_SS", "_BUS____4_SS", "_BUS____5_SS", "_BUS____8_SS") - .voltageLevels( + .withVoltageLevels( "_BUS___10_VL", "_BUS___11_VL", "_BUS___12_VL", "_BUS___13_VL", "_BUS___14_VL", "_BUS____1_VL", "_BUS____2_VL", "_BUS____3_VL", "_BUS____4_VL", "_BUS____5_VL", "_BUS____6_VL", "_BUS____7_VL", "_BUS____8_VL", "_BUS____9_VL") - .terminals( + .withTerminals( "_BANK___9_SC_TE", "_BUS___10-BUS___11-1_AC_TE_EX", "_BUS___10-BUS___11-1_AC_TE_OR", "_BUS___12-BUS___13-1_AC_TE_EX", "_BUS___12-BUS___13-1_AC_TE_OR", "_BUS___13-BUS___14-1_AC_TE_EX", @@ -231,7 +231,7 @@ private static CgmesModel expectedIeee14() { "_LOAD__11_EC_TE", "_LOAD__12_EC_TE", "_LOAD__13_EC_TE", "_LOAD__14_EC_TE", "_LOAD___2_EC_TE", "_LOAD___3_EC_TE", "_LOAD___4_EC_TE", "_LOAD___5_EC_TE", "_LOAD___6_EC_TE", "_LOAD___9_EC_TE") - .operationalLimits( + .withOperationalLimits( "_BUS___10-BUS___11-1_AC_CL", "_BUS___12-BUS___13-1_AC_CL", "_BUS___13-BUS___14-1_AC_CL", "_BUS____1-BUS____2-1_AC_CL", "_BUS____1-BUS____5-1_AC_CL", "_BUS____2-BUS____3-1_AC_CL", @@ -244,13 +244,13 @@ private static CgmesModel expectedIeee14() { "_BUS____6-BUS___13-1_AC_CL", "_BUS____7-BUS____8-1_AC_CL", "_BUS____7-BUS____9-1_AC_CL", "_BUS____9-BUS___10-1_AC_CL", "_BUS____9-BUS___14-1_AC_CL") - .topologicalNodes( + .withTopologicalNodes( "_BUS___10_TN", "_BUS___11_TN", "_BUS___12_TN", "_BUS___13_TN", "_BUS___14_TN", "_BUS____1_TN", "_BUS____2_TN", "_BUS____3_TN", "_BUS____4_TN", "_BUS____5_TN", "_BUS____6_TN", "_BUS____7_TN", "_BUS____8_TN", "_BUS____9_TN") - .acLineSegments("_BUS___10-BUS___11-1_AC", "_BUS___12-BUS___13-1_AC", + .withAcLineSegments("_BUS___10-BUS___11-1_AC", "_BUS___12-BUS___13-1_AC", "_BUS___13-BUS___14-1_AC", "_BUS____1-BUS____2-1_AC", "_BUS____1-BUS____5-1_AC", "_BUS____2-BUS____3-1_AC", "_BUS____2-BUS____4-1_AC", "_BUS____2-BUS____5-1_AC", @@ -259,26 +259,26 @@ private static CgmesModel expectedIeee14() { "_BUS____6-BUS___12-1_AC", "_BUS____6-BUS___13-1_AC", "_BUS____7-BUS____8-1_AC", "_BUS____7-BUS____9-1_AC", "_BUS____9-BUS___10-1_AC", "_BUS____9-BUS___14-1_AC") - .transformers("_BUS____4-BUS____7-1_PT", "_BUS____4-BUS____9-1_PT", + .withTransformers("_BUS____4-BUS____7-1_PT", "_BUS____4-BUS____9-1_PT", "_BUS____5-BUS____6-1_PT") - .transformerEnds("_BUS____4-BUS____7-1_TW_EX", "_BUS____4-BUS____7-1_TW_OR", + .withTransformerEnds("_BUS____4-BUS____7-1_TW_EX", "_BUS____4-BUS____7-1_TW_OR", "_BUS____4-BUS____9-1_TW_EX", "_BUS____4-BUS____9-1_TW_OR", "_BUS____5-BUS____6-1_TW_EX", "_BUS____5-BUS____6-1_TW_OR") - .ratioTapChangers("_BUS____4-BUS____7-1_RTC_OR", "_BUS____4-BUS____9-1_RTC_OR", + .withRatioTapChangers("_BUS____4-BUS____7-1_RTC_OR", "_BUS____4-BUS____9-1_RTC_OR", "_BUS____5-BUS____6-1_RTC_OR") - .energyConsumers("_LOAD__10_EC", "_LOAD__11_EC", "_LOAD__12_EC", "_LOAD__13_EC", + .withEnergyConsumers("_LOAD__10_EC", "_LOAD__11_EC", "_LOAD__12_EC", "_LOAD__13_EC", "_LOAD__14_EC", "_LOAD___2_EC", "_LOAD___3_EC", "_LOAD___4_EC", "_LOAD___5_EC", "_LOAD___6_EC", "_LOAD___9_EC") - .shuntCompensators("_BANK___9_SC") - .synchronousMachinesGenerators("_GEN____1_SM", "_GEN____2_SM", "_GEN____3_SM", "_GEN____6_SM", + .withShuntCompensators("_BANK___9_SC") + .withSynchronousMachinesGenerators("_GEN____1_SM", "_GEN____2_SM", "_GEN____3_SM", "_GEN____6_SM", "_GEN____8_SM"); } private static CgmesModel expectedNordic32() { return new InMemoryCgmesModel() - .modelId("Nordic32") - .version(VERSION) - .substations( + .withModelId("Nordic32") + .withVersion(VERSION) + .withSubstations( "_N1011____SS", "_N1012____SS", "_N1022____SS", "_N1041____SS", "_N1044____SS", "_N1045____SS", "_N2031____SS", "_N4032____SS", "_N4043____SS", "_N4046____SS", "_N4061____SS", "_NG11_____SS", @@ -286,7 +286,7 @@ private static CgmesModel expectedNordic32() { "_NG17_____SS", "_NG18_____SS", "_NG19_____SS", "_NG20_____SS", "_NG2______SS", "_NG3______SS", "_NG4______SS", "_NG6______SS", "_NG7______SS", "_NG8______SS") - .voltageLevels( + .withVoltageLevels( "_N1011____VL", "_N1012____VL", "_N1013____VL", "_N1014____VL", "_N1021____VL", "_N1022____VL", "_N1041____VL", "_N1042____VL", "_N1043____VL", "_N1044____VL", "_N1045____VL", "_N2031____VL", @@ -300,7 +300,7 @@ private static CgmesModel expectedNordic32() { "_NG18_____VL", "_NG19_____VL", "_NG1______VL", "_NG20_____VL", "_NG2______VL", "_NG3______VL", "_NG4______VL", "_NG5______VL", "_NG6______VL", "_NG7______VL", "_NG8______VL", "_NG9______VL") - .terminals( + .withTerminals( "_G10______SM_TE", "_G11______SM_TE", "_G12______SM_TE", "_G13______SM_TE", "_G14______SM_TE", "_G15______SM_TE", "_G16______SM_TE", "_G17______SM_TE", "_G18______SM_TE", "_G19______SM_TE", "_G1_______SM_TE", "_G20______SM_TE", @@ -397,7 +397,7 @@ private static CgmesModel expectedNordic32() { "_NG7_____-N1043___-1_TW_OR_TE", "_NG8_____-N2032___-1_TW_EX_TE", "_NG8_____-N2032___-1_TW_OR_TE", "_NG9_____-N4011___-1_TW_EX_TE", "_NG9_____-N4011___-1_TW_OR_TE") - .operationalLimits( + .withOperationalLimits( "_N1011___-N1013___-1_AC_CL", "_N1011___-N1013___-2_AC_CL", "_N1011___-N4011___-1_TW_EX_CL", "_N1011___-N4011___-1_TW_OR_CL", "_N1012___-N1014___-1_AC_CL", "_N1012___-N1014___-2_AC_CL", @@ -452,7 +452,7 @@ private static CgmesModel expectedNordic32() { "_NG7_____-N1043___-1_TW_EX_CL", "_NG7_____-N1043___-1_TW_OR_CL", "_NG8_____-N2032___-1_TW_EX_CL", "_NG8_____-N2032___-1_TW_OR_CL", "_NG9_____-N4011___-1_TW_EX_CL", "_NG9_____-N4011___-1_TW_OR_CL") - .topologicalNodes( + .withTopologicalNodes( "_N1011____TN", "_N1012____TN", "_N1013____TN", "_N1014____TN", "_N1021____TN", "_N1022____TN", "_N1041____TN", "_N1042____TN", "_N1043____TN", "_N1044____TN", "_N1045____TN", "_N2031____TN", @@ -466,7 +466,7 @@ private static CgmesModel expectedNordic32() { "_NG18_____TN", "_NG19_____TN", "_NG1______TN", "_NG20_____TN", "_NG2______TN", "_NG3______TN", "_NG4______TN", "_NG5______TN", "_NG6______TN", "_NG7______TN", "_NG8______TN", "_NG9______TN") - .acLineSegments( + .withAcLineSegments( "_N1011___-N1013___-1_AC", "_N1011___-N1013___-2_AC", "_N1012___-N1014___-1_AC", "_N1012___-N1014___-2_AC", "_N1013___-N1014___-1_AC", "_N1013___-N1014___-2_AC", @@ -493,7 +493,7 @@ private static CgmesModel expectedNordic32() { "_N4046___-N4047___-1_AC", "_N4061___-N4062___-1_AC", "_N4062___-N4063___-1_AC", "_N4062___-N4063___-2_AC", "_N4071___-N4072___-1_AC", "_N4071___-N4072___-2_AC") - .transformers( + .withTransformers( "_N1011___-N4011___-1_PT", "_N1012___-N4012___-1_PT", "_N1022___-N4022___-1_PT", "_N1044___-N4044___-1_PT", "_N1044___-N4044___-2_PT", "_N1045___-N4045___-1_PT", @@ -508,7 +508,7 @@ private static CgmesModel expectedNordic32() { "_NG4_____-N1021___-1_PT", "_NG5_____-N1022___-1_PT", "_NG6_____-N1042___-1_PT", "_NG7_____-N1043___-1_PT", "_NG8_____-N2032___-1_PT", "_NG9_____-N4011___-1_PT") - .transformerEnds( + .withTransformerEnds( "_N1011___-N4011___-1_TW_EX", "_N1011___-N4011___-1_TW_OR", "_N1012___-N4012___-1_TW_EX", "_N1012___-N4012___-1_TW_OR", "_N1022___-N4022___-1_TW_EX", "_N1022___-N4022___-1_TW_OR", @@ -537,18 +537,18 @@ private static CgmesModel expectedNordic32() { "_NG7_____-N1043___-1_TW_EX", "_NG7_____-N1043___-1_TW_OR", "_NG8_____-N2032___-1_TW_EX", "_NG8_____-N2032___-1_TW_OR", "_NG9_____-N4011___-1_TW_EX", "_NG9_____-N4011___-1_TW_OR") - .energyConsumers( + .withEnergyConsumers( "_N1011____EC", "_N1012____EC", "_N1013____EC", "_N1022____EC", "_N1041____EC", "_N1042____EC", "_N1043____EC", "_N1044____EC", "_N1045____EC", "_N2031____EC", "_N2032____EC", "_N4041____EC", "_N4042____EC", "_N4043____EC", "_N4046____EC", "_N4047____EC", "_N4051____EC", "_N4061____EC", "_N4062____EC", "_N4063____EC", "_N4071____EC", "_N4072____EC") - .shuntCompensators( + .withShuntCompensators( "_N1022____SC", "_N1041____SC", "_N1043____SC", "_N1044____SC", "_N1045____SC", "_N4012____SC", "_N4041____SC", "_N4043____SC", "_N4046____SC", "_N4051____SC", "_N4071____SC") - .synchronousMachinesGenerators( + .withSynchronousMachinesGenerators( "_G10______SM", "_G11______SM", "_G12______SM", "_G13______SM", "_G14______SM", "_G15______SM", "_G16______SM", "_G17______SM", "_G18______SM", "_G19______SM", "_G1_______SM", "_G20______SM", diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java index a2a5fd0128b..7be03bc6da1 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/InMemoryCgmesModel.java @@ -117,17 +117,17 @@ public boolean hasEquipmentCore() { return true; } - public InMemoryCgmesModel modelId(String modelId) { + public InMemoryCgmesModel withModelId(String modelId) { this.modelId = modelId; return this; } - public InMemoryCgmesModel version(String version) { + public InMemoryCgmesModel withVersion(String version) { this.version = version; return this; } - public InMemoryCgmesModel nodeBreaker(boolean b) { + public InMemoryCgmesModel withNodeBreaker(boolean b) { isNodeBreaker = b; return this; } @@ -140,7 +140,7 @@ public boolean hasBoundary() { return false; } - public InMemoryCgmesModel substations(String... ids) { + public InMemoryCgmesModel withSubstations(String... ids) { fakeObjectsFromIdentifiers("Substation", ids, substations); // Add a default SubRegion to every substation substations.forEach(s -> { @@ -152,122 +152,112 @@ public InMemoryCgmesModel substations(String... ids) { return this; } - public InMemoryCgmesModel voltageLevels(String... ids) { + public InMemoryCgmesModel withVoltageLevels(String... ids) { fakeObjectsFromIdentifiers("VoltageLevel", ids, voltageLevels); return this; } - public InMemoryCgmesModel terminals(String... ids) { + public InMemoryCgmesModel withTerminals(String... ids) { fakeObjectsFromIdentifiers("Terminal", ids, terminals); return this; } - public InMemoryCgmesModel operationalLimits(String... ids) { + public InMemoryCgmesModel withOperationalLimits(String... ids) { fakeObjectsFromIdentifiers("OperationalLimit", ids, operationalLimits); return this; } - public InMemoryCgmesModel topologicalNodes(String... ids) { + public InMemoryCgmesModel withTopologicalNodes(String... ids) { fakeObjectsFromIdentifiers("TopologicalNode", ids, topologicalNodes); return this; } - public InMemoryCgmesModel busBarSections(String... ids) { + public InMemoryCgmesModel withBusBarSections(String... ids) { fakeObjectsFromIdentifiers("BusbarSection", ids, busbarSections); return this; } - public InMemoryCgmesModel switches(String... ids) { + public InMemoryCgmesModel withSwitches(String... ids) { fakeObjectsFromIdentifiers("Switch", ids, switches); return this; } - public InMemoryCgmesModel acLineSegments(String... ids) { + public InMemoryCgmesModel withAcLineSegments(String... ids) { fakeObjectsFromIdentifiers("ACLineSegment", ids, acLineSegments); return this; } - @Override - public PropertyBags equivalentBranches() { - return equivalentBranches; - } - - @Override - public PropertyBags seriesCompensators() { - return seriesCompensators; - } - - public InMemoryCgmesModel transformers(String... ids) { + public InMemoryCgmesModel withTransformers(String... ids) { fakeObjectsFromIdentifiers("PowerTransformer", ids, transformers); return this; } - public InMemoryCgmesModel transformerEnds(String... ids) { + public InMemoryCgmesModel withTransformerEnds(String... ids) { fakeObjectsFromIdentifiers("TransformerEnd", ids, transformerEnds); return this; } - public InMemoryCgmesModel ratioTapChangers(String... ids) { + public InMemoryCgmesModel withRatioTapChangers(String... ids) { fakeObjectsFromIdentifiers("RatioTapChanger", ids, ratioTapChangers); return this; } - public InMemoryCgmesModel phaseTapChangers(String... ids) { + public InMemoryCgmesModel withPhaseTapChangers(String... ids) { fakeObjectsFromIdentifiers("PhaseTapChanger", ids, phaseTapChangers); return this; } - public InMemoryCgmesModel energyConsumers(String... ids) { + public InMemoryCgmesModel withEnergyConsumers(String... ids) { fakeObjectsFromIdentifiers("EnergyConsumer", ids, energyConsumers); return this; } - public InMemoryCgmesModel shuntCompensators(String... ids) { + public InMemoryCgmesModel withShuntCompensators(String... ids) { fakeObjectsFromIdentifiers("ShuntCompensator", ids, shuntCompensators); return this; } - public InMemoryCgmesModel shuntCompensatorsPoints(String... ids) { + public InMemoryCgmesModel withShuntCompensatorsPoints(String... ids) { fakeObjectsFromIdentifiers("NonlinearShuntCompensatorPoint", ids, shuntCompensatorPoints); return this; } - public InMemoryCgmesModel staticVarCompensators(String... ids) { + public InMemoryCgmesModel withStaticVarCompensators(String... ids) { fakeObjectsFromIdentifiers("StaticVarCompensator", ids, staticVarCompensators); return this; } - public InMemoryCgmesModel synchronousMachinesGenerators(String... ids) { + public InMemoryCgmesModel withSynchronousMachinesGenerators(String... ids) { fakeObjectsFromIdentifiers("SynchronousMachine", ids, synchronousMachinesGenerators); return this; } - public InMemoryCgmesModel asynchronousMachines(String... ids) { + public InMemoryCgmesModel withAsynchronousMachines(String... ids) { fakeObjectsFromIdentifiers("AsynchronousMachine", ids, asynchronousMachines); return this; } - public InMemoryCgmesModel acDcConverters(String... ids) { + public InMemoryCgmesModel withAcDcConverters(String... ids) { fakeObjectsFromIdentifiers("ACDCConverter", ids, acDcConverters); return this; } - public InMemoryCgmesModel dcLineSegments(String... ids) { + public InMemoryCgmesModel withDcLineSegments(String... ids) { fakeObjectsFromIdentifiers("DCLineSegment", ids, dcLineSegments); return this; } - public InMemoryCgmesModel dcTerminals(String... ids) { + public InMemoryCgmesModel withDcTerminals(String... ids) { fakeObjectsFromIdentifiers("DCTerminal", ids, dcTerminals); return this; } - public InMemoryCgmesModel tieFlows(String... ids) { + public InMemoryCgmesModel withTieFlows(String... ids) { fakeObjectsFromIdentifiers("TieFlow", ids, tieFlows); return this; } - public InMemoryCgmesModel modelProfiles(String... ids) { + public InMemoryCgmesModel withModelProfiles(String... ids) { fakeObjectsFromIdentifiers("FullModel", ids, modelProfiles); return this; } @@ -391,6 +381,16 @@ public PropertyBags acLineSegments() { return acLineSegments; } + @Override + public PropertyBags equivalentBranches() { + return equivalentBranches; + } + + @Override + public PropertyBags seriesCompensators() { + return seriesCompensators; + } + @Override public PropertyBags transformers() { return transformers;