Skip to content

Commit

Permalink
Merge branch 'main' into breadth_first_topology_traverser
Browse files Browse the repository at this point in the history
  • Loading branch information
jonenst authored Aug 30, 2023
2 parents 50a8916 + 9bcf231 commit 8af07fb
Show file tree
Hide file tree
Showing 25 changed files with 198 additions and 118 deletions.
2 changes: 0 additions & 2 deletions lombok.config

This file was deleted.

2 changes: 1 addition & 1 deletion network-store-client-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-client-parent</artifactId>
<version>1.3.0-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
</parent>

<artifactId>powsybl-network-store-client-distribution</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion network-store-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-client-parent</artifactId>
<version>1.3.0-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
</parent>

<artifactId>powsybl-network-store-client</artifactId>
Expand Down
Empty file.
1 change: 1 addition & 0 deletions network-store-iidm-impl/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import target/configs/powsybl-build-tools.jar!powsybl-build-tools/lombok.config
16 changes: 8 additions & 8 deletions network-store-iidm-impl/pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2020, RTE (http://www.rte-france.com)
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -14,13 +12,20 @@
<parent>
<artifactId>powsybl-network-store-client-parent</artifactId>
<groupId>com.powsybl</groupId>
<version>1.3.0-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
</parent>

<artifactId>powsybl-network-store-iidm-impl</artifactId>
<name>Network store IIDM impl</name>

<dependencies>
<!-- Annotation processors dependencies -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

<!-- compile scope -->
<dependency>
<groupId>com.powsybl</groupId>
Expand Down Expand Up @@ -70,11 +75,6 @@
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.powsybl</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import com.powsybl.commons.extensions.AbstractExtension;
import com.powsybl.iidm.network.BusbarSection;
import com.powsybl.iidm.network.Validable;
import com.powsybl.iidm.network.ValidationException;
import com.powsybl.iidm.network.extensions.BusbarSectionPosition;
import com.powsybl.network.store.model.BusbarSectionAttributes;
import com.powsybl.network.store.model.BusbarSectionPositionAttributes;
Expand All @@ -20,13 +22,13 @@ public class BusbarSectionPositionImpl extends AbstractExtension<BusbarSection>

public BusbarSectionPositionImpl(BusbarSectionImpl busbarSectionImpl) {
super(busbarSectionImpl);
checkIndex(getBusbarIndex());
checkIndex(getSectionIndex());
checkIndex(busbarSectionImpl, getBusbarIndex(), "Busbar");
checkIndex(busbarSectionImpl, getSectionIndex(), "Section");
}

private static int checkIndex(int index) {
private static int checkIndex(Validable validable, int index, String equipmentTypeLabel) {
if (index < 0) {
throw new IllegalArgumentException("Busbar index has to be greater or equals to zero");
throw new ValidationException(validable, equipmentTypeLabel + " index has to be greater or equals to zero");
}
return index;
}
Expand All @@ -50,7 +52,7 @@ private BusbarSectionPositionAttributes getPositionAttributes(Resource<BusbarSec

@Override
public BusbarSectionPosition setBusbarIndex(int busbarIndex) {
getBusbarSection().updateResource(res -> getPositionAttributes(res).setBusbarIndex(checkIndex(busbarIndex)));
getBusbarSection().updateResource(res -> getPositionAttributes(res).setBusbarIndex(checkIndex(getBusbarSection(), busbarIndex, "Busbar")));
return this;
}

Expand All @@ -61,7 +63,7 @@ public int getSectionIndex() {

@Override
public BusbarSectionPosition setSectionIndex(int sectionIndex) {
getBusbarSection().updateResource(res -> getPositionAttributes(res).setSectionIndex(checkIndex(sectionIndex)));
getBusbarSection().updateResource(res -> getPositionAttributes(res).setSectionIndex(checkIndex(getBusbarSection(), sectionIndex, "Section")));
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ public PhaseTapChanger add() {
if (tapChangerParentAttributes.getRatioTapChangerAttributes() != null) {
LOGGER.warn("{} has both Ratio and Phase Tap Changer", tapChangerParentAttributes);
}
tapChangerParentAttributes.setPhaseTapChangerAttributes(phaseTapChangerAttributes);

tapChangerParent.setPhaseTapChanger(phaseTapChangerAttributes);

return new PhaseTapChangerImpl(tapChangerParent, index, attributesGetter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ public PhaseTapChangerStep getCurrentStep() {

@Override
public void remove() {
//TODO
throw new UnsupportedOperationException("TODO");
parent.setPhaseTapChanger(null);
}

protected String getTapChangerAttribute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ public RatioTapChanger add() {
if (tapChangerParentAttributes.getPhaseTapChangerAttributes() != null) {
LOGGER.warn("{} has both Ratio and Phase Tap Changer", tapChangerParentAttributes);
}
tapChangerParentAttributes.setRatioTapChangerAttributes(ratioTapChangerAttributes);

tapChangerParent.setRatioTapChanger(ratioTapChangerAttributes);

return new RatioTapChangerImpl(tapChangerParent, index, attributesGetter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ public RatioTapChangerStep getCurrentStep() {

@Override
public void remove() {
//TODO
throw new UnsupportedOperationException("TODO");
parent.setRatioTapChanger(null);
}

protected String getTapChangerAttribute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.powsybl.iidm.network.RatioTapChanger;
import com.powsybl.iidm.network.TapChanger;
import com.powsybl.iidm.network.Validable;
import com.powsybl.network.store.model.PhaseTapChangerAttributes;
import com.powsybl.network.store.model.RatioTapChangerAttributes;

import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -41,4 +43,8 @@ public interface TapChangerParent extends Validable {
PhaseTapChanger getPhaseTapChanger();

RatioTapChanger getRatioTapChanger();

void setPhaseTapChanger(PhaseTapChangerAttributes attributes);

void setRatioTapChanger(RatioTapChangerAttributes attributes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,20 @@ public RatioTapChangerAdder newRatioTapChanger() {
return new RatioTapChangerAdderImpl(this, index, attributes -> legGetter.apply((ThreeWindingsTransformerAttributes) attributes));
}

@Override
public void setPhaseTapChanger(PhaseTapChangerAttributes attributes) {
PhaseTapChangerAttributes oldValue = getLegAttributes().getPhaseTapChangerAttributes();
transformer.updateResource(res -> legGetter.apply(res.getAttributes()).setPhaseTapChangerAttributes(attributes));
index.notifyUpdate(transformer, "phaseTapChanger", oldValue, attributes);
}

@Override
public void setRatioTapChanger(RatioTapChangerAttributes attributes) {
RatioTapChangerAttributes oldValue = getLegAttributes().getRatioTapChangerAttributes();
transformer.updateResource(res -> legGetter.apply(res.getAttributes()).setRatioTapChangerAttributes(attributes));
index.notifyUpdate(transformer, "ratioTapChanger", oldValue, attributes);
}

@Override
public PhaseTapChanger getPhaseTapChanger() {
return getLegAttributes().getPhaseTapChangerAttributes() != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.powsybl.iidm.network.extensions.TwoWindingsTransformerPhaseAngleClock;
import com.powsybl.network.store.iidm.impl.extensions.CgmesTapChangersImpl;
import com.powsybl.network.store.iidm.impl.extensions.TwoWindingsTransformerPhaseAngleClockImpl;
import com.powsybl.network.store.model.PhaseTapChangerAttributes;
import com.powsybl.network.store.model.RatioTapChangerAttributes;
import com.powsybl.network.store.model.Resource;
import com.powsybl.network.store.model.TapChangerParentAttributes;
import com.powsybl.network.store.model.TwoWindingsTransformerAttributes;
Expand Down Expand Up @@ -62,6 +64,20 @@ public PhaseTapChangerAdder newPhaseTapChanger() {
return new PhaseTapChangerAdderImpl(this, index, TapChangerParentAttributes.class::cast);
}

@Override
public void setPhaseTapChanger(PhaseTapChangerAttributes attributes) {
PhaseTapChangerAttributes oldValue = getResource().getAttributes().getPhaseTapChangerAttributes();
updateResource(res -> res.getAttributes().setPhaseTapChangerAttributes(attributes));
index.notifyUpdate(this, "phaseTapChanger", oldValue, attributes);
}

@Override
public void setRatioTapChanger(RatioTapChangerAttributes attributes) {
RatioTapChangerAttributes oldValue = getResource().getAttributes().getRatioTapChangerAttributes();
updateResource(res -> res.getAttributes().setRatioTapChangerAttributes(attributes));
index.notifyUpdate(this, "ratioTapChanger", oldValue, attributes);
}

@Override
public RatioTapChanger getRatioTapChanger() {
var resource = getResource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public StandbyAutomatonAdderImpl(StaticVarCompensator svc) {

@Override
protected StandbyAutomaton createExtension(StaticVarCompensator svc) {
var attributes = StandbyAutomatonImpl.createAttributes(b0, standby,
var attributes = StandbyAutomatonImpl.createAttributes((StaticVarCompensatorImpl) svc, b0, standby,
lowVoltageSetpoint, highVoltageSetpoint, lowVoltageThreshold, highVoltageThreshold);
((StaticVarCompensatorImpl) svc).updateResource(res -> res.getAttributes().setStandbyAutomaton(attributes));
return new StandbyAutomatonImpl(svc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import com.powsybl.commons.extensions.AbstractExtension;
import com.powsybl.iidm.network.StaticVarCompensator;
import com.powsybl.iidm.network.Validable;
import com.powsybl.iidm.network.ValidationException;
import com.powsybl.iidm.network.extensions.StandbyAutomaton;
import com.powsybl.network.store.iidm.impl.StaticVarCompensatorImpl;
import com.powsybl.network.store.model.Resource;
Expand All @@ -23,29 +25,29 @@ public class StandbyAutomatonImpl extends AbstractExtension<StaticVarCompensator

private static final Logger LOGGER = LoggerFactory.getLogger(StandbyAutomatonImpl.class);

private static double checkB0(double b0) {
private static double checkB0(Validable validable, double b0) {
if (Double.isNaN(b0)) {
throw new IllegalArgumentException("b0 is invalid");
throw new ValidationException(validable, "b0 is invalid");
}
return b0;
}

private static void checkVoltageConfig(double lowVoltageSetpoint, double highVoltageSetpoint,
private static void checkVoltageConfig(Validable validable, double lowVoltageSetpoint, double highVoltageSetpoint,
double lowVoltageThreshold, double highVoltageThreshold) {
if (Double.isNaN(lowVoltageSetpoint)) {
throw new IllegalArgumentException("lowVoltageSetpoint is invalid");
throw new ValidationException(validable, "lowVoltageSetpoint is invalid");
}
if (Double.isNaN(highVoltageSetpoint)) {
throw new IllegalArgumentException("highVoltageSetpoint is invalid");
throw new ValidationException(validable, "highVoltageSetpoint is invalid");
}
if (Double.isNaN(lowVoltageThreshold)) {
throw new IllegalArgumentException("lowVoltageThreshold is invalid");
throw new ValidationException(validable, "lowVoltageThreshold is invalid");
}
if (Double.isNaN(highVoltageThreshold)) {
throw new IllegalArgumentException("highVoltageThreshold is invalid");
throw new ValidationException(validable, "highVoltageThreshold is invalid");
}
if (lowVoltageThreshold >= highVoltageThreshold) {
throw new IllegalArgumentException("Inconsistent low (" + lowVoltageThreshold + ") and high (" + highVoltageThreshold + ") voltage thresholds");
throw new ValidationException(validable, "Inconsistent low (" + lowVoltageThreshold + ") and high (" + highVoltageThreshold + ") voltage thresholds");
}
if (lowVoltageSetpoint < lowVoltageThreshold) {
LOGGER.warn("Invalid low voltage setpoint {} < threshold {}", lowVoltageSetpoint, lowVoltageThreshold);
Expand All @@ -55,19 +57,10 @@ private static void checkVoltageConfig(double lowVoltageSetpoint, double highVol
}
}

public static StandbyAutomatonAttributes createAttributes(StandbyAutomaton standbyAutomaton) {
return createAttributes(standbyAutomaton.getB0(),
standbyAutomaton.isStandby(),
standbyAutomaton.getLowVoltageSetpoint(),
standbyAutomaton.getHighVoltageSetpoint(),
standbyAutomaton.getLowVoltageThreshold(),
standbyAutomaton.getHighVoltageThreshold());
}

public static StandbyAutomatonAttributes createAttributes(double b0, boolean standby, double lowVoltageSetpoint, double highVoltageSetpoint,
public static StandbyAutomatonAttributes createAttributes(Validable validable, double b0, boolean standby, double lowVoltageSetpoint, double highVoltageSetpoint,
double lowVoltageThreshold, double highVoltageThreshold) {
checkVoltageConfig(lowVoltageSetpoint, highVoltageSetpoint, lowVoltageThreshold, highVoltageThreshold);
checkB0(b0);
checkVoltageConfig(validable, lowVoltageSetpoint, highVoltageSetpoint, lowVoltageThreshold, highVoltageThreshold);
checkB0(validable, b0);
return StandbyAutomatonAttributes.builder()
.b0(b0)
.standby(standby)
Expand Down Expand Up @@ -112,7 +105,7 @@ public double getB0() {

@Override
public StandbyAutomatonImpl setB0(double b0) {
getSvc().updateResource(res -> getAttributes(res).setB0(checkB0(b0)));
getSvc().updateResource(res -> getAttributes(res).setB0(checkB0(getSvc(), b0)));
return this;
}

Expand All @@ -123,7 +116,7 @@ public double getHighVoltageSetpoint() {

@Override
public StandbyAutomatonImpl setHighVoltageSetpoint(double highVoltageSetpoint) {
checkVoltageConfig(getLowVoltageSetpoint(), highVoltageSetpoint, getLowVoltageThreshold(), getHighVoltageThreshold());
checkVoltageConfig(getSvc(), getLowVoltageSetpoint(), highVoltageSetpoint, getLowVoltageThreshold(), getHighVoltageThreshold());
getSvc().updateResource(res -> getAttributes(res).setHighVoltageSetpoint(highVoltageSetpoint));
return this;
}
Expand All @@ -135,7 +128,7 @@ public double getHighVoltageThreshold() {

@Override
public StandbyAutomatonImpl setHighVoltageThreshold(double highVoltageThreshold) {
checkVoltageConfig(getLowVoltageSetpoint(), getHighVoltageSetpoint(), getLowVoltageThreshold(), highVoltageThreshold);
checkVoltageConfig(getSvc(), getLowVoltageSetpoint(), getHighVoltageSetpoint(), getLowVoltageThreshold(), highVoltageThreshold);
getSvc().updateResource(res -> getAttributes(res).setHighVoltageThreshold(highVoltageThreshold));
return this;
}
Expand All @@ -147,7 +140,7 @@ public double getLowVoltageSetpoint() {

@Override
public StandbyAutomatonImpl setLowVoltageSetpoint(double lowVoltageSetpoint) {
checkVoltageConfig(lowVoltageSetpoint, getHighVoltageSetpoint(), getLowVoltageThreshold(), getHighVoltageThreshold());
checkVoltageConfig(getSvc(), lowVoltageSetpoint, getHighVoltageSetpoint(), getLowVoltageThreshold(), getHighVoltageThreshold());
getSvc().updateResource(res -> getAttributes(res).setLowVoltageSetpoint(lowVoltageSetpoint));
return this;
}
Expand All @@ -159,7 +152,7 @@ public double getLowVoltageThreshold() {

@Override
public StandbyAutomatonImpl setLowVoltageThreshold(double lowVoltageThreshold) {
checkVoltageConfig(getLowVoltageSetpoint(), getHighVoltageSetpoint(), lowVoltageThreshold, getHighVoltageThreshold());
checkVoltageConfig(getSvc(), getLowVoltageSetpoint(), getHighVoltageSetpoint(), lowVoltageThreshold, getHighVoltageThreshold());
getSvc().updateResource(res -> getAttributes(res).setLowVoltageThreshold(lowVoltageThreshold));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package com.powsybl.network.store.iidm.impl;

import com.powsybl.iidm.network.*;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.junit.Test;

import java.util.Arrays;
Expand All @@ -20,17 +19,6 @@
* @author Slimane Amar <slimane.amar at rte-france.com>
*/
public class BusBreakerCalculatedBusTest {

@Test
public void equalsContract() {
NetworkObjectIndex index1 = new NetworkObjectIndex(new CachedNetworkStoreClient(new OfflineNetworkStoreClient()));
NetworkObjectIndex index2 = new NetworkObjectIndex(new CachedNetworkStoreClient(new OfflineNetworkStoreClient()));
EqualsVerifier.simple().forClass(CalculatedBus.class).withIgnoredFields("connectedComponent", "synchronousComponent")
.withPrefabValues(NetworkObjectIndex.class, index1, index2)
.withPrefabValues(ComponentImpl.class, new ComponentImpl(null, null), new ComponentImpl(null, null))
.verify();
}

@Test
public void testCalculatedBusesWithMultiBuses() {
Network network = CreateNetworksUtil.createBusBreakerNetworkWithMultiBuses();
Expand Down
Loading

0 comments on commit 8af07fb

Please sign in to comment.