Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add regulating point for ratio and phase tap changers #84

Open
wants to merge 5 commits into
base: move-boolean-regulating-from-equipment-to-regulatingPoint
Choose a base branch
from

Conversation

EtienneLt
Copy link
Contributor

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR already have an issue describing the problem?

What kind of change does this PR introduce?

What is the current behavior?

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change or deprecate an API?

  • Yes
  • No

If yes, please check if the following requirements are fulfilled

  • The Breaking Change or Deprecated label has been added
  • The migration steps are described in the following section

What changes might users need to make in their application due to this PR? (migration steps)

Other information:

@EtienneLt EtienneLt self-assigned this Nov 27, 2024
Copy link
Contributor

@antoinebhs antoinebhs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some first comments, not tested yet

@EtienneLt EtienneLt force-pushed the add-regulating-point-for-transformers branch from 4ff4275 to 3b5b544 Compare December 6, 2024 12:43
Signed-off-by: Etienne LESOT <etienne.lesot@rte-france.com>
Signed-off-by: Etienne LESOT <etienne.lesot@rte-france.com>
Signed-off-by: Etienne LESOT <etienne.lesot@rte-france.com>
@EtienneLt EtienneLt force-pushed the add-regulating-point-for-transformers branch from 3b5b544 to efe2df9 Compare December 10, 2024 15:26
@EtienneLt EtienneLt changed the base branch from main to move-boolean-regulating-from-equipment-to-regulatingPoint December 11, 2024 10:00
Comment on lines 2366 to 2460
// for two winding transformers
// using the request on a small number of ids and not on all elements
private void setTapChangerRegulatingPointAndRegulatingEquipmentsWithIds(List<Resource<TwoWindingsTransformerAttributes>> elements, UUID networkUuid, int variantNum) {
// regulating points
List<String> elementIds = elements.stream().map(Resource::getId).toList();
Map<RegulatingOwnerInfo, RegulatingPointAttributes> twtTapChangerRegulatingPointAttributes = getRegulatingPointsWithInClause(networkUuid, variantNum,
REGULATING_EQUIPMENT_ID, elementIds, ResourceType.TWO_WINDINGS_TRANSFORMER);
Map<OwnerInfo, List<RegulatingEquipmentIdentifier>> regulatingEquipments = getRegulatingEquipmentsWithInClause(networkUuid, variantNum,
"regulatingterminalconnectableid", elementIds, ResourceType.TWO_WINDINGS_TRANSFORMER);
elements.forEach(element -> {
PhaseTapChangerAttributes phaseTapChangerAttributes = element.getAttributes().getPhaseTapChangerAttributes();
if (phaseTapChangerAttributes != null) {
phaseTapChangerAttributes.setRegulatingPoint(
twtTapChangerRegulatingPointAttributes.get(new RegulatingOwnerInfo(element.getId(), ResourceType.TWO_WINDINGS_TRANSFORMER,
RegulatingTapChangerType.PHASE_TAP_CHANGER, networkUuid, variantNum)));
}
RatioTapChangerAttributes ratioTapChangerAttributes = element.getAttributes().getRatioTapChangerAttributes();
if (ratioTapChangerAttributes != null) {
ratioTapChangerAttributes.setRegulatingPoint(
twtTapChangerRegulatingPointAttributes.get(new RegulatingOwnerInfo(element.getId(), ResourceType.TWO_WINDINGS_TRANSFORMER,
RegulatingTapChangerType.RATIO_TAP_CHANGER, networkUuid, variantNum)));
}
element.getAttributes().setRegulatingEquipments(regulatingEquipments.get(
new OwnerInfo(element.getId(), ResourceType.TWO_WINDINGS_TRANSFORMER, networkUuid, variantNum)));
});
}

