Skip to content

Commit

Permalink
add missing function for regulation point for identifiable getter (#65)
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne LESOT <etienne.lesot@rte-france.com>
  • Loading branch information
EtienneLt authored Sep 13, 2024
1 parent 4374bfc commit 834ae2e
Showing 1 changed file with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,16 @@ private <T extends IdentifiableAttributes> Resource<T> completeResourceInfos(Res
case VSC_CONVERTER_STATION ->
completeVscConverterStationInfos(resource, networkUuid, variantNum, equipmentId);
case DANGLING_LINE -> completeDanglingLineInfos(resource, networkUuid, variantNum, equipmentId);
case STATIC_VAR_COMPENSATOR -> completeStaticVarCompensatorInfos(resource, networkUuid, variantNum, equipmentId);
case SHUNT_COMPENSATOR -> completeShuntCompensatorInfos(resource, networkUuid, variantNum, equipmentId);
default -> resource;
};
}

private <T extends IdentifiableAttributes> Resource<T> completeGeneratorInfos(Resource<T> resource, UUID networkUuid, int variantNum, String equipmentId) {
Map<OwnerInfo, List<ReactiveCapabilityCurvePointAttributes>> reactiveCapabilityCurvePoints = getReactiveCapabilityCurvePoints(networkUuid, variantNum, EQUIPMENT_ID_COLUMN, equipmentId);
insertReactiveCapabilityCurvePointsInEquipments(networkUuid, List.of((Resource<GeneratorAttributes>) resource), reactiveCapabilityCurvePoints);
insertRegulationPointIntoEquipment(networkUuid, variantNum, equipmentId, resource, ResourceType.GENERATOR);
return resource;
}

Expand Down Expand Up @@ -643,6 +646,7 @@ private <T extends IdentifiableAttributes> Resource<T> completeThreeWindingsTran
private <T extends IdentifiableAttributes> Resource<T> completeVscConverterStationInfos(Resource<T> resource, UUID networkUuid, int variantNum, String equipmentId) {
Map<OwnerInfo, List<ReactiveCapabilityCurvePointAttributes>> reactiveCapabilityCurvePoints = getReactiveCapabilityCurvePoints(networkUuid, variantNum, EQUIPMENT_ID_COLUMN, equipmentId);
insertReactiveCapabilityCurvePointsInEquipments(networkUuid, List.of((Resource<VscConverterStationAttributes>) resource), reactiveCapabilityCurvePoints);
insertRegulationPointIntoEquipment(networkUuid, variantNum, equipmentId, resource, ResourceType.VSC_CONVERTER_STATION);
return resource;
}

Expand All @@ -652,6 +656,16 @@ private <T extends IdentifiableAttributes> Resource<T> completeDanglingLineInfos
return resource;
}

private <T extends IdentifiableAttributes> Resource<T> completeStaticVarCompensatorInfos(Resource<T> resource, UUID networkUuid, int variantNum, String equipmentId) {
insertRegulationPointIntoEquipment(networkUuid, variantNum, equipmentId, resource, ResourceType.STATIC_VAR_COMPENSATOR);
return resource;
}

private <T extends IdentifiableAttributes> Resource<T> completeShuntCompensatorInfos(Resource<T> resource, UUID networkUuid, int variantNum, String equipmentId) {
insertRegulationPointIntoEquipment(networkUuid, variantNum, equipmentId, resource, ResourceType.SHUNT_COMPENSATOR);
return resource;
}

private <T extends IdentifiableAttributes> List<Resource<T>> getIdentifiablesInternal(int variantNum, PreparedStatement preparedStmt, TableMapping tableMapping) throws SQLException {
try (ResultSet resultSet = preparedStmt.executeQuery()) {
List<Resource<T>> resources = new ArrayList<>();
Expand Down Expand Up @@ -921,16 +935,7 @@ public void createGenerators(UUID networkUuid, List<Resource<GeneratorAttributes

public Optional<Resource<GeneratorAttributes>> getGenerator(UUID networkUuid, int variantNum, String generatorId) {
Optional<Resource<GeneratorAttributes>> generatorResource = getIdentifiable(networkUuid, variantNum, generatorId, mappings.getGeneratorMappings());
if (generatorResource.isPresent()) {
Map<OwnerInfo, RegulationPointAttributes> regulationPointAttributes = getRegulationPointsWithInClause(networkUuid, variantNum,
REGULATED_EQUIPMENT_ID, Collections.singletonList(generatorResource.get().getId()), ResourceType.GENERATOR);
if (regulationPointAttributes.size() > 1) {
throw new PowsyblException("a generator can only have one regulating point");
} else if (regulationPointAttributes.size() == 1) {
regulationPointAttributes.values().forEach(regulationPointAttribute ->
generatorResource.get().getAttributes().setRegulationPoint(regulationPointAttribute));
}
}
generatorResource.ifPresent(generatorAttributesResource -> insertRegulationPointIntoEquipment(networkUuid, variantNum, generatorId, generatorAttributesResource, ResourceType.GENERATOR));
return generatorResource;
}

Expand Down Expand Up @@ -2406,6 +2411,18 @@ protected <T extends ReactiveLimitHolder & IdentifiableAttributes> Map<OwnerInfo
return map;
}

private <T extends IdentifiableAttributes> void insertRegulationPointIntoEquipment(UUID networkUuid, int variantNum, String equipmentId, Resource<T> resource, ResourceType resourceType) {
Map<OwnerInfo, RegulationPointAttributes> regulationPointAttributes = getRegulationPointsWithInClause(networkUuid, variantNum,
REGULATED_EQUIPMENT_ID, Collections.singletonList(equipmentId), resourceType);
if (regulationPointAttributes.size() != 1) {
throw new PowsyblException("a regulating element must have one regulating point");
} else {
regulationPointAttributes.values().forEach(regulationPointAttribute ->
((AbstractIdentifiableAttributes) resource.getAttributes()).setRegulationPoint(regulationPointAttribute));
}

}

protected <T extends ReactiveLimitHolder & IdentifiableAttributes> void insertReactiveCapabilityCurvePointsInEquipments(UUID networkUuid, List<Resource<T>> equipments, Map<OwnerInfo, List<ReactiveCapabilityCurvePointAttributes>> reactiveCapabilityCurvePoints) {

if (!reactiveCapabilityCurvePoints.isEmpty() && !equipments.isEmpty()) {
Expand Down

0 comments on commit 834ae2e

Please sign in to comment.