Skip to content

Commit

Permalink
Fix busbar section get p and get q (#372)
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
  • Loading branch information
geofjamg authored Dec 21, 2023
1 parent 8cbaada commit 5de2220
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void setConnectableBus(String bus) {

@Override
public double getP() {
throw new AssertionError();
return 0;
}

@Override
Expand All @@ -114,7 +114,7 @@ public void setP(double p) {

@Override
public double getQ() {
throw new AssertionError();
return 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public double getP() {
@Override
public Terminal setP(double p) {
if (connectable.getType() == IdentifiableType.BUSBAR_SECTION) {
throw new ValidationException(this, "cannot set active power on a busbar section");
throw new ValidationException(this, " cannot set active power on a busbar section");
}
getAbstractIdentifiable().updateResource(r -> getAttributes().setP(p), AttributeFilter.SV);
return this;
Expand All @@ -126,7 +126,7 @@ public double getQ() {
@Override
public Terminal setQ(double q) {
if (connectable.getType() == IdentifiableType.BUSBAR_SECTION) {
throw new ValidationException(this, "cannot set reactive power on a busbar section");
throw new ValidationException(this, " cannot set reactive power on a busbar section");
}
getAbstractIdentifiable().updateResource(r -> getAttributes().setQ(q), AttributeFilter.SV);
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2023, 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/.
*/
package com.powsybl.network.store.iidm.impl;

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.BusbarSection;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.Terminal;
import com.powsybl.iidm.network.test.FourSubstationsNodeBreakerFactory;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
class BusbarSectionGetPqTest {

@Test
void test() {
Network network = FourSubstationsNodeBreakerFactory.create();
BusbarSection bbs = network.getBusbarSection("S1VL1_BBS");
Terminal terminal = bbs.getTerminal();
assertEquals(0, terminal.getP());
assertEquals(0, terminal.getQ());
PowsyblException e = assertThrows(PowsyblException.class, () -> terminal.setP(1));
assertEquals("Terminal of connectable : S1VL1_BBS cannot set active power on a busbar section", e.getMessage());
e = assertThrows(PowsyblException.class, () -> terminal.setQ(1));
assertEquals("Terminal of connectable : S1VL1_BBS cannot set reactive power on a busbar section", e.getMessage());
}
}

0 comments on commit 5de2220

Please sign in to comment.