// on all elements of the network
private void setTapChangerRegulatingPointAndRegulatingEquipments(List<Resource<TwoWindingsTransformerAttributes>> twoWindingTransformers, UUID networkUuid, int variantNum) {
// regulating points
Map<RegulatingOwnerInfo, RegulatingPointAttributes> twtRegulatingPointAttributes = getRegulatingPoints(networkUuid, variantNum, ResourceType.TWO_WINDINGS_TRANSFORMER);
Map<OwnerInfo, List<RegulatingEquipmentIdentifier>> regulatingEquipments = getRegulatingEquipments(networkUuid, variantNum, ResourceType.TWO_WINDINGS_TRANSFORMER);
twoWindingTransformers.forEach(element -> {
PhaseTapChangerAttributes phaseTapChangerAttributes = element.getAttributes().getPhaseTapChangerAttributes();
if (phaseTapChangerAttributes != null) {
phaseTapChangerAttributes.setRegulatingPoint(
twtRegulatingPointAttributes.get(new RegulatingOwnerInfo(element.getId(), ResourceType.TWO_WINDINGS_TRANSFORMER,
RegulatingTapChangerType.PHASE_TAP_CHANGER, networkUuid, variantNum)));
}
RatioTapChangerAttributes ratioTapChangerAttributes = element.getAttributes().getRatioTapChangerAttributes();
if (ratioTapChangerAttributes != null) {
ratioTapChangerAttributes.setRegulatingPoint(
twtRegulatingPointAttributes.get(new RegulatingOwnerInfo(element.getId(), ResourceType.TWO_WINDINGS_TRANSFORMER,
RegulatingTapChangerType.RATIO_TAP_CHANGER, networkUuid, variantNum)));
}
element.getAttributes().setRegulatingEquipments(regulatingEquipments.get(
new OwnerInfo(element.getId(), ResourceType.TWO_WINDINGS_TRANSFORMER, networkUuid, variantNum)));
});
}

// three windings transformers
private void setRegulatingPointForThreeWindingsTransformers(List<Resource<ThreeWindingsTransformerAttributes>> threeWindingTransformers, UUID networkUuid, int variantNum) {
Map<RegulatingOwnerInfo, RegulatingPointAttributes> twtRegulatingPointAttributes = getRegulatingPoints(networkUuid, variantNum, ResourceType.THREE_WINDINGS_TRANSFORMER);
threeWindingTransformers.forEach(element -> {
for (ThreeSides side : ThreeSides.values()) {
PhaseTapChangerAttributes phaseTapChangerAttributes = element.getAttributes().getLeg(side.getNum()).getPhaseTapChangerAttributes();
if (phaseTapChangerAttributes != null) {
phaseTapChangerAttributes.setRegulatingPoint(
twtRegulatingPointAttributes.get(new RegulatingOwnerInfo(element.getId(), ResourceType.THREE_WINDINGS_TRANSFORMER,
RegulatingTapChangerType.getThreeWindingType(side, RegulatingTapChangerType.PHASE_TAP_CHANGER), networkUuid, variantNum)));
}
RatioTapChangerAttributes ratioTapChangerAttributes = element.getAttributes().getLeg(side.getNum()).getRatioTapChangerAttributes();
if (ratioTapChangerAttributes != null) {
ratioTapChangerAttributes.setRegulatingPoint(
twtRegulatingPointAttributes.get(new RegulatingOwnerInfo(element.getId(), ResourceType.THREE_WINDINGS_TRANSFORMER,
RegulatingTapChangerType.getThreeWindingType(side, RegulatingTapChangerType.RATIO_TAP_CHANGER), networkUuid, variantNum))
);
}
}
});
}

