Skip to content

Commit

Permalink
Get tapChangersTablePoints by tableId instead of all in a Map
Browse files Browse the repository at this point in the history
Signed-off-by: Romain Courtier <[email protected]>
  • Loading branch information
rcourtier committed Dec 2, 2024
1 parent 37cad9a commit ea68a93
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -287,8 +255,6 @@ private static void logIssue(ConversionIssueCategory category, String what, Supp
private final LoadingLimitsMapping loadingLimitsMapping;
private final RegulatingControlMapping regulatingControlMapping;

private final Map<String, PropertyBags> ratioTapChangerTables;
private final Map<String, PropertyBags> phaseTapChangerTables;
private final Map<String, PropertyBags> reactiveCapabilityCurveData;

private static final Logger LOG = LoggerFactory.getLogger(Context.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<CgmesTerminal> computedTerminals() {
if (cachedTerminals == null) {
Expand Down Expand Up @@ -207,6 +223,17 @@ private Map<String, PropertyBags> computeGroupedRatioTapChangers() {
return groupedRatioTapChangers;
}

private Map<String, PropertyBags> computeGroupedRatioTapChangerTablePoints() {
Map<String, PropertyBags> groupedRatioTapChangerTablePoints = new HashMap<>();
ratioTapChangerTablePoints()
.forEach(point -> {
String tableId = point.getId("RatioTapChangerTable");
groupedRatioTapChangerTablePoints.computeIfAbsent(tableId, bag -> new PropertyBags())
.add(point);
});
return groupedRatioTapChangerTablePoints;
}

private Map<String, PropertyBags> computeGroupedPhaseTapChangers() {
Map<String, PropertyBags> groupedPhaseTapChangers = new HashMap<>();
phaseTapChangers()
Expand All @@ -218,6 +245,17 @@ private Map<String, PropertyBags> computeGroupedPhaseTapChangers() {
return groupedPhaseTapChangers;
}

private Map<String, PropertyBags> computeGroupedPhaseTapChangerTablePoints() {
Map<String, PropertyBags> 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();
Expand Down Expand Up @@ -334,7 +372,9 @@ protected void invalidateCaches() {
private Map<String, PropertyBags> cachedGroupedShuntCompensatorPoints;
private Map<String, PropertyBags> cachedGroupedTransformerEnds;
private Map<String, PropertyBags> cachedGroupedRatioTapChangers;
private Map<String, PropertyBags> cachedGroupedRatioTapChangerTablePoints;
private Map<String, PropertyBags> cachedGroupedPhaseTapChangers;
private Map<String, PropertyBags> cachedGroupedPhaseTapChangerTablePoints;
private Map<String, CgmesTerminal> cachedTerminals;
private Map<String, CgmesContainer> cachedContainers;
private Map<String, Double> cachedBaseVoltages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
35 changes: 2 additions & 33 deletions cgmes/cgmes-model/src/main/resources/CIM16.sparql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ea68a93

Please sign in to comment.