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 sections management to shunt compensators creation #355

Merged
merged 7 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package org.gridsuite.modification.server.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.ReporterModel;
Expand Down Expand Up @@ -35,14 +34,16 @@
@ModificationErrorTypeName("CREATE_SHUNT_COMPENSATOR_ERROR")
public class ShuntCompensatorCreationInfos extends InjectionCreationInfos {
@Schema(description = "Maximum number of sections")
private Integer maximumNumberOfSections;
private Integer maximumSectionCount;

@Schema(description = "Susceptance per section")
private Double susceptancePerSection;
@Schema(description = "Section count")
private Integer sectionCount;

@JsonProperty("qAtNominalV")
@Schema(description = "Q at Nominal Voltage")
private Double qAtNominalV;
@Schema(description = "Maximal susceptance available")
private Double maxSusceptance;

@Schema(description = "Qmax available at nominal voltage")
private Double maxQAtNominalV;

@Schema(description = "Shunt Compensator Type")
private ShuntCompensatorType shuntCompensatorType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,37 @@
@PrimaryKeyJoinColumn(foreignKey = @ForeignKey(name = "shuntCompensatorCreation_id_fk_constraint"))
public class ShuntCompensatorCreationEntity extends InjectionCreationEntity {
@Column
private int maximumNumberOfSections;
private int maximumSectionCount;

@Column
private Double susceptancePerSection;
private int sectionCount;

@Column
private Double qAtNominalV;
private Double maxSusceptance;

@Column
private Double maxQAtNominalV;

@Column
private ShuntCompensatorType shuntCompensatorType;

public ShuntCompensatorCreationEntity(ShuntCompensatorCreationInfos creationInfos) {
super(creationInfos);
maximumNumberOfSections = creationInfos.getMaximumNumberOfSections() != null ? creationInfos.getMaximumNumberOfSections() : 1;
susceptancePerSection = creationInfos.getSusceptancePerSection();
qAtNominalV = creationInfos.getQAtNominalV();
maximumSectionCount = creationInfos.getMaximumSectionCount();
sectionCount = creationInfos.getSectionCount();
maxSusceptance = creationInfos.getMaxSusceptance();
maxQAtNominalV = creationInfos.getMaxQAtNominalV();
shuntCompensatorType = creationInfos.getShuntCompensatorType();
}

@Override
public void update(ModificationInfos modificationInfos) {
super.update(modificationInfos);
ShuntCompensatorCreationInfos shuntCompensatorCreationInfos = (ShuntCompensatorCreationInfos) modificationInfos;
maximumNumberOfSections = shuntCompensatorCreationInfos.getMaximumNumberOfSections() != null ? shuntCompensatorCreationInfos.getMaximumNumberOfSections() : 1;
susceptancePerSection = shuntCompensatorCreationInfos.getSusceptancePerSection();
qAtNominalV = shuntCompensatorCreationInfos.getQAtNominalV();
maximumSectionCount = shuntCompensatorCreationInfos.getMaximumSectionCount();
sectionCount = shuntCompensatorCreationInfos.getSectionCount();
maxSusceptance = shuntCompensatorCreationInfos.getMaxSusceptance();
maxQAtNominalV = shuntCompensatorCreationInfos.getMaxQAtNominalV();
shuntCompensatorType = shuntCompensatorCreationInfos.getShuntCompensatorType();
}

Expand All @@ -68,9 +73,10 @@ public ShuntCompensatorCreationInfos toModificationInfos() {
.equipmentName(getEquipmentName())
.voltageLevelId(getVoltageLevelId())
.busOrBusbarSectionId(getBusOrBusbarSectionId())
.maximumNumberOfSections(getMaximumNumberOfSections())
.susceptancePerSection(getSusceptancePerSection())
.qAtNominalV(getQAtNominalV())
.maximumSectionCount(getMaximumSectionCount())
.sectionCount(getSectionCount())
.maxSusceptance(getMaxSusceptance())
.maxQAtNominalV(getMaxQAtNominalV())
.shuntCompensatorType(getShuntCompensatorType())
.connectionName(getConnectionName())
.connectionDirection(getConnectionDirection())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.powsybl.iidm.modification.topology.CreateFeederBay;
import com.powsybl.iidm.modification.topology.CreateFeederBayBuilder;
import com.powsybl.iidm.network.*;
import org.apache.commons.lang3.ObjectUtils;
import org.gridsuite.modification.server.NetworkModificationException;
import org.gridsuite.modification.server.dto.ShuntCompensatorCreationInfos;
import org.gridsuite.modification.server.dto.ShuntCompensatorType;
Expand Down Expand Up @@ -43,12 +42,12 @@ public void check(Network network) throws NetworkModificationException {
public void apply(Network network, Reporter subReporter) {
// create the shunt compensator in the network
VoltageLevel voltageLevel = ModificationUtils.getInstance().getVoltageLevel(network, modificationInfos.getVoltageLevelId());
if (modificationInfos.getSusceptancePerSection() == null) {
Double susceptancePerSection = modificationInfos.getQAtNominalV() / Math.pow(voltageLevel.getNominalV(), 2);
modificationInfos.setSusceptancePerSection(
if (modificationInfos.getMaxSusceptance() == null) {
Double maxSusceptance = (modificationInfos.getMaxQAtNominalV()) / Math.pow(voltageLevel.getNominalV(), 2);
modificationInfos.setMaxSusceptance(
modificationInfos.getShuntCompensatorType() == ShuntCompensatorType.CAPACITOR
? susceptancePerSection
: -susceptancePerSection);
? maxSusceptance
: -maxSusceptance);
}
if (voltageLevel.getTopologyKind() == TopologyKind.NODE_BREAKER) {
ShuntCompensatorAdder shuntCompensatorAdder = createShuntAdderInNodeBreaker(voltageLevel, modificationInfos);
Expand Down Expand Up @@ -78,39 +77,29 @@ private ShuntCompensatorAdder createShuntAdderInNodeBreaker(VoltageLevel voltage
ShuntCompensatorAdder shuntAdder = voltageLevel.newShuntCompensator()
.setId(shuntCompensatorInfos.getEquipmentId())
.setName(shuntCompensatorInfos.getEquipmentName())
.setSectionCount(determinateSectionCountModification(shuntCompensatorInfos));
.setSectionCount(shuntCompensatorInfos.getSectionCount());

/* when we create non-linear shunt, this is where we branch ;) */
shuntAdder.newLinearModel()
.setBPerSection(shuntCompensatorInfos.getSusceptancePerSection())
.setMaximumSectionCount(ObjectUtils.defaultIfNull(shuntCompensatorInfos.getMaximumNumberOfSections(), 1))
.setBPerSection(shuntCompensatorInfos.getMaxSusceptance() / shuntCompensatorInfos.getMaximumSectionCount())
.setMaximumSectionCount(shuntCompensatorInfos.getMaximumSectionCount())
.add();

return shuntAdder;
}

private int determinateSectionCountModification(ShuntCompensatorCreationInfos shuntCompensatorInfos) {
if (shuntCompensatorInfos.getSusceptancePerSection() != null) {
return modificationInfos.getSusceptancePerSection() == 0 ? 0 : 1;
}
if (shuntCompensatorInfos.getQAtNominalV() != null) {
return modificationInfos.getQAtNominalV() == 0 ? 0 : 1;
}
return 0;
}

private void createShuntInBusBreaker(VoltageLevel voltageLevel, ShuntCompensatorCreationInfos shuntCompensatorInfos) {
Bus bus = ModificationUtils.getInstance().getBusBreakerBus(voltageLevel, shuntCompensatorInfos.getBusOrBusbarSectionId());
/* creating the shunt compensator */
voltageLevel.newShuntCompensator()
.setId(shuntCompensatorInfos.getEquipmentId())
.setName(shuntCompensatorInfos.getEquipmentName())
.setSectionCount(determinateSectionCountModification(shuntCompensatorInfos))
.setSectionCount(shuntCompensatorInfos.getSectionCount())
.setBus(bus.getId())
.setConnectableBus(bus.getId())
.newLinearModel()
.setBPerSection(shuntCompensatorInfos.getSusceptancePerSection())
.setMaximumSectionCount(ObjectUtils.defaultIfNull(shuntCompensatorInfos.getMaximumNumberOfSections(), 1))
.setBPerSection(shuntCompensatorInfos.getMaxSusceptance() / shuntCompensatorInfos.getMaximumSectionCount())
.setMaximumSectionCount(shuntCompensatorInfos.getMaximumSectionCount())
.add()
.add();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="marcelinhug (generated)" id="1697725848755-29">
<renameColumn tableName="shunt_compensator_creation_entity"
columnDataType="float(53)"
oldColumnName="q_at_nominalv"
newColumnName="maxqat_nominalv" />
</changeSet>
<changeSet author="marcelinhug (generated)" id="1697725848755-27">
<renameColumn tableName="shunt_compensator_creation_entity"
columnDataType="float(53)"
oldColumnName="susceptance_per_section"
newColumnName="max_susceptance" />
</changeSet>
<changeSet author="marcelinhug (generated)" id="1697725848755-28">
<renameColumn tableName="shunt_compensator_creation_entity"
columnDataType="integer"
oldColumnName="maximum_number_of_sections"
newColumnName="maximum_section_count" />
</changeSet>
<changeSet author="marcelinhug (generated)" id="1697725848755-30">
<addColumn tableName="shunt_compensator_creation_entity">
<column name="section_count" type="integer"/>
</addColumn>
</changeSet>
<changeSet author="marcelinhug" id="migrate_section_count_1">
<update tableName="shunt_compensator_creation_entity">
<column name="section_count" valueNumeric="0"/>
<where>max_susceptance=0 or maxqat_nominalv=0</where>
</update>
</changeSet>
<changeSet author="marcelinhug" id="migrate_section_count_0">
<update tableName="shunt_compensator_creation_entity">
<column name="section_count" valueNumeric="1"/>
<where>max_susceptance!=0 or maxqat_nominalv!=0</where>
</update>
</changeSet>
</databaseChangeLog>
3 changes: 3 additions & 0 deletions src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,6 @@ databaseChangeLog:
- include:
file: changesets/changelog_20231011T120303Z.xml
relativeToChangelogFile: true
- include:
file: changesets/changelog_20231019T143032Z.xml
relativeToChangelogFile: true
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ protected ModificationInfos buildModification() {
.date(ZonedDateTime.now().truncatedTo(ChronoUnit.MICROS))
.equipmentId("shuntOneId")
.equipmentName("hopOne")
.maximumNumberOfSections(1)
.susceptancePerSection(0.)
.maximumSectionCount(10)
.sectionCount(6)
.maxSusceptance(0.)
.voltageLevelId("v2")
.busOrBusbarSectionId("bus2")
.connectionName("cn2")
Expand All @@ -68,8 +69,9 @@ protected ModificationInfos buildModificationUpdate() {
.date(ZonedDateTime.now().truncatedTo(ChronoUnit.MICROS))
.equipmentId("shuntOneIdEdited")
.equipmentName("hopEdited")
.maximumNumberOfSections(1)
.susceptancePerSection(1.)
.maximumSectionCount(20)
.sectionCount(3)
.maxSusceptance(1.)
.voltageLevelId("v4")
.busOrBusbarSectionId("bus3")
.connectionName("cnEdited")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ protected ModificationInfos buildModification() {
.date(ZonedDateTime.now().truncatedTo(ChronoUnit.MICROS))
.equipmentId("shuntOneId")
.equipmentName("hop")
.maximumNumberOfSections(1)
.susceptancePerSection(0.)
.maximumSectionCount(10)
.sectionCount(6)
.maxSusceptance(0.)
.voltageLevelId("v2")
.busOrBusbarSectionId("1B")
.connectionName("cn")
Expand All @@ -61,8 +62,9 @@ protected ModificationInfos buildModificationUpdate() {
.date(ZonedDateTime.now().truncatedTo(ChronoUnit.MICROS))
.equipmentId("shuntOneIdEdited")
.equipmentName("hopEdited")
.maximumNumberOfSections(1)
.susceptancePerSection(0.)
.maximumSectionCount(20)
.sectionCount(3)
.maxSusceptance(0.)
.voltageLevelId("v4")
.busOrBusbarSectionId("1.A")
.connectionName("cnEdited")
Expand Down Expand Up @@ -107,8 +109,8 @@ public void testCreateWithExistingConnectionPosition() throws Exception {
@Test
public void testCreateWithQAtNominalV() throws Exception {
ShuntCompensatorCreationInfos dto = (ShuntCompensatorCreationInfos) buildModification();
dto.setSusceptancePerSection(null);
dto.setQAtNominalV(80.0);
dto.setMaxSusceptance(null);
dto.setMaxQAtNominalV(80.0);
//CAPACITOR test
dto.setShuntCompensatorType(ShuntCompensatorType.CAPACITOR);
String modificationToCreateJson = mapper.writeValueAsString(dto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,9 @@ public void runBuildTest() throws Exception {
.equipmentName("shunt9")
.voltageLevelId("v2")
.busOrBusbarSectionId("1A")
.maximumNumberOfSections(2)
.susceptancePerSection(1.)
.maximumSectionCount(2)
.sectionCount(1)
.maxSusceptance(1.)
.connectionDirection(ConnectablePosition.Direction.UNDEFINED)
.connectionName("shunt9")
.build().toEntity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,16 @@ public void testGeneratorCreation() {
public void testShuntCompensatorCreation() {
var shunt1 = ShuntCompensatorCreationInfos.builder()
.equipmentId("shunt1").equipmentName("nameOne")
.maximumNumberOfSections(2)
.susceptancePerSection(1.)
.maximumSectionCount(2)
.sectionCount(1)
.maxSusceptance(1.)
.voltageLevelId("vlId1").busOrBusbarSectionId("busId1")
.build();
var shunt2 = ShuntCompensatorCreationInfos.builder()
.equipmentId("shunt2").equipmentName("notNameOne")
.maximumNumberOfSections(2)
.susceptancePerSection(1.)
.maximumSectionCount(2)
.sectionCount(0)
.maxSusceptance(1.)
.voltageLevelId("vlId1").busOrBusbarSectionId("busId1")
.build();

Expand Down
Loading