Skip to content

Commit

Permalink
Get curveData by curveId 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 9, 2024
1 parent 1bb1bc8 commit 4ed9550
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

private final Map<String, PropertyBags> reactiveCapabilityCurveData;

private static final Logger LOG = LoggerFactory.getLogger(Context.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Double, Range<Double>> qRanges = new HashMap<>();
curveData.forEach(d -> getReactiveCapabilityCurveData(d, qRanges));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CgmesTerminal> computedTerminals() {
if (cachedTerminals == null) {
Expand Down Expand Up @@ -256,6 +264,17 @@ private Map<String, PropertyBags> computeGroupedPhaseTapChangerTablePoints() {
return groupedPhaseTapChangerTablePoints;
}

private Map<String, PropertyBags> computeGroupedCurveData() {
Map<String, PropertyBags> 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();
Expand Down Expand Up @@ -355,6 +374,7 @@ protected void invalidateCaches() {
cachedGroupedTransformerEnds = null;
cachedGroupedRatioTapChangers = null;
cachedGroupedPhaseTapChangers = null;
cachedGroupedCurveData = null;
cachedTerminals = null;
cachedContainers = null;
cachedBaseVoltages = null;
Expand All @@ -375,6 +395,7 @@ protected void invalidateCaches() {
private Map<String, PropertyBags> cachedGroupedRatioTapChangerTablePoints;
private Map<String, PropertyBags> cachedGroupedPhaseTapChangers;
private Map<String, PropertyBags> cachedGroupedPhaseTapChangerTablePoints;
private Map<String, PropertyBags> cachedGroupedCurveData;
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 @@ -166,7 +166,9 @@ default PropertyBags synchronousMachinesAll() {

PropertyBags asynchronousMachines();

PropertyBags reactiveCapabilityCurveData();
PropertyBags curveData();

PropertyBags curveData(String curveId);

PropertyBags controlAreas();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ public PropertyBags asynchronousMachines() {
}

@Override
public PropertyBags reactiveCapabilityCurveData() {
return namedQuery("reactiveCapabilityCurveData");
public PropertyBags curveData() {
return namedQuery("curveData");
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion cgmes/cgmes-model/src/main/resources/CIM16.sparql
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ WHERE {
}}
}

# query: reactiveCapabilityCurveData
# query: curveData
SELECT *
WHERE {
?CurveData
Expand Down

0 comments on commit 4ed9550

Please sign in to comment.