Skip to content

Commit

Permalink
Fix non linear shunt conversion performances issue (#3218)
Browse files Browse the repository at this point in the history
* Query all nonLinearShuntCompensatorPoints and group them later by nonLinearShuntCompensator in order to improve performances
* API for shunt compensator points has only one method with 2 overloads
* Make argument name consistent in API and its implementations

Signed-off-by: Romain Courtier <[email protected]>
  • Loading branch information
rcourtier authored Nov 29, 2024
1 parent 808ad7b commit dab6fc8
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,11 @@ 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",
"7dc75c5a-74cc-434c-a125-860960b6ed35",
"89e965d7-0348-4dc1-98d4-be3bf8891fad",
"8b93ca77-3cc3-4c82-8524-2f8a13513e20",
"ca954c3a-5194-49eb-9097-10c77cea36b9");
Set<String> tlremove = new HashSet<>(Arrays.asList(
"acbd4688-6393-4b43-a9f4-27d8c3f8c309",
"1c8440dc-e65d-4337-9d3e-7558062228da1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private void testCompare(CgmesModel expected, CgmesModel actual) {
testPropertyBags(expected.phaseTapChangers(), actual.phaseTapChangers());
testPropertyBags(expected.energyConsumers(), actual.energyConsumers());
testPropertyBags(expected.shuntCompensators(), actual.shuntCompensators());
testPropertyBags(expected.nonlinearShuntCompensatorPoints(), actual.nonlinearShuntCompensatorPoints());
testPropertyBags(expected.staticVarCompensators(), actual.staticVarCompensators());
testPropertyBags(expected.synchronousMachinesGenerators(), actual.synchronousMachinesGenerators());
testPropertyBags(expected.synchronousMachinesCondensers(), actual.synchronousMachinesCondensers());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ 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 Map<String, PropertyBags> groupedTransformerEnds() {
if (cachedGroupedTransformerEnds == null) {
Expand Down Expand Up @@ -161,6 +169,17 @@ private CgmesContainer container(CgmesTerminal t, boolean nodeBreaker) {
return (containerId == null) ? null : container(containerId);
}

private Map<String, PropertyBags> computeGroupedShuntCompensatorPoints() {
Map<String, PropertyBags> groupedShuntCompensatorPoints = new HashMap<>();
nonlinearShuntCompensatorPoints()
.forEach(point -> {
String shuntCompensator = point.getId("Shunt");
groupedShuntCompensatorPoints.computeIfAbsent(shuntCompensator, bag -> new PropertyBags())
.add(point);
});
return groupedShuntCompensatorPoints;
}

private Map<String, PropertyBags> computeGroupedTransformerEnds() {
// Alternative implementation:
// instead of sorting after building each list,
Expand Down Expand Up @@ -291,6 +310,7 @@ public void read(ReadOnlyDataSource ds, ReportNode reportNode) {
}

protected void invalidateCaches() {
cachedGroupedShuntCompensatorPoints = null;
cachedGroupedTransformerEnds = null;
powerTransformerRatioTapChanger = null;
powerTransformerPhaseTapChanger = null;
Expand All @@ -308,6 +328,7 @@ protected void invalidateCaches() {
private String baseName;

// Caches
private Map<String, PropertyBags> cachedGroupedShuntCompensatorPoints;
private Map<String, PropertyBags> cachedGroupedTransformerEnds;
private Map<String, CgmesTerminal> cachedTerminals;
private Map<String, CgmesContainer> cachedContainers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,18 @@ default PropertyBags fullModels() {

PropertyBags equivalentShunts();

PropertyBags nonlinearShuntCompensatorPoints(String id);
/**
* Query all NonlinearShuntCompensatorPoint in the CgmesModel.
* @return A {@link PropertyBags} with the shunt compensators points properties.
*/
PropertyBags nonlinearShuntCompensatorPoints();

/**
* Query the NonlinearShuntCompensatorPoint associated to the given NonlinearShuntCompensator.
* @param shuntId The id of the NonlinearShuntCompensator.
* @return A {@link PropertyBags} with the given shunt compensator's points properties.
*/
PropertyBags nonlinearShuntCompensatorPoints(String shuntId);

PropertyBags staticVarCompensators();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public final class InMemoryCgmesModel implements CgmesModel {
private PropertyBags energyConsumers;
private PropertyBags energySources;
private PropertyBags shuntCompensators;
private PropertyBags shuntCompensatorPoints;
private PropertyBags staticVarCompensators;
private PropertyBags equivalentShunts;
private PropertyBags synchronousMachinesGenerators;
Expand Down Expand Up @@ -90,6 +91,7 @@ public InMemoryCgmesModel() {
energyConsumers = new PropertyBags();
energySources = new PropertyBags();
shuntCompensators = new PropertyBags();
shuntCompensatorPoints = new PropertyBags();
equivalentShunts = new PropertyBags();
staticVarCompensators = new PropertyBags();
synchronousMachinesGenerators = new PropertyBags();
Expand Down Expand Up @@ -225,6 +227,11 @@ public InMemoryCgmesModel shuntCompensators(String... ids) {
return this;
}

public InMemoryCgmesModel shuntCompensatorsPoints(String... ids) {
fakeObjectsFromIdentifiers("NonlinearShuntCompensatorPoint", ids, shuntCompensatorPoints);
return this;
}

public InMemoryCgmesModel staticVarCompensators(String... ids) {
fakeObjectsFromIdentifiers("StaticVarCompensator", ids, staticVarCompensators);
return this;
Expand Down Expand Up @@ -431,15 +438,21 @@ public PropertyBags shuntCompensators() {
}

@Override
public PropertyBags equivalentShunts() {
return equivalentShunts;
public PropertyBags nonlinearShuntCompensatorPoints() {
return shuntCompensatorPoints;
}

@Override
public PropertyBags nonlinearShuntCompensatorPoints(String scId) {
public PropertyBags nonlinearShuntCompensatorPoints(String shuntId) {
// FakeCgmesModel does not provide grouped shunt compensator points
return new PropertyBags();
}

@Override
public PropertyBags equivalentShunts() {
return equivalentShunts;
}

@Override
public PropertyBags staticVarCompensators() {
return staticVarCompensators;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,8 @@ public PropertyBags equivalentShunts() {
}

@Override
public PropertyBags nonlinearShuntCompensatorPoints(String scId) {
Objects.requireNonNull(scId);
return namedQuery("nonlinearShuntCompensatorPoints", scId);
public PropertyBags nonlinearShuntCompensatorPoints() {
return namedQuery("nonlinearShuntCompensatorPoints");
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions cgmes/cgmes-model/src/main/resources/CIM16.sparql
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,7 @@ WHERE {
cim:NonlinearShuntCompensatorPoint.NonlinearShuntCompensator ?Shunt ;
cim:NonlinearShuntCompensatorPoint.sectionNumber ?sectionNumber ;
cim:NonlinearShuntCompensatorPoint.b ?b ;
cim:NonlinearShuntCompensatorPoint.g ?g .
FILTER REGEX ( STR (?Shunt), "{0}")
cim:NonlinearShuntCompensatorPoint.g ?g .
}

# query: synchronousMachinesGenerators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface SectionAdder {
SectionAdder setB(double b);

/***
* Set the accumulated conductance is S when the section to be added is the last section in service.
* Set the accumulated conductance in S when the section to be added is the last section in service.
* If the accumulated conductance is undefined, its conductance per section is considered equal to 0:
* it is equal to the accumulated conductance of the previous section.
*/
Expand Down

0 comments on commit dab6fc8

Please sign in to comment.