private void setRegulatingPointForThreeWindingsTransformersWithIds(List<Resource<ThreeWindingsTransformerAttributes>> threeWindingTransformers, UUID networkUuid, int variantNum) {
List<String> elementIds = threeWindingTransformers.stream().map(Resource::getId).toList();
Map<RegulatingOwnerInfo, RegulatingPointAttributes> twtRegulatingPointAttributes = getRegulatingPointsWithInClause(networkUuid, variantNum,
REGULATING_EQUIPMENT_ID, elementIds, ResourceType.THREE_WINDINGS_TRANSFORMER);
threeWindingTransformers.forEach(element -> {
for (ThreeSides side : ThreeSides.values()) {
PhaseTapChangerAttributes phaseTapChangerAttributes = element.getAttributes().getLeg(side.getNum()).getPhaseTapChangerAttributes();
if (phaseTapChangerAttributes != null) {
phaseTapChangerAttributes.setRegulatingPoint(
twtRegulatingPointAttributes.get(new RegulatingOwnerInfo(element.getId(), ResourceType.THREE_WINDINGS_TRANSFORMER,
RegulatingTapChangerType.getThreeWindingType(side, RegulatingTapChangerType.PHASE_TAP_CHANGER), networkUuid, variantNum)));
}
RatioTapChangerAttributes ratioTapChangerAttributes = element.getAttributes().getLeg(side.getNum()).getRatioTapChangerAttributes();
if (ratioTapChangerAttributes != null) {
ratioTapChangerAttributes.setRegulatingPoint(
twtRegulatingPointAttributes.get(new RegulatingOwnerInfo(element.getId(), ResourceType.THREE_WINDINGS_TRANSFORMER,
RegulatingTapChangerType.getThreeWindingType(side, RegulatingTapChangerType.RATIO_TAP_CHANGER), networkUuid, variantNum))
);
}
}
});
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we share a bit the code or extract methods or I don't know but it would be nice to improve readability

Comment on lines 2543 to 2545
// the primary key is type + id + variant num + network uuid so there is no mean
// to distinct ratio tap changer of leg one and the one from leg 2
// so the side will be added in the id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this still a valid comment?


// three windings transformers
private void setRegulatingPointForThreeWindingsTransformers(List<Resource<ThreeWindingsTransformerAttributes>> threeWindingTransformers, UUID networkUuid, int variantNum) {
Map<RegulatingOwnerInfo, RegulatingPointAttributes> twtRegulatingPointAttributes = getRegulatingPoints(networkUuid, variantNum, ResourceType.THREE_WINDINGS_TRANSFORMER);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why no regulating equipments as 3wt?


private void setRegulatingPointForThreeWindingsTransformersWithIds(List<Resource<ThreeWindingsTransformerAttributes>> threeWindingTransformers, UUID networkUuid, int variantNum) {
List<String> elementIds = threeWindingTransformers.stream().map(Resource::getId).toList();
Map<RegulatingOwnerInfo, RegulatingPointAttributes> twtRegulatingPointAttributes = getRegulatingPointsWithInClause(networkUuid, variantNum,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why no regulating equipments as 3wt?

Copy link
Contributor

@antoinebhs antoinebhs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error at first start of network-store-server

grid-network-store-server-1  | Caused by: liquibase.exception.DatabaseException: ERROR: more than one row returned by a subquery used as an expression [Failed SQL: (0) UPDATE regulatingpoint r1
grid-network-store-server-1  | SET regulatedequipmenttype = (select CASE
grid-network-store-server-1  |                                                     WHEN bat.id IS NOT NULL THEN 'BATTERY'
grid-network-store-server-1  |                                                     WHEN bbs.id IS NOT NULL THEN 'BUSBAR_SECTION'
grid-network-store-server-1  |                                                     WHEN ld.id IS NOT NULL THEN 'LOAD'
grid-network-store-server-1  |                                                     WHEN gen.id IS NOT NULL THEN 'GENERATOR'
grid-network-store-server-1  |                                                     WHEN sc.id IS NOT NULL THEN 'SHUNT_COMPENSATOR'
grid-network-store-server-1  |                                                     WHEN vsc.id IS NOT NULL THEN 'VSC_CONVERTER_STATION'
grid-network-store-server-1  |                                                     WHEN lcc.id IS NOT NULL THEN 'LCC_CONVERTER_STATION'
grid-network-store-server-1  |                                                     WHEN svc.id IS NOT NULL THEN 'STATIC_VAR_COMPENSATOR'
grid-network-store-server-1  |                                                     WHEN twt.id IS NOT NULL THEN 'TWO_WINDINGS_TRANSFORMER'
grid-network-store-server-1  |                                                     WHEN ttwt.id IS NOT NULL THEN 'THREE_WINDINGS_TRANSFORMER'
grid-network-store-server-1  |                                                     WHEN l.id IS NOT NULL THEN 'LINE'
grid-network-store-server-1  |                                                     WHEN hvdc.id IS NOT NULL THEN 'HVDC_LINE'
grid-network-store-server-1  |                                                     WHEN dl.id IS NOT NULL THEN 'DANGLING_LINE'
grid-network-store-server-1  |                                                     END
grid-network-store-server-1  |                                          FROM  regulatingpoint r  LEFT JOIN battery bat ON r.regulatingterminalconnectableid = bat.id and r.networkuuid = bat.networkuuid and r.variantnum = bat.variantnum
grid-network-store-server-1  |                                                                   LEFT JOIN busbarsection bbs ON r.regulatingterminalconnectableid = bbs.id and r.networkuuid = bbs.networkuuid and r.variantnum = bbs.variantnum
grid-network-store-server-1  |                                                                   LEFT JOIN load ld ON r.regulatingterminalconnectableid = ld.id and r.networkuuid = ld.networkuuid and r.variantnum = ld.variantnum
grid-network-store-server-1  |                                                                   LEFT JOIN generator gen ON r.regulatingterminalconnectableid = gen.id and r.networkuuid = gen.networkuuid and r.variantnum = gen.variantnum
grid-network-store-server-1  |                                                                   LEFT JOIN shuntcompensator sc ON r.regulatingterminalconnectableid = sc.id and r.networkuuid = sc.networkuuid and r.variantnum = sc.variantnum
grid-network-store-server-1  |                                                                   LEFT JOIN vscconverterstation vsc ON r.regulatingterminalconnectableid = vsc.id and r.networkuuid = vsc.networkuuid and r.variantnum = vsc.variantnum
grid-network-store-server-1  |                                                                   LEFT JOIN lccconverterstation lcc ON r.regulatingterminalconnectableid = lcc.id and r.networkuuid = lcc.networkuuid and r.variantnum = lcc.variantnum
grid-network-store-server-1  |                                                                   LEFT JOIN staticvarcompensator svc ON r.regulatingterminalconnectableid = svc.id and r.networkuuid = svc.networkuuid and r.variantnum = svc.variantnum
grid-network-store-server-1  |                                                                   LEFT JOIN twowindingstransformer twt ON r.regulatingterminalconnectableid = twt.id and r.networkuuid = twt.networkuuid and r.variantnum = twt.variantnum
grid-network-store-server-1  |                                                                   LEFT JOIN threewindingstransformer ttwt ON r.regulatingterminalconnectableid = ttwt.id and r.networkuuid = ttwt.networkuuid and r.variantnum = ttwt.variantnum
grid-network-store-server-1  |                                                                   LEFT JOIN line l ON r.regulatingterminalconnectableid = l.id and r.networkuuid = l.networkuuid and r.variantnum = l.variantnum
grid-network-store-server-1  |                                                                   LEFT JOIN hvdcline hvdc ON r.regulatingterminalconnectableid = hvdc.id and r.networkuuid = hvdc.networkuuid and r.variantnum = hvdc.variantnum
grid-network-store-server-1  |                                                                   LEFT JOIN danglingline dl ON r.regulatingterminalconnectableid = dl.id and r.networkuuid = dl.networkuuid and r.variantnum = dl.variantnum
grid-network-store-server-1  |                                          WHERE r1.networkuuid = r.networkuuid and  r1.variantnum = r.variantnum
grid-network-store-server-1  |                                            and r1.regulatingequipmentid = r.regulatingequipmentid and r1.regulatingequipmenttype = r.regulatingequipmenttype)
grid-network-store-server-1  | WHERE regulatedequipmenttype is null AND r1.regulatingequipmentid <> r1.regulatingterminalconnectableid]

on my network with 1 stanway study + 2 studies with 3wt

Signed-off-by: Etienne LESOT <etienne.lesot@rte-france.com>
Signed-off-by: Etienne LESOT <etienne.lesot@rte-france.